Repository: ignite Updated Branches: refs/heads/ignite-1093-3 751d2c2cd -> 2b23a3db8
1093 Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/2b23a3db Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/2b23a3db Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/2b23a3db Branch: refs/heads/ignite-1093-3 Commit: 2b23a3db819e79cbb6fcce590a3abe95362b3a3b Parents: 751d2c2 Author: Anton Vinogradov <[email protected]> Authored: Wed Oct 28 19:07:20 2015 +0300 Committer: Anton Vinogradov <[email protected]> Committed: Wed Oct 28 19:07:20 2015 +0300 ---------------------------------------------------------------------- .../dht/GridCacheTxNodeFailureSelfTest.java | 157 ++++++++++--------- 1 file changed, 79 insertions(+), 78 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/2b23a3db/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheTxNodeFailureSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheTxNodeFailureSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheTxNodeFailureSelfTest.java index cadd03f..fc7b49f 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheTxNodeFailureSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheTxNodeFailureSelfTest.java @@ -17,6 +17,11 @@ package org.apache.ignite.internal.processors.cache.distributed.dht; +import java.util.Collection; +import java.util.Collections; +import java.util.concurrent.Callable; +import java.util.concurrent.CountDownLatch; +import javax.cache.CacheException; import org.apache.ignite.Ignite; import org.apache.ignite.IgniteCache; import org.apache.ignite.IgniteException; @@ -46,12 +51,6 @@ import org.apache.ignite.transactions.Transaction; import org.apache.ignite.transactions.TransactionConcurrency; import org.apache.ignite.transactions.TransactionRollbackException; -import javax.cache.CacheException; -import java.util.Collection; -import java.util.Collections; -import java.util.concurrent.Callable; -import java.util.concurrent.CountDownLatch; - import static org.apache.ignite.transactions.TransactionConcurrency.OPTIMISTIC; import static org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC; import static org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ; @@ -99,6 +98,13 @@ public class GridCacheTxNodeFailureSelfTest extends GridCommonAbstractTest { } /** + * + */ + @Override protected void afterTest() throws Exception { + stopAllGrids(); + } + + /** * @throws Exception If failed. */ public void testPrimaryNodeFailureBackupCommitPessimistic() throws Exception { @@ -198,83 +204,53 @@ public class GridCacheTxNodeFailureSelfTest extends GridCommonAbstractTest { for (int i = 0; i < gridCount(); i++) info("Grid " + i + ": " + ignite(i).cluster().localNode().id()); - try { - final Ignite ignite = ignite(0); + final Ignite ignite = ignite(0); - final IgniteCache<Object, Object> cache = ignite.cache(null).withNoRetries(); + final IgniteCache<Object, Object> cache = ignite.cache(null).withNoRetries(); - final int key = generateKey(ignite, backup); + final int key = generateKey(ignite, backup); - IgniteEx backupNode = (IgniteEx)backupNode(key, null); + IgniteEx backupNode = (IgniteEx)backupNode(key, null); - assertNotNull(backupNode); + assertNotNull(backupNode); - final CountDownLatch commitLatch = new CountDownLatch(1); + final CountDownLatch commitLatch = new CountDownLatch(1); - if (!commit) - communication(1).bannedClasses(Collections.<Class>singletonList(GridDhtTxPrepareRequest.class)); - else { - if (!backup) { - communication(2).bannedClasses(Collections.<Class>singletonList(GridDhtTxPrepareResponse.class)); - communication(3).bannedClasses(Collections.<Class>singletonList(GridDhtTxPrepareResponse.class)); - } - else - communication(0).bannedClasses(Collections.<Class>singletonList(GridDhtTxPrepareResponse.class)); + if (!commit) + communication(1).bannedClasses(Collections.<Class>singletonList(GridDhtTxPrepareRequest.class)); + else { + if (!backup) { + communication(2).bannedClasses(Collections.<Class>singletonList(GridDhtTxPrepareResponse.class)); + communication(3).bannedClasses(Collections.<Class>singletonList(GridDhtTxPrepareResponse.class)); } + else + communication(0).bannedClasses(Collections.<Class>singletonList(GridDhtTxPrepareResponse.class)); + } - IgniteInternalFuture<Object> fut = GridTestUtils.runAsync(new Callable<Object>() { - @Override public Object call() throws Exception { - if (conc != null) { - try (Transaction tx = ignite.transactions().txStart(conc, REPEATABLE_READ)) { - cache.put(key, key); - - Transaction asyncTx = (Transaction)tx.withAsync(); - - asyncTx.commit(); - - commitLatch.countDown(); - - try { - IgniteFuture<Object> fut = asyncTx.future(); - - fut.get(); - - if (!commit) { - error("Transaction has been committed"); - - fail("Transaction has been committed: " + tx); - } - } - catch (TransactionRollbackException e) { - if (commit) { - error(e.getMessage(), e); - - fail("Failed to commit: " + e); - } - else - assertTrue(X.hasCause(e, TransactionRollbackException.class)); - } - } - } - else { - IgniteCache<Object, Object> cache0 = cache.withAsync(); + IgniteInternalFuture<Object> fut = GridTestUtils.runAsync(new Callable<Object>() { + @Override public Object call() throws Exception { + if (conc != null) { + try (Transaction tx = ignite.transactions().txStart(conc, REPEATABLE_READ)) { + cache.put(key, key); - cache0.put(key, key); + Transaction asyncTx = (Transaction)tx.withAsync(); - Thread.sleep(1000); + asyncTx.commit(); commitLatch.countDown(); try { - cache0.future().get(); + IgniteFuture<Object> fut = asyncTx.future(); + + fut.get(); if (!commit) { error("Transaction has been committed"); - fail("Transaction has been committed."); + fail("Transaction has been committed: " + tx); } } - catch (CacheException e) { + catch (TransactionRollbackException e) { if (commit) { error(e.getMessage(), e); @@ -284,28 +260,53 @@ public class GridCacheTxNodeFailureSelfTest extends GridCommonAbstractTest { assertTrue(X.hasCause(e, TransactionRollbackException.class)); } } + } + else { + IgniteCache<Object, Object> cache0 = cache.withAsync(); + + cache0.put(key, key); + + Thread.sleep(1000); + + commitLatch.countDown(); - return null; + try { + cache0.future().get(); + + if (!commit) { + error("Transaction has been committed"); + + fail("Transaction has been committed."); + } + } + catch (CacheException e) { + if (commit) { + error(e.getMessage(), e); + + fail("Failed to commit: " + e); + } + else + assertTrue(X.hasCause(e, TransactionRollbackException.class)); + } } - }); - commitLatch.await(); + return null; + } + }); - stopGrid(1); + commitLatch.await(); - // Check that thread successfully finished. - fut.get(); + stopGrid(1); - // Check there are no hanging transactions. - assertEquals(0, ((IgniteEx)ignite(0)).context().cache().context().tm().idMapSize()); - assertEquals(0, ((IgniteEx)ignite(2)).context().cache().context().tm().idMapSize()); - assertEquals(0, ((IgniteEx)ignite(3)).context().cache().context().tm().idMapSize()); + // Check that thread successfully finished. + fut.get(); - dataCheck((IgniteKernal)ignite(0), (IgniteKernal)backupNode, key, commit); - } - finally { - stopAllGrids(); - } + // Check there are no hanging transactions. + assertEquals(0, ((IgniteEx)ignite(0)).context().cache().context().tm().idMapSize()); + assertEquals(0, ((IgniteEx)ignite(2)).context().cache().context().tm().idMapSize()); + assertEquals(0, ((IgniteEx)ignite(3)).context().cache().context().tm().idMapSize()); + + dataCheck((IgniteKernal)ignite(0), (IgniteKernal)backupNode, key, commit); } /**
