FIX: possible resource leaking in testcases (all created transactions are closed by followed try statement) (#1273)

This commit is contained in:
Roland Praml
2018-02-26 08:40:53 +13:00
committed by Rob Bygrave
parent 8e9843ab8a
commit e3425a8850
23 changed files with 278 additions and 265 deletions
@@ -3,6 +3,7 @@ package org.tests.delete;
import io.ebean.BaseTestCase;
import io.ebean.Ebean;
import io.ebean.EbeanServer;
import io.ebean.Transaction;
import org.tests.model.basic.Product;
import org.tests.model.basic.ResetBasicData;
import org.junit.Assert;
@@ -26,21 +27,21 @@ public class TestDeleteByIdWithPersistenceContext extends BaseTestCase {
Product prod2 = createProduct(101, "bananas");
server.insert(prod2);
server.beginTransaction();
// effectively load these into the persistence context
server.find(Product.class, prod1.getId());
server.find(Product.class, prod2.getId());
try (Transaction txn = server.beginTransaction()) {
// effectively load these into the persistence context
server.find(Product.class, prod1.getId());
server.find(Product.class, prod2.getId());
server.deleteAll(Product.class, Arrays.asList(prod1.getId(), prod2.getId()));
server.deleteAll(Product.class, Arrays.asList(prod1.getId(), prod2.getId()));
// are these found in the persistence context?
Product shadow1 = server.find(Product.class, prod1.getId());
Product shadow2 = server.find(Product.class, prod2.getId());
// are these found in the persistence context?
Product shadow1 = server.find(Product.class, prod1.getId());
Product shadow2 = server.find(Product.class, prod2.getId());
Assert.assertNull(shadow1);
Assert.assertNull(shadow2);
Assert.assertNull(shadow1);
Assert.assertNull(shadow2);
server.endTransaction();
}
}