diff --git a/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/ClientServerTransactionDUnitTest.java b/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/ClientServerTransactionDUnitTest.java index d8a79f7b82c1..6e513ee96e25 100644 --- a/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/ClientServerTransactionDUnitTest.java +++ b/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/ClientServerTransactionDUnitTest.java @@ -23,6 +23,7 @@ import static org.apache.geode.test.awaitility.GeodeAwaitility.await; import static org.apache.geode.test.dunit.LogWriterUtils.getDUnitLogLevel; import static org.apache.geode.test.dunit.LogWriterUtils.getLogWriter; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -47,7 +48,6 @@ import javax.transaction.Synchronization; import javax.transaction.UserTransaction; -import org.assertj.core.api.Assertions; import org.junit.Ignore; import org.junit.Test; @@ -118,7 +118,6 @@ import org.apache.geode.test.dunit.SerializableCallable; import org.apache.geode.test.dunit.SerializableRunnable; import org.apache.geode.test.dunit.VM; -import org.apache.geode.test.dunit.WaitCriterion; import org.apache.geode.test.dunit.cache.internal.JUnit4CacheTestCase; import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase; import org.apache.geode.util.internal.GeodeGlossary; @@ -190,7 +189,7 @@ private Integer createRegionOnServer(VM vm, final boolean startServer, final boo private Integer createRegionOnServerWithTimeout(VM vm, final boolean startServer, final boolean accessor, final int redundantCopies, final int txTimeoutSecs) { - return (Integer) vm.invoke(new SerializableCallable() { + return (Integer) vm.invoke(new SerializableCallable() { @Override public Object call() throws Exception { createRegion(accessor, redundantCopies, null); @@ -209,7 +208,7 @@ public Object call() throws Exception { } private Integer createRegionOnDisconnectedServer(VM vm, final boolean startServer) { - return (Integer) vm.invoke(new SerializableCallable() { + return (Integer) vm.invoke(new SerializableCallable() { @Override public Object call() throws Exception { AttributesFactory af = new AttributesFactory(); @@ -246,9 +245,9 @@ private void createClientRegion(VM vm, final int port, final boolean isEmpty) { private void createClientRegionAndPopulateData(VM vm, final int port, final boolean isEmpty) { createClientRegion(vm, port, isEmpty); - vm.invoke(new SerializableCallable() { + vm.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { populateData(); return null; } @@ -256,9 +255,9 @@ public Object call() throws Exception { } private void createClientRegion2(VM vm, final int port, final boolean isEmpty, final boolean ri) { - vm.invoke(new SerializableCallable() { + vm.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { ClientCacheFactory ccf = new ClientCacheFactory(); setCCF(port, ccf); // these settings were used to manually check that tx operation stats were being updated @@ -473,7 +472,7 @@ public void testCleanupAfterClientFailure() { SerializableCallable verifyExists = new SerializableCallable("verify txstate for client exists") { @Override - public Object call() throws Exception { + public Object call() { TXManagerImpl txmgr = getGemfireCache().getTxManager(); Set states = txmgr.getTransactionsForClient((InternalDistributedMember) myId); assertEquals(1, states.size()); // only one in-progress transaction @@ -488,22 +487,14 @@ public Object call() throws Exception { SerializableCallable verifyExpired = new SerializableCallable("verify txstate is expired") { @Override - public Object call() throws Exception { + public Object call() { final TXManagerImpl txmgr = getGemfireCache().getTxManager(); try { - GeodeAwaitility.await().untilAsserted(new WaitCriterion() { - @Override - public boolean done() { - Set states = txmgr.getTransactionsForClient((InternalDistributedMember) myId); - getLogWriter() - .info("found " + states.size() + " tx states for " + myId); - return states.isEmpty(); - } - - @Override - public String description() { - return "Waiting for transaction state to expire"; - } + GeodeAwaitility.await().untilAsserted(() -> { + Set states = txmgr.getTransactionsForClient((InternalDistributedMember) myId); + getLogWriter() + .info("found " + states.size() + " tx states for " + myId); + assertThat(states).as("Waiting for transaction state to expire").isEmpty(); }); return null; } finally { @@ -553,7 +544,7 @@ public void testCleanupAfterClientAndProxyFailure() { SerializableCallable verifyExists = new SerializableCallable("verify txstate for client exists") { @Override - public Object call() throws Exception { + public Object call() { TXManagerImpl txmgr = getGemfireCache().getTxManager(); Set states = txmgr.getTransactionsForClient((InternalDistributedMember) myId); assertEquals(1, states.size()); // only one in-progress transaction @@ -569,7 +560,7 @@ public Object call() throws Exception { SerializableCallable verifyExpired = new SerializableCallable("verify txstate is expired") { @Override - public Object call() throws Exception { + public Object call() { final TXManagerImpl txmgr = getGemfireCache().getTxManager(); return verifyTXStateExpired(myId, txmgr); } @@ -637,7 +628,7 @@ public void testFailoverAfterProxyFailure() throws InterruptedException { SerializableCallable verifyExists = new SerializableCallable("verify txstate for client exists") { @Override - public Object call() throws Exception { + public Object call() { TXManagerImpl txmgr = getGemfireCache().getTxManager(); Set states = txmgr.getTransactionsForClient((InternalDistributedMember) myId); assertEquals(1, states.size()); // only one in-progress transaction @@ -649,7 +640,7 @@ public Object call() throws Exception { SerializableCallable getProxyServer = new SerializableCallable("get proxy server") { @Override - public Object call() throws Exception { + public Object call() { final TXManagerImpl txmgr = getGemfireCache().getTxManager(); DistributedMember proxyServer = null; TXStateProxyImpl tx = null; @@ -682,7 +673,7 @@ public Object call() throws Exception { SerializableCallable verifyProxyServerChanged = new SerializableCallable("verify proxy server is updated") { @Override - public Object call() throws Exception { + public Object call() { final TXManagerImpl txmgr = getGemfireCache().getTxManager(); TXStateProxyImpl tx = null; Set states = @@ -754,7 +745,7 @@ private void doBasicTransaction(final boolean prePopulateData, final boolean use createClientRegion(client, port1, false); } - client.invoke(new SerializableCallable() { + client.invoke(new SerializableCallable() { @Override public Object call() throws Exception { String suffix = prePopulateData ? "Updated" : ""; @@ -841,9 +832,9 @@ public Object call() throws Exception { } }); - server.invoke(new SerializableCallable() { + server.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region r = getGemfireCache().getRegion(D_REFERENCE); Region pr = getGemfireCache().getRegion(CUSTOMER); int expectedRegionSize = isCommit ? MAX_ENTRIES : 5; @@ -855,9 +846,9 @@ public Object call() throws Exception { } }); - server.invoke(new SerializableCallable() { + server.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { String suffix = prePopulateData ? "Updated" : ""; Region r = getGemfireCache().getRegion(D_REFERENCE); Region pr = getGemfireCache().getRegion(CUSTOMER); @@ -881,17 +872,17 @@ public Object call() throws Exception { @Override @Test - public void testTXCreationAndCleanupAtCommit() throws Exception { + public void testTXCreationAndCleanupAtCommit() { doBasicChecks(true); } @Override @Test - public void testTXCreationAndCleanupAtRollback() throws Exception { + public void testTXCreationAndCleanupAtRollback() { doBasicChecks(false); } - private void doBasicChecks(final boolean commit) throws Exception { + private void doBasicChecks(final boolean commit) { Host host = Host.getHost(0); VM server = host.getVM(0); VM client = host.getVM(1); @@ -902,16 +893,16 @@ private void doBasicChecks(final boolean commit) throws Exception { server.invoke(new SerializableCallable("verify tx") { @Override - public Object call() throws Exception { + public Object call() { TXManagerImpl mgr = getGemfireCache().getTxManager(); assertTrue(mgr.isHostedTxInProgress(txId)); return null; } }); - client.invoke(new SerializableCallable() { + client.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { TXManagerImpl mgr = getGemfireCache().getTxManager(); mgr.resume(txId); TXStateProxy tx = mgr.pauseTransaction(); @@ -926,38 +917,28 @@ public Object call() throws Exception { } }); - server.invoke(new SerializableCallable() { + server.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { final TXManagerImpl mgr = getGemfireCache().getTxManager(); - WaitCriterion w = new WaitCriterion() { - @Override - public boolean done() { - return !mgr.isHostedTxInProgress(txId); - } - - @Override - public String description() { - return "waiting for hosted tx in progress to terminate"; - } - }; - GeodeAwaitility.await().untilAsserted(w); + GeodeAwaitility.await().untilAsserted(() -> assertThat(mgr.isHostedTxInProgress(txId)) + .as("waiting for hosted tx in progress to terminate").isFalse()); return null; } }); if (commit) { - client.invoke(new SerializableCallable() { + client.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { verifyAfterCommit(OP.PUT); System.out.println("expected verification to fail for this VM"); return null; } }); } else { - client.invoke(new SerializableCallable() { + client.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { verifyAfterRollback(OP.PUT); return null; } @@ -1027,7 +1008,7 @@ public void run() throws Exception { server.invoke(new SerializableCallable("verify tx") { @Override - public Object call() throws Exception { + public Object call() { TXManagerImpl mgr = getGemfireCache().getTxManager(); Region orderRegion = getCache().getRegion(ORDER); mgr.begin(); @@ -1054,7 +1035,7 @@ public void testPutallRollbackInServer() throws Exception { server.invoke(new SerializableCallable("verify tx") { @Override - public Object call() throws Exception { + public Object call() { TXManagerImpl mgr = getGemfireCache().getTxManager(); Region orderRegion = getCache().getRegion(ORDER); mgr.begin(); @@ -1079,7 +1060,7 @@ public void testPutallRollbackInClient() throws Exception { server.invoke(new SerializableCallable("verify tx") { @Override - public Object call() throws Exception { + public Object call() { TXManagerImpl mgr = getGemfireCache().getTxManager(); Region orderRegion = getCache().getRegion(ORDER); mgr.begin(); @@ -1105,7 +1086,7 @@ public void testGetAllRollbackInServer() throws Exception { server.invoke(new SerializableCallable("verify getAll tx") { @Override - public Object call() throws Exception { + public Object call() { TXManagerImpl mgr = getGemfireCache().getTxManager(); Region orderRegion = getCache().getRegion(ORDER); orderRegion.getAttributesMutator().setCacheLoader(new CacheLoader() { @@ -1142,7 +1123,7 @@ public void testGetAllRollbackInClient() throws Exception { server.invoke(new SerializableCallable("add cache loader") { @Override - public Object call() throws Exception { + public Object call() { Region orderRegion = getCache().getRegion(ORDER); orderRegion.getAttributesMutator().setCacheLoader(new CacheLoader() { @Override @@ -1159,7 +1140,7 @@ public Object load(LoaderHelper helper) throws CacheLoaderException { client.invoke(new SerializableCallable("verify getAll uses tx") { @Override - public Object call() throws Exception { + public Object call() { Region orderRegion = getCache().getRegion(ORDER); TXManagerImpl mgr = getGemfireCache().getTxManager(); mgr.begin(); @@ -1190,9 +1171,9 @@ public void testClientCommitAndDataStoreGetsEvent() throws Exception { createClientRegion(client, port, false, true); - datastore.invoke(new SerializableCallable() { + datastore.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region custRegion = getCache().getRegion(CUSTOMER); custRegion.getAttributesMutator().addCacheListener(new ServerListener()); return null; @@ -1200,9 +1181,9 @@ public Object call() throws Exception { }); - client.invoke(new SerializableCallable() { + client.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region custRegion = getCache().getRegion(CUSTOMER); // Region orderRegion = getCache().getRegion(ORDER); // Region refRegion = getCache().getRegion(D_REFERENCE); @@ -1217,9 +1198,9 @@ public Object call() throws Exception { } }); - datastore.invoke(new SerializableCallable() { + datastore.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region custRegion = getCache().getRegion(CUSTOMER); // Region orderRegion = getCache().getRegion(ORDER); // Region refRegion = getCache().getRegion(D_REFERENCE); @@ -1245,9 +1226,9 @@ public void testClientCreateAndTwoInvalidates() throws Exception { createClientRegion(client, port, false, true); - datastore.invoke(new SerializableCallable() { + datastore.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region custRegion = getCache().getRegion(CUSTOMER); custRegion.getAttributesMutator().addCacheListener(new ClientListener()); return null; @@ -1255,9 +1236,9 @@ public Object call() throws Exception { }); - client.invoke(new SerializableCallable() { + client.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region custRegion = getCache().getRegion(CUSTOMER); // Region orderRegion = getCache().getRegion(ORDER); // Region refRegion = getCache().getRegion(D_REFERENCE); @@ -1290,9 +1271,9 @@ public void testClientCommitsAndJustGets() throws Exception { createClientRegion(client, port, false, true); - datastore.invoke(new SerializableCallable() { + datastore.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region custRegion = getCache().getRegion(CUSTOMER); custRegion.getAttributesMutator().addCacheListener(new ClientListener()); return null; @@ -1300,9 +1281,9 @@ public Object call() throws Exception { }); - client.invoke(new SerializableCallable() { + client.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region custRegion = getCache().getRegion(CUSTOMER); // Region orderRegion = getCache().getRegion(ORDER); // Region refRegion = getCache().getRegion(D_REFERENCE); @@ -1332,9 +1313,9 @@ public void testClientDoesUnsupportedLocalOps() throws Exception { createClientRegion(client, port, false, true); - datastore.invoke(new SerializableCallable() { + datastore.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region custRegion = getCache().getRegion(CUSTOMER); custRegion.getAttributesMutator().addCacheListener(new ClientListener()); return null; @@ -1342,9 +1323,9 @@ public Object call() throws Exception { }); - client.invoke(new SerializableCallable() { + client.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region custRegion = getCache().getRegion(CUSTOMER); // Region orderRegion = getCache().getRegion(ORDER); // Region refRegion = getCache().getRegion(D_REFERENCE); @@ -1388,9 +1369,9 @@ public void testClientCommitsWithRIAndOnlyGetsOneEvent() throws Exception { createClientRegion(client, port, false, true); - datastore.invoke(new SerializableCallable() { + datastore.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region custRegion = getCache().getRegion(CUSTOMER); custRegion.getAttributesMutator().addCacheListener(new ClientListener()); return null; @@ -1398,9 +1379,9 @@ public Object call() throws Exception { }); - client.invoke(new SerializableCallable() { + client.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region custRegion = getCache().getRegion(CUSTOMER); // Region orderRegion = getCache().getRegion(ORDER); // Region refRegion = getCache().getRegion(D_REFERENCE); @@ -1415,9 +1396,9 @@ public Object call() throws Exception { } }); - client.invoke(new SerializableCallable() { + client.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region custRegion = getCache().getRegion(CUSTOMER); // Region orderRegion = getCache().getRegion(ORDER); // Region refRegion = getCache().getRegion(D_REFERENCE); @@ -1441,9 +1422,9 @@ public void testDatastoreCommitsWithPutAllAndRI() throws Exception { createClientRegion(client, port, false, true); - datastore.invoke(new SerializableCallable() { + datastore.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region custRegion = getCache().getRegion(CUSTOMER); custRegion.getAttributesMutator().addCacheListener(new ClientListener()); return null; @@ -1451,9 +1432,9 @@ public Object call() throws Exception { }); - datastore.invoke(new SerializableCallable() { + datastore.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region custRegion = getCache().getRegion(CUSTOMER); // Region orderRegion = getCache().getRegion(ORDER); // Region refRegion = getCache().getRegion(D_REFERENCE); @@ -1470,26 +1451,16 @@ public Object call() throws Exception { } }); - client.invoke(new SerializableCallable() { + client.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { final Region custRegion = getCache().getRegion(CUSTOMER); // Region orderRegion = getCache().getRegion(ORDER); // Region refRegion = getCache().getRegion(D_REFERENCE); final ClientListener cl = (ClientListener) custRegion.getAttributes().getCacheListeners()[0]; - GeodeAwaitility.await().untilAsserted(new WaitCriterion() { - - @Override - public boolean done() { - return cl.invoked; - } - - @Override - public String description() { - return "Listener was not invoked in 30 seconds"; - } - }); + GeodeAwaitility.await().untilAsserted(() -> assertThat(cl.invoked) + .as("Listener was not invoked in 30 seconds").isTrue()); assertEquals(1, cl.invokeCount); return null; @@ -1511,9 +1482,9 @@ public void testClientCommitsWithPutAllAndRI() throws Exception { createClientRegion(client, port, false, true); - datastore.invoke(new SerializableCallable() { + datastore.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region custRegion = getCache().getRegion(CUSTOMER); custRegion.getAttributesMutator().addCacheListener(new ClientListener()); return null; @@ -1521,9 +1492,9 @@ public Object call() throws Exception { }); - client.invoke(new SerializableCallable() { + client.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region custRegion = getCache().getRegion(CUSTOMER); // Region orderRegion = getCache().getRegion(ORDER); // Region refRegion = getCache().getRegion(D_REFERENCE); @@ -1540,9 +1511,9 @@ public Object call() throws Exception { } }); - client.invoke(new SerializableCallable() { + client.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region custRegion = getCache().getRegion(CUSTOMER); // Region orderRegion = getCache().getRegion(ORDER); // Region refRegion = getCache().getRegion(D_REFERENCE); @@ -1569,9 +1540,9 @@ public void testClientRollsbackWithPutAllAndRI() throws Exception { createClientRegion(client, port, false, true); - datastore.invoke(new SerializableCallable() { + datastore.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region custRegion = getCache().getRegion(CUSTOMER); custRegion.getAttributesMutator().addCacheListener(new ClientListener()); return null; @@ -1579,9 +1550,9 @@ public Object call() throws Exception { }); - client.invoke(new SerializableCallable() { + client.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region custRegion = getCache().getRegion(CUSTOMER); // Region orderRegion = getCache().getRegion(ORDER); // Region refRegion = getCache().getRegion(D_REFERENCE); @@ -1598,9 +1569,9 @@ public Object call() throws Exception { } }); - client.invoke(new SerializableCallable() { + client.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region custRegion = getCache().getRegion(CUSTOMER); // Region orderRegion = getCache().getRegion(ORDER); // Region refRegion = getCache().getRegion(D_REFERENCE); @@ -1626,9 +1597,9 @@ public void testClientInitiatedInvalidates() throws Exception { createClientRegion(client, port, false, true); - datastore.invoke(new SerializableCallable() { + datastore.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region custRegion = getCache().getRegion(CUSTOMER); custRegion.getAttributesMutator().addCacheListener(new ClientListener()); return null; @@ -1640,9 +1611,9 @@ public Object call() throws Exception { * Test a no-op commit: put/invalidate */ - client.invoke(new SerializableCallable() { + client.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region custRegion = getCache().getRegion(CUSTOMER); // Region orderRegion = getCache().getRegion(ORDER); // Region refRegion = getCache().getRegion(D_REFERENCE); @@ -1660,9 +1631,9 @@ public Object call() throws Exception { /* * Validate nothing came through */ - client.invoke(new SerializableCallable() { + client.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region custRegion = getCache().getRegion(CUSTOMER); // Region orderRegion = getCache().getRegion(ORDER); // Region refRegion = getCache().getRegion(D_REFERENCE); @@ -1680,9 +1651,9 @@ public Object call() throws Exception { } }); - datastore.invoke(new SerializableCallable() { + datastore.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region custRegion = getCache().getRegion(CUSTOMER); // Region orderRegion = getCache().getRegion(ORDER); // Region refRegion = getCache().getRegion(D_REFERENCE); @@ -1707,9 +1678,9 @@ public Object call() throws Exception { client.invoke(doAPutInTx); client.invoke(doAnInvalidateInTx); - client.invoke(new SerializableCallable() { + client.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region custRegion = getCache().getRegion(CUSTOMER); // Region orderRegion = getCache().getRegion(ORDER); // Region refRegion = getCache().getRegion(D_REFERENCE); @@ -1726,9 +1697,9 @@ public Object call() throws Exception { } }); - datastore.invoke(new SerializableCallable() { + datastore.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region custRegion = getCache().getRegion(CUSTOMER); // Region orderRegion = getCache().getRegion(ORDER); // Region refRegion = getCache().getRegion(D_REFERENCE); @@ -1748,9 +1719,9 @@ public Object call() throws Exception { - SerializableCallable validateNoEvents = new SerializableCallable() { + SerializableCallable validateNoEvents = new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region custRegion = getCache().getRegion(CUSTOMER); // Region orderRegion = getCache().getRegion(ORDER); // Region refRegion = getCache().getRegion(D_REFERENCE); @@ -1763,9 +1734,9 @@ public Object call() throws Exception { }; - SerializableCallable doAPutInTx = new SerializableCallable() { + SerializableCallable doAPutInTx = new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region custRegion = getCache().getRegion(CUSTOMER); // Region orderRegion = getCache().getRegion(ORDER); // Region refRegion = getCache().getRegion(D_REFERENCE); @@ -1779,9 +1750,9 @@ public Object call() throws Exception { }; - SerializableCallable doAnInvalidateInTx = new SerializableCallable() { + SerializableCallable doAnInvalidateInTx = new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region custRegion = getCache().getRegion(CUSTOMER); // Region orderRegion = getCache().getRegion(ORDER); // Region refRegion = getCache().getRegion(D_REFERENCE); @@ -1809,9 +1780,9 @@ public void testServerDelegate() { createClientRegion(client, port, false); - client.invoke(new SerializableCallable() { + client.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { TXManagerImpl mgr = getGemfireCache().getTxManager(); Region r = getGemfireCache().getRegion(D_REFERENCE); Region pr = getGemfireCache().getRegion(CUSTOMER); @@ -1827,9 +1798,9 @@ public Object call() throws Exception { return null; } }); - server1.invoke(new SerializableCallable() { + server1.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region r = getGemfireCache().getRegion(D_REFERENCE); Region pr = getGemfireCache().getRegion(CUSTOMER); assertEquals(new Customer("name10", "address10"), pr.get(new CustId(10))); @@ -1860,9 +1831,9 @@ private void doTxWithPRAccessor(final boolean commit) { TransactionId txId = client.invoke(() -> doTransactionPut(port1)); - SerializableCallable countActiveTx = new SerializableCallable() { + SerializableCallable countActiveTx = new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { TXManagerImpl mgr = getGemfireCache().getTxManager(); return mgr.hostedTransactionsInProgressForTest(); } @@ -1896,9 +1867,9 @@ public void testConnectionAffinity() throws Exception { final int port2 = createRegionsAndStartServer(server2, false); - SerializableCallable hostedSize = new SerializableCallable() { + SerializableCallable hostedSize = new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { TXManagerImpl mgr = getGemfireCache().getTxManager(); return mgr.hostedTransactionsInProgressForTest(); } @@ -1909,9 +1880,9 @@ public Object call() throws Exception { - final TXId txid = (TXId) client.invoke(new SerializableCallable() { + final TXId txid = (TXId) client.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { ClientCacheFactory ccf = new ClientCacheFactory(); ccf.addPoolServer("localhost"/* getServerHostName(Host.getHost(0)) */, port1); ccf.addPoolServer("localhost", port2); @@ -1941,9 +1912,9 @@ public Object call() throws Exception { } }); - SerializableCallable activeTx = new SerializableCallable() { + SerializableCallable activeTx = new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { TXManagerImpl mgr = getGemfireCache().getTxManager(); TXStateProxy tx = mgr.getHostedTXState(txid); mgr.getCache().getLogger().info("SWAP:activeTx:" + tx); @@ -1964,9 +1935,9 @@ public Object call() throws Exception { int myCount = (Integer) server1.invoke(activeTx) + (Integer) server2.invoke(activeTx); assertTrue("expected count to be 11 or 12 but was " + myCount, myCount >= 11 && myCount <= 12); - client.invoke(new SerializableCallable() { + client.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { TXManagerImpl mgr = getGemfireCache().getTxManager(); mgr.resume(txid); mgr.commit(); @@ -2034,9 +2005,9 @@ private void doFailoverWork(VM accessor1, VM accessor2, VM datastore, VM client, final int port3 = serverOnDatastore ? createRegionsAndStartServer(datastore, false) : createRegionOnServer(datastore, false, false); - final TXId txid = (TXId) client.invoke(new SerializableCallable() { + final TXId txid = (TXId) client.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { System.setProperty(GeodeGlossary.GEMFIRE_PREFIX + "bridge.disableShufflingOfEndpoints", "true"); ClientCacheFactory ccf = new ClientCacheFactory(); @@ -2071,9 +2042,9 @@ public Object call() throws Exception { } }); - accessor1.invoke(new SerializableCallable() { + accessor1.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { for (CacheServer s : getCache().getCacheServers()) { getCache().getLogger().info("SWAP:Stopping " + s); s.stop(); @@ -2082,9 +2053,9 @@ public Object call() throws Exception { } }); - client.invoke(new SerializableCallable() { + client.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { TXManagerImpl mgr = getGemfireCache().getTxManager(); mgr.resume(txid); Region r = getGemfireCache().getRegion(D_REFERENCE); @@ -2100,18 +2071,18 @@ public Object call() throws Exception { } }); - datastore.invoke(new SerializableCallable() { + datastore.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { TXManagerImpl mgr = getGemfireCache().getTxManager(); assertEquals(1, mgr.hostedTransactionsInProgressForTest()); return null; } }); - client.invoke(new SerializableCallable() { + client.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { TXManagerImpl mgr = getGemfireCache().getTxManager(); mgr.resume(txid); Region r = getGemfireCache().getRegion(D_REFERENCE); @@ -2140,9 +2111,9 @@ public void testGetEntry() { int port = createRegionsAndStartServer(datastore, false); createClientRegion(client, port, true); - datastore.invoke(new SerializableCallable() { + datastore.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region pr = getGemfireCache().getRegion(CUSTOMER); pr.getAttributesMutator().setCacheLoader(new CacheLoader() { @Override @@ -2159,9 +2130,9 @@ public Customer load(LoaderHelper helper) throws CacheLoaderEx } }); - client.invoke(new SerializableCallable() { + client.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { TXManagerImpl mgr = getGemfireCache().getTxManager(); // Region r = getGemfireCache().getRegion(D_REFERENCE); Region pr = getGemfireCache().getRegion(CUSTOMER); @@ -2195,17 +2166,17 @@ public void testBug42920() { int port = createRegionsAndStartServer(datastore, false); createClientRegion(client, port, true); - datastore.invoke(new SerializableCallable() { + datastore.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region pr = getGemfireCache().getRegion(CUSTOMER); pr.getAttributesMutator().setCacheWriter(new ServerWriter()); return null; } }); - client.invoke(new SerializableCallable() { + client.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region pr = getGemfireCache().getRegion(CUSTOMER); /* CacheTransactionManager mgr = */ getCache().getCacheTransactionManager(); pr.put(new CustId(0), new Customer("name0", "address0")); @@ -2324,9 +2295,9 @@ public void beforeUpdate(EntryEvent event) throws CacheWriterException { } } - datastore.invoke(new SerializableCallable() { + datastore.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { CacheTransactionManager mgr = getCache().getCacheTransactionManager(); mgr.addListener(new ClientTxListener()); mgr.setWriter(new ClientTxWriter()); @@ -2337,9 +2308,9 @@ public Object call() throws Exception { } }); - client.invoke(new SerializableCallable() { + client.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { CacheTransactionManager mgr = getCache().getCacheTransactionManager(); mgr.addListener(new ClientTxListener()); try { @@ -2383,10 +2354,10 @@ public Object call() throws Exception { } client.invoke(new doOps(false)); - datastore.invoke(new SerializableCallable() { + datastore.invoke(new SerializableCallable() { @Override @SuppressWarnings("synthetic-access") - public Object call() throws Exception { + public Object call() { CacheTransactionManager mgr = getGemfireCache().getCacheTransactionManager(); ClientTxListener l = (ClientTxListener) mgr.getListeners()[0]; assertTrue(l.afterRollbackInvoked); @@ -2396,9 +2367,9 @@ public Object call() throws Exception { client.invoke(new doOps(true)); - datastore.invoke(new SerializableCallable() { + datastore.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { CacheTransactionManager mgr = getGemfireCache().getCacheTransactionManager(); ClientTxListener l = (ClientTxListener) mgr.getListeners()[0]; assertTrue(l.afterCommitInvoked); @@ -2408,9 +2379,9 @@ public Object call() throws Exception { } }); - client.invoke(new SerializableCallable() { + client.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { CacheTransactionManager mgr = getGemfireCache().getCacheTransactionManager(); ClientTxListener l = (ClientTxListener) mgr.getListeners()[0]; assertFalse(l.afterCommitInvoked); @@ -2441,9 +2412,9 @@ public void afterCommit(TransactionEvent event) { } } - SerializableCallable registerTxListener = new SerializableCallable() { + SerializableCallable registerTxListener = new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { getCache().getCacheTransactionManager().addListener(new RedundantListener()); return null; } @@ -2452,9 +2423,9 @@ public Object call() throws Exception { datastore1.invoke(registerTxListener); datastore2.invoke(registerTxListener); - client.invoke(new SerializableCallable() { + client.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region pr = getGemfireCache().getRegion(CUSTOMER); getGemfireCache().getCacheTransactionManager().begin(); pr.put(new CustId(1), new Customer("name1", "address1")); @@ -2463,9 +2434,9 @@ public Object call() throws Exception { } }); - SerializableCallable listenerInvoked = new SerializableCallable() { + SerializableCallable listenerInvoked = new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { RedundantListener l = (RedundantListener) getCache().getCacheTransactionManager().getListeners()[0]; return l.invoked; @@ -2526,9 +2497,9 @@ public String getId() { } } - SerializableCallable registerFunction = new SerializableCallable() { + SerializableCallable registerFunction = new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { FunctionService.registerFunction(new BasicTransactionalFunction()); return null; } @@ -2539,9 +2510,9 @@ public Object call() throws Exception { accessor.invoke(registerFunction); } - client.invoke(new SerializableCallable() { + client.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { FunctionService.registerFunction(new BasicTransactionalFunction()); Region pr = getGemfireCache().getRegion(CUSTOMER); Region r = getGemfireCache().getRegion(D_REFERENCE); @@ -2583,9 +2554,9 @@ public void testEmptyTX() { int port = createRegionsAndStartServer(datastore, false); createClientRegion(client, port, false); - client.invoke(new SerializableCallable() { + client.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region pr = getGemfireCache().getRegion(CUSTOMER); getCache().getCacheTransactionManager().begin(); pr.size(); @@ -2604,7 +2575,7 @@ public void testSuspendResumeOnDifferentThreads() { final int port1 = createRegionsAndStartServer(server1, false); final int port2 = createRegionsAndStartServer(server2, false); - client.invoke(new SerializableCallable() { + client.invoke(new SerializableCallable() { @Override public Object call() throws Exception { ClientCacheFactory ccf = new ClientCacheFactory(); @@ -2798,7 +2769,7 @@ public void testDestroyCreateConflation() {} @Override @Test - public void testTXWithRI() throws Exception {} + public void testTXWithRI() {} @Override @Test @@ -2806,7 +2777,7 @@ public void testBug43176() {} @Override @Test - public void testTXWithRICommitInDatastore() throws Exception {} + public void testTXWithRICommitInDatastore() {} @Override @Test @@ -2835,9 +2806,9 @@ public void testBug42942() { createClientRegion(client, port, false); final CustId key = new CustId(1); - client.invoke(new SerializableCallable() { + client.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region pr = getCache().getRegion(CUSTOMER); assertNull(pr.get(key)); getCache().getCacheTransactionManager().begin(); @@ -2847,17 +2818,17 @@ public Object call() throws Exception { } }); - datastore.invoke(new SerializableCallable() { + datastore.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { getCache().close(); return null; } }); - client.invoke(new SerializableCallable() { + client.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { try { getCache().getCacheTransactionManager().commit(); fail("expected exception not thrown"); @@ -2880,9 +2851,9 @@ public void testOnlyGet() { createRegionOnServer(datastore, false, false); createClientRegion(client, port, false); - client.invoke(new SerializableCallable() { + client.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region pr = getCache().getRegion(CUSTOMER); pr.put(new CustId(1), new Customer("name1", "address")); getCache().getCacheTransactionManager().begin(); @@ -2900,9 +2871,9 @@ public void testBug43237() { VM client = host.getVM(1); int port = createRegionsAndStartServer(server, false); - server.invoke(new SerializableCallable() { + server.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region pr = getCache().getRegion(CUSTOMER); Region r = getCache().getRegion(D_REFERENCE); pr.getAttributesMutator().addCacheListener(new ServerListener()); @@ -2911,9 +2882,9 @@ public Object call() throws Exception { } }); createClientRegion(client, port, false); - client.invoke(new SerializableCallable() { + client.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region pr = getCache().getRegion(CUSTOMER); Region r = getCache().getRegion(D_REFERENCE); pr.getAttributesMutator().addCacheListener(new ClientListener()); @@ -2921,9 +2892,9 @@ public Object call() throws Exception { return null; } }); - client.invoke(new SerializableCallable() { + client.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region pr = getCache().getRegion(CUSTOMER); Region r = getCache().getRegion(D_REFERENCE); pr.put(new CustId(1), new Customer("name1", "address1")); @@ -2951,9 +2922,9 @@ public Object call() throws Exception { return null; } }); - server.invoke(new SerializableCallable() { + server.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region pr = getCache().getRegion(CUSTOMER); Region r = getCache().getRegion(D_REFERENCE); ServerListener prl = (ServerListener) pr.getAttributes().getCacheListeners()[0]; @@ -2998,9 +2969,9 @@ public void testFailoverAfterCommitDistribution() { VM client = host.getVM(3); final int port1 = createRegionsAndStartServer(accessor, true); - final int port2 = (Integer) datastore1.invoke(new SerializableCallable() { + final int port2 = (Integer) datastore1.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { return getRandomAvailableTCPPort(); } }); @@ -3009,9 +2980,9 @@ public Object call() throws Exception { accessor.invoke(new CreateReplicateRegion("r2")); - client.invoke(new SerializableCallable() { + client.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { disconnectFromDS(); System.setProperty(GeodeGlossary.GEMFIRE_PREFIX + "bridge.disableShufflingOfEndpoints", "true"); @@ -3034,9 +3005,9 @@ public Object call() throws Exception { datastore1.invoke(new CreateReplicateRegion("r1")); datastore2.invoke(new CreateReplicateRegion("r2")); - final TransactionId txId = (TransactionId) client.invoke(new SerializableCallable() { + final TransactionId txId = (TransactionId) client.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { ClientCache cCache = (ClientCache) getCache(); Region r1 = cCache.getRegion("r1"); Region r2 = cCache.getRegion("r2"); @@ -3048,7 +3019,7 @@ public Object call() throws Exception { } }); - datastore1.invoke(new SerializableCallable() { + datastore1.invoke(new SerializableCallable() { @Override public Object call() throws Exception { CacheServer s = getCache().addCacheServer(); @@ -3059,9 +3030,9 @@ public Object call() throws Exception { } }); - accessor.invoke(new SerializableCallable() { + accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { getCache().getLogger().info("SWAP:accessor"); final TXManagerImpl mgr = (TXManagerImpl) getCache().getCacheTransactionManager(); assertTrue(mgr.isHostedTxInProgress((TXId) txId)); @@ -3082,9 +3053,9 @@ public Object call() throws Exception { } }); - client.invoke(new SerializableCallable() { + client.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { getCache().getLogger().info("SWAP:commiting transaction"); getCache().getCacheTransactionManager().resume(txId); getCache().getCacheTransactionManager().commit(); @@ -3202,7 +3173,7 @@ public void testClientTxLocks() { VM client = host.getVM(1); int port = createRegionsAndStartServer(server, false); createClientRegion(client, port, false); - client.invoke(new SerializableCallable() { + client.invoke(new SerializableCallable() { @Override public Object call() throws Exception { final Region r = getCache().getRegion(CUSTOMER); @@ -3289,9 +3260,9 @@ public void testBasicResumableTX() { - client.invoke(new SerializableCallable() { + client.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region cust = getCache().getRegion(CUSTOMER); assertNull(cust.get(new CustId(0))); assertNull(cust.get(new CustId(1))); @@ -3360,9 +3331,9 @@ public void run() { server2.invoke(suspectStrings); try { - client.invoke(new SerializableCallable() { + client.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { System.setProperty( GeodeGlossary.GEMFIRE_PREFIX + "bridge.disableShufflingOfEndpoints", "true"); ClientCacheFactory ccf = new ClientCacheFactory(getDistributedSystemProperties()); @@ -3472,9 +3443,9 @@ private void doFunctionWithFailureWork(final boolean commit) { createClientRegion(client, port, true); - final TransactionId txId = (TransactionId) client.invoke(new SerializableCallable() { + final TransactionId txId = (TransactionId) client.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region cust = getCache().getRegion(CUSTOMER); assertNull(cust.get(new CustId(0))); assertNull(cust.get(new CustId(1))); @@ -3506,17 +3477,17 @@ public Object call() throws Exception { } }); - server2.invoke(new SerializableCallable() { + server2.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { disconnectFromDS(); return null; } }); - client.invoke(new SerializableCallable() { + client.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region cust = getCache().getRegion(CUSTOMER); try { List list = null; @@ -3559,9 +3530,9 @@ private void doTestFunctionFromPeer(final boolean commit) { createRegionOnServer(peer2); createRegionOnServer(accessor, false, true); - final TransactionId txId = (TransactionId) peer1.invoke(new SerializableCallable() { + final TransactionId txId = (TransactionId) peer1.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { PartitionedRegion r = (PartitionedRegion) getCache().getRegion(CUSTOMER); CustId cust = null; DistributedMember myId = getCache().getDistributedSystem().getDistributedMember(); @@ -3585,9 +3556,9 @@ public Object call() throws Exception { assertNotNull(txId); - accessor.invoke(new SerializableCallable() { + accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Execution exe = FunctionService.onMember(((TXId) txId).getMemberId()).setArguments(txId); List list = null; if (commit) { @@ -3612,9 +3583,9 @@ public void testBug43752() { createRegionOnServer(server1); createRegionOnServer(server2); - server1.invoke(new SerializableCallable() { + server1.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region r = getCache().getRegion(CUSTOMER); CacheTransactionManager mgr = getCache().getCacheTransactionManager(); mgr.begin(); @@ -3642,9 +3613,9 @@ public void testSuspendTimeout() throws Exception { final int port = createRegionsAndStartServer(server, false); createClientRegion(client, port, true); - final TransactionId txId = (TransactionId) client.invoke(new SerializableCallable() { + final TransactionId txId = (TransactionId) client.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { TXManagerImpl mgr = (TXManagerImpl) getCache().getCacheTransactionManager(); mgr.setSuspendedTransactionTimeout(1); Region r = getCache().getRegion(CUSTOMER); @@ -3654,20 +3625,10 @@ public Object call() throws Exception { assertTrue(txState.isInProgress()); r.put(new CustId(101), new Customer("name101", "address101")); TransactionId txId = mgr.suspend(MILLISECONDS); - WaitCriterion waitForTxTimeout = new WaitCriterion() { - @Override - public boolean done() { - return !txState.isInProgress(); - } - - @Override - public String description() { - return "txState stayed in progress indicating that the suspend did not timeout"; - } - }; // tx should timeout after 1 ms but to deal with loaded machines and thread // scheduling latency wait for 10 seconds before reporting an error. - GeodeAwaitility.await().untilAsserted(waitForTxTimeout); + GeodeAwaitility.await().untilAsserted(() -> assertThat(txState.isInProgress()) + .as("txState suspend did not timeout").isFalse()); try { mgr.resume(txId); fail("expected exception not thrown"); @@ -3677,9 +3638,9 @@ public String description() { return txId; } }); - server.invoke(new SerializableCallable() { + server.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { TXManagerImpl mgr = (TXManagerImpl) getCache().getCacheTransactionManager(); assertNull(mgr.getHostedTXState((TXId) txId)); assertEquals(0, mgr.hostedTransactionsInProgressForTest()); @@ -3701,9 +3662,9 @@ public void testEventTracker() { final int port1 = createRegionsAndStartServer(delegate, true); final int port2 = createRegionsAndStartServer(server, false); - final TXId txid = (TXId) client.invoke(new SerializableCallable() { + final TXId txid = (TXId) client.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { System.setProperty(GeodeGlossary.GEMFIRE_PREFIX + "bridge.disableShufflingOfEndpoints", "true"); ClientCacheFactory ccf = new ClientCacheFactory(); @@ -3731,9 +3692,9 @@ public Object call() throws Exception { } }); - client.invoke(new SerializableCallable() { + client.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { TXManagerImpl mgr = getGemfireCache().getTxManager(); mgr.resume(txid); EntryEventImpl event = null; @@ -3752,9 +3713,9 @@ public Object call() throws Exception { } }); - server.invoke(new SerializableCallable() { + server.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { TXManagerImpl mgr = getGemfireCache().getTxManager(); TXStateProxyImpl txProxy = (TXStateProxyImpl) mgr.getHostedTXState(txid); assert txProxy.isRealDealLocal(); @@ -3766,9 +3727,9 @@ public Object call() throws Exception { } }); - delegate.invoke(new SerializableCallable() { + delegate.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { for (CacheServer s : getCache().getCacheServers()) { getCache().getLogger().info("SWAP:Stopping " + s); s.stop(); @@ -3777,9 +3738,9 @@ public Object call() throws Exception { } }); - client.invoke(new SerializableCallable() { + client.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { TXManagerImpl mgr = getGemfireCache().getTxManager(); mgr.resume(txid); mgr.commit(); @@ -3831,9 +3792,9 @@ private void throwException(EntryEvent event) { } } } - server1.invoke(new SerializableCallable() { + server1.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region ref = getCache().getRegion(D_REFERENCE); getCache().getLogger().info("SWAP:ADDWRITER:server1"); ref.getAttributesMutator().setCacheWriter(new ExceptionWriter()); @@ -3841,9 +3802,9 @@ public Object call() throws Exception { } }); - /* final TXId txid = (TXId) */client.invoke(new SerializableCallable() { + /* final TXId txid = (TXId) */client.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { System.setProperty(GeodeGlossary.GEMFIRE_PREFIX + "bridge.disableShufflingOfEndpoints", "true"); ClientCacheFactory ccf = new ClientCacheFactory(); @@ -3878,9 +3839,9 @@ public Object call() throws Exception { }); // make sure tx has not failed over to server2 - server2.invoke(new SerializableCallable() { + server2.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { GemFireCacheImpl cache = getGemfireCache(); assertEquals(0, cache.getTxManager().hostedTransactionsInProgressForTest()); return null; @@ -3922,9 +3883,9 @@ private void enrollRegion(EntryEvent event) { } } - server.invoke(new SerializableCallable() { + server.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region ref = getCache().getRegion(D_REFERENCE); Region r = getCache().createRegionFactory(RegionShortcut.REPLICATE).create(regionName); ref.getAttributesMutator().setCacheWriter(new SecurityWriter()); @@ -3932,9 +3893,9 @@ public Object call() throws Exception { } }); - /* final TXId txid = (TXId) */client.invoke(new SerializableCallable() { + /* final TXId txid = (TXId) */client.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { System.setProperty(GeodeGlossary.GEMFIRE_PREFIX + "bridge.disableShufflingOfEndpoints", "true"); ClientCacheFactory ccf = new ClientCacheFactory(); @@ -3975,9 +3936,9 @@ public void testAdjunctMessage() { final int port1 = createRegionsAndStartServer(server1, false); final int port2 = createRegionsAndStartServer(server2, false); - SerializableCallable createServerRegionWithInterest = new SerializableCallable() { + SerializableCallable createServerRegionWithInterest = new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { RegionFactory rf = getCache().createRegionFactory(RegionShortcut.PARTITION); rf.setSubscriptionAttributes(new SubscriptionAttributes(InterestPolicy.CACHE_CONTENT)); rf.create(regionName); @@ -3988,9 +3949,9 @@ public Object call() throws Exception { server2.invoke(createServerRegionWithInterest); // get two colocated keys on server1 - final List keys = (List) server1.invoke(new SerializableCallable() { + final List keys = (List) server1.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region r = getCache().getRegion(regionName); PartitionedRegion pr = (PartitionedRegion) r; List server1Keys = new ArrayList<>(); @@ -4026,9 +3987,9 @@ private void add(EntryEvent event) { keys.add(event.getKey()); } } - client2.invoke(new SerializableCallable() { + client2.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { System.setProperty(GeodeGlossary.GEMFIRE_PREFIX + "bridge.disableShufflingOfEndpoints", "true"); ClientCacheFactory ccf = new ClientCacheFactory(); @@ -4045,9 +4006,9 @@ public Object call() throws Exception { return null; } }); - client1.invoke(new SerializableCallable() { + client1.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { System.setProperty(GeodeGlossary.GEMFIRE_PREFIX + "bridge.disableShufflingOfEndpoints", "true"); ClientCacheFactory ccf = new ClientCacheFactory(); @@ -4066,9 +4027,9 @@ public Object call() throws Exception { return null; } }); - client2.invoke(new SerializableCallable() { + client2.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region r = getCache().getRegion(regionName); CacheListener[] listeners = r.getAttributes().getCacheListeners(); boolean foundListener = false; @@ -4076,18 +4037,8 @@ public Object call() throws Exception { if (listener instanceof ClientListener) { foundListener = true; final ClientListener clientListener = (ClientListener) listener; - WaitCriterion wc = new WaitCriterion() { - @Override - public boolean done() { - return clientListener.keys.containsAll(keys); - } - - @Override - public String description() { - return "expected:" + keys + " found:" + clientListener.keys; - } - }; - GeodeAwaitility.await().untilAsserted(wc); + GeodeAwaitility.await().untilAsserted( + () -> assertThat(clientListener.keys).containsExactlyElementsOf(keys)); } } assertTrue(foundListener); @@ -4208,19 +4159,11 @@ public void beforeLock(InternalRegion owner, CacheEvent event) { Object verifyTXStateExpired(final DistributedMember myId, final TXManagerImpl txmgr) { try { - GeodeAwaitility.await().untilAsserted(new WaitCriterion() { - @Override - public boolean done() { - Set states = txmgr.getTransactionsForClient((InternalDistributedMember) myId); - getLogWriter() - .info("found " + states.size() + " tx states for " + myId); - return states.isEmpty(); - } - - @Override - public String description() { - return "Waiting for transaction state to expire"; - } + GeodeAwaitility.await().untilAsserted(() -> { + Set states = txmgr.getTransactionsForClient((InternalDistributedMember) myId); + getLogWriter() + .info("found " + states.size() + " tx states for " + myId); + assertThat(states).isEmpty(); }); return null; } finally { @@ -4269,7 +4212,7 @@ public void testTXStateCleanedUpIfJTABeforeCompletionFailedOnClient() { client1.invoke(() -> verifyClientCacheData(regionName)); - client1.invoke(new SerializableCallable() { + client1.invoke(new SerializableCallable() { @Override public Object call() throws Exception { final CountDownLatch latch1 = new CountDownLatch(1); @@ -4298,9 +4241,9 @@ private void verifyTXStateEmpty(DistributedMember clientId) { // There exists a race that TXState is yet to be removed when client JTA tx is finished. // Add the wait before checking the TXState. await() - .untilAsserted(() -> Assertions - .assertThat(txmgr.getTransactionsForClient((InternalDistributedMember) clientId).size()) - .isEqualTo(0)); + .untilAsserted(() -> assertThat( + txmgr.getTransactionsForClient((InternalDistributedMember) clientId).size()) + .isEqualTo(0)); } private SerializableCallable getClientDM() { diff --git a/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/RemoteTransactionDUnitTest.java b/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/RemoteTransactionDUnitTest.java index c131acfbe99a..ab51be767677 100644 --- a/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/RemoteTransactionDUnitTest.java +++ b/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/RemoteTransactionDUnitTest.java @@ -20,13 +20,11 @@ import static org.apache.geode.internal.AvailablePortHelper.getRandomAvailableTCPPort; import static org.apache.geode.internal.cache.ExpiryTask.permitExpiration; import static org.apache.geode.internal.cache.ExpiryTask.suspendExpiration; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import java.io.IOException; +import java.time.Duration; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; @@ -44,6 +42,7 @@ import javax.transaction.Status; import javax.transaction.UserTransaction; +import org.awaitility.core.ThrowingRunnable; import org.junit.Ignore; import org.junit.Test; @@ -117,8 +116,6 @@ import org.apache.geode.test.dunit.LogWriterUtils; import org.apache.geode.test.dunit.SerializableCallable; import org.apache.geode.test.dunit.VM; -import org.apache.geode.test.dunit.Wait; -import org.apache.geode.test.dunit.WaitCriterion; import org.apache.geode.test.dunit.cache.internal.JUnit4CacheTestCase; @@ -128,35 +125,27 @@ public class RemoteTransactionDUnitTest extends JUnit4CacheTestCase { protected final String ORDER = "orderRegion"; protected final String D_REFERENCE = "distrReference"; - private final SerializableCallable getNumberOfTXInProgress = new SerializableCallable() { - @Override - public Object call() throws Exception { - TXManagerImpl mgr = getGemfireCache().getTxManager(); - return mgr.hostedTransactionsInProgressForTest(); - } - }; - private final SerializableCallable verifyNoTxState = new SerializableCallable() { + private final SerializableCallable getNumberOfTXInProgress = + new SerializableCallable() { + @Override + public Object call() { + TXManagerImpl mgr = getCache().getTxManager(); + return mgr.hostedTransactionsInProgressForTest(); + } + }; + private final SerializableCallable verifyNoTxState = new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { try { CacheFactory.getAnyInstance(); } catch (CacheClosedException e) { return null; } - // TXManagerImpl mgr = getGemfireCache().getTxManager(); + // TXManagerImpl mgr = getCache().getTxManager(); // assertIndexDetailsEquals(0, mgr.hostedTransactionsInProgressForTest()); - final TXManagerImpl mgr = getGemfireCache().getTxManager(); - Wait.waitForCriterion(new WaitCriterion() { - @Override - public boolean done() { - return mgr.hostedTransactionsInProgressForTest() == 0; - } - - @Override - public String description() { - return ""; - } - }, 30 * 1000, 500, true/* throwOnTimeout */); + final TXManagerImpl mgr = getCache().getTxManager(); + GeodeAwaitility.await().atMost(Duration.ofMillis(30000)).untilAsserted( + () -> assertThat(mgr.hostedTransactionsInProgressForTest()).isZero()); return null; } }; @@ -177,7 +166,7 @@ public Properties getDistributedSystemProperties() { } @Override - public final void preTearDownCacheTestCase() throws Exception { + public final void preTearDownCacheTestCase() { try { Invoke.invokeInEveryVM(verifyNoTxState); } finally { @@ -186,12 +175,12 @@ public final void preTearDownCacheTestCase() throws Exception { } void createRegion(boolean accessor, int redundantCopies, InterestPolicy interestPolicy) { - AttributesFactory af = new AttributesFactory(); + AttributesFactory af = new AttributesFactory(); af.setScope(Scope.DISTRIBUTED_ACK); af.setDataPolicy(DataPolicy.REPLICATE); af.setConcurrencyChecksEnabled(getConcurrencyChecksEnabled()); getCache().createRegion(D_REFERENCE, af.create()); - af = new AttributesFactory(); + af = new AttributesFactory(); af.setConcurrencyChecksEnabled(getConcurrencyChecksEnabled()); if (interestPolicy != null) { af.setSubscriptionAttributes(new SubscriptionAttributes(interestPolicy)); @@ -213,9 +202,9 @@ protected boolean getConcurrencyChecksEnabled() { } void populateData() { - Region custRegion = getCache().getRegion(CUSTOMER); - Region orderRegion = getCache().getRegion(ORDER); - Region refRegion = getCache().getRegion(D_REFERENCE); + Region custRegion = getCache().getRegion(CUSTOMER); + Region orderRegion = getCache().getRegion(ORDER); + Region refRegion = getCache().getRegion(D_REFERENCE); for (int i = 0; i < 5; i++) { CustId custId = new CustId(i); Customer customer = new Customer("customer" + i, "address" + i); @@ -228,17 +217,17 @@ void populateData() { } protected void initAccessorAndDataStore(VM accessor, VM datastore, final int redundantCopies) { - accessor.invoke(new SerializableCallable() { + accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { createRegion(true/* accessor */, redundantCopies, null); return null; } }); - datastore.invoke(new SerializableCallable() { + datastore.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { createRegion(false/* accessor */, redundantCopies, null); populateData(); return null; @@ -248,9 +237,9 @@ public Object call() throws Exception { protected void initAccessorAndDataStore(VM accessor, VM datastore1, VM datastore2, final int redundantCopies) { - datastore2.invoke(new SerializableCallable() { + datastore2.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { createRegion(false/* accessor */, redundantCopies, null); return null; } @@ -261,9 +250,9 @@ public Object call() throws Exception { private void initAccessorAndDataStoreWithInterestPolicy(VM accessor, VM datastore1, VM datastore2, final int redundantCopies) { - datastore2.invoke(new SerializableCallable() { + datastore2.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { createRegion(false/* accessor */, redundantCopies, InterestPolicy.ALL); return null; } @@ -272,7 +261,7 @@ public Object call() throws Exception { initAccessorAndDataStore(accessor, datastore1, redundantCopies); } - protected class DoOpsInTX extends SerializableCallable { + protected class DoOpsInTX extends SerializableCallable { private final OP op; Customer expectedCust; Customer expectedRefCust = null; @@ -285,8 +274,8 @@ protected class DoOpsInTX extends SerializableCallable { } @Override - public Object call() throws Exception { - CacheTransactionManager mgr = getGemfireCache().getTxManager(); + public Object call() { + CacheTransactionManager mgr = getCache().getTxManager(); LogWriterUtils.getLogWriter().fine("testTXPut starting tx"); mgr.begin(); Region custRegion = getCache().getRegion(CUSTOMER); @@ -304,25 +293,23 @@ public Object call() throws Exception { expectedOrder3 = new Order("fooOrder3"); custRegion.put(custId, expectedCust); orderRegion.put(orderId, expectedOrder); - Map orders = new HashMap(); + Map orders = new HashMap(); orders.put(orderId2, expectedOrder2); orders.put(orderId3, expectedOrder3); - getGemfireCache().getLogger().fine("SWAP:doingPutAll"); - // orderRegion.putAll(orders); + getCache().getLogger().fine("SWAP:doingPutAll"); refRegion.put(custId, expectedCust); Set ordersSet = new HashSet<>(); ordersSet.add(orderId); ordersSet.add(orderId2); ordersSet.add(orderId3); - // validateContains(custId, ordersSet, true); break; case GET: expectedCust = custRegion.get(custId); expectedOrder = orderRegion.get(orderId); expectedRefCust = refRegion.get(custId); - assertNotNull(expectedCust); - assertNotNull(expectedOrder); - assertNotNull(expectedRefCust); + assertThat(expectedCust).isNotNull(); + assertThat(expectedOrder).isNotNull(); + assertThat(expectedRefCust).isNotNull(); validateContains(custId, Collections.singleton(orderId), true, true); break; case DESTROY: @@ -365,7 +352,7 @@ void validateContains(CustId custId, Set ordersSet, boolean containsKey boolean rContainsKC = custRegion.containsKey(custId); boolean rContainsKO = containsKey; for (OrderId o : ordersSet) { - getGemfireCache().getLogger() + getCache().getLogger() .fine("SWAP:rContainsKO:" + rContainsKO + " containsKey:" + orderRegion.containsKey(o)); rContainsKO = rContainsKO && orderRegion.containsKey(o); } @@ -378,23 +365,21 @@ void validateContains(CustId custId, Set ordersSet, boolean containsKey } boolean rContainsVR = refRegion.containsValueForKey(custId); - - assertEquals(containsKey, rContainsKC); - assertEquals(containsKey, rContainsKO); - assertEquals(containsKey, rContainsKR); - assertEquals(containsValue, rContainsVR); - assertEquals(containsValue, rContainsVC); - assertEquals(containsValue, rContainsVO); - + assertThat(containsKey).isEqualTo(rContainsKC); + assertThat(containsKey).isEqualTo(rContainsKO); + assertThat(containsKey).isEqualTo(rContainsKR); + assertThat(containsValue).isEqualTo(rContainsVR); + assertThat(containsValue).isEqualTo(rContainsVC); + assertThat(containsValue).isEqualTo(rContainsVO); if (containsKey) { Region.Entry eC = custRegion.getEntry(custId); for (OrderId o : ordersSet) { - assertNotNull(orderRegion.getEntry(o)); + assertThat(orderRegion.getEntry(o)).isNotNull(); } Region.Entry eR = refRegion.getEntry(custId); - assertNotNull(eC); - assertNotNull(eR); + assertThat(eC).isNotNull(); + assertThat(eR).isNotNull(); // assertIndexDetailsEquals(1,custRegion.size()); // assertIndexDetailsEquals(1,orderRegion.size()); // assertIndexDetailsEquals(1,refRegion.size()); @@ -405,23 +390,23 @@ void validateContains(CustId custId, Set ordersSet, boolean containsKey // assertIndexDetailsEquals(0,refRegion.size()); try { Region.Entry eC = custRegion.getEntry(custId); - assertNull("should have had an EntryNotFoundException:" + eC, eC); + assertThat(eC).as("should have had an EntryNotFoundException:" + eC).isNull(); } catch (EntryNotFoundException enfe) { // this is what we expect } try { for (OrderId o : ordersSet) { - assertNull("should have had an EntryNotFoundException:" + orderRegion.getEntry(o), - orderRegion.getEntry(o)); + assertThat(orderRegion.getEntry(o)) + .as("should have had an EntryNotFoundException:" + orderRegion.getEntry(o)) + .isNull(); } - } catch (EntryNotFoundException enfe) { // this is what we expect } try { Region.Entry eR = refRegion.getEntry(custId); - assertNull("should have had an EntryNotFoundException:" + eR, eR); + assertThat(eR).as("should have had an EntryNotFoundException:" + eR).isNull(); } catch (EntryNotFoundException enfe) { // this is what we expect } @@ -451,20 +436,23 @@ void verifyAfterCommit(OP op) { expectedOrder2 = new Order("fooOrder2"); expectedOrder3 = new Order("fooOrder3"); expectedRef = expectedCust; - assertNotNull(custRegion.getEntry(custId)); - assertEquals(expectedCust, custRegion.getEntry(custId).getValue()); + assertThat(custRegion.getEntry(custId)).isNotNull(); + assertThat(expectedCust).isEqualTo(custRegion.getEntry(custId).getValue()); /* - * assertNotNull(orderRegion.getEntry(orderId)); assertIndexDetailsEquals(expectedOrder, + * assertThat(orderRegion.getEntry(orderId)).isNotNull(); + * assertIndexDetailsEquals(expectedOrder, * orderRegion.getEntry(orderId).getValue()); * - * assertNotNull(orderRegion.getEntry(orderId2)); assertIndexDetailsEquals(expectedOrder2, + * assertThat(orderRegion.getEntry(orderId2)).isNotNull(); + * assertIndexDetailsEquals(expectedOrder2, * orderRegion.getEntry(orderId2).getValue()); * - * assertNotNull(orderRegion.getEntry(orderId3)); assertIndexDetailsEquals(expectedOrder3, + * assertThat(orderRegion.getEntry(orderId3)).isNotNull(); + * assertIndexDetailsEquals(expectedOrder3, * orderRegion.getEntry(orderId3).getValue()); */ - assertNotNull(refRegion.getEntry(custId)); - assertEquals(expectedRef, refRegion.getEntry(custId).getValue()); + assertThat(refRegion.getEntry(custId)).isNotNull(); + assertThat(expectedRef).isEqualTo(refRegion.getEntry(custId).getValue()); // Set ordersSet = new HashSet<>(); // ordersSet.add(orderId);ordersSet.add(orderId2);ordersSet.add(orderId3); @@ -477,21 +465,21 @@ void verifyAfterCommit(OP op) { validateContains(custId, Collections.singleton(orderId), true); break; case DESTROY: - assertTrue(!custRegion.containsKey(custId)); - assertTrue(!orderRegion.containsKey(orderId)); - assertTrue(!refRegion.containsKey(custId)); + assertThat(!custRegion.containsKey(custId)).isTrue(); + assertThat(!orderRegion.containsKey(orderId)).isTrue(); + assertThat(!refRegion.containsKey(custId)).isTrue(); validateContains(custId, Collections.singleton(orderId), false); break; case INVALIDATE: boolean validateContainsKey = true; if (!((GemFireCacheImpl) custRegion.getCache()).isClient()) { - assertTrue(custRegion.containsKey(custId)); - assertTrue(orderRegion.containsKey(orderId)); - assertTrue(refRegion.containsKey(custId)); + assertThat(custRegion.containsKey(custId)).isTrue(); + assertThat(orderRegion.containsKey(orderId)).isTrue(); + assertThat(refRegion.containsKey(custId)).isTrue(); } - assertNull(custRegion.get(custId)); - assertNull(orderRegion.get(orderId)); - assertNull(refRegion.get(custId)); + assertThat(custRegion.get(custId)).isNull(); + assertThat(orderRegion.get(orderId)).isNull(); + assertThat(refRegion.get(custId)).isNull(); validateContains(custId, Collections.singleton(orderId), validateContainsKey, false); break; default: @@ -504,9 +492,9 @@ void verifyAfterRollback(OP op) { Region custRegion = getCache().getRegion(CUSTOMER); Region orderRegion = getCache().getRegion(ORDER); Region refRegion = getCache().getRegion(D_REFERENCE); - assertNotNull(custRegion); - assertNotNull(orderRegion); - assertNotNull(refRegion); + assertThat(custRegion).isNotNull(); + assertThat(orderRegion).isNotNull(); + assertThat(refRegion).isNotNull(); CustId custId = new CustId(1); OrderId orderId = new OrderId(1, custId); @@ -520,16 +508,17 @@ void verifyAfterRollback(OP op) { expectedCust = new Customer("customer1", "address1"); expectedOrder = new Order("order1"); expectedRef = new Customer("customer1", "address1"); - assertEquals(expectedCust, custRegion.getEntry(custId).getValue()); - assertEquals(expectedOrder, orderRegion.getEntry(orderId).getValue()); + assertThat(expectedCust).isEqualTo(custRegion.getEntry(custId).getValue()); + assertThat(expectedOrder).isEqualTo(orderRegion.getEntry(orderId).getValue()); getCache().getLogger().info("SWAP:verifyRollback:" + orderRegion); getCache().getLogger().info("SWAP:verifyRollback:" + orderRegion.getEntry(orderId2)); - assertNull(getGemfireCache().getTXMgr().getTXState()); - assertNull("" + orderRegion.getEntry(orderId2), orderRegion.getEntry(orderId2)); - assertNull(orderRegion.getEntry(orderId3)); - assertNull(orderRegion.get(orderId2)); - assertNull(orderRegion.get(orderId3)); - assertEquals(expectedRef, refRegion.getEntry(custId).getValue()); + assertThat(getCache().getTXMgr().getTXState()).isNull(); + assertThat(orderRegion.getEntry(orderId2)) + .as("" + orderRegion.getEntry(orderId2)).isNull(); + assertThat(orderRegion.getEntry(orderId3)).isNull(); + assertThat(orderRegion.get(orderId2)).isNull(); + assertThat(orderRegion.get(orderId3)).isNull(); + assertThat(expectedRef).isEqualTo(refRegion.getEntry(custId).getValue()); validateContains(custId, Collections.singleton(orderId), true); break; case GET: @@ -539,18 +528,18 @@ void verifyAfterRollback(OP op) { validateContains(custId, Collections.singleton(orderId), true); break; case DESTROY: - assertTrue(!custRegion.containsKey(custId)); - assertTrue(!orderRegion.containsKey(orderId)); - assertTrue(!refRegion.containsKey(custId)); + assertThat(custRegion.containsKey(custId)).isFalse(); + assertThat(orderRegion.containsKey(orderId)).isFalse(); + assertThat(refRegion.containsKey(custId)).isFalse(); validateContains(custId, Collections.singleton(orderId), true); break; case INVALIDATE: - assertTrue(custRegion.containsKey(custId)); - assertTrue(orderRegion.containsKey(orderId)); - assertTrue(refRegion.containsKey(custId)); - assertNull(custRegion.get(custId)); - assertNull(orderRegion.get(orderId)); - assertNull(refRegion.get(custId)); + assertThat(custRegion.containsKey(custId)).isTrue(); + assertThat(orderRegion.containsKey(orderId)).isTrue(); + assertThat(refRegion.containsKey(custId)).isTrue(); + assertThat(custRegion.get(custId)).isNull(); + assertThat(orderRegion.get(orderId)).isNull(); + assertThat(refRegion.get(custId)).isNull(); validateContains(custId, Collections.singleton(orderId), true, true); break; default: @@ -559,18 +548,17 @@ void verifyAfterRollback(OP op) { } - @Test - public void testTXCreationAndCleanupAtCommit() throws Exception { + public void testTXCreationAndCleanupAtCommit() { doBasicChecks(true); } @Test - public void testTXCreationAndCleanupAtRollback() throws Exception { + public void testTXCreationAndCleanupAtRollback() { doBasicChecks(false); } - private void doBasicChecks(final boolean commit) throws Exception { + private void doBasicChecks(final boolean commit) { Host host = Host.getHost(0); VM accessor = host.getVM(0); VM datastore = host.getVM(1); @@ -578,22 +566,23 @@ private void doBasicChecks(final boolean commit) throws Exception { final TXId txId = (TXId) accessor.invoke(new DoOpsInTX(OP.PUT)); - datastore.invoke(new SerializableCallable("verify tx") { + datastore.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - TXManagerImpl mgr = getGemfireCache().getTxManager(); - assertTrue(mgr.isHostedTxInProgress(txId)); + public Object call() { + TXManagerImpl mgr = getCache().getTxManager(); + assertThat(mgr).isNotNull(); + assertThat(mgr.isHostedTxInProgress(txId)).isTrue(); return null; } }); - accessor.invoke(new SerializableCallable() { + accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - TXManagerImpl mgr = getGemfireCache().getTxManager(); + public Object call() { + TXManagerImpl mgr = getCache().getTxManager(); mgr.resume(txId); TXStateProxy tx = mgr.pauseTransaction(); - assertNotNull(tx); + assertThat(tx).isNotNull(); mgr.unpauseTransaction(tx); if (commit) { mgr.commit(); @@ -604,26 +593,26 @@ public Object call() throws Exception { } }); - datastore.invoke(new SerializableCallable() { + datastore.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - TXManagerImpl mgr = getGemfireCache().getTxManager(); - assertFalse(mgr.isHostedTxInProgress(txId)); + public Object call() { + TXManagerImpl mgr = getCache().getTxManager(); + assertThat(mgr.isHostedTxInProgress(txId)).isFalse(); return null; } }); if (commit) { - accessor.invoke(new SerializableCallable() { + accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { verifyAfterCommit(OP.PUT); return null; } }); } else { - accessor.invoke(new SerializableCallable() { + accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { verifyAfterRollback(OP.PUT); return null; } @@ -640,33 +629,33 @@ public void testPRTXGet() { final TXId txId = (TXId) accessor.invoke(new DoOpsInTX(OP.GET)); - datastore.invoke(new SerializableCallable() { + datastore.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - TXManagerImpl mgr = getGemfireCache().getTxManager(); - assertTrue(mgr.isHostedTxInProgress(txId)); + public Object call() { + TXManagerImpl mgr = getCache().getTxManager(); + assertThat(mgr.isHostedTxInProgress(txId)).isTrue(); TXStateProxy tx = mgr.getHostedTXState(txId); System.out.println("TXRS:" + tx.getRegions()); - assertEquals(3, tx.getRegions().size());// 2 buckets for the two puts we - // did in the accessor - // plus the dist. region + assertThat(tx.getRegions().size()).isEqualTo(3);// 2 buckets for the two puts we + // did in the accessor + // plus the dist. region for (InternalRegion r : tx.getRegions()) { - assertTrue(r instanceof BucketRegion || r instanceof DistributedRegion); + assertThat(r instanceof DistributedRegion).isTrue(); TXRegionState rs = tx.readRegion(r); for (Object key : rs.getEntryKeys()) { TXEntryState es = rs.readEntry(key); - assertNotNull(es.getValue(key, r, false)); - assertFalse(es.isDirty()); + assertThat(es.getValue(key, r, false)).isNotNull(); + assertThat(es.isDirty()).isFalse(); } } return null; } }); - accessor.invoke(new SerializableCallable() { + accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - CacheTransactionManager mgr = getGemfireCache().getTxManager(); + public Object call() { + CacheTransactionManager mgr = getCache().getTxManager(); mgr.resume(txId); mgr.commit(); verifyAfterCommit(OP.GET); @@ -682,11 +671,11 @@ public void testPRTXGetOnRemoteWithLoader() { VM datastore = host.getVM(1); initAccessorAndDataStore(accessor, datastore, 0); - - datastore.invoke(new SerializableCallable() { + datastore.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - AttributesMutator am = getCache().getRegion(CUSTOMER).getAttributesMutator(); + public Object call() { + AttributesMutator am = + getCache().getRegion(CUSTOMER).getAttributesMutator(); am.setCacheLoader(new CacheLoader() { @Override public Object load(LoaderHelper helper) throws CacheLoaderException { @@ -700,23 +689,23 @@ public void close() {} } }); - accessor.invoke(new SerializableCallable() { + accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - CacheTransactionManager mgr = getGemfireCache().getTxManager(); + public Object call() { + TXManagerImpl mgr = getCache().getTxManager(); mgr.begin(); - Region cust = getCache().getRegion(CUSTOMER); + Region cust = getCache().getRegion(CUSTOMER); Customer s = (Customer) cust.get(new CustId(8)); - assertEquals(new Customer("sup dawg", "add"), s); - assertTrue(cust.containsKey(new CustId(8))); - TXStateProxy tx = ((TXManagerImpl) mgr).pauseTransaction(); - assertFalse(cust.containsKey(new CustId(8))); - ((TXManagerImpl) mgr).unpauseTransaction(tx); + assertThat(new Customer("sup dawg", "add")).isEqualTo(s); + assertThat(cust.containsKey(new CustId(8))).isTrue(); + TXStateProxy tx = mgr.pauseTransaction(); + assertThat(cust.containsKey(new CustId(8))).isFalse(); + mgr.unpauseTransaction(tx); mgr.commit(); Customer s2 = (Customer) cust.get(new CustId(8)); Customer ex = new Customer("sup dawg", "add"); - assertEquals(ex, s); - assertEquals(ex, s2); + assertThat(ex).isEqualTo(s); + assertThat(ex).isEqualTo(s2); return null; } }); @@ -732,54 +721,51 @@ public void testPRTXGetEntryOnRemoteSide() { VM datastore = host.getVM(1); initAccessorAndDataStore(accessor, datastore, 0); - - datastore.invoke(new SerializableCallable() { + datastore.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { return null; } }); - accessor.invoke(new SerializableCallable() { + accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - Region cust = getCache().getRegion(CUSTOMER); + public Object call() { + Region cust = getCache().getRegion(CUSTOMER); CustId sup = new CustId(7); Region.Entry e = cust.getEntry(sup); - assertNull(e); + assertThat(e).isNull(); CustId custId = new CustId(5); cust.put(custId, new Customer("customer5", "address5")); Region.Entry ee = cust.getEntry(custId); - assertNotNull(ee); + assertThat(ee).isNotNull(); - CacheTransactionManager mgr = getGemfireCache().getTxManager(); + CacheTransactionManager mgr = getCache().getTxManager(); mgr.begin(); Region.Entry e2 = cust.getEntry(sup); - assertNull(e2); + assertThat(e2).isNull(); mgr.commit(); Region.Entry e3 = cust.getEntry(sup); - assertNull(e3); - + assertThat(e3).isNull(); mgr.begin(); Customer dawg = new Customer("dawg", "dawgaddr"); cust.put(sup, dawg); Region.Entry e4 = cust.getEntry(sup); - assertNotNull(e4); - assertEquals(dawg, e4.getValue()); + assertThat(e4).isNotNull(); + assertThat(dawg).isEqualTo(e4.getValue()); mgr.commit(); Region.Entry e5 = cust.getEntry(sup); - assertNotNull(e5); - assertEquals(dawg, e5.getValue()); + assertThat(e5).isNotNull(); + assertThat(dawg).isEqualTo(e5.getValue()); return null; } }); } - @Test public void testPRTXGetOnLocalWithLoader() { Host host = Host.getHost(0); @@ -787,21 +773,21 @@ public void testPRTXGetOnLocalWithLoader() { VM datastore = host.getVM(1); initAccessorAndDataStore(accessor, datastore, 0); - - datastore.invoke(new SerializableCallable() { + datastore.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - AttributesMutator am = getCache().getRegion(CUSTOMER).getAttributesMutator(); - am.setCacheLoader(new CacheLoader() { + public Object call() { + AttributesMutator am = + getCache().getRegion(CUSTOMER).getAttributesMutator(); + am.setCacheLoader(new CacheLoader() { @Override - public Object load(LoaderHelper helper) throws CacheLoaderException { + public Object load(LoaderHelper helper) throws CacheLoaderException { return new Customer("sup dawg", "addr"); } @Override public void close() {} }); - CacheTransactionManager mgr = getGemfireCache().getTxManager(); + CacheTransactionManager mgr = getCache().getTxManager(); mgr.begin(); Region cust = getCache().getRegion(CUSTOMER); CustId custId = new CustId(6); @@ -809,22 +795,21 @@ public void close() {} mgr.commit(); Customer s2 = (Customer) cust.get(custId); Customer expectedCust = new Customer("sup dawg", "addr"); - assertEquals(s, expectedCust); - assertEquals(s2, expectedCust); + assertThat(s).isEqualTo(expectedCust); + assertThat(s2).isEqualTo(expectedCust); return null; } }); - accessor.invoke(new SerializableCallable() { + accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { return null; } }); } - @Test public void testTXPut() { Host host = Host.getHost(0); @@ -835,37 +820,37 @@ public void testTXPut() { final TXId txId = (TXId) accessor.invoke(new DoOpsInTX(OP.PUT)); - datastore.invoke(new SerializableCallable() { + datastore.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - TXManagerImpl mgr = getGemfireCache().getTxManager(); - assertTrue(mgr.isHostedTxInProgress(txId)); + public Object call() { + TXManagerImpl mgr = getCache().getTxManager(); + assertThat(mgr.isHostedTxInProgress(txId)).isTrue(); TXStateProxy tx = mgr.getHostedTXState(txId); - assertEquals(3, tx.getRegions().size());// 2 buckets for the two puts we - // did in the accessor - // +1 for the dist_region + assertThat(tx.getRegions().size()).isEqualTo(3);// 2 buckets for the two puts we + // did in the accessor + // +1 for the dist_region for (InternalRegion r : tx.getRegions()) { - assertTrue(r instanceof BucketRegion || r instanceof DistributedRegion); + assertThat(r instanceof DistributedRegion).isTrue(); TXRegionState rs = tx.readRegion(r); for (Object key : rs.getEntryKeys()) { TXEntryState es = rs.readEntry(key); - assertNotNull(es.getValue(key, r, false)); - assertTrue(es.isDirty()); + assertThat(es.getValue(key, r, false)).isNotNull(); + assertThat(es.isDirty()).isTrue(); } } return null; } }); - accessor.invoke(new SerializableCallable() { + accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - TXManagerImpl mgr = getGemfireCache().getTxManager(); + public Object call() { + TXManagerImpl mgr = getCache().getTxManager(); mgr.resume(txId); - assertNotNull(mgr.getTXState()); + assertThat(mgr.getTXState()).isNotNull(); getCache().getLogger().fine("SWAP:accessorTXState:" + mgr.getTXState()); mgr.commit(); verifyAfterCommit(OP.PUT); - assertNull(mgr.getTXState()); + assertThat(mgr.getTXState()).isNull(); return null; } }); @@ -879,34 +864,33 @@ public void testTXInvalidate() { initAccessorAndDataStore(acc, datastore, 0); VM accessor = getVMForTransactions(acc, datastore); - final TXId txId = (TXId) accessor.invoke(new DoOpsInTX(OP.INVALIDATE)); - datastore.invoke(new SerializableCallable() { + datastore.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - TXManagerImpl mgr = getGemfireCache().getTxManager(); - assertTrue(mgr.isHostedTxInProgress(txId)); + public Object call() { + TXManagerImpl mgr = getCache().getTxManager(); + assertThat(mgr.isHostedTxInProgress(txId)).isTrue(); TXStateProxy tx = mgr.getHostedTXState(txId); - assertEquals(3, tx.getRegions().size());// 2 buckets for the two puts we + assertThat(tx.getRegions().size()).isEqualTo(3);// 2 buckets for the two puts we // did in the accessor // plus the dist. region for (InternalRegion r : tx.getRegions()) { - assertTrue(r instanceof BucketRegion || r instanceof DistributedRegion); + assertThat(r instanceof DistributedRegion).isTrue(); TXRegionState rs = tx.readRegion(r); for (Object key : rs.getEntryKeys()) { TXEntryState es = rs.readEntry(key); - assertNotNull(es.getValue(key, r, false)); - assertTrue(es.isDirty()); + assertThat(es.getValue(key, r, false)).isNotNull(); + assertThat(es.isDirty()).isTrue(); } } return null; } }); - accessor.invoke(new SerializableCallable() { + accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - CacheTransactionManager mgr = getGemfireCache().getTxManager(); + public Object call() { + CacheTransactionManager mgr = getCache().getTxManager(); mgr.resume(txId); mgr.commit(); verifyAfterCommit(OP.INVALIDATE); @@ -924,34 +908,33 @@ public void testTXDestroy() { initAccessorAndDataStore(acc, datastore, 0); VM accessor = getVMForTransactions(acc, datastore); - final TXId txId = (TXId) accessor.invoke(new DoOpsInTX(OP.DESTROY)); - datastore.invoke(new SerializableCallable() { + datastore.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - TXManagerImpl mgr = getGemfireCache().getTxManager(); - assertTrue(mgr.isHostedTxInProgress(txId)); + public Object call() { + TXManagerImpl mgr = getCache().getTxManager(); + assertThat(mgr.isHostedTxInProgress(txId)).isTrue(); TXStateProxy tx = mgr.getHostedTXState(txId); - assertEquals(3, tx.getRegions().size());// 2 buckets for the two puts we + assertThat(tx.getRegions().size()).isEqualTo(3);// 2 buckets for the two puts we // did in the accessor // plus the dist. region for (InternalRegion r : tx.getRegions()) { - assertTrue(r instanceof BucketRegion || r instanceof DistributedRegion); + assertThat(r instanceof DistributedRegion); TXRegionState rs = tx.readRegion(r); for (Object key : rs.getEntryKeys()) { TXEntryState es = rs.readEntry(key); - assertNull(es.getValue(key, r, false)); - assertTrue(es.isDirty()); + assertThat(es.getValue(key, r, false)).isNull(); + assertThat(es.isDirty()).isTrue(); } } return null; } }); - accessor.invoke(new SerializableCallable() { + accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - CacheTransactionManager mgr = getGemfireCache().getTxManager(); + public Object call() { + CacheTransactionManager mgr = getCache().getTxManager(); mgr.resume(txId); mgr.commit(); verifyAfterCommit(OP.DESTROY); @@ -970,35 +953,36 @@ public void testTxPutIfAbsent() { final CustId newCustId = new CustId(10); final Customer updateCust = new Customer("customer10", "address10"); - final TXId txId = (TXId) accessor.invoke(new SerializableCallable() { + final TXId txId = (TXId) accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - TXManagerImpl mgr = getGemfireCache().getTxManager(); + public Object call() { + TXManagerImpl mgr = getCache().getTxManager(); mgr.begin(); - Region cust = getGemfireCache().getRegion(CUSTOMER); - Region rr = getGemfireCache().getRegion(D_REFERENCE); + Region cust = getCache().getRegion(CUSTOMER); + Region rr = getCache().getRegion(D_REFERENCE); Customer expectedCust = new Customer("customer" + 1, "address" + 1); - getGemfireCache().getLogger().fine("SWAP:doingPutIfAbsent"); + getCache().getLogger().fine("SWAP:doingPutIfAbsent"); CustId oldCustId = new CustId(1); Customer old = cust.putIfAbsent(oldCustId, updateCust); - assertTrue("expected:" + expectedCust + " but was " + old, expectedCust.equals(old)); + assertThat(expectedCust).as("expected:" + expectedCust + " but was " + old) + .isEqualTo(old); // transaction should be bootstrapped old = rr.putIfAbsent(oldCustId, updateCust); - assertTrue("expected:" + expectedCust + " but was " + old, expectedCust.equals(old)); + assertThat(expectedCust).as("expected:" + expectedCust + " but was " + old).isEqualTo(old); // now a key that does not exist old = cust.putIfAbsent(newCustId, updateCust); - assertNull(old); + assertThat(old).isNull(); old = rr.putIfAbsent(newCustId, updateCust); - assertNull(old); - Region order = getGemfireCache().getRegion(ORDER); + assertThat(old).isNull(); + Region order = getCache().getRegion(ORDER); Order oldOrder = order.putIfAbsent(new OrderId(10, newCustId), new Order("order10")); - assertNull(old); - assertNull(oldOrder); - assertNotNull(cust.get(newCustId)); - assertNotNull(rr.get(newCustId)); + assertThat(old).isNull(); + assertThat(oldOrder).isNull(); + assertThat(cust.get(newCustId)).isNotNull(); + assertThat(rr.get(newCustId)).isNotNull(); TXStateProxy tx = mgr.pauseTransaction(); - assertNull(cust.get(newCustId)); - assertNull(rr.get(newCustId)); + assertThat(cust.get(newCustId)).isNull(); + assertThat(rr.get(newCustId)).isNull(); mgr.unpauseTransaction(tx); cust.put(oldCustId, new Customer("foo", "bar")); rr.put(oldCustId, new Customer("foo", "bar")); @@ -1006,41 +990,40 @@ public Object call() throws Exception { } }); - datastore.invoke(new SerializableCallable() { + datastore.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - Region cust = getGemfireCache().getRegion(CUSTOMER); + public Object call() { + Region cust = getCache().getRegion(CUSTOMER); int hash1 = PartitionedRegionHelper.getHashKey((PartitionedRegion) cust, new CustId(1)); int hash10 = PartitionedRegionHelper.getHashKey((PartitionedRegion) cust, new CustId(10)); - TXManagerImpl mgr = getGemfireCache().getTxManager(); - assertTrue(mgr.isHostedTxInProgress(txId)); + TXManagerImpl mgr = getCache().getTxManager(); + assertThat(mgr.isHostedTxInProgress(txId)).isTrue(); TXStateProxy tx = mgr.getHostedTXState(txId); - assertEquals(3 + (hash1 == hash10 ? 0 : 1), tx.getRegions().size());// 2 buckets for the two - // puts we - // did in the accessor one dist. region, and one more bucket if Cust1 and Cust10 resolve to - // different buckets + assertThat(tx.getRegions().size()).isEqualTo(3 + (hash1 == hash10 ? 0 : 1));// 2 buckets for + // the two puts we did in the accessor one dist. region, and one more bucket if Cust1 and + // Cust10 resolve to different buckets for (InternalRegion r : tx.getRegions()) { - assertTrue(r instanceof BucketRegion || r instanceof DistributedRegion); + assertThat(r instanceof DistributedRegion).isTrue(); TXRegionState rs = tx.readRegion(r); for (Object key : rs.getEntryKeys()) { TXEntryState es = rs.readEntry(key); - assertNotNull(es.getValue(key, r, false)); - assertTrue("key:" + key + " r:" + r.getFullPath(), es.isDirty()); + assertThat(es.getValue(key, r, false)).isNotNull(); + assertThat(es.isDirty()).as("key:" + key + " r:" + r.getFullPath()).isTrue(); } } return null; } }); - accessor.invoke(new SerializableCallable() { + accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - TXManagerImpl mgr = getGemfireCache().getTxManager(); + public Object call() { + TXManagerImpl mgr = getCache().getTxManager(); mgr.resume(txId); mgr.commit(); - Region cust = getGemfireCache().getRegion(CUSTOMER); - Region rr = getGemfireCache().getRegion(D_REFERENCE); - assertEquals(updateCust, cust.get(newCustId)); - assertEquals(updateCust, rr.get(newCustId)); + Region cust = getCache().getRegion(CUSTOMER); + Region rr = getCache().getRegion(D_REFERENCE); + assertThat(updateCust).isEqualTo(cust.get(newCustId)); + assertThat(updateCust).isEqualTo(rr.get(newCustId)); // test conflict mgr.begin(); CustId conflictCust = new CustId(11); @@ -1048,11 +1031,7 @@ public Object call() throws Exception { TXStateProxy tx = mgr.pauseTransaction(); cust.put(conflictCust, new Customer("foo", "bar")); mgr.unpauseTransaction(tx); - try { - mgr.commit(); - fail("expected exception not thrown"); - } catch (CommitConflictException ignored) { - } + assertThatThrownBy(mgr::commit).isInstanceOf(CommitConflictException.class); return null; } }); @@ -1072,71 +1051,67 @@ public void testTxRemove() { VM accessor = getVMForTransactions(acc, datastore); final CustId custId = new CustId(1); - final TXId txId = (TXId) accessor.invoke(new SerializableCallable() { + final TXId txId = (TXId) accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - Region cust = getGemfireCache().getRegion(CUSTOMER); - Region ref = getGemfireCache().getRegion(D_REFERENCE); - TXManagerImpl mgr = getGemfireCache().getTxManager(); + public Object call() { + Region cust = getCache().getRegion(CUSTOMER); + Region ref = getCache().getRegion(D_REFERENCE); + TXManagerImpl mgr = getCache().getTxManager(); mgr.begin(); Customer customer = new Customer("customer1", "address1"); Customer fakeCust = new Customer("foo", "bar"); - assertFalse(cust.remove(custId, fakeCust)); - assertTrue(cust.remove(custId, customer)); - assertFalse(ref.remove(custId, fakeCust)); - assertTrue(ref.remove(custId, customer)); + assertThat(cust.remove(custId, fakeCust)).isFalse(); + assertThat(cust.remove(custId, customer)).isTrue(); + assertThat(ref.remove(custId, fakeCust)).isFalse(); + assertThat(ref.remove(custId, customer)).isTrue(); TXStateProxy tx = mgr.pauseTransaction(); - assertNotNull(cust.get(custId)); - assertNotNull(ref.get(custId)); + assertThat(cust.get(custId)).isNotNull(); + assertThat(ref.get(custId)).isNotNull(); mgr.unpauseTransaction(tx); return mgr.suspend(); } }); - datastore.invoke(new SerializableCallable() { + datastore.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - TXManagerImpl mgr = getGemfireCache().getTxManager(); - assertTrue(mgr.isHostedTxInProgress(txId)); + public Object call() { + TXManagerImpl mgr = getCache().getTxManager(); + assertThat(mgr.isHostedTxInProgress(txId)).isTrue(); TXStateProxy tx = mgr.getHostedTXState(txId); - assertEquals(2, tx.getRegions().size());// 2 buckets for the two puts we + assertThat(tx.getRegions().size()).isEqualTo(2);// 2 buckets for the two puts we // did in the accessor one dist. region, and one more bucket if Cust1 and Cust10 resolve to // different buckets for (InternalRegion r : tx.getRegions()) { - assertTrue(r instanceof BucketRegion || r instanceof DistributedRegion); + assertThat(r instanceof DistributedRegion).isTrue(); TXRegionState rs = tx.readRegion(r); for (Object key : rs.getEntryKeys()) { TXEntryState es = rs.readEntry(key); - assertNull(es.getValue(key, r, false)); - assertTrue("key:" + key + " r:" + r.getFullPath(), es.isDirty()); + assertThat(es.getValue(key, r, false)).isNull(); + assertThat(es.isDirty()).as("key:" + key + " r:" + r.getFullPath()).isTrue(); } } return null; } }); - accessor.invoke(new SerializableCallable() { + accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - TXManagerImpl mgr = getGemfireCache().getTxManager(); + public Object call() { + TXManagerImpl mgr = getCache().getTxManager(); mgr.resume(txId); mgr.commit(); - Region cust = getGemfireCache().getRegion(CUSTOMER); - Region rr = getGemfireCache().getRegion(D_REFERENCE); - assertNull(cust.get(custId)); - assertNull(rr.get(custId)); + Region cust = getCache().getRegion(CUSTOMER); + Region rr = getCache().getRegion(D_REFERENCE); + assertThat(cust.get(custId)).isNull(); + assertThat(rr.get(custId)).isNull(); // check conflict mgr.begin(); CustId conflictCust = new CustId(2); Customer customer = new Customer("customer2", "address2"); - getGemfireCache().getLogger().fine("SWAP:removeConflict"); - assertTrue(cust.remove(conflictCust, customer)); + getCache().getLogger().fine("SWAP:removeConflict"); + assertThat(cust.remove(conflictCust, customer)).isTrue(); TXStateProxy tx = mgr.pauseTransaction(); cust.put(conflictCust, new Customer("foo", "bar")); mgr.unpauseTransaction(tx); - try { - mgr.commit(); - fail("expected exception not thrown"); - } catch (CommitConflictException ignored) { - } + assertThatThrownBy(mgr::commit).isInstanceOf(CommitConflictException.class); return null; } }); @@ -1153,12 +1128,12 @@ public void testTxRemoveAll() { final CustId custId1 = new CustId(1); final CustId custId2 = new CustId(2); final CustId custId20 = new CustId(20); - final TXId txId = (TXId) accessor.invoke(new SerializableCallable() { + final TXId txId = (TXId) accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - Region cust = getGemfireCache().getRegion(CUSTOMER); - Region ref = getGemfireCache().getRegion(D_REFERENCE); - TXManagerImpl mgr = getGemfireCache().getTxManager(); + public Object call() { + Region cust = getCache().getRegion(CUSTOMER); + Region ref = getCache().getRegion(D_REFERENCE); + TXManagerImpl mgr = getCache().getTxManager(); mgr.begin(); Customer customer = new Customer("customer1", "address1"); Customer customer2 = new Customer("customer2", "address2"); @@ -1166,77 +1141,73 @@ public Object call() throws Exception { cust.removeAll(Arrays.asList(custId1, custId2, custId20)); ref.removeAll(Arrays.asList(custId1, custId2, custId20)); TXStateProxy tx = mgr.pauseTransaction(); - assertNotNull(cust.get(custId1)); - assertNotNull(ref.get(custId2)); + assertThat(cust.get(custId1)).isNotNull(); + assertThat(ref.get(custId2)).isNotNull(); mgr.unpauseTransaction(tx); return mgr.suspend(); } }); - datastore.invoke(new SerializableCallable() { + datastore.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - TXManagerImpl mgr = getGemfireCache().getTxManager(); - assertTrue(mgr.isHostedTxInProgress(txId)); + public Object call() { + TXManagerImpl mgr = getCache().getTxManager(); + assertThat(mgr.isHostedTxInProgress(txId)).isTrue(); TXStateProxy tx = mgr.getHostedTXState(txId); - assertEquals(4, tx.getRegions().size());// 2 buckets for the two puts we + assertThat(tx.getRegions().size()).isEqualTo(4);// 2 buckets for the two puts we // did in the accessor one dist. region, and one more bucket if Cust1 and Cust10 resolve to // different buckets for (InternalRegion r : tx.getRegions()) { - assertTrue(r instanceof BucketRegion || r instanceof DistributedRegion); + assertThat(r instanceof DistributedRegion).isTrue(); TXRegionState rs = tx.readRegion(r); for (Object key : rs.getEntryKeys()) { TXEntryState es = rs.readEntry(key); - assertNull(es.getValue(key, r, false)); + assertThat(es.getValue(key, r, false)).isNull(); // custId20 won't be dirty because it doesn't exist. - assertTrue("key:" + key + " r:" + r.getFullPath(), - key.equals(custId20) || es.isDirty()); + assertThat(key.equals(custId20) || es.isDirty()) + .as("key:" + key + " r:" + r.getFullPath()).isTrue(); } } return null; } }); - accessor.invoke(new SerializableCallable() { + accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - TXManagerImpl mgr = getGemfireCache().getTxManager(); + public Object call() { + TXManagerImpl mgr = getCache().getTxManager(); mgr.resume(txId); mgr.commit(); - Region cust = getGemfireCache().getRegion(CUSTOMER); - Region rr = getGemfireCache().getRegion(D_REFERENCE); - assertNull(cust.get(custId1)); - assertNull(rr.get(custId2)); + Region cust = getCache().getRegion(CUSTOMER); + Region rr = getCache().getRegion(D_REFERENCE); + assertThat(cust.get(custId1)).isNull(); + assertThat(rr.get(custId2)).isNull(); // check conflict mgr.begin(); CustId custId3 = new CustId(3); CustId custId4 = new CustId(4); - getGemfireCache().getLogger().fine("SWAP:removeConflict"); + getCache().getLogger().fine("SWAP:removeConflict"); cust.removeAll(Arrays.asList(custId3, custId20, custId4)); TXStateProxy tx = mgr.pauseTransaction(); // cust.put(custId3, new Customer("foo", "bar")); cust.put(custId20, new Customer("foo", "bar")); - assertNotNull(cust.get(custId20)); + assertThat(cust.get(custId20)).isNotNull(); cust.put(custId4, new Customer("foo", "bar")); mgr.unpauseTransaction(tx); - try { - mgr.commit(); - fail("expected exception not thrown"); - } catch (CommitConflictException ignored) { - } - assertNotNull(cust.get(custId3)); - assertNotNull(cust.get(custId4)); - assertNotNull(cust.get(custId20)); + assertThatThrownBy(mgr::commit).isInstanceOf(CommitConflictException.class); + assertThat(cust.get(custId3)).isNotNull(); + assertThat(cust.get(custId4)).isNotNull(); + assertThat(cust.get(custId20)).isNotNull(); // Test a removeall an already missing key. // custId2 has already been removed mgr.begin(); - getGemfireCache().getLogger().fine("SWAP:removeConflict"); + getCache().getLogger().fine("SWAP:removeConflict"); cust.removeAll(Arrays.asList(custId2, custId3)); tx = mgr.pauseTransaction(); cust.put(custId2, new Customer("foo", "bar")); mgr.unpauseTransaction(tx); mgr.commit(); - assertNotNull(cust.get(custId2)); - assertNull(cust.get(custId3)); + assertThat(cust.get(custId2)).isNotNull(); + assertThat(cust.get(custId3)).isNull(); return null; } }); @@ -1248,9 +1219,9 @@ public void testTxRemoveAllNotColocated() { VM acc = host.getVM(0); VM datastore1 = host.getVM(1); VM datastore2 = host.getVM(3); - datastore2.invoke(new SerializableCallable() { + datastore2.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { createRegion(false/* accessor */, 0, null); return null; } @@ -1264,27 +1235,25 @@ public Object call() throws Exception { final CustId custId3 = new CustId(3); final CustId custId4 = new CustId(4); final CustId custId20 = new CustId(20); - final TXId txId = (TXId) accessor.invoke(new SerializableCallable() { + final TXId txId = (TXId) accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - Region cust = getGemfireCache().getRegion(CUSTOMER); - Region ref = getGemfireCache().getRegion(D_REFERENCE); - TXManagerImpl mgr = getGemfireCache().getTxManager(); + public Object call() { + Region cust = getCache().getRegion(CUSTOMER); + Region ref = getCache().getRegion(D_REFERENCE); + TXManagerImpl mgr = getCache().getTxManager(); mgr.begin(); Customer customer = new Customer("customer1", "address1"); Customer customer2 = new Customer("customer2", "address2"); Customer fakeCust = new Customer("foo2", "bar2"); - try { - cust.removeAll(Arrays.asList(custId0, custId4, custId1, custId2, custId3, custId20)); - fail("expected exception not thrown"); - } catch (TransactionDataNotColocatedException e) { - mgr.rollback(); - } - assertNotNull(cust.get(custId0)); - assertNotNull(cust.get(custId1)); - assertNotNull(cust.get(custId2)); - assertNotNull(cust.get(custId3)); - assertNotNull(cust.get(custId4)); + assertThatThrownBy(() -> cust + .removeAll(Arrays.asList(custId0, custId4, custId1, custId2, custId3, custId20))) + .isInstanceOf(TransactionDataNotColocatedException.class); + mgr.rollback(); + assertThat(cust.get(custId0)).isNotNull(); + assertThat(cust.get(custId1)).isNotNull(); + assertThat(cust.get(custId2)).isNotNull(); + assertThat(cust.get(custId3)).isNotNull(); + assertThat(cust.get(custId4)).isNotNull(); return mgr.getTransactionId(); } }); @@ -1298,9 +1267,9 @@ public void testTxRemoveAllWithRedundancy() { VM datastore2 = host.getVM(3); // Create a second data store. - datastore2.invoke(new SerializableCallable() { + datastore2.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { createRegion(false/* accessor */, 1, null); return null; } @@ -1313,27 +1282,27 @@ public Object call() throws Exception { final CustId custId0 = new CustId(0); final CustId custId4 = new CustId(4); final CustId custId20 = new CustId(20); - final TXId txId = (TXId) accessor.invoke(new SerializableCallable() { + final TXId txId = (TXId) accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - Region cust = getGemfireCache().getRegion(CUSTOMER); - Region ref = getGemfireCache().getRegion(D_REFERENCE); - TXManagerImpl mgr = getGemfireCache().getTxManager(); + public Object call() { + Region cust = getCache().getRegion(CUSTOMER); + Region ref = getCache().getRegion(D_REFERENCE); + TXManagerImpl mgr = getCache().getTxManager(); mgr.begin(); cust.removeAll(Arrays.asList(custId0, custId4)); mgr.commit(); - assertNull(cust.get(custId0)); - assertNull(cust.get(custId4)); + assertThat(cust.get(custId0)).isNull(); + assertThat(cust.get(custId4)).isNull(); return mgr.getTransactionId(); } }); - SerializableCallable checkArtifacts = new SerializableCallable() { + SerializableCallable checkArtifacts = new SerializableCallable() { @Override - public Object call() throws Exception { - PartitionedRegion cust = (PartitionedRegion) getGemfireCache().getRegion(CUSTOMER); - assertNull(cust.get(custId0)); - assertNull(cust.get(custId4)); + public Object call() { + PartitionedRegion cust = (PartitionedRegion) getCache().getRegion(CUSTOMER); + assertThat(cust.get(custId0)).isNull(); + assertThat(cust.get(custId4)).isNull(); return null; } }; @@ -1351,71 +1320,68 @@ public void testTxReplace() { final CustId custId = new CustId(1); final Customer updatedCust = new Customer("updated", "updated"); - final TXId txId = (TXId) accessor.invoke(new SerializableCallable() { + final TXId txId = (TXId) accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - Region cust = getGemfireCache().getRegion(CUSTOMER); - Region ref = getGemfireCache().getRegion(D_REFERENCE); - TXManagerImpl mgr = getGemfireCache().getTxManager(); + public Object call() { + Region cust = getCache().getRegion(CUSTOMER); + Region ref = getCache().getRegion(D_REFERENCE); + TXManagerImpl mgr = getCache().getTxManager(); mgr.begin(); Customer customer = new Customer("customer1", "address1"); Customer fakeCust = new Customer("foo", "bar"); - assertFalse(cust.replace(custId, fakeCust, updatedCust)); - assertTrue(cust.replace(custId, customer, updatedCust)); - assertFalse(ref.replace(custId, fakeCust, updatedCust)); - assertTrue(ref.replace(custId, customer, updatedCust)); + assertThat(cust.replace(custId, fakeCust, updatedCust)).isFalse(); + assertThat(cust.replace(custId, customer, updatedCust)).isTrue(); + assertThat(ref.replace(custId, fakeCust, updatedCust)).isFalse(); + assertThat(ref.replace(custId, customer, updatedCust)).isTrue(); TXStateProxy tx = mgr.pauseTransaction(); - assertEquals(cust.get(custId), customer); - assertEquals(ref.get(custId), customer); + assertThat(cust.get(custId)).isEqualTo(customer); + assertThat(ref.get(custId)).isEqualTo(customer); mgr.unpauseTransaction(tx); return mgr.suspend(); } }); - datastore.invoke(new SerializableCallable() { + datastore.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - TXManagerImpl mgr = getGemfireCache().getTxManager(); - assertTrue(mgr.isHostedTxInProgress(txId)); + public Object call() { + TXManagerImpl mgr = getCache().getTxManager(); + assertThat(mgr.isHostedTxInProgress(txId)).isTrue(); TXStateProxy tx = mgr.getHostedTXState(txId); - assertEquals(2, tx.getRegions().size());// 2 buckets for the two puts we + assertThat(tx.getRegions().size()).isEqualTo(2);// 2 buckets for the two puts we // did in the accessor one dist. region, and one more bucket if Cust1 and Cust10 resolve to // different buckets for (InternalRegion r : tx.getRegions()) { - assertTrue(r instanceof BucketRegion || r instanceof DistributedRegion); + assertThat(r instanceof DistributedRegion).isTrue(); TXRegionState rs = tx.readRegion(r); for (Object key : rs.getEntryKeys()) { TXEntryState es = rs.readEntry(key); - assertNotNull(es.getValue(key, r, false)); - assertTrue("key:" + key + " r:" + r.getFullPath(), es.isDirty()); + assertThat(es.getValue(key, r, false)).isNotNull(); + assertThat(es.isDirty()).as("key:" + key + " r:" + r.getFullPath()).isTrue(); } } return null; } }); - accessor.invoke(new SerializableCallable() { + accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - TXManagerImpl mgr = getGemfireCache().getTxManager(); + public Object call() { + TXManagerImpl mgr = getCache().getTxManager(); mgr.resume(txId); mgr.commit(); - Region cust = getGemfireCache().getRegion(CUSTOMER); - Region rr = getGemfireCache().getRegion(D_REFERENCE); - assertEquals(updatedCust, cust.get(custId)); - assertEquals(updatedCust, rr.get(custId)); + Region cust = getCache().getRegion(CUSTOMER); + Region rr = getCache().getRegion(D_REFERENCE); + assertThat(updatedCust).isEqualTo(cust.get(custId)); + assertThat(updatedCust).isEqualTo(rr.get(custId)); // check conflict mgr.begin(); CustId conflictCust = new CustId(2); Customer customer = new Customer("customer2", "address2"); - getGemfireCache().getLogger().fine("SWAP:removeConflict"); - assertTrue(cust.replace(conflictCust, customer, new Customer("conflict", "conflict"))); + getCache().getLogger().fine("SWAP:removeConflict"); + assertThat(cust.replace(conflictCust, customer, new Customer("conflict", "conflict"))) + .isTrue(); TXStateProxy tx = mgr.pauseTransaction(); cust.put(conflictCust, new Customer("foo", "bar")); mgr.unpauseTransaction(tx); - try { - mgr.commit(); - fail("expected exception not thrown"); - } catch (CommitConflictException ignored) { - } + assertThatThrownBy(mgr::commit).isInstanceOf(CommitConflictException.class); return null; } }); @@ -1433,9 +1399,9 @@ public void testNonColocatedTX() { VM datastore1 = host.getVM(1); VM datastore2 = host.getVM(2); - datastore2.invoke(new SerializableCallable() { + datastore2.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { createRegion(false, 1, null); return null; } @@ -1443,27 +1409,22 @@ public Object call() throws Exception { initAccessorAndDataStore(accessor, datastore1, 1); - accessor.invoke(new SerializableCallable() { + accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region custRegion = getCache().getRegion(CUSTOMER); Region orderRegion = getCache().getRegion(ORDER); - CacheTransactionManager mgr = getGemfireCache().getTxManager(); + CacheTransactionManager mgr = getCache().getTxManager(); mgr.begin(); - try { - put10Entries(custRegion, orderRegion); - fail("Expected TransactionDataNotColocatedException not thrown"); - } catch (TransactionDataNotColocatedException ignored) { - } + assertThatThrownBy(() -> put10Entries(custRegion, orderRegion)) + .isInstanceOf(TransactionDataNotColocatedException.class); mgr.rollback(); put10Entries(custRegion, orderRegion); mgr.begin(); - try { - put10Entries(custRegion, orderRegion); - fail("Expected TransactionDataNotColocatedException not thrown"); - } catch (TransactionDataNotColocatedException ignored) { - } + + assertThatThrownBy(() -> put10Entries(custRegion, orderRegion)) + .isInstanceOf(TransactionDataNotColocatedException.class); mgr.rollback(); return null; } @@ -1508,9 +1469,9 @@ private void doTestListeners(final OP op) { initAccessorAndDataStore(acc, datastore, 0); VM accessor = getVMForTransactions(acc, datastore); - accessor.invoke(new SerializableCallable() { + accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region ref = getCache().getRegion(D_REFERENCE); ref.getAttributesMutator().addCacheListener(new TestCacheListener(true)); ref.getAttributesMutator().setCacheWriter(new TestCacheWriter(true)); @@ -1520,17 +1481,17 @@ public Object call() throws Exception { Region order = getCache().getRegion(ORDER); order.getAttributesMutator().addCacheListener(new TestCacheListener(true)); order.getAttributesMutator().setCacheWriter(new TestCacheWriter(true)); - getGemfireCache().getTxManager().addListener(new TestTxListener(true)); - if (!getGemfireCache().isClient()) { - getGemfireCache().getTxManager().setWriter(new TestTxWriter(true)); + getCache().getTxManager().addListener(new TestTxListener(true)); + if (!getCache().isClient()) { + getCache().getTxManager().setWriter(new TestTxWriter(true)); } return null; } }); - SerializableCallable addListenersToDataStore = new SerializableCallable() { + SerializableCallable addListenersToDataStore = new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region ref = getCache().getRegion(D_REFERENCE); ref.getAttributesMutator().addCacheListener(new TestCacheListener(false)); ref.getAttributesMutator().setCacheWriter(new TestCacheWriter(false)); @@ -1540,9 +1501,9 @@ public Object call() throws Exception { Region order = getCache().getRegion(ORDER); order.getAttributesMutator().addCacheListener(new TestCacheListener(false)); order.getAttributesMutator().setCacheWriter(new TestCacheWriter(false)); - getGemfireCache().getTxManager().addListener(new TestTxListener(false)); - if (!getGemfireCache().isClient()) { - getGemfireCache().getTxManager().setWriter(new TestTxWriter(false)); + getCache().getTxManager().addListener(new TestTxListener(false)); + if (!getCache().isClient()) { + getCache().getTxManager().setWriter(new TestTxWriter(false)); } return null; } @@ -1554,53 +1515,53 @@ public Object call() throws Exception { // Invalidate operations don't fire cache writers, so don't assert they were fired. if (op != OP.INVALIDATE) { // Ensure the cache writer was not fired in accessor - accessor.invoke(new SerializableCallable() { + accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region cust = getCache().getRegion(CUSTOMER); - assertFalse(((TestCacheWriter) cust.getAttributes().getCacheWriter()).wasFired); + assertThat(((TestCacheWriter) cust.getAttributes().getCacheWriter()).wasFired).isFalse(); Region order = getCache().getRegion(ORDER); - assertFalse(((TestCacheWriter) order.getAttributes().getCacheWriter()).wasFired); + assertThat(((TestCacheWriter) order.getAttributes().getCacheWriter()).wasFired).isFalse(); Region ref = getCache().getRegion(D_REFERENCE); - assertFalse(((TestCacheWriter) ref.getAttributes().getCacheWriter()).wasFired); + assertThat(((TestCacheWriter) ref.getAttributes().getCacheWriter()).wasFired).isFalse(); return null; } }); // Ensure the cache writer was fired in the primary - datastore.invoke(new SerializableCallable() { + datastore.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region cust = getCache().getRegion(CUSTOMER); - assertTrue(((TestCacheWriter) cust.getAttributes().getCacheWriter()).wasFired); + assertThat(((TestCacheWriter) cust.getAttributes().getCacheWriter()).wasFired).isTrue(); Region order = getCache().getRegion(ORDER); - assertTrue(((TestCacheWriter) order.getAttributes().getCacheWriter()).wasFired); + assertThat(((TestCacheWriter) order.getAttributes().getCacheWriter()).wasFired).isTrue(); Region ref = getCache().getRegion(D_REFERENCE); - assertTrue(((TestCacheWriter) ref.getAttributes().getCacheWriter()).wasFired); + assertThat(((TestCacheWriter) ref.getAttributes().getCacheWriter()).wasFired).isTrue(); return null; } }); } - accessor.invoke(new SerializableCallable() { + accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - CacheTransactionManager mgr = getGemfireCache().getTxManager(); + public Object call() { + CacheTransactionManager mgr = getCache().getTxManager(); mgr.resume(txId); mgr.commit(); return null; } }); - datastore.invoke(new SerializableCallable() { + datastore.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - TestTxListener l = (TestTxListener) getGemfireCache().getTxManager().getListener(); - assertTrue(l.isListenerInvoked()); + public Object call() { + TestTxListener l = (TestTxListener) getCache().getTxManager().getListener(); + assertThat(l.isListenerInvoked()).isTrue(); return null; } }); - SerializableCallable verifyListeners = new SerializableCallable() { + SerializableCallable verifyListeners = new SerializableCallable() { @Override public Object call() throws Exception { Region cust = getCache().getRegion(CUSTOMER); @@ -1609,18 +1570,18 @@ public Object call() throws Exception { throwListenerException(order); throwWriterException(cust); throwWriterException(order); - if (!getGemfireCache().isClient()) { + if (!getCache().isClient()) { throwTransactionCallbackException(); } return null; } private void throwTransactionCallbackException() throws Exception { - TestTxListener l = (TestTxListener) getGemfireCache().getTxManager().getListener(); + TestTxListener l = (TestTxListener) getCache().getTxManager().getListener(); if (l.ex != null) { throw l.ex; } - TestTxWriter w = (TestTxWriter) getGemfireCache().getTxManager().getWriter(); + TestTxWriter w = (TestTxWriter) getCache().getTxManager().getWriter(); if (w.ex != null) { throw w.ex; } @@ -1656,13 +1617,13 @@ private void throwWriterException(Region r) throws Exception { datastore.invoke(verifyListeners); } - abstract class CacheCallback { + abstract static class CacheCallback { protected boolean isAccessor; protected Exception ex = null; protected void verifyOrigin(EntryEvent event) { try { - assertEquals(!isAccessor, event.isOriginRemote()); + assertThat(!isAccessor).isEqualTo(event.isOriginRemote()); } catch (Exception e) { ex = e; } @@ -1673,8 +1634,8 @@ protected void verifyPutAll(EntryEvent event) { OrderId knownOrderId = new OrderId(2, knownCustId); if (event.getKey().equals(knownOrderId)) { try { - assertTrue(event.getOperation().isPutAll()); - assertNotNull(event.getTransactionId()); + assertThat(event.getOperation().isPutAll()).isTrue(); + assertThat(event.getTransactionId()).isNotNull(); } catch (Exception e) { ex = e; } @@ -1739,40 +1700,40 @@ class TestCacheWriter extends CacheCallback implements CacheWriter { @Override public void beforeCreate(EntryEvent event) throws CacheWriterException { - getGemfireCache().getLogger() + getCache().getLogger() .info("SWAP:beforeCreate:" + event + " op:" + event.getOperation()); verifyOrigin(event); verifyPutAll(event); - setFired(event); + setFired(); } - public void setFired(EntryEvent event) { + public void setFired() { wasFired = true; } @Override public void beforeUpdate(EntryEvent event) throws CacheWriterException { - getGemfireCache().getLogger() + getCache().getLogger() .info("SWAP:beforeCreate:" + event + " op:" + event.getOperation()); verifyOrigin(event); verifyPutAll(event); - setFired(event); + setFired(); } @Override public void beforeDestroy(EntryEvent event) throws CacheWriterException { verifyOrigin(event); - setFired(event); + setFired(); } @Override public void beforeRegionClear(RegionEvent event) throws CacheWriterException { - setFired(null); + setFired(); } @Override public void beforeRegionDestroy(RegionEvent event) throws CacheWriterException { - setFired(null); + setFired(); } @Override @@ -1792,7 +1753,7 @@ protected void verify(TransactionEvent txEvent) { private void verifyOrigin(CacheEvent event) { try { - assertEquals(true, event.isOriginRemote()); // change to !isAccessor after fixing #41498 + assertThat(event.isOriginRemote()).isTrue(); // change to !isAccessor after fixing #41498 } catch (Exception e) { ex = e; } @@ -1807,8 +1768,8 @@ private void verifyPutAll(CacheEvent p_event) { OrderId knownOrderId = new OrderId(2, knownCustId); if (event.getKey().equals(knownOrderId)) { try { - assertTrue(event.getOperation().isPutAll()); - assertNotNull(event.getTransactionId()); + assertThat(event.getOperation().isPutAll()).isTrue(); + assertThat(event.getTransactionId()).isNotNull(); } catch (Exception e) { ex = e; } @@ -1870,10 +1831,10 @@ public void testRemoteExceptionThrown() { initAccessorAndDataStore(acc, datastore, 0); VM accessor = getVMForTransactions(acc, datastore); - datastore.invoke(new SerializableCallable() { + datastore.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - getGemfireCache().getTxManager().setWriter(new TransactionWriter() { + public Object call() { + getCache().getTxManager().setWriter(new TransactionWriter() { @Override public void close() {} @@ -1886,18 +1847,14 @@ public void beforeCommit(TransactionEvent event) throws TransactionWriterExcepti } }); - accessor.invoke(new SerializableCallable() { + accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - getGemfireCache().getTxManager().begin(); + public Object call() { + getCache().getTxManager().begin(); Region r = getCache().getRegion(CUSTOMER); r.put(new CustId(8), new Customer("name8", "address8")); - try { - getGemfireCache().getTxManager().commit(); - fail("Expected exception not thrown"); - } catch (Exception e) { - assertEquals("AssertionError", e.getCause().getMessage()); - } + assertThatThrownBy(() -> getCache().getTxManager().commit()) + .isInstanceOf(CommitConflictException.class); return null; } }); @@ -1922,26 +1879,26 @@ private void doSizeTest(final boolean isAccessor) { VM taskVM = isAccessor ? accessor : datastore1; - final TXId txId = (TXId) taskVM.invoke(new SerializableCallable() { + final TXId txId = (TXId) taskVM.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region custRegion = getCache().getRegion(CUSTOMER); - TXManagerImpl mgr = getGemfireCache().getTxManager(); + TXManagerImpl mgr = getCache().getTxManager(); mgr.begin(); - assertEquals(5, custRegion.size()); - assertNotNull(mgr.getTXState()); + assertThat(custRegion.size()).isEqualTo(5); + assertThat(mgr.getTXState()).isNotNull(); return mgr.suspend(); } }); datastore1.invoke(verifyNoTxState); datastore2.invoke(verifyNoTxState); - taskVM.invoke(new SerializableCallable() { + taskVM.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region custRegion = getCache().getRegion(CUSTOMER); Region orderRegion = getCache().getRegion(ORDER); - TXManagerImpl mgr = getGemfireCache().getTxManager(); + TXManagerImpl mgr = getCache().getTxManager(); PartitionedRegion custPR = (PartitionedRegion) custRegion; int remoteKey = -1; for (int i = 100; i < 200; i++) { @@ -1955,26 +1912,26 @@ public Object call() throws Exception { throw new IllegalStateException("expected non-negative key"); } mgr.resume(txId); - assertNotNull(mgr.getTXState()); + assertThat(mgr.getTXState()).isNotNull(); CustId custId = new CustId(remoteKey); OrderId orderId = new OrderId(remoteKey, custId); custRegion.put(custId, new Customer("customer" + remoteKey, "address" + remoteKey)); getCache().getLogger() .info("Putting " + custId + ", keyInfo:" + custPR.getKeyInfo(new CustId(remoteKey))); orderRegion.put(orderId, new Order("order" + remoteKey)); - assertEquals(6, custRegion.size()); + assertThat(custRegion.size()).isEqualTo(6); mgr.suspend(); return null; } }); final Integer txOnDatastore1 = (Integer) datastore1.invoke(getNumberOfTXInProgress); final Integer txOnDatastore2 = (Integer) datastore2.invoke(getNumberOfTXInProgress); - assertEquals(1, txOnDatastore1 + txOnDatastore2); + assertThat(txOnDatastore1 + txOnDatastore2).isOne(); - taskVM.invoke(new SerializableCallable() { + taskVM.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - CacheTransactionManager mgr = getGemfireCache().getTxManager(); + public Object call() { + CacheTransactionManager mgr = getCache().getTxManager(); mgr.resume(txId); mgr.commit(); return null; @@ -1984,11 +1941,10 @@ public Object call() throws Exception { datastore1.invoke(verifyNoTxState); datastore2.invoke(verifyNoTxState); - final Integer txOnDatastore1_1 = (Integer) datastore1.invoke(getNumberOfTXInProgress); final Integer txOnDatastore2_2 = (Integer) datastore2.invoke(getNumberOfTXInProgress); - assertEquals(0, txOnDatastore1_1.intValue()); - assertEquals(0, txOnDatastore2_2.intValue()); + assertThat(txOnDatastore1_1.intValue()).isZero(); + assertThat(txOnDatastore2_2.intValue()).isZero(); } @Test @@ -2057,58 +2013,58 @@ private void doTestIterator(final OP iteratorType, final int redundancy, final O VM datastore2 = VM.getVM(2); initAccessorAndDataStore(accessor, datastore1, datastore2, redundancy); - final TXId txId = (TXId) accessor.invoke(new SerializableCallable() { + final TXId txId = (TXId) accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region custRegion = getCache().getRegion(CUSTOMER); Set originalSet; - TXManagerImpl mgr = getGemfireCache().getTxManager(); + TXManagerImpl mgr = getCache().getTxManager(); mgr.begin(); switch (iteratorType) { case KEYS: originalSet = getCustIdSet(5); - assertTrue(originalSet.containsAll(custRegion.keySet())); - assertEquals(5, custRegion.keySet().size()); + assertThat(originalSet.containsAll(custRegion.keySet())).isTrue(); + assertThat(custRegion.keySet().size()).isEqualTo(5); break; case VALUES: originalSet = getCustomerSet(5); - assertTrue(originalSet.containsAll(custRegion.values())); - assertEquals(5, custRegion.values().size()); + assertThat(originalSet.containsAll(custRegion.values())).isTrue(); + assertThat(custRegion.values().size()).isEqualTo(5); break; case ENTRIES: - Set originalKeySet = getCustIdSet(5); - Set originalValueSet = getCustomerSet(5); - Set entrySet = new HashSet(); + Set originalKeySet = getCustIdSet(5); + Set originalValueSet = getCustomerSet(5); + Set entrySet = new HashSet(); Region.Entry entry; for (final Object value : custRegion.entrySet()) { entrySet.add(value); } for (final Object o : entrySet) { entry = (Entry) o; - assertTrue(originalKeySet.contains(entry.getKey())); - assertTrue(originalValueSet.contains(entry.getValue())); + assertThat(originalKeySet.contains(entry.getKey())).isTrue(); + assertThat(originalValueSet.contains(entry.getValue())).isTrue(); } - assertEquals(5, custRegion.entrySet().size()); + assertThat(custRegion.entrySet().size()).isEqualTo(5); break; default: throw new IllegalArgumentException(); } - assertNotNull(mgr.getTXState()); + assertThat(mgr.getTXState()).isNotNull(); return mgr.suspend(); } }); datastore1.invoke(verifyNoTxState); datastore2.invoke(verifyNoTxState); - accessor.invoke(new SerializableCallable() { + accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region custRegion = getCache().getRegion(CUSTOMER); Region orderRegion = getCache().getRegion(ORDER); - TXManagerImpl mgr = getGemfireCache().getTxManager(); + TXManagerImpl mgr = getCache().getTxManager(); mgr.resume(txId); - assertNotNull(mgr.getTXState()); + assertThat(mgr.getTXState()).isNotNull(); int expectedSetSize = 0; switch (op) { case PUT: @@ -2129,17 +2085,14 @@ public Object call() throws Exception { throw new IllegalStateException(); } - Set expectedSet; switch (iteratorType) { case KEYS: - expectedSet = getCustIdSet(expectedSetSize); - assertTrue(expectedSet.containsAll(custRegion.keySet())); - assertEquals(expectedSetSize, custRegion.keySet().size()); + assertThat(getCustIdSet(expectedSetSize).containsAll(custRegion.keySet())).isTrue(); + assertThat(expectedSetSize).isEqualTo(custRegion.keySet().size()); break; case VALUES: - expectedSet = getCustomerSet(expectedSetSize); - assertTrue(expectedSet.containsAll(custRegion.values())); - assertEquals(expectedSetSize, custRegion.values().size()); + assertThat(getCustomerSet(expectedSetSize).containsAll(custRegion.values())).isTrue(); + assertThat(expectedSetSize).isEqualTo(custRegion.values().size()); break; case ENTRIES: Set originalKeySet = getCustIdSet(expectedSetSize); @@ -2151,10 +2104,10 @@ public Object call() throws Exception { } for (final Object o : entrySet) { entry = (Entry) o; - assertTrue(originalKeySet.contains(entry.getKey())); - assertTrue(originalValueSet.contains(entry.getValue())); + assertThat(originalKeySet.contains(entry.getKey())).isTrue(); + assertThat(originalValueSet.contains(entry.getValue())).isTrue(); } - assertEquals(expectedSetSize, custRegion.entrySet().size()); + assertThat(expectedSetSize).isEqualTo(custRegion.entrySet().size()); break; default: throw new IllegalArgumentException(); @@ -2165,12 +2118,12 @@ public Object call() throws Exception { }); final Integer txOnDatastore1 = (Integer) datastore1.invoke(getNumberOfTXInProgress); final Integer txOnDatastore2 = (Integer) datastore2.invoke(getNumberOfTXInProgress); - assertEquals(1, txOnDatastore1 + txOnDatastore2); + assertThat(txOnDatastore1 + txOnDatastore2).isOne(); - accessor.invoke(new SerializableCallable() { + accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - CacheTransactionManager mgr = getGemfireCache().getTxManager(); + public Object call() { + CacheTransactionManager mgr = getCache().getTxManager(); mgr.resume(txId); mgr.commit(); return null; @@ -2178,9 +2131,9 @@ public Object call() throws Exception { }); final Integer txOnDatastore1_1 = (Integer) datastore1.invoke(getNumberOfTXInProgress); final Integer txOnDatastore2_2 = (Integer) datastore2.invoke(getNumberOfTXInProgress); - assertEquals(0, txOnDatastore1_1 + txOnDatastore2_2); + assertThat(txOnDatastore1_1 + txOnDatastore2_2).isZero(); - datastore1.invoke(new SerializableCallable() { + datastore1.invoke(new SerializableCallable() { CustId custId; Customer customer; PartitionedRegion custRegion; @@ -2188,22 +2141,22 @@ public Object call() throws Exception { int expectedSetSize; @Override - public Object call() throws Exception { - TXManagerImpl mgr = getGemfireCache().getTXMgr(); - custRegion = (PartitionedRegion) getGemfireCache().getRegion(CUSTOMER); + public Object call() { + TXManagerImpl mgr = getCache().getTXMgr(); + custRegion = (PartitionedRegion) getCache().getRegion(CUSTOMER); mgr.begin(); doLocalOp(); Set expectedSet; switch (iteratorType) { case KEYS: expectedSet = getExpectedCustIdSet(); - assertEquals(expectedSet, custRegion.keySet()); - assertEquals(expectedSetSize, custRegion.keySet().size()); + assertThat(expectedSet).isEqualTo(custRegion.keySet()); + assertThat(expectedSetSize).isEqualTo(custRegion.keySet().size()); break; case VALUES: expectedSet = getExpectedCustomerSet(); - assertEquals(expectedSet, custRegion.values()); - assertEquals(expectedSetSize, custRegion.values().size()); + assertThat(expectedSet).isEqualTo(custRegion.values()); + assertThat(expectedSetSize).isEqualTo(custRegion.values().size()); break; case ENTRIES: Set originalKeySet = getExpectedCustIdSet(); @@ -2215,10 +2168,10 @@ public Object call() throws Exception { } for (final Object o : entrySet) { entry = (Entry) o; - assertTrue(originalKeySet.contains(entry.getKey())); - assertTrue(originalValueSet.contains(entry.getValue())); + assertThat(originalKeySet.contains(entry.getKey())).isTrue(); + assertThat(originalValueSet.contains(entry.getValue())).isTrue(); } - assertEquals(expectedSetSize, custRegion.entrySet().size()); + assertThat(expectedSetSize).isEqualTo(custRegion.entrySet().size()); break; default: throw new IllegalArgumentException(); @@ -2235,7 +2188,7 @@ private void doLocalOp() { customer = new Customer("customer" + i, "address" + i); int bucketId = PartitionedRegionHelper.getHashKey(custRegion, custId); InternalDistributedMember primary = custRegion.getBucketPrimary(bucketId); - if (primary.equals(getGemfireCache().getMyId())) { + if (primary.equals(getCache().getMyId())) { custRegion.put(custId, customer); break; } @@ -2249,7 +2202,7 @@ private void doLocalOp() { customer = new Customer("customer" + i, "address" + i); int bucketId = PartitionedRegionHelper.getHashKey(custRegion, custId); InternalDistributedMember primary = custRegion.getBucketPrimary(bucketId); - if (primary.equals(getGemfireCache().getMyId())) { + if (primary.equals(getCache().getMyId())) { custRegion.destroy(custId); break; } @@ -2303,12 +2256,12 @@ public void testKeyIterationOnRR() { VM datastore2 = host.getVM(2); initAccessorAndDataStore(accessor, datastore1, datastore2, 0); - accessor.invoke(new SerializableCallable() { + accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - Region custRegion = getGemfireCache().getRegion(CUSTOMER); - Region rr = getGemfireCache().getRegion(D_REFERENCE); - TXManagerImpl mgr = getGemfireCache().getTxManager(); + public Object call() { + Region custRegion = getCache().getRegion(CUSTOMER); + Region rr = getCache().getRegion(D_REFERENCE); + TXManagerImpl mgr = getCache().getTxManager(); mgr.begin(); CustId custId = new CustId(5); Customer customer = new Customer("customer5", "address5"); @@ -2320,25 +2273,25 @@ public Object call() throws Exception { i++; it.next(); } - assertEquals(5, i); - assertTrue(getCustIdSet(5).equals(set)); - assertEquals(5, rr.keySet().size()); + assertThat(i).isEqualTo(5); + assertThat(getCustIdSet(5)).isEqualTo(set); + assertThat(rr.keySet().size()).isEqualTo(5); rr.put(custId, customer); set = rr.keySet(); - assertTrue(getCustIdSet(6).equals(set)); + assertThat(getCustIdSet(6)).isEqualTo(set); it = set.iterator(); i = 0; while (it.hasNext()) { i++; it.next(); } - assertEquals(6, i); - assertEquals(6, rr.keySet().size()); - assertNotNull(rr.get(custId)); + assertThat(i).isEqualTo(6); + assertThat(rr.keySet().size()).isEqualTo(6); + assertThat(rr.get(custId)).isNotNull(); TXStateProxy tx = mgr.pauseTransaction(); - assertEquals(getCustIdSet(5), rr.keySet()); - assertEquals(5, rr.keySet().size()); - assertNull(rr.get(custId)); + assertThat(getCustIdSet(5)).isEqualTo(rr.keySet()); + assertThat(rr.keySet().size()).isEqualTo(5); + assertThat(rr.get(custId)).isNull(); mgr.unpauseTransaction(tx); mgr.commit(); return null; @@ -2354,12 +2307,12 @@ public void testValuesIterationOnRR() { VM datastore2 = host.getVM(2); initAccessorAndDataStore(accessor, datastore1, datastore2, 0); - accessor.invoke(new SerializableCallable() { + accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - Region custRegion = getGemfireCache().getRegion(CUSTOMER); - Region rr = getGemfireCache().getRegion(D_REFERENCE); - TXManagerImpl mgr = getGemfireCache().getTxManager(); + public Object call() { + Region custRegion = getCache().getRegion(CUSTOMER); + Region rr = getCache().getRegion(D_REFERENCE); + TXManagerImpl mgr = getCache().getTxManager(); mgr.begin(); CustId custId = new CustId(5); Customer customer = new Customer("customer5", "address5"); @@ -2371,25 +2324,25 @@ public Object call() throws Exception { i++; it.next(); } - assertEquals(5, i); - assertTrue(getCustomerSet(5).equals(set)); - assertEquals(5, rr.values().size()); + assertThat(i).isEqualTo(5); + assertThat(getCustomerSet(5)).isEqualTo(set); + assertThat(rr.values().size()).isEqualTo(5); rr.put(custId, customer); set = (Set) rr.values(); - assertTrue(getCustomerSet(6).equals(set)); + assertThat(getCustomerSet(6)).isEqualTo(set); it = set.iterator(); i = 0; while (it.hasNext()) { i++; it.next(); } - assertEquals(6, i); - assertEquals(6, rr.values().size()); - assertNotNull(rr.get(custId)); + assertThat(i).isEqualTo(6); + assertThat(rr.values().size()).isEqualTo(6); + assertThat(rr.get(custId)).isNotNull(); TXStateProxy tx = mgr.pauseTransaction(); - assertEquals(getCustomerSet(5), rr.values()); - assertEquals(5, rr.values().size()); - assertNull(rr.get(custId)); + assertThat(getCustomerSet(5)).isEqualTo(rr.values()); + assertThat(rr.values().size()).isEqualTo(5); + assertThat(rr.get(custId)).isNull(); mgr.unpauseTransaction(tx); mgr.commit(); return null; @@ -2405,12 +2358,12 @@ public void testEntriesIterationOnRR() { VM datastore2 = host.getVM(2); initAccessorAndDataStore(accessor, datastore1, datastore2, 0); - accessor.invoke(new SerializableCallable() { + accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - Region custRegion = getGemfireCache().getRegion(CUSTOMER); - Region rr = getGemfireCache().getRegion(D_REFERENCE); - TXManagerImpl mgr = getGemfireCache().getTxManager(); + public Object call() { + Region custRegion = getCache().getRegion(CUSTOMER); + Region rr = getCache().getRegion(D_REFERENCE); + TXManagerImpl mgr = getCache().getTxManager(); mgr.begin(); CustId custId = new CustId(5); Customer customer = new Customer("customer5", "address5"); @@ -2422,25 +2375,25 @@ public Object call() throws Exception { i++; it.next(); } - assertEquals(5, i); - // assertTrue(getCustIdSet(5).equals(set)); - assertEquals(5, rr.entrySet().size()); + assertThat(i).isEqualTo(5); + // assertThat(getCustIdSet(5).equals(set)).isTrue(); + assertThat(rr.entrySet().size()).isEqualTo(5); rr.put(custId, customer); set = rr.entrySet(); - // assertTrue(getCustIdSet(6).equals(set)); + // assertThat(getCustIdSet(6).equals(set)).isTrue(); it = set.iterator(); i = 0; while (it.hasNext()) { i++; it.next(); } - assertEquals(6, i); - assertEquals(6, rr.entrySet().size()); - assertNotNull(rr.get(custId)); + assertThat(i).isEqualTo(6); + assertThat(rr.entrySet().size()).isEqualTo(6); + assertThat(rr.get(custId)).isNotNull(); TXStateProxy tx = mgr.pauseTransaction(); // assertIndexDetailsEquals(getCustIdSet(5), rr.entrySet()); - assertEquals(5, rr.entrySet().size()); - assertNull(rr.get(custId)); + assertThat(rr.entrySet().size()).isEqualTo(5); + assertThat(rr.get(custId)).isNull(); mgr.unpauseTransaction(tx); mgr.commit(); return null; @@ -2456,52 +2409,23 @@ public void testIllegalIteration() { VM datastore2 = host.getVM(2); initAccessorAndDataStore(accessor, datastore1, datastore2, 0); - SerializableCallable doIllegalIteration = new SerializableCallable() { + SerializableCallable doIllegalIteration = new SerializableCallable() { @Override - public Object call() throws Exception { - Region r = getGemfireCache().getRegion(CUSTOMER); + public Object call() { + Region r = getCache().getRegion(CUSTOMER); Set keySet = r.keySet(); Set entrySet = r.entrySet(); Set valueSet = (Set) r.values(); - CacheTransactionManager mgr = getGemfireCache().getTXMgr(); + CacheTransactionManager mgr = getCache().getTXMgr(); mgr.begin(); // now we allow for using non-TX iterators in TX context - try { - keySet.size(); - fail("Expected exception not thrown"); - } catch (IllegalStateException expected) { - // ignore - } - try { - entrySet.size(); - fail("Expected exception not thrown"); - } catch (IllegalStateException expected) { - // ignore - } - try { - valueSet.size(); - fail("Expected exception not thrown"); - } catch (IllegalStateException expected) { - // ignore - } - try { - keySet.iterator(); - fail("Expected exception not thrown"); - } catch (IllegalStateException expected) { - // ignore - } - try { - entrySet.iterator(); - fail("Expected exception not thrown"); - } catch (IllegalStateException expected) { - // ignore - } - try { - valueSet.iterator(); - fail("Expected exception not thrown"); - } catch (IllegalStateException expected) { - // ignore - } + assertThatThrownBy(keySet::size).isInstanceOf(IllegalStateException.class); + assertThatThrownBy(entrySet::size).isInstanceOf(IllegalStateException.class); + assertThatThrownBy(valueSet::size).isInstanceOf(IllegalStateException.class); + + assertThatThrownBy(keySet::iterator).isInstanceOf(IllegalStateException.class); + assertThatThrownBy(entrySet::iterator).isInstanceOf(IllegalStateException.class); + assertThatThrownBy(valueSet::iterator).isInstanceOf(IllegalStateException.class); // TX iterators keySet = r.keySet(); @@ -2509,42 +2433,14 @@ public Object call() throws Exception { valueSet = (Set) r.values(); mgr.commit(); // don't allow for TX iterator after TX has committed - try { - keySet.size(); - fail("Expected exception not thrown"); - } catch (IllegalStateException expected) { - // ignore - } - try { - entrySet.size(); - fail("Expected exception not thrown"); - } catch (IllegalStateException expected) { - // ignore - } - try { - valueSet.size(); - fail("Expected exception not thrown"); - } catch (IllegalStateException expected) { - // ignore - } - try { - keySet.iterator(); - fail("Expected exception not thrown"); - } catch (IllegalStateException expected) { - // ignore - } - try { - entrySet.iterator(); - fail("Expected exception not thrown"); - } catch (IllegalStateException expected) { - // ignore - } - try { - valueSet.iterator(); - fail("Expected exception not thrown"); - } catch (IllegalStateException expected) { - // ignore - } + assertThatThrownBy(keySet::size).isInstanceOf(IllegalStateException.class); + assertThatThrownBy(entrySet::size).isInstanceOf(IllegalStateException.class); + assertThatThrownBy(valueSet::size).isInstanceOf(IllegalStateException.class); + + assertThatThrownBy(keySet::iterator).isInstanceOf(IllegalStateException.class); + assertThatThrownBy(entrySet::iterator).isInstanceOf(IllegalStateException.class); + assertThatThrownBy(valueSet::iterator).isInstanceOf(IllegalStateException.class); + return null; } }; @@ -2561,9 +2457,8 @@ class TXFunction implements Function { @Override public void execute(FunctionContext context) { - Region r = null; - r = getGemfireCache().getRegion(CUSTOMER); - getGemfireCache().getLogger().fine("SWAP:callingPut"); + Region r = getCache().getRegion(CUSTOMER); + getCache().getLogger().fine("SWAP:callingPut"); r.put(expectedCustId, expectedCustomer); GemFireCacheImpl.getInstance().getLogger().warning(" XXX DOIN A PUT ", new Exception()); context.getResultSender().lastResult(Boolean.TRUE); @@ -2611,9 +2506,9 @@ private void doTestTxFunction(final Executions e) { VM datastore2 = host.getVM(2); initAccessorAndDataStore(accessor, datastore1, datastore2, 0); - SerializableCallable registerFunction = new SerializableCallable() { + SerializableCallable registerFunction = new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { FunctionService.registerFunction(new TXFunction()); return null; } @@ -2623,16 +2518,16 @@ public Object call() throws Exception { datastore1.invoke(registerFunction); datastore2.invoke(registerFunction); - TXId txId = (TXId) accessor.invoke(new SerializableCallable() { + TXId txId = (TXId) accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - PartitionedRegion custRegion = (PartitionedRegion) getGemfireCache().getRegion(CUSTOMER); - TXManagerImpl mgr = getGemfireCache().getTXMgr(); + public Object call() { + PartitionedRegion custRegion = (PartitionedRegion) getCache().getRegion(CUSTOMER); + TXManagerImpl mgr = getCache().getTXMgr(); Set regions = new HashSet(); regions.add(custRegion); - regions.add(getGemfireCache().getRegion(ORDER)); + regions.add(getCache().getRegion(ORDER)); mgr.begin(); - try { + assertThatThrownBy(() -> { switch (e) { case OnRegion: FunctionService.onRegion(custRegion).execute(TXFunction.id).getResult(); @@ -2641,14 +2536,11 @@ public Object call() throws Exception { FunctionService.onMembers().execute(TXFunction.id).getResult(); break; } - fail("Expected exception not thrown"); - } catch (TransactionException ignored) { - } - try { - InternalFunctionService.onRegions(regions).execute(TXFunction.id).getResult(); - fail("Expected exception not thrown"); - } catch (TransactionException ignored) { - } + }).isInstanceOf(TransactionException.class); + + assertThatThrownBy( + () -> InternalFunctionService.onRegions(regions).execute(TXFunction.id).getResult()) + .isInstanceOf(TransactionException.class); Set filter = new HashSet(); filter.add(expectedCustId); switch (e) { @@ -2664,7 +2556,7 @@ public Object call() throws Exception { } TXStateProxy tx = mgr.pauseTransaction(); GemFireCacheImpl.getInstance().getLogger().warning("TX SUSPENDO:" + tx); - assertNull(custRegion.get(expectedCustId)); + assertThat(custRegion.get(expectedCustId)).isNull(); mgr.unpauseTransaction(tx); return mgr.suspend(); } @@ -2672,33 +2564,33 @@ public Object call() throws Exception { final Integer txOnDatastore1 = (Integer) datastore1.invoke(getNumberOfTXInProgress); final Integer txOnDatastore2 = (Integer) datastore2.invoke(getNumberOfTXInProgress); - assertEquals(1, txOnDatastore1 + txOnDatastore2); + assertThat(txOnDatastore1 + txOnDatastore2).isOne(); - accessor.invoke(new SerializableCallable() { + accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - CacheTransactionManager mgr = getGemfireCache().getTXMgr(); + public Object call() { + CacheTransactionManager mgr = getCache().getTXMgr(); mgr.resume(txId); mgr.commit(); return null; } }); - datastore1.invoke(new SerializableCallable() { + datastore1.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - Region custRegion = getGemfireCache().getRegion(CUSTOMER); - assertEquals(expectedCustomer, custRegion.get(expectedCustId)); + public Object call() { + Region custRegion = getCache().getRegion(CUSTOMER); + assertThat(expectedCustomer).isEqualTo(custRegion.get(expectedCustId)); return null; } }); - accessor.invoke(new SerializableCallable() { + accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - TXManagerImpl mgr = getGemfireCache().getTXMgr(); + public Object call() { + TXManagerImpl mgr = getCache().getTXMgr(); mgr.begin(); - PartitionedRegion custRegion = (PartitionedRegion) getGemfireCache().getRegion(CUSTOMER); + PartitionedRegion custRegion = (PartitionedRegion) getCache().getRegion(CUSTOMER); Set filter = new HashSet(); filter.add(expectedCustId); switch (e) { @@ -2715,11 +2607,7 @@ public Object call() throws Exception { TXStateProxy tx = mgr.pauseTransaction(); custRegion.put(expectedCustId, new Customer("Cust6", "updated6")); mgr.unpauseTransaction(tx); - try { - mgr.commit(); - fail("expected commit conflict not thrown"); - } catch (CommitConflictException ignored) { - } + assertThatThrownBy(mgr::commit).isInstanceOf(CommitConflictException.class); return null; } }); @@ -2738,13 +2626,10 @@ class NestedTxFunction2 extends FunctionAdapter { @Override public void execute(FunctionContext context) { - TXManagerImpl mgr = getGemfireCache().getTxManager(); - assertNotNull(mgr.getTXState()); - try { - mgr.commit(); - fail("expected exceptio not thrown"); - } catch (UnsupportedOperationInTransactionException ignored) { - } + TXManagerImpl mgr = getCache().getTxManager(); + assertThat(mgr.getTXState()).isNotNull(); + assertThatThrownBy(mgr::commit) + .isInstanceOf(UnsupportedOperationInTransactionException.class); context.getResultSender().lastResult(Boolean.TRUE); } @@ -2762,17 +2647,17 @@ public void execute(FunctionContext context) { if (context instanceof RegionFunctionContext) { r = PartitionRegionHelper.getLocalDataForContext((RegionFunctionContext) context); } else { - r = getGemfireCache().getRegion(CUSTOMER); + r = getCache().getRegion(CUSTOMER); } - assertNotNull(getGemfireCache().getTxManager().getTXState()); - PartitionedRegion pr = (PartitionedRegion) getGemfireCache().getRegion(CUSTOMER); + assertThat(getCache().getTxManager().getTXState()).isNotNull(); + PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(CUSTOMER); Set filter = new HashSet(); filter.add(expectedCustId); LogWriterUtils.getLogWriter().info("SWAP:inside NestedTxFunc calling func2:"); r.put(expectedCustId, expectedCustomer); FunctionService.onRegion(pr).withFilter(filter).execute(new NestedTxFunction2()) .getResult(); - assertNotNull(getGemfireCache().getTxManager().getTXState()); + assertThat(getCache().getTxManager().getTXState()).isNotNull(); context.getResultSender().lastResult(Boolean.TRUE); } @@ -2787,19 +2672,18 @@ public String getId() { } } - - accessor.invoke(new SerializableCallable() { + accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - TXManagerImpl mgr = getGemfireCache().getTxManager(); - PartitionedRegion pr = (PartitionedRegion) getGemfireCache().getRegion(CUSTOMER); + public Object call() { + TXManagerImpl mgr = getCache().getTxManager(); + PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(CUSTOMER); mgr.begin(); Set filter = new HashSet(); filter.add(expectedCustId); FunctionService.onRegion(pr).withFilter(filter).execute(new NestedTxFunction()).getResult(); - assertNotNull(getGemfireCache().getTxManager().getTXState()); + assertThat(getCache().getTxManager().getTXState()).isNotNull(); mgr.commit(); - assertEquals(expectedCustomer, pr.get(expectedCustId)); + assertThat(expectedCustomer).isEqualTo(pr.get(expectedCustId)); return null; } }); @@ -2820,7 +2704,7 @@ public CreateDR(boolean isAccessor) { } @Override - public Object call() throws Exception { + public Object call() { AttributesFactory af = new AttributesFactory(); af.setDataPolicy(isAccessor ? DataPolicy.EMPTY : DataPolicy.REPLICATE); af.setScope(Scope.DISTRIBUTED_ACK); @@ -2842,9 +2726,9 @@ public Object call() throws Exception { datastore2.invoke(new CreateDR(false)); accessor.invoke(new CreateDR(true)); - SerializableCallable registerFunction = new SerializableCallable() { + SerializableCallable registerFunction = new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { FunctionService.registerFunction(new TXFunction()); return null; } @@ -2854,31 +2738,31 @@ public Object call() throws Exception { datastore1.invoke(registerFunction); datastore2.invoke(registerFunction); - accessor.invoke(new SerializableCallable() { + accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - Region custRegion = getGemfireCache().getRegion(CUSTOMER); - TXManagerImpl mgr = getGemfireCache().getTXMgr(); + public Object call() { + Region custRegion = getCache().getRegion(CUSTOMER); + TXManagerImpl mgr = getCache().getTXMgr(); mgr.begin(); FunctionService.onRegion(custRegion).execute(TXFunction.id).getResult(); - assertNotNull(mgr.getTXState()); + assertThat(mgr.getTXState()).isNotNull(); TXStateProxy tx = mgr.pauseTransaction(); - assertNull(mgr.getTXState()); - getGemfireCache().getLogger().fine("SWAP:callingget"); - assertNull("expected null but was:" + custRegion.get(expectedCustId), - custRegion.get(expectedCustId)); + assertThat(mgr.getTXState()).isNull(); + getCache().getLogger().fine("SWAP:callingget"); + assertThat(custRegion.get(expectedCustId)) + .as("expected null but was:" + custRegion.get(expectedCustId)).isNull(); mgr.unpauseTransaction(tx); mgr.commit(); - assertEquals(expectedCustomer, custRegion.get(expectedCustId)); + assertThat(expectedCustomer).isEqualTo(custRegion.get(expectedCustId)); return null; } }); - datastore1.invoke(new SerializableCallable() { + datastore1.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - final Region custRegion = getGemfireCache().getRegion(CUSTOMER); - TXManagerImpl mgr = getGemfireCache().getTXMgr(); + public Object call() { + final Region custRegion = getCache().getRegion(CUSTOMER); + TXManagerImpl mgr = getCache().getTXMgr(); mgr.begin(); FunctionService.onRegion(custRegion).execute(new FunctionAdapter() { @Override @@ -2888,16 +2772,16 @@ public String getId() { @Override public void execute(FunctionContext context) { - assertNotNull(getGemfireCache().getTxManager().getTXState()); + assertThat(getCache().getTxManager().getTXState()).isNotNull(); custRegion.destroy(expectedCustId); context.getResultSender().lastResult(Boolean.TRUE); } }).getResult(); TXStateProxy tx = mgr.pauseTransaction(); - assertEquals(custRegion.get(expectedCustId), expectedCustomer); + assertThat(custRegion.get(expectedCustId)).isEqualTo(expectedCustomer); mgr.unpauseTransaction(tx); mgr.commit(); - assertNull(custRegion.get(expectedCustId)); + assertThat(custRegion.get(expectedCustId)).isNull(); return null; } }); @@ -2911,9 +2795,9 @@ public void testTxFunctionWithOtherOps() { VM datastore2 = host.getVM(2); initAccessorAndDataStore(accessor, datastore1, datastore2, 0); - SerializableCallable registerFunction = new SerializableCallable() { + SerializableCallable registerFunction = new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { FunctionService.registerFunction(new TXFunction()); return null; } @@ -2923,23 +2807,21 @@ public Object call() throws Exception { datastore1.invoke(registerFunction); datastore2.invoke(registerFunction); - TXId txId = (TXId) accessor.invoke(new SerializableCallable() { + TXId txId = (TXId) accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - Region custRegion = getGemfireCache().getRegion(CUSTOMER); - TXManagerImpl mgr = getGemfireCache().getTXMgr(); + public Object call() { + Region custRegion = getCache().getRegion(CUSTOMER); + TXManagerImpl mgr = getCache().getTXMgr(); mgr.begin(); - try { - FunctionService.onRegion(custRegion).execute(TXFunction.id).getResult(); - fail("Expected exception not thrown"); - } catch (TransactionException ignored) { - } + assertThatThrownBy( + () -> FunctionService.onRegion(custRegion).execute(TXFunction.id).getResult()) + .isInstanceOf(TransactionException.class); Set filter = new HashSet(); filter.add(expectedCustId); FunctionService.onRegion(custRegion).withFilter(filter).execute(TXFunction.id).getResult(); - assertEquals(expectedCustomer, custRegion.get(expectedCustId)); + assertThat(expectedCustomer).isEqualTo(custRegion.get(expectedCustId)); TXStateProxy tx = mgr.pauseTransaction(); - assertNull(custRegion.get(expectedCustId)); + assertThat(custRegion.get(expectedCustId)).isNull(); mgr.unpauseTransaction(tx); return mgr.suspend(); } @@ -2947,98 +2829,97 @@ public Object call() throws Exception { final Integer txOnDatastore1 = (Integer) datastore1.invoke(getNumberOfTXInProgress); final Integer txOnDatastore2 = (Integer) datastore2.invoke(getNumberOfTXInProgress); - assertEquals(1, txOnDatastore1 + txOnDatastore2); + assertThat(txOnDatastore1 + txOnDatastore2).isOne(); - accessor.invoke(new SerializableCallable() { + accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - Region custRegion = getGemfireCache().getRegion(CUSTOMER); - CacheTransactionManager mgr = getGemfireCache().getTXMgr(); + public Object call() { + Region custRegion = getCache().getRegion(CUSTOMER); + CacheTransactionManager mgr = getCache().getTXMgr(); mgr.resume(txId); mgr.commit(); - assertEquals(expectedCustomer, custRegion.get(expectedCustId)); + assertThat(expectedCustomer).isEqualTo(custRegion.get(expectedCustId)); custRegion.destroy(expectedCustId); return null; } }); // test onMembers - SerializableCallable getMember = new SerializableCallable() { + SerializableCallable getMember = new SerializableCallable() { @Override - public Object call() throws Exception { - return getGemfireCache().getMyId(); + public Object call() { + return getCache().getMyId(); } }; final InternalDistributedMember ds1 = (InternalDistributedMember) datastore1.invoke(getMember); final InternalDistributedMember ds2 = (InternalDistributedMember) datastore2.invoke(getMember); - TXId txId2 = (TXId) accessor.invoke(new SerializableCallable() { + TXId txId2 = (TXId) accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - PartitionedRegion pr = (PartitionedRegion) getGemfireCache().getRegion(CUSTOMER); + public Object call() { + PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(CUSTOMER); // get owner for expectedKey DistributedMember owner = pr.getOwnerForKey(pr.getKeyInfo(expectedCustId)); // get key on datastore1 CustId keyOnOwner = null; keyOnOwner = getKeyOnMember(owner, pr); - TXManagerImpl mgr = getGemfireCache().getTXMgr(); + TXManagerImpl mgr = getCache().getTXMgr(); mgr.begin(); // bootstrap tx on owner pr.get(keyOnOwner); Set members = new HashSet<>(); members.add(ds1); members.add(ds2); - try { - FunctionService.onMembers(members).execute(TXFunction.id).getResult(); - fail("expected exception not thrown"); - } catch (TransactionException ignored) { - } + assertThatThrownBy( + () -> FunctionService.onMembers(members).execute(TXFunction.id).getResult()) + .isInstanceOf(TransactionException.class); FunctionService.onMember(owner).execute(TXFunction.id).getResult(); - assertEquals(expectedCustomer, pr.get(expectedCustId)); + assertThat(expectedCustomer).isEqualTo(pr.get(expectedCustId)); TXStateProxy tx = mgr.pauseTransaction(); - assertNull(pr.get(expectedCustId)); + assertThat(pr.get(expectedCustId)).isNull(); mgr.unpauseTransaction(tx); return mgr.suspend(); } }); final Integer txOnDatastore1_1 = (Integer) datastore1.invoke(getNumberOfTXInProgress); final Integer txOnDatastore2_1 = (Integer) datastore2.invoke(getNumberOfTXInProgress); - assertEquals(1, txOnDatastore1_1 + txOnDatastore2_1); + assertThat(txOnDatastore1_1 + txOnDatastore2_1).isOne(); - accessor.invoke(new SerializableCallable() { + accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - Region custRegion = getGemfireCache().getRegion(CUSTOMER); - CacheTransactionManager mgr = getGemfireCache().getTXMgr(); + public Object call() { + Region custRegion = getCache().getRegion(CUSTOMER); + CacheTransactionManager mgr = getCache().getTXMgr(); mgr.resume(txId2); mgr.commit(); - assertEquals(expectedCustomer, custRegion.get(expectedCustId)); + assertThat(expectedCustomer).isEqualTo(custRegion.get(expectedCustId)); custRegion.destroy(expectedCustId); return null; } }); // test function execution on data store - final DistributedMember owner = (DistributedMember) accessor.invoke(new SerializableCallable() { - @Override - public Object call() throws Exception { - PartitionedRegion pr = (PartitionedRegion) getGemfireCache().getRegion(CUSTOMER); - return pr.getOwnerForKey(pr.getKeyInfo(expectedCustId)); - } - }); + final DistributedMember owner = + (DistributedMember) accessor.invoke(new SerializableCallable() { + @Override + public Object call() { + PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(CUSTOMER); + return pr.getOwnerForKey(pr.getKeyInfo(expectedCustId)); + } + }); - SerializableCallable testFnOnDs = new SerializableCallable() { + SerializableCallable testFnOnDs = new SerializableCallable() { @Override - public Object call() throws Exception { - TXManagerImpl mgr = getGemfireCache().getTXMgr(); - PartitionedRegion pr = (PartitionedRegion) getGemfireCache().getRegion(CUSTOMER); + public Object call() { + TXManagerImpl mgr = getCache().getTXMgr(); + PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(CUSTOMER); CustId keyOnDs = getKeyOnMember(pr.getMyId(), pr); mgr.begin(); pr.get(keyOnDs); Set filter = new HashSet(); filter.add(keyOnDs); FunctionService.onRegion(pr).withFilter(filter).execute(TXFunction.id).getResult(); - assertEquals(expectedCustomer, pr.get(expectedCustId)); + assertThat(expectedCustomer).isEqualTo(pr.get(expectedCustId)); TXStateProxy tx = mgr.pauseTransaction(); - assertNull(pr.get(expectedCustId)); + assertThat(pr.get(expectedCustId)).isNull(); mgr.unpauseTransaction(tx); return mgr.suspend(); } @@ -3049,8 +2930,8 @@ public Object call() throws Exception { final Integer txOnDatastore1_2 = (Integer) datastore1.invoke(getNumberOfTXInProgress); final Integer txOnDatastore2_2 = (Integer) datastore2.invoke(getNumberOfTXInProgress); - assertEquals(0, txOnDatastore1_2 + txOnDatastore2_2);// ds1 has a local transaction, not - // remote + assertThat(txOnDatastore1_2 + txOnDatastore2_2).isZero();// ds1 has a local transaction, + // not remote CloseFnOnDsTx closeFnOnDsTx = new CloseFnOnDsTx(dsTxId); datastore1.invoke(closeFnOnDsTx); } else { @@ -3058,41 +2939,36 @@ public Object call() throws Exception { final Integer txOnDatastore1_2 = (Integer) datastore1.invoke(getNumberOfTXInProgress); final Integer txOnDatastore2_2 = (Integer) datastore2.invoke(getNumberOfTXInProgress); - assertEquals(0, txOnDatastore1_2 + txOnDatastore2_2);// ds1 has a local transaction, not - // remote + assertThat(txOnDatastore1_2 + txOnDatastore2_2).isZero();// ds1 has a local transaction, + // not remote CloseFnOnDsTx closeFnOnDsTx = new CloseFnOnDsTx(dsTxId); datastore2.invoke(closeFnOnDsTx); } // test that function is rejected if function target is not same as txState target - accessor.invoke(new SerializableCallable() { + accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - CacheTransactionManager mgr = getGemfireCache().getTXMgr(); - PartitionedRegion pr = (PartitionedRegion) getGemfireCache().getRegion(CUSTOMER); + public Object call() { + CacheTransactionManager mgr = getCache().getTXMgr(); + PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(CUSTOMER); CustId keyOnDs1 = getKeyOnMember(ds1, pr); CustId keyOnDs2 = getKeyOnMember(ds2, pr); mgr.begin(); pr.get(keyOnDs1);// bootstrap txState Set filter = new HashSet(); filter.add(keyOnDs2); - try { - FunctionService.onRegion(pr).withFilter(filter).execute(TXFunction.id).getResult(); - fail("expected Exception not thrown"); - } catch (TransactionDataRebalancedException ignored) { - } - try { - FunctionService.onMember(ds2).execute(TXFunction.id).getResult(); - fail("expected exception not thrown"); - } catch (TransactionDataNotColocatedException ignored) { - } + assertThatThrownBy(() -> FunctionService.onRegion(pr).withFilter(filter) + .execute(TXFunction.id).getResult()) + .isInstanceOf(TransactionDataRebalancedException.class); + assertThatThrownBy(() -> FunctionService.onMember(ds2).execute(TXFunction.id).getResult()) + .isInstanceOf(TransactionDataNotColocatedException.class); mgr.commit(); return null; } }); } - protected class CloseFnOnDsTx extends SerializableCallable { + protected class CloseFnOnDsTx extends SerializableCallable { private final TXId txId; @@ -3101,12 +2977,12 @@ protected class CloseFnOnDsTx extends SerializableCallable { } @Override - public Object call() throws Exception { - Region custRegion = getGemfireCache().getRegion(CUSTOMER); - CacheTransactionManager mgr = getGemfireCache().getTXMgr(); + public Object call() { + Region custRegion = getCache().getRegion(CUSTOMER); + CacheTransactionManager mgr = getCache().getTXMgr(); mgr.resume(txId); mgr.commit(); - assertEquals(expectedCustomer, custRegion.get(expectedCustId)); + assertThat(expectedCustomer).isEqualTo(custRegion.get(expectedCustId)); custRegion.destroy(expectedCustId); return null; } @@ -3161,39 +3037,39 @@ private void doRemoteJTA(final boolean isCommit) { initAccessorAndDataStore(acc, datastore, 0); VM accessor = getVMForTransactions(acc, datastore); - datastore.invoke(new SerializableCallable() { + datastore.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - getGemfireCache().getTxManager().addListener(new TestTxListener(false)); + public Object call() { + getCache().getTxManager().addListener(new TestTxListener(false)); return null; } }); final CustId expectedCustId = new CustId(6); final Customer expectedCustomer = new Customer("customer6", "address6"); - accessor.invoke(new SerializableCallable() { + accessor.invoke(new SerializableCallable() { @Override public Object call() throws Exception { - getGemfireCache().getTxManager().addListener(new TestTxListener(true)); + getCache().getTxManager().addListener(new TestTxListener(true)); Region custRegion = getCache().getRegion(CUSTOMER); Context ctx = getCache().getJNDIContext(); UserTransaction tx = (UserTransaction) ctx.lookup("java:/UserTransaction"); - assertEquals(Status.STATUS_NO_TRANSACTION, tx.getStatus()); + assertThat(Status.STATUS_NO_TRANSACTION).isEqualTo(tx.getStatus()); tx.begin(); - assertEquals(Status.STATUS_ACTIVE, tx.getStatus()); + assertThat(Status.STATUS_ACTIVE).isEqualTo(tx.getStatus()); custRegion.put(expectedCustId, expectedCustomer); - assertEquals(expectedCustomer, custRegion.get(expectedCustId)); + assertThat(expectedCustomer).isEqualTo(custRegion.get(expectedCustId)); return null; } }); - datastore.invoke(new SerializableCallable() { + datastore.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region custRegion = getCache().getRegion(CUSTOMER); - assertNull(custRegion.get(expectedCustId)); + assertThat(custRegion.get(expectedCustId)).isNull(); return null; } }); - accessor.invoke(new SerializableCallable() { + accessor.invoke(new SerializableCallable() { @Override public Object call() throws Exception { Region custRegion = getCache().getRegion(CUSTOMER); @@ -3201,19 +3077,19 @@ public Object call() throws Exception { UserTransaction tx = (UserTransaction) ctx.lookup("java:/UserTransaction"); if (isCommit) { tx.commit(); - assertEquals(expectedCustomer, custRegion.get(expectedCustId)); + assertThat(expectedCustomer).isEqualTo(custRegion.get(expectedCustId)); } else { tx.rollback(); - assertNull(custRegion.get(expectedCustId)); + assertThat(custRegion.get(expectedCustId)).isNull(); } return null; } }); - datastore.invoke(new SerializableCallable() { + datastore.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - TestTxListener l = (TestTxListener) getGemfireCache().getTXMgr().getListener(); - assertTrue(l.isListenerInvoked()); + public Object call() { + TestTxListener l = (TestTxListener) getCache().getTXMgr().getListener(); + assertThat(l.isListenerInvoked()).isTrue(); return null; } }); @@ -3242,7 +3118,7 @@ public void beforeCreate(EntryEvent event) throws CacheWriterException { @Override public void beforeDestroy(EntryEvent event) throws CacheWriterException { - getGemfireCache().getLogger().fine("SWAP:writer:createEvent:" + event); + getCache().getLogger().fine("SWAP:writer:createEvent:" + event); if (!event.isOriginRemote()) { throw new CacheWriterException("SUP?? This DESTROY is supposed to be isOriginRemote"); } @@ -3258,10 +3134,10 @@ public void beforeUpdate(EntryEvent event) throws CacheWriterException { } } - datastore.invoke(new SerializableCallable() { + datastore.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region refRegion = getCache().getRegion(D_REFERENCE); refRegion.getAttributesMutator().setCacheWriter(new OriginRemoteRRWriter()); return null; @@ -3271,13 +3147,13 @@ public Object call() throws Exception { TXId putTxId = (TXId) accessor.invoke(new DoOpsInTX(OP.PUT)); - accessor.invoke(new SerializableCallable() { + accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - TXManagerImpl mgr = getGemfireCache().getTxManager(); + public Object call() { + TXManagerImpl mgr = getCache().getTxManager(); mgr.resume(putTxId); TXStateProxy tx = mgr.pauseTransaction(); - assertNotNull(tx); + assertThat(tx).isNotNull(); mgr.unpauseTransaction(tx); mgr.commit(); return null; @@ -3286,13 +3162,13 @@ public Object call() throws Exception { TXId destroyTxId = (TXId) accessor.invoke(new DoOpsInTX(OP.DESTROY)); - accessor.invoke(new SerializableCallable() { + accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - TXManagerImpl mgr = getGemfireCache().getTxManager(); + public Object call() { + TXManagerImpl mgr = getCache().getTxManager(); mgr.resume(destroyTxId); TXStateProxy tx = mgr.pauseTransaction(); - assertNotNull(tx); + assertThat(tx).isNotNull(); mgr.unpauseTransaction(tx); mgr.commit(); return null; @@ -3301,35 +3177,34 @@ public Object call() throws Exception { TXId putTxId2 = (TXId) accessor.invoke(new DoOpsInTX(OP.PUT)); - accessor.invoke(new SerializableCallable() { + accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - TXManagerImpl mgr = getGemfireCache().getTxManager(); + public Object call() { + TXManagerImpl mgr = getCache().getTxManager(); mgr.resume(putTxId2); TXStateProxy tx = mgr.pauseTransaction(); - assertNotNull(tx); + assertThat(tx).isNotNull(); mgr.unpauseTransaction(tx); mgr.commit(); return null; } }); - datastore.invoke(new SerializableCallable() { + datastore.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region refRegion = getCache().getRegion(D_REFERENCE); OriginRemoteRRWriter w = (OriginRemoteRRWriter) refRegion.getAttributes().getCacheWriter(); - assertEquals(1, w.fireC); - assertEquals(1, w.fireD); - assertEquals(1, w.fireU); + assertThat(w.fireC).isOne(); + assertThat(w.fireD).isOne(); + assertThat(w.fireU).isOne(); return null; } }); } - @Test public void testRemoteCreateInReplicatedRegion() { Host host = Host.getHost(0); @@ -3339,35 +3214,35 @@ public void testRemoteCreateInReplicatedRegion() { TXId txId = (TXId) accessor.invoke(new DoOpsInTX(OP.PUT)); - accessor.invoke(new SerializableCallable() { + accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region refRegion = getCache().getRegion(D_REFERENCE); refRegion.create("sup", "dawg"); return null; } }); - accessor.invoke(new SerializableCallable() { + accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - TXManagerImpl mgr = getGemfireCache().getTxManager(); + public Object call() { + TXManagerImpl mgr = getCache().getTxManager(); mgr.resume(txId); TXStateProxy tx = mgr.pauseTransaction(); - assertNotNull(tx); + assertThat(tx).isNotNull(); mgr.unpauseTransaction(tx); mgr.commit(); return null; } }); - accessor.invoke(new SerializableCallable() { + accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region refRegion = getCache().getRegion(D_REFERENCE); - assertEquals("dawg", refRegion.get("sup")); + assertThat(refRegion.get("sup")).isEqualTo("dawg"); return null; } }); @@ -3380,9 +3255,9 @@ public void testRemoteTxCleanupOnCrash() { VM datastore = host.getVM(1); initAccessorAndDataStore(accessor, datastore, 0); - accessor.invoke(new SerializableCallable() { + accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region cust = getCache().getRegion(CUSTOMER); TXManagerImpl mgr = getCache().getTxManager(); mgr.begin(); @@ -3391,19 +3266,19 @@ public Object call() throws Exception { } }); final InternalDistributedMember member = - (InternalDistributedMember) accessor.invoke(new SerializableCallable() { + (InternalDistributedMember) accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { return getCache().getMyId(); } }); - datastore.invoke(new SerializableCallable() { + datastore.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { TXManagerImpl mgr = getCache().getTxManager(); - assertEquals(1, mgr.hostedTransactionsInProgressForTest()); + assertThat(mgr.hostedTransactionsInProgressForTest()).isOne(); mgr.memberDeparted(getCache().getDistributionManager(), member, true); - assertEquals(0, mgr.hostedTransactionsInProgressForTest()); + assertThat(mgr.hostedTransactionsInProgressForTest()).isZero(); return null; } }); @@ -3431,19 +3306,19 @@ private void doNonColocatedbulkOp(final OP op) { VM datastore2 = host.getVM(2); initAccessorAndDataStore(accessor, datastore1, datastore2, 0); - accessor.invoke(new SerializableCallable() { + accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - Map custMap = new HashMap(); + public Object call() { + Map custMap = new HashMap(); for (int i = 0; i < 10; i++) { CustId cId = new CustId(i); Customer c = new Customer("name" + i, "addr" + i); custMap.put(cId, c); } - GemFireCacheImpl cache = getGemfireCache(); + InternalCache cache = getCache(); cache.getCacheTransactionManager().begin(); - Region r = cache.getRegion(CUSTOMER); - try { + Region r = cache.getRegion(CUSTOMER); + assertThatThrownBy(() -> { switch (op) { case PUTALL: r.putAll(custMap); @@ -3455,9 +3330,7 @@ public Object call() throws Exception { default: break; } - fail("expected exception not thrown"); - } catch (TransactionDataNotColocatedException ignored) { - } + }).isInstanceOf(TransactionDataNotColocatedException.class); cache.getCacheTransactionManager().rollback(); return null; } @@ -3484,9 +3357,9 @@ private void doTestBasicBulkOP(final OP op) { if (op.equals(OP.REMOVEALL)) { // for remove all populate more data - accessor.invoke(new SerializableCallable() { + accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region custRegion = getCache().getRegion(CUSTOMER); for (int i = 0; i < 50; i++) { custRegion.put(new CustId(i), new Customer("name" + i, "address" + i)); @@ -3496,9 +3369,9 @@ public Object call() throws Exception { }); } - final List ds1Buckets = (List) datastore1.invoke(new SerializableCallable() { + final List ds1Buckets = (List) datastore1.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { // do local operations with rollback and then commit Map custMap = new HashMap<>(); Region custRegion = getCache().getRegion(CUSTOMER); @@ -3521,7 +3394,7 @@ public Object call() throws Exception { custRegion.removeAll(custMap.keySet()); } getCache().getCacheTransactionManager().rollback(); - assertEquals(regionSize, custRegion.size()); + assertThat(regionSize).isEqualTo(custRegion.size()); // now commit getCache().getCacheTransactionManager().begin(); if (op.equals(OP.PUTALL)) { @@ -3530,7 +3403,7 @@ public Object call() throws Exception { custRegion.removeAll(custMap.keySet()); } getCache().getCacheTransactionManager().commit(); - assertEquals(getExpectedSize(custMap, regionSize), custRegion.size()); + assertThat(getExpectedSize(custMap, regionSize)).isEqualTo(custRegion.size()); // bulk op on other member custMap.clear(); @@ -3550,7 +3423,7 @@ public Object call() throws Exception { custRegion.removeAll(custMap.keySet()); } getCache().getCacheTransactionManager().rollback(); - assertEquals(regionSize, custRegion.size()); + assertThat(regionSize).isEqualTo(custRegion.size()); // now commit getCache().getCacheTransactionManager().begin(); if (op.equals(OP.PUTALL)) { @@ -3559,7 +3432,7 @@ public Object call() throws Exception { custRegion.removeAll(custMap.keySet()); } getCache().getCacheTransactionManager().commit(); - assertEquals(getExpectedSize(custMap, regionSize), custRegion.size()); + assertThat(getExpectedSize(custMap, regionSize)).isEqualTo(custRegion.size()); return localBuckets; } @@ -3571,9 +3444,9 @@ private int getExpectedSize(Map custMap, int regionSize) { } }); - accessor.invoke(new SerializableCallable() { + accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { // do a transaction on one of the nodes Map custMap = new HashMap<>(); Region custRegion = getCache().getRegion(CUSTOMER); @@ -3593,7 +3466,7 @@ public Object call() throws Exception { custRegion.removeAll(custMap.keySet()); } getCache().getCacheTransactionManager().rollback(); - assertEquals(regionSize, custRegion.size()); + assertThat(regionSize).isEqualTo(custRegion.size()); // now commit getCache().getCacheTransactionManager().begin(); if (op.equals(OP.PUTALL)) { @@ -3602,7 +3475,7 @@ public Object call() throws Exception { custRegion.removeAll(custMap.keySet()); } getCache().getCacheTransactionManager().commit(); - assertEquals(getExpectedSize(custMap, regionSize), custRegion.size()); + assertThat(getExpectedSize(custMap, regionSize)).isEqualTo(custRegion.size()); return null; } @@ -3622,9 +3495,9 @@ public void testDestroyCreateConflation() { VM datastore = host.getVM(1); initAccessorAndDataStore(accessor, datastore, 0); - datastore.invoke(new SerializableCallable() { + datastore.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region cust = getCache().getRegion(D_REFERENCE); cust.put("meow", "this is a meow, deal with it"); cust.getAttributesMutator().addCacheListener(new OneUpdateCacheListener()); @@ -3634,21 +3507,19 @@ public Object call() throws Exception { } }); - accessor.invoke(new SerializableCallable() { + accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region cust = getCache().getRegion(D_REFERENCE); cust.getAttributesMutator().addCacheListener(new OneUpdateCacheListener()); return null; } }); - - - datastore.invoke(new SerializableCallable() { + datastore.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - CacheTransactionManager mgr = getGemfireCache().getTxManager(); + public Object call() { + CacheTransactionManager mgr = getCache().getTxManager(); mgr.begin(); Region cust = getCache().getRegion(D_REFERENCE); cust.destroy("meow"); @@ -3658,22 +3529,21 @@ public Object call() throws Exception { } }); - accessor.invoke(new SerializableCallable() { + accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region cust = getCache().getRegion(D_REFERENCE); OneUpdateCacheListener rat = (OneUpdateCacheListener) cust.getAttributes().getCacheListener(); - if (!rat.getSuccess()) { - fail("The OneUpdateCacheListener didnt get an update"); - } + assertThat(rat.getSuccess()) + .as("The OneUpdateCacheListener didnt get an update").isTrue(); return null; } }); - datastore.invoke(new SerializableCallable() { + datastore.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region cust = getCache().getRegion(D_REFERENCE); OneDestroyAndThenOneCreateCacheWriter wri = (OneDestroyAndThenOneCreateCacheWriter) cust.getAttributes().getCacheWriter(); @@ -3694,27 +3564,24 @@ public boolean getSuccess() { @Override public void afterCreate(EntryEvent event) { - fail("create not expected"); + throw new UnsupportedOperationException("create not expected"); } @Override public void afterUpdate(EntryEvent event) { - if (!success) { - System.out.println("WE WIN!"); - success = true; - } else { - fail("Should have only had one update"); - } + assertThat(success).as("Should have only had one update").isFalse(); + System.out.println("WE WIN!"); + success = true; } @Override public void afterDestroy(EntryEvent event) { - fail("destroy not expected"); + throw new UnsupportedOperationException("destroy not expected"); } @Override public void afterInvalidate(EntryEvent event) { - fail("invalidate not expected"); + throw new UnsupportedOperationException("invalidate not expected"); } } @@ -3722,51 +3589,37 @@ class OneDestroyAndThenOneCreateCacheWriter extends CacheWriterAdapter { private boolean oneDestroy; private boolean oneCreate; - public void checkSuccess() throws Exception { - if (oneDestroy && oneCreate) { - // chill - } else { - fail("Didn't get both events. oneDestroy=" + oneDestroy + " oneCreate=" + oneCreate); - } + public void checkSuccess() { + assertThat(oneDestroy && oneCreate) + .as("Didn't get both events. oneDestroy=" + oneDestroy + " oneCreate=" + oneCreate) + .isTrue(); } @Override public void beforeCreate(EntryEvent event) throws CacheWriterException { - if (!oneDestroy) { - fail("destroy should have arrived in writer before create"); - } else { - if (oneCreate) { - fail("more than one create detected! expecting destroy then create"); - } else { - oneCreate = true; - } - } + assertThat(oneDestroy).isTrue(); + assertThat(oneCreate).isFalse(); + oneCreate = true; } @Override public void beforeUpdate(EntryEvent event) throws CacheWriterException { - fail("update not expected"); + throw new UnsupportedOperationException("update not expected"); } @Override public void beforeDestroy(EntryEvent event) throws CacheWriterException { - if (oneDestroy) { - fail("only one destroy expected"); - } else { - if (oneCreate) { - fail("destroy is supposed to precede create"); - } else { - oneDestroy = true; - } - } + assertThat(oneDestroy).isFalse(); + assertThat(oneCreate).isFalse(); + oneDestroy = true; } } protected Integer startServer(VM vm) { - return (Integer) vm.invoke(new SerializableCallable() { + return (Integer) vm.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() throws IOException { int port = getRandomAvailableTCPPort(); CacheServer s = getCache().addCacheServer(); s.setPort(port); @@ -3778,9 +3631,9 @@ public Object call() throws Exception { protected void createClientRegion(VM vm, final int port, final boolean isEmpty, final boolean ri) { - vm.invoke(new SerializableCallable() { + vm.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { ClientCacheFactory ccf = new ClientCacheFactory(); ccf.addPoolServer("localhost"/* getServerHostName(Host.getHost(0)) */, port); ccf.setPoolSubscriptionEnabled(true); @@ -3920,27 +3773,27 @@ protected static class ServerWriter extends CacheWriterAdapter { public void beforeCreate(EntryEvent event) throws CacheWriterException { invoked = true; event.getRegion().getCache().getLogger().info("SWAP:writer:" + event); - assertTrue(event.isOriginRemote()); + assertThat(event.isOriginRemote()).isTrue(); } @Override public void beforeUpdate(EntryEvent event) throws CacheWriterException { invoked = true; event.getRegion().getCache().getLogger().info("SWAP:writer:" + event); - assertTrue(event.isOriginRemote()); + assertThat(event.isOriginRemote()).isTrue(); } @Override public void beforeDestroy(EntryEvent event) throws CacheWriterException { invoked = true; event.getRegion().getCache().getLogger().info("SWAP:writer:" + event); - assertTrue(event.isOriginRemote()); + assertThat(event.isOriginRemote()).isTrue(); } } @Test - public void testTXWithRI() throws Exception { + public void testTXWithRI() { Host host = Host.getHost(0); VM accessor = host.getVM(0); VM datastore = host.getVM(1); @@ -3950,9 +3803,9 @@ public void testTXWithRI() throws Exception { int port = startServer(datastore); createClientRegion(client, port, false, true); - accessor.invoke(new SerializableCallable() { + accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region custRegion = getCache().getRegion(CUSTOMER); Region orderRegion = getCache().getRegion(ORDER); Region refRegion = getCache().getRegion(D_REFERENCE); @@ -3967,26 +3820,17 @@ public Object call() throws Exception { } }); - client.invoke(new SerializableCallable() { + client.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region custRegion = getCache().getRegion(CUSTOMER); Region orderRegion = getCache().getRegion(ORDER); Region refRegion = getCache().getRegion(D_REFERENCE); final ClientListener cl = (ClientListener) custRegion.getAttributes().getCacheListeners()[0]; - WaitCriterion waitForListenerInvocation = new WaitCriterion() { - @Override - public boolean done() { - return cl.invoked; - } + GeodeAwaitility.await().untilAsserted( + () -> assertThat(cl.invoked).isTrue().as("listener was never invoked")); - @Override - public String description() { - return "listener was never invoked"; - } - }; - GeodeAwaitility.await().untilAsserted(waitForListenerInvocation); return null; } }); @@ -4000,9 +3844,9 @@ public void testBug43176() { VM datastore = host.getVM(0); VM client = host.getVM(1); - datastore.invoke(new SerializableCallable() { + datastore.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { AttributesFactory af = new AttributesFactory<>(); af.setScope(Scope.DISTRIBUTED_ACK); af.setDataPolicy(DataPolicy.EMPTY); @@ -4015,9 +3859,9 @@ public Object call() throws Exception { }); final int port = startServer(datastore); - client.invoke(new SerializableCallable() { + client.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { ClientCacheFactory ccf = new ClientCacheFactory(); ccf.addPoolServer("localhost"/* getServerHostName(Host.getHost(0)) */, port); ccf.setPoolSubscriptionEnabled(true); @@ -4035,48 +3879,38 @@ public Object call() throws Exception { } }); - datastore.invoke(new SerializableCallable() { + datastore.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region ref = getCache().getRegion(D_REFERENCE); Region empty = getCache().getRegion(EMPTY_REGION); - getGemfireCache().getCacheTransactionManager().begin(); + getCache().getCacheTransactionManager().begin(); ref.put("one", "value1"); empty.put("eone", "valueOne"); getCache().getLogger().info("SWAP:callingCommit"); - getGemfireCache().getCacheTransactionManager().commit(); - assertTrue(ref.containsKey("one")); - assertEquals("value1", ref.get("one")); - assertFalse(empty.containsKey("eone")); - assertNull(empty.get("eone")); + getCache().getCacheTransactionManager().commit(); + assertThat(ref.containsKey("one")).isTrue(); + assertThat(ref.get("one")).isEqualTo("value1"); + assertThat(empty.containsKey("eone")).isFalse(); + assertThat(empty.get("eone")).isNull(); return null; } }); - client.invoke(new SerializableCallable() { + client.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region empty = getCache().getRegion(EMPTY_REGION); final ClientListener l = (ClientListener) empty.getAttributes().getCacheListeners()[0]; - WaitCriterion wc = new WaitCriterion() { - @Override - public boolean done() { - return l.invoked; - } - - @Override - public String description() { - return "listener invoked:" + l.invoked; - } - }; - GeodeAwaitility.await().untilAsserted(wc); + GeodeAwaitility.await().untilAsserted( + () -> assertThat(l.invoked).isTrue()); return null; } }); } @Test - public void testTXWithRICommitInDatastore() throws Exception { + public void testTXWithRICommitInDatastore() { Host host = Host.getHost(0); VM accessor = host.getVM(0); VM datastore = host.getVM(1); @@ -4086,9 +3920,9 @@ public void testTXWithRICommitInDatastore() throws Exception { int port = startServer(datastore); createClientRegion(client, port, false, true); - datastore.invoke(new SerializableCallable() { + datastore.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region custRegion = getCache().getRegion(CUSTOMER); Region orderRegion = getCache().getRegion(ORDER); Region refRegion = getCache().getRegion(D_REFERENCE); @@ -4103,26 +3937,18 @@ public Object call() throws Exception { } }); - client.invoke(new SerializableCallable() { + client.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region custRegion = getCache().getRegion(CUSTOMER); Region orderRegion = getCache().getRegion(ORDER); Region refRegion = getCache().getRegion(D_REFERENCE); final ClientListener cl = (ClientListener) custRegion.getAttributes().getCacheListeners()[0]; - WaitCriterion waitForListenerInvocation = new WaitCriterion() { - @Override - public boolean done() { - return cl.invoked; - } - @Override - public String description() { - return "listener was never invoked"; - } - }; - GeodeAwaitility.await().untilAsserted(waitForListenerInvocation); + GeodeAwaitility.await().untilAsserted( + () -> assertThat(cl.invoked).isTrue().as("listener was never invoked")); + return null; } }); @@ -4137,9 +3963,9 @@ public void testListenersNotInvokedOnSecondary() { VM datastore2 = host.getVM(2); initAccessorAndDataStoreWithInterestPolicy(accessor, datastore1, datastore2, 1); - SerializableCallable registerListener = new SerializableCallable() { + SerializableCallable registerListener = new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region custRegion = getCache().getRegion(CUSTOMER); custRegion.getAttributesMutator().addCacheListener(new ListenerInvocationCounter()); return null; @@ -4148,9 +3974,9 @@ public Object call() throws Exception { datastore1.invoke(registerListener); datastore2.invoke(registerListener); - datastore1.invoke(new SerializableCallable() { + datastore1.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region custRegion = getCache().getRegion(CUSTOMER); getCache().getCacheTransactionManager().begin(); CustId custId = new CustId(1); @@ -4161,9 +3987,9 @@ public Object call() throws Exception { } }); - SerializableCallable getListenerCount = new SerializableCallable() { + SerializableCallable getListenerCount = new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region custRegion = getCache().getRegion(CUSTOMER); ListenerInvocationCounter l = (ListenerInvocationCounter) custRegion.getAttributes().getCacheListeners()[0]; @@ -4174,7 +4000,7 @@ public Object call() throws Exception { int totalInvocation = (Integer) datastore1.invoke(getListenerCount) + (Integer) datastore2.invoke(getListenerCount); - assertEquals(1, totalInvocation); + assertThat(totalInvocation).isOne(); } private class ListenerInvocationCounter extends CacheListenerAdapter { @@ -4196,34 +4022,32 @@ public void testBug33073() { initAccessorAndDataStore(accessor, datastore1, datastore2, 0); final CustId custId = new CustId(19); - final TXId txId = (TXId) datastore1.invoke(new SerializableCallable() { + final TXId txId = (TXId) datastore1.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region refRegion = getCache().getRegion(D_REFERENCE); - assertNull(refRegion.get(custId)); + assertThat(refRegion.get(custId)).isNull(); getCache().getCacheTransactionManager().begin(); refRegion.put(custId, new Customer("name1", "address1")); return getCache().getCacheTransactionManager().suspend(); } }); - datastore2.invoke(new SerializableCallable() { + datastore2.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region refRegion = getCache().getRegion(D_REFERENCE); - assertNull(refRegion.get(custId)); + assertThat(refRegion.get(custId)).isNull(); refRegion.put(custId, new Customer("nameNew", "addressNew")); return null; } }); - datastore1.invoke(new SerializableCallable() { + datastore1.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { - try { + public Object call() { + assertThatThrownBy(() -> { getCache().getCacheTransactionManager().resume(txId); getCache().getCacheTransactionManager().commit(); - fail("expected commit conflict not thrown"); - } catch (CommitConflictException ignored) { - } + }).isInstanceOf(CommitConflictException.class); return null; } }); @@ -4234,7 +4058,7 @@ public void testBug43081() throws Exception { createRegion(false, 0, null); Context ctx = getCache().getJNDIContext(); UserTransaction tx = (UserTransaction) ctx.lookup("java:/UserTransaction"); - assertEquals(Status.STATUS_NO_TRANSACTION, tx.getStatus()); + assertThat(Status.STATUS_NO_TRANSACTION).isEqualTo(tx.getStatus()); Region pr = getCache().getRegion(CUSTOMER); Region rr = getCache().getRegion(D_REFERENCE); // test all ops @@ -4286,7 +4110,7 @@ public void testBug43081() throws Exception { // Putting a string key causes this, the partition resolver // doesn't handle it. IgnoredException.addIgnoredException("IllegalStateException"); - assertEquals(Status.STATUS_ACTIVE, tx.getStatus()); + assertThat(Status.STATUS_ACTIVE).isEqualTo(tx.getStatus()); final CountDownLatch latch = new CountDownLatch(1); Thread t = new Thread(() -> { Context ctx1 = getCache().getJNDIContext(); @@ -4303,12 +4127,10 @@ public void testBug43081() throws Exception { }); t.start(); latch.await(); - try { + assertThatThrownBy(() -> { pr.put(new CustId(1), new Customer("name11", "address11")); tx.commit(); - fail("expected exception not thrown"); - } catch (RollbackException ignored) { - } + }).isInstanceOf(RollbackException.class); } } @@ -4335,26 +4157,26 @@ public void afterUpdate(EntryEvent event) { } } - accessor.invoke(new SerializableCallable() { + accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region r = getCache().createRegionFactory(RegionShortcut.REPLICATE_PROXY).create(name); r.getAttributesMutator().addCacheListener(new CountingListener()); return null; } }); - datastore.invoke(new SerializableCallable() { + datastore.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region r = getCache().createRegionFactory(RegionShortcut.REPLICATE).create(name); r.getAttributesMutator().addCacheListener(new CountingListener()); r.put("key1", "value1"); return null; } }); - final TransactionId txid = (TransactionId) accessor.invoke(new SerializableCallable() { + final TransactionId txid = (TransactionId) accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region r = getCache().getRegion(name); CacheTransactionManager tm = getCache().getCacheTransactionManager(); getCache().getLogger().fine("SWAP:BeginTX"); @@ -4363,49 +4185,49 @@ public Object call() throws Exception { return tm.suspend(); } }); - datastore.invoke(new SerializableCallable() { + datastore.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region rgn = getCache().getRegion(name); - assertNull(rgn.get("txkey")); - TXManagerImpl txMgr = getGemfireCache().getTxManager(); + assertThat(rgn.get("txkey")).isNull(); + TXManagerImpl txMgr = getCache().getTxManager(); TXStateProxy tx = txMgr.getHostedTXState((TXId) txid); - assertEquals(1, tx.getRegions().size()); + assertThat(tx.getRegions().size()).isOne(); for (InternalRegion r : tx.getRegions()) { - assertTrue(r instanceof DistributedRegion); + assertThat(r instanceof DistributedRegion).isTrue(); TXRegionState rs = tx.readRegion(r); for (Object key : rs.getEntryKeys()) { TXEntryState es = rs.readEntry(key); - assertEquals("txkey", key); - assertNotNull(es.getValue(key, r, false)); + assertThat(key).isEqualTo("txkey"); + assertThat(es.getValue(key, r, false)).isNotNull(); if (key.equals("txkey")) { - assertTrue(es.isDirty()); + assertThat(es.isDirty()).isTrue(); } } } return null; } }); - accessor.invoke(new SerializableCallable() { + accessor.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region rgn = getCache().getRegion(name); - assertNull(rgn.get("txkey")); + assertThat(rgn.get("txkey")).isNull(); CacheTransactionManager mgr = getCache().getCacheTransactionManager(); mgr.resume(txid); mgr.commit(); CountingListener cl = (CountingListener) rgn.getAttributes().getCacheListeners()[0]; - assertEquals(0, cl.count); - assertEquals("txvalue", rgn.get("txkey")); + assertThat(cl.count).isZero(); + assertThat(rgn.get("txkey")).isEqualTo("txvalue"); return null; } }); - datastore.invoke(new SerializableCallable() { + datastore.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region rgn = getCache().getRegion(name); CountingListener cl = (CountingListener) rgn.getAttributes().getCacheListeners()[0]; - assertEquals(2, cl.count); + assertThat(cl.count).isEqualTo(2); return null; } }); @@ -4419,9 +4241,9 @@ public void testExpirySuspend_bug45984() { final String regionName = getName(); // create region with expiration - vm1.invoke(new SerializableCallable() { + vm1.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { System.setProperty(LocalRegion.EXPIRY_MS_PROPERTY, "true"); try { RegionFactory rf = getCache().createRegionFactory(); @@ -4436,30 +4258,19 @@ public Object call() throws Exception { }); // create replicate region - vm2.invoke(new SerializableCallable() { + vm2.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { getCache().createRegionFactory(RegionShortcut.REPLICATE).create(regionName); return null; } }); - vm1.invoke(new SerializableCallable() { + vm1.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { final Region r = getCache().getRegion(regionName); - WaitCriterion wc2 = new WaitCriterion() { - @Override - public boolean done() { - return !r.containsKey("key") && !r.containsKey("nonTXKey"); - } - @Override - public String description() { - return "did not expire containsKey(key)=" + r.containsKey("key") - + " r.containsKey(nonTXKey)=" + r.containsKey("nonTXKey"); - } - }; suspendExpiration(); Region.Entry entry = null; long tilt; @@ -4474,15 +4285,20 @@ public String description() { permitExpiration(); } TransactionId tx = getCache().getCacheTransactionManager().suspend(); + + ThrowingRunnable runnable = + () -> assertThat(!r.containsKey("key") && !r.containsKey("nonTXKey")).isTrue(); + // A remote tx will allow expiration to happen on the side that // is not hosting the tx. But it will not allow an expiration // initiated on the hosting jvm. // tx is hosted in vm2 so expiration can happen in vm1. - GeodeAwaitility.await().untilAsserted(wc2); + GeodeAwaitility.await().untilAsserted(runnable); getCache().getCacheTransactionManager().resume(tx); - assertTrue(r.containsKey("key")); + assertThat(r.containsKey("key")).isTrue(); getCache().getCacheTransactionManager().commit(); - GeodeAwaitility.await().untilAsserted(wc2); + GeodeAwaitility.await().untilAsserted(runnable); + return null; } }); @@ -4496,9 +4312,9 @@ public void testRemoteFetchVersionMessage() { VM vm1 = host.getVM(1); final String regionName = getName(); - final VersionTag tag = (VersionTag) vm0.invoke(new SerializableCallable() { + final VersionTag tag = (VersionTag) vm0.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { LocalRegion r = (LocalRegion) getCache().createRegionFactory(RegionShortcut.REPLICATE) .create(regionName); r.put("key", "value"); @@ -4506,9 +4322,9 @@ public Object call() throws Exception { } }); - vm1.invoke(new SerializableCallable() { + vm1.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { AttributesFactory af = new AttributesFactory(); af.setDataPolicy(DataPolicy.EMPTY); af.setScope(Scope.DISTRIBUTED_ACK); @@ -4516,12 +4332,9 @@ public Object call() throws Exception { r.cache.getLogger().info("SWAP:sending:remoteTagRequest"); VersionTag remote = r.fetchRemoteVersionTag("key"); r.cache.getLogger().info("SWAP:remoteTag:" + remote); - try { - remote = r.fetchRemoteVersionTag("nonExistentKey"); - fail("expected exception not thrown"); - } catch (EntryNotFoundException ignored) { - } - assertEquals(tag, remote); + assertThatThrownBy(() -> r.fetchRemoteVersionTag("nonExistentKey")) + .isInstanceOf(EntryNotFoundException.class); + assertThat(tag).isEqualTo(remote); return null; } }); @@ -4535,9 +4348,9 @@ public void testTransactionWithRemoteVersionFetch() { final String regionNameNormal = getName() + "_normal"; final String regionName = getName(); - vm0.invoke(new SerializableCallable() { + vm0.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region r = getCache().createRegionFactory(RegionShortcut.REPLICATE).create(regionName); Region n = getCache().createRegionFactory(RegionShortcut.REPLICATE).create(regionNameNormal); @@ -4548,18 +4361,18 @@ public Object call() throws Exception { } }); - final VersionTag tag = (VersionTag) vm1.invoke(new SerializableCallable() { + final VersionTag tag = (VersionTag) vm1.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region r = getCache().createRegionFactory(RegionShortcut.REPLICATE).create(regionName); AttributesFactory af = new AttributesFactory(); af.setDataPolicy(DataPolicy.NORMAL); af.setScope(Scope.DISTRIBUTED_ACK); Region n = getCache().createRegion(regionNameNormal, af.create()); - TXManagerImpl mgr = getGemfireCache().getTxManager(); + TXManagerImpl mgr = getCache().getTxManager(); mgr.begin(); r.put("key", "value"); - assertTrue(mgr.getTXState().isRealDealLocal()); + assertThat(mgr.getTXState().isRealDealLocal()).isTrue(); getCache().getLogger().fine("SWAP:doingPutInNormalRegion"); n.put("key", "value"); getCache().getLogger().fine("SWAP:commiting"); @@ -4568,14 +4381,14 @@ public Object call() throws Exception { } }); - vm0.invoke(new SerializableCallable() { + vm0.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region n = getCache().getRegion(regionNameNormal); VersionTag localTag = ((LocalRegion) n).getRegionEntry("key").getVersionStamp().asVersionTag(); - assertEquals(tag.getEntryVersion(), localTag.getEntryVersion()); - assertEquals(tag.getRegionVersion(), localTag.getRegionVersion()); + assertThat(tag.getEntryVersion()).isEqualTo(localTag.getEntryVersion()); + assertThat(tag.getRegionVersion()).isEqualTo(localTag.getRegionVersion()); return null; } }); @@ -4589,9 +4402,9 @@ public void testBug49398() { VM vm2 = host.getVM(1); final String lrName = getName() + "_lr"; - SerializableCallable createRegion = new SerializableCallable() { + SerializableCallable createRegion = new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { createRegion(false, 1, null); getCache().createRegionFactory(RegionShortcut.LOCAL).create(lrName); return null; @@ -4601,9 +4414,9 @@ public Object call() throws Exception { vm1.invoke(createRegion); vm2.invoke(createRegion); - vm1.invoke(new SerializableCallable() { + vm1.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { CacheTransactionManager txMgr = getCache().getCacheTransactionManager(); Region ref = getCache().getRegion(D_REFERENCE); Region lr = getCache().getRegion(lrName); @@ -4616,11 +4429,11 @@ public Object call() throws Exception { }); // make sure local region changes are not reflected in the other vm - vm2.invoke(new SerializableCallable() { + vm2.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region lr = getCache().getRegion(lrName); - assertNull(lr.get("key")); + assertThat(lr.get("key")).isNull(); return null; } }); @@ -4657,9 +4470,9 @@ public void afterCreate(EntryEvent event) { } } - SerializableCallable createRegionWithListener = new SerializableCallable() { + SerializableCallable createRegionWithListener = new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { createRegion(false, 0, null); getCache().getRegion(D_REFERENCE).getAttributesMutator() .addCacheListener(new NonInlineListener()); @@ -4670,9 +4483,9 @@ public Object call() throws Exception { vm0.invoke(createRegionWithListener); vm1.invoke(createRegionWithListener); - vm0.invoke(new SerializableCallable() { + vm0.invoke(new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { Region region = getCache().getRegion(D_REFERENCE); CacheTransactionManager mgr = getCache().getCacheTransactionManager(); mgr.begin(); @@ -4683,15 +4496,15 @@ public Object call() throws Exception { } }); - SerializableCallable verifyAssert = new SerializableCallable() { + SerializableCallable verifyAssert = new SerializableCallable() { @Override - public Object call() throws Exception { + public Object call() { CacheListener[] listeners = getCache().getRegion(D_REFERENCE).getAttributes().getCacheListeners(); for (CacheListener listener : listeners) { if (listener instanceof NonInlineListener) { NonInlineListener l = (NonInlineListener) listener; - assertFalse(l.assertException); + assertThat(l.assertException).isFalse(); } } return null;