mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
FIX: possible resource leaking in testcases (all created transactions are closed by followed try statement) (#1273)
This commit is contained in:
committed by
Rob Bygrave
parent
8e9843ab8a
commit
e3425a8850
+32
-31
@@ -16,50 +16,51 @@ public class TestL2DirtyFlagOnLazyLoad extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void dirtyFlag_reset_after_lazy() {
|
||||
|
||||
//PREPARE
|
||||
Transaction tx0 = Ebean.beginTransaction();
|
||||
L2CachedLazyDirtFlagResetBean bean = new L2CachedLazyDirtFlagResetBean();
|
||||
bean.setName("findById");
|
||||
Ebean.save(bean);
|
||||
//bean.save();
|
||||
tx0.commit();
|
||||
//PREPARE
|
||||
try (Transaction tx0 = Ebean.beginTransaction()) {
|
||||
bean.setName("findById");
|
||||
Ebean.save(bean);
|
||||
//bean.save();
|
||||
tx0.commit();
|
||||
}
|
||||
|
||||
// clearAll() caches via the ServerCacheManager ...
|
||||
// Clear all the caches on the default/primary EbeanServer
|
||||
server().getServerCacheManager().clearAll();
|
||||
|
||||
//TEST
|
||||
Transaction tx1 = Ebean.beginTransaction();
|
||||
// load (and dont touch any related entity)
|
||||
L2CachedLazyDirtFlagResetBean bean1 = Ebean.find(L2CachedLazyDirtFlagResetBean.class, bean.getId());
|
||||
assertThat(bean1).isNotNull();
|
||||
tx1.commit();
|
||||
try (Transaction tx1 = Ebean.beginTransaction()) {
|
||||
// load (and dont touch any related entity)
|
||||
L2CachedLazyDirtFlagResetBean bean1 = Ebean.find(L2CachedLazyDirtFlagResetBean.class, bean.getId());
|
||||
assertThat(bean1).isNotNull();
|
||||
tx1.commit();
|
||||
}
|
||||
|
||||
try (Transaction tx2 = Ebean.beginTransaction()) {
|
||||
// load (and modify)
|
||||
|
||||
Transaction tx2 = Ebean.beginTransaction();
|
||||
// load (and modify)
|
||||
L2CachedLazyDirtFlagResetBean bean2 = Ebean.find(L2CachedLazyDirtFlagResetBean.class, bean.getId());
|
||||
assertNotNull(bean2);
|
||||
assertEquals("findById", bean2.getName());
|
||||
bean2.setName("something");
|
||||
BeanState beanState = Ebean.getBeanState(bean2);
|
||||
assertTrue(beanState.isDirty());
|
||||
//bean2.getChildren().size();
|
||||
bean2.someRichObjectMethod();
|
||||
assertTrue(beanState.isDirty());
|
||||
|
||||
L2CachedLazyDirtFlagResetBean bean2 = Ebean.find(L2CachedLazyDirtFlagResetBean.class, bean.getId());
|
||||
assertNotNull(bean2);
|
||||
assertEquals("findById", bean2.getName());
|
||||
bean2.setName("something");
|
||||
BeanState beanState = Ebean.getBeanState(bean2);
|
||||
assertTrue(beanState.isDirty());
|
||||
//bean2.getChildren().size();
|
||||
bean2.someRichObjectMethod();
|
||||
assertTrue(beanState.isDirty());
|
||||
Ebean.update(bean2);
|
||||
tx2.commit();
|
||||
}
|
||||
|
||||
Ebean.update(bean2);
|
||||
tx2.commit();
|
||||
try(Transaction tx3 = Ebean.beginTransaction()) {
|
||||
// validation
|
||||
|
||||
Transaction tx3 = Ebean.beginTransaction();
|
||||
// validation
|
||||
L2CachedLazyDirtFlagResetBean bean3 = Ebean.find(L2CachedLazyDirtFlagResetBean.class, bean.getId());
|
||||
assertEquals("something", bean3.getName());
|
||||
|
||||
L2CachedLazyDirtFlagResetBean bean3 = Ebean.find(L2CachedLazyDirtFlagResetBean.class, bean.getId());
|
||||
assertEquals("something", bean3.getName());
|
||||
|
||||
tx3.rollback();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user