ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [49/50] [abbrv] ignite git commit: ignite-6181-1
Date Tue, 19 Sep 2017 14:46:15 GMT
http://git-wip-us.apache.org/repos/asf/ignite/blob/2468e009/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
index 2d6264c..caa1545 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutTest.java
@@ -25,7 +25,6 @@ import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteException;
 import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.configuration.TransactionConfiguration;
 import org.apache.ignite.internal.IgniteEx;
 import org.apache.ignite.internal.IgniteInternalFuture;
 import org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal;
@@ -57,9 +56,6 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
     private static final long TX_MIN_TIMEOUT = 1;
 
     /** */
-    private static final long TX_TIMEOUT = 500;
-
-    /** */
     private static final String CACHE_NAME = "test";
 
     /** IP finder. */
@@ -68,12 +64,6 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
     /** */
     private static final int GRID_CNT = 3;
 
-    /** */
-    private final CountDownLatch blocked = new CountDownLatch(1);
-
-    /** */
-    private final CountDownLatch unblocked = new CountDownLatch(1);
-
     /** {@inheritDoc} */
     @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws
Exception {
         IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
@@ -82,12 +72,8 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
 
         ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(IP_FINDER);
 
-        TransactionConfiguration txCfg = new TransactionConfiguration();
-        txCfg.setDefaultTxTimeout(TX_TIMEOUT);
-
-        cfg.setTransactionConfiguration(txCfg);
-
         CacheConfiguration ccfg = new CacheConfiguration(CACHE_NAME);
+
         ccfg.setAtomicityMode(TRANSACTIONAL);
         ccfg.setBackups(2);
 
@@ -113,7 +99,7 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
     /**
      * @param e Exception.
      */
-    protected void validateException(Exception e) {
+    protected void validateDeadlockException(Exception e) {
         assertEquals("Deadlock report is expected",
             TransactionDeadlockException.class, e.getCause().getCause().getClass());
     }
@@ -191,50 +177,22 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest
{
      *
      * @throws Exception If failed.
      */
-    public void testWaitingTxUnblockedOnTimeout1() throws Exception {
-        testWaitingTxUnblockedOnTimeout0(grid(0), grid(0));
-    }
+    public void testWaitingTxUnblockedOnTimeout() throws Exception {
+        waitingTxUnblockedOnTimeout(grid(0), grid(0));
 
-    /**
-     * Tests if timeout on first tx unblocks second tx waiting for the locked key.
-     *
-     * @throws Exception If failed.
-     */
-    public void testWaitingTxUnblockedOnTimeout2() throws Exception {
-        testWaitingTxUnblockedOnTimeout0(grid(0), grid(1));
-    }
+        waitingTxUnblockedOnTimeout(grid(0), grid(1));
 
-    /**
-     * Tests if timeout on first tx unblocks second tx waiting for the locked key.
-     *
-     * @throws Exception If failed.
-     */
-    public void testWaitingTxUnblockedOnTimeout3() throws Exception {
         Ignite client = startGrid("client");
 
-        testWaitingTxUnblockedOnTimeout0(grid(0), client);
-    }
+        waitingTxUnblockedOnTimeout(grid(0), client);
 
-    /**
-     * Tests if timeout on first tx unblocks second tx waiting for the locked key.
-     *
-     * @throws Exception If failed.
-     */
-    public void testWaitingTxUnblockedOnTimeout4() throws Exception {
-        Ignite client = startGrid("client");
+        waitingTxUnblockedOnTimeout(grid(1), client);
 
-        testWaitingTxUnblockedOnTimeout0(client, grid(0));
-    }
+        waitingTxUnblockedOnTimeout(client, grid(0));
 
-    /**
-     * Tests if timeout on first tx unblocks second tx waiting for the locked key.
-     *
-     * @throws Exception If failed.
-     */
-    public void testWaitingTxUnblockedOnTimeout5() throws Exception {
-        Ignite client = startGrid("client");
+        waitingTxUnblockedOnTimeout(client, grid(1));
 
-        testWaitingTxUnblockedOnTimeout0(client, client);
+        waitingTxUnblockedOnTimeout(client, client);
     }
 
     /**
@@ -242,50 +200,22 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest
{
      *
      * @throws Exception If failed.
      */
-    public void testWaitingTxUnblockedOnTimeout6() throws Exception {
-        testWaitingTxUnblockedOnThreadDeath0(grid(0), grid(0));
-    }
+    public void testWaitingTxUnblockedOnThreadDeath() throws Exception {
+        waitingTxUnblockedOnThreadDeath(grid(0), grid(0));
 
-    /**
-     * Tests if timeout on first tx unblocks second tx waiting for the locked key.
-     *
-     * @throws Exception If failed.
-     */
-    public void testWaitingTxUnblockedOnTimeout7() throws Exception {
-        testWaitingTxUnblockedOnThreadDeath0(grid(0), grid(1));
-    }
+        waitingTxUnblockedOnThreadDeath(grid(0), grid(1));
 
-    /**
-     * Tests if timeout on first tx unblocks second tx waiting for the locked key.
-     *
-     * @throws Exception If failed.
-     */
-    public void testWaitingTxUnblockedOnTimeout8() throws Exception {
         Ignite client = startGrid("client");
 
-        testWaitingTxUnblockedOnThreadDeath0(grid(0), client);
-    }
+        waitingTxUnblockedOnThreadDeath(grid(0), client);
 
-    /**
-     * Tests if timeout on first tx unblocks second tx waiting for the locked key.
-     *
-     * @throws Exception If failed.
-     */
-    public void testWaitingTxUnblockedOnTimeout9() throws Exception {
-        Ignite client = startGrid("client");
+        waitingTxUnblockedOnThreadDeath(grid(1), client);
 
-        testWaitingTxUnblockedOnThreadDeath0(client, grid(0));
-    }
+        waitingTxUnblockedOnThreadDeath(client, grid(0));
 
-    /**
-     * Tests if timeout on first tx unblocks second tx waiting for the locked key.
-     *
-     * @throws Exception If failed.
-     */
-    public void testWaitingTxUnblockedOnTimeout10() throws Exception {
-        Ignite client = startGrid("client");
+        waitingTxUnblockedOnThreadDeath(client, grid(1));
 
-        testWaitingTxUnblockedOnThreadDeath0(client, client);
+        waitingTxUnblockedOnThreadDeath(client, client);
     }
 
     /**
@@ -293,28 +223,16 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest
{
      *
      * @throws Exception If failed.
      */
-    public void testDeadlockUnblockedOnTimeout1() throws Exception {
-        testDeadlockUnblockedOnTimeout0(ignite(0), ignite(1));
-    }
+    public void testDeadlockUnblockedOnTimeout() throws Exception {
+        deadlockUnblockedOnTimeout(ignite(0), ignite(1));
 
-    /**
-     * Tests if deadlock is resolved on timeout with correct message.
-     *
-     * @throws Exception If failed.
-     */
-    public void testDeadlockUnblockedOnTimeout2() throws Exception {
-        testDeadlockUnblockedOnTimeout0(ignite(0), ignite(0));
-    }
+        deadlockUnblockedOnTimeout(ignite(0), ignite(0));
 
-    /**
-     * Tests if deadlock is resolved on timeout with correct message.
-     *
-     * @throws Exception If failed.
-     */
-    public void testDeadlockUnblockedOnTimeout3() throws Exception {
         Ignite client = startGrid("client");
 
-        testDeadlockUnblockedOnTimeout0(ignite(0), client);
+        deadlockUnblockedOnTimeout(ignite(0), client);
+
+        deadlockUnblockedOnTimeout(client, ignite(0));
     }
 
     /**
@@ -324,19 +242,22 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest
{
      * @param node2 Second node.
      * @throws Exception If failed.
      */
-    private void testDeadlockUnblockedOnTimeout0(final Ignite node1, final Ignite node2)
throws Exception {
+    private void deadlockUnblockedOnTimeout(final Ignite node1, final Ignite node2) throws
Exception {
+        info("Start test [node1=" + node1.name() + ", node2=" + node2.name() + ']');
+
         final CountDownLatch l = new CountDownLatch(2);
 
-        IgniteInternalFuture<?> fut1 = multithreadedAsync(new Runnable() {
+        IgniteInternalFuture<?> fut1 = GridTestUtils.runAsync(new Runnable() {
             @Override public void run() {
                 try {
-                    try (Transaction tx = node1.transactions().txStart()) {
-                        node1.cache(CACHE_NAME).put(1, 1);
+                    try (Transaction tx = node1.transactions().txStart(PESSIMISTIC, REPEATABLE_READ,
5000, 2)) {
+                        node1.cache(CACHE_NAME).put(1, 10);
 
                         l.countDown();
+
                         U.awaitQuiet(l);
 
-                        node1.cache(CACHE_NAME).put(2, 2);
+                        node1.cache(CACHE_NAME).put(2, 20);
 
                         tx.commit();
 
@@ -345,17 +266,18 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest
{
                 }
                 catch (CacheException e) {
                     // No-op.
-                    validateException(e);
+                    validateDeadlockException(e);
                 }
             }
-        }, 1, "First");
+        }, "First");
 
-        IgniteInternalFuture<?> fut2 = multithreadedAsync(new Runnable() {
+        IgniteInternalFuture<?> fut2 = GridTestUtils.runAsync(new Runnable() {
             @Override public void run() {
                 try (Transaction tx = node2.transactions().txStart(PESSIMISTIC, REPEATABLE_READ,
0, 2)) {
                     node2.cache(CACHE_NAME).put(2, 2);
 
                     l.countDown();
+
                     U.awaitQuiet(l);
 
                     node2.cache(CACHE_NAME).put(1, 1);
@@ -363,13 +285,13 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest
{
                     tx.commit();
                 }
             }
-        }, 1, "Second");
+        }, "Second");
 
         fut1.get();
         fut2.get();
 
-        assertTrue("Expecting commited key 2", node1.cache(CACHE_NAME).containsKey(2));
-        assertTrue("Expecting commited key 1", node1.cache(CACHE_NAME).containsKey(1));
+        assertTrue("Expecting committed key 2", node1.cache(CACHE_NAME).containsKey(2));
+        assertTrue("Expecting committed key 1", node1.cache(CACHE_NAME).containsKey(1));
     }
 
     /**
@@ -380,6 +302,8 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
     public void testTimeoutRemoval() throws Exception {
         IgniteEx client = (IgniteEx)startGrid("client");
 
+        final long TX_TIMEOUT = 250;
+
         int modesCnt = 5;
 
         for (int i = 0; i < modesCnt; i++)
@@ -421,6 +345,8 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
 
         final int key = 1, val = 1;
 
+        final long TX_TIMEOUT = 250;
+
         try (Transaction tx = near.transactions().txStart(concurrency, isolation, TX_TIMEOUT,
1)) {
             near.cache(CACHE_NAME).put(key, val);
 
@@ -496,16 +422,30 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest
{
      * @param other Node starting second tx.
      * @throws Exception If failed.
      */
-    private void testWaitingTxUnblockedOnTimeout0(final Ignite near, final Ignite other)
throws Exception {
-        final int recordsCnt = 100;
+    private void waitingTxUnblockedOnTimeout(final Ignite near, final Ignite other) throws
Exception {
+        info("Start test [node1=" + near.name() + ", node2=" + other.name() + ']');
 
-        IgniteInternalFuture<?> fut1 = multithreadedAsync(new Runnable() {
+        final CountDownLatch blocked = new CountDownLatch(1);
+
+        final CountDownLatch unblocked = new CountDownLatch(1);
+
+        final int recordsCnt = 5;
+
+        IgniteInternalFuture<?> fut1 = GridTestUtils.runAsync(new Runnable() {
             @Override public void run() {
-                try (Transaction tx = near.transactions().txStart()) {
-                    for (int i = 0; i < recordsCnt; i++)
-                        near.cache(CACHE_NAME).put(i, i);
+                try (Transaction tx = near.transactions().txStart(PESSIMISTIC, REPEATABLE_READ,
1000, 0)) {
+                    try {
+                        for (int i = 0; i < recordsCnt; i++)
+                            near.cache(CACHE_NAME).put(i, i);
 
-                    blocked.countDown();
+                        info("Locked all keys.");
+                    }
+                    catch (CacheException e) {
+                        info("Failed to lock keys: " + e);
+                    }
+                    finally {
+                        blocked.countDown();
+                    }
 
                     // Will be unblocked after tx timeout occurs.
                     U.awaitQuiet(unblocked);
@@ -530,16 +470,16 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest
{
                 }
 
                 // Check thread is able to start new tx.
-                try (Transaction tx = near.transactions().txStart()) {
+                try (Transaction tx = near.transactions().txStart(PESSIMISTIC, REPEATABLE_READ,
60_000, 0)) {
                     for (int i = 0; i < recordsCnt; i++)
                         near.cache(CACHE_NAME).put(i, i);
 
                     tx.commit();
                 }
             }
-        }, 1, "First");
+        }, "First");
 
-        IgniteInternalFuture<?> fut2 = multithreadedAsync(new Runnable() {
+        IgniteInternalFuture<?> fut2 = GridTestUtils.runAsync(new Runnable() {
             @Override public void run() {
                 U.awaitQuiet(blocked);
 
@@ -551,7 +491,7 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
                     tx.commit();
                 }
             }
-        }, 1, "Second");
+        }, "Second");
 
         fut2.get();
 
@@ -565,17 +505,45 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest
{
      * @param other Node starting second tx.
      * @throws Exception If failed.
      */
-    private void testWaitingTxUnblockedOnThreadDeath0(final Ignite near, final Ignite other)
throws Exception {
-        final int recordsCnt = 100;
+    private void waitingTxUnblockedOnThreadDeath(final Ignite near, final Ignite other) throws
Exception {
+        waitingTxUnblockedOnThreadDeath0(near, other, 10, 1000); // Try provoke timeout after
all keys are locked.
+
+        waitingTxUnblockedOnThreadDeath0(near, other, 1000, 100);  // Try provoke timeout
while trying to lock keys.
+    }
+
+    /**
+     * @param near Node starting tx which is timed out.
+     * @param other Node starting second tx.
+     * @param recordsCnt Number of records to locks.
+     * @param timeout Transaction timeout.
+     * @throws Exception If failed.
+     */
+    private void waitingTxUnblockedOnThreadDeath0(final Ignite near,
+        final Ignite other,
+        final int recordsCnt,
+        final long timeout)
+        throws Exception
+    {
+        info("Start test [node1=" + near.name() + ", node2=" + other.name() + ']');
+
+        final CountDownLatch blocked = new CountDownLatch(1);
 
         IgniteInternalFuture<?> fut1 = multithreadedAsync(new Runnable() {
             @Override public void run() {
-                near.transactions().txStart();
+                near.transactions().txStart(PESSIMISTIC, REPEATABLE_READ, timeout, recordsCnt);
 
-                for (int i = 0; i < recordsCnt; i++)
-                    near.cache(CACHE_NAME).put(i, i);
+                try {
+                    for (int i = 0; i < recordsCnt; i++)
+                        near.cache(CACHE_NAME).put(i, i);
 
-                blocked.countDown();
+                    log.info("Locked all records.");
+                }
+                catch (Exception e) {
+                    log.info("Failed to locked all records: " + e);
+                }
+                finally {
+                    blocked.countDown();
+                }
 
                 throw new IgniteException("Failure");
             }
@@ -585,7 +553,7 @@ public class TxRollbackOnTimeoutTest extends GridCommonAbstractTest {
             @Override public void run() {
                 U.awaitQuiet(blocked);
 
-                try (Transaction tx = other.transactions().txStart(PESSIMISTIC, REPEATABLE_READ,
0, 1)) {
+                try (Transaction tx = other.transactions().txStart(PESSIMISTIC, REPEATABLE_READ,
0, recordsCnt)) {
                     for (int i = 0; i < recordsCnt; i++)
                         other.cache(CACHE_NAME).put(i, i);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/2468e009/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
index bf01c0c..99de6c8 100755
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
@@ -82,8 +82,8 @@ import org.apache.ignite.internal.processors.cache.IgniteCacheAtomicInvokeTest;
 import org.apache.ignite.internal.processors.cache.IgniteCacheAtomicLocalInvokeTest;
 import org.apache.ignite.internal.processors.cache.IgniteCacheAtomicLocalWithStoreInvokeTest;
 import org.apache.ignite.internal.processors.cache.IgniteCacheAtomicNearEnabledInvokeTest;
-import org.apache.ignite.internal.processors.cache.IgniteCacheAtomicWithStoreInvokeTest;
 import org.apache.ignite.internal.processors.cache.IgniteCacheAtomicStopBusySelfTest;
+import org.apache.ignite.internal.processors.cache.IgniteCacheAtomicWithStoreInvokeTest;
 import org.apache.ignite.internal.processors.cache.IgniteCacheEntryListenerAtomicLocalTest;
 import org.apache.ignite.internal.processors.cache.IgniteCacheEntryListenerAtomicReplicatedTest;
 import org.apache.ignite.internal.processors.cache.IgniteCacheEntryListenerAtomicTest;
@@ -123,6 +123,7 @@ import org.apache.ignite.internal.processors.cache.distributed.IgniteCacheConnec
 import org.apache.ignite.internal.processors.cache.distributed.IgniteCacheMessageRecoveryIdleConnectionTest;
 import org.apache.ignite.internal.processors.cache.distributed.IgniteCacheMessageWriteTimeoutTest;
 import org.apache.ignite.internal.processors.cache.distributed.IgniteCacheSystemTransactionsSelfTest;
+import org.apache.ignite.internal.processors.cache.distributed.IgniteCacheThreadLocalTxTest;
 import org.apache.ignite.internal.processors.cache.distributed.IgniteCacheTxMessageRecoveryTest;
 import org.apache.ignite.internal.processors.cache.distributed.IgniteCrossCacheTxStoreSelfTest;
 import org.apache.ignite.internal.processors.cache.distributed.dht.GridCacheAtomicNearCacheSelfTest;
@@ -318,6 +319,7 @@ public class IgniteCacheTestSuite extends TestSuite {
 
         suite.addTestSuite(TxRollbackOnTimeoutTest.class);
         suite.addTestSuite(TxRollbackOnTimeoutNoDeadlockDetectionTest.class);
+        suite.addTestSuite(IgniteCacheThreadLocalTxTest.class);
 
         return suite;
     }


Mime
View raw message