From e913f88f52afcf93972bee155be4e78158ab5b7d Mon Sep 17 00:00:00 2001 From: rob bygrave Date: Sun, 25 Jun 2017 21:43:37 +1200 Subject: [PATCH] Fix test - TestCommitAndContinue ... close extra transactions used in asserts --- .../transaction/TestCommitAndContinue.java | 44 ++++++++++--------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/src/test/java/org/tests/transaction/TestCommitAndContinue.java b/src/test/java/org/tests/transaction/TestCommitAndContinue.java index f95035092..9d5a5e359 100644 --- a/src/test/java/org/tests/transaction/TestCommitAndContinue.java +++ b/src/test/java/org/tests/transaction/TestCommitAndContinue.java @@ -41,13 +41,12 @@ public class TestCommitAndContinue extends BaseTestCase { // use a different transaction to assert EbeanServer server = Ebean.getDefaultServer(); - Transaction anotherTxn = server.createTransaction(); - - // success prior to commitAndContinue - assertNotNull(server.find(MnyB.class, a.getId(), anotherTxn)); - - // insert failed after commitAndContinue - assertNull(server.find(MnyB.class, b.getId(), anotherTxn)); + try (Transaction anotherTxn = server.createTransaction()) { + // success prior to commitAndContinue + assertNotNull(server.find(MnyB.class, a.getId(), anotherTxn)); + // insert failed after commitAndContinue + assertNull(server.find(MnyB.class, b.getId(), anotherTxn)); + } } } @@ -78,18 +77,21 @@ public class TestCommitAndContinue extends BaseTestCase { txn.setRollbackOnly(); // use a different transaction to assert - Transaction anotherTxn = server.createTransaction(); - // success prior to commitAndContinue - assertNotNull(server.find(MnyB.class, a.getId(), anotherTxn)); - // insert failed after commitAndContinue - assertNull(server.find(MnyB.class, b.getId(), anotherTxn)); + try (Transaction anotherTxn = server.createTransaction()) { + // success prior to commitAndContinue + assertNotNull(server.find(MnyB.class, a.getId(), anotherTxn)); + // insert failed after commitAndContinue + assertNull(server.find(MnyB.class, b.getId(), anotherTxn)); + //anotherTxn.end(); + } } // does not commit due to the txn.setRollbackOnly(); txn.commit(); } finally { - server.endTransaction(); + //server.endTransaction(); + txn.end(); } } @@ -130,16 +132,16 @@ public class TestCommitAndContinue extends BaseTestCase { // asserts EbeanServer server = Ebean.getDefaultServer(); - Transaction txnForAssert = server.createTransaction(); + try (Transaction txnForAssert = server.createTransaction()) { + // success prior to commitAndContinue + assertNotNull(server.find(MnyB.class, a.getId(), txnForAssert)); - // success prior to commitAndContinue - assertNotNull(server.find(MnyB.class, a.getId(), txnForAssert)); + // insert failed after commitAndContinue + assertNull(server.find(MnyB.class, b.getId(), txnForAssert)); - // insert failed after commitAndContinue - assertNull(server.find(MnyB.class, b.getId(), txnForAssert)); - - // successful insert using txn2 - assertNotNull(server.find(MnyB.class, c.getId(), txnForAssert)); + // successful insert using txn2 + assertNotNull(server.find(MnyB.class, c.getId(), txnForAssert)); + } } @Test