Repository: ignite
Updated Branches:
  refs/heads/ignite-6181-1 2468e0090 -> 8e89ff291


ignite-6181-1


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/8e89ff29
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/8e89ff29
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/8e89ff29

Branch: refs/heads/ignite-6181-1
Commit: 8e89ff29179651c10c5918c1e8d0928e738ae8ae
Parents: 2468e00
Author: sboikov <[email protected]>
Authored: Tue Sep 19 18:01:38 2017 +0300
Committer: sboikov <[email protected]>
Committed: Tue Sep 19 18:16:29 2017 +0300

----------------------------------------------------------------------
 .../IgniteCacheThreadLocalTxTest.java           | 64 +++++++++++++---
 .../TxRollbackOnTimeoutNearCacheTest.java       | 28 +++++++
 .../transactions/TxRollbackOnTimeoutTest.java   | 79 ++++++++++++++++----
 .../ignite/testsuites/IgniteCacheTestSuite.java |  2 +
 4 files changed, 149 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/8e89ff29/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCacheThreadLocalTxTest.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCacheThreadLocalTxTest.java
 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCacheThreadLocalTxTest.java
index d62bae2..4b08500 100644
--- 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCacheThreadLocalTxTest.java
+++ 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCacheThreadLocalTxTest.java
@@ -22,8 +22,13 @@ import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCache;
 import org.apache.ignite.IgniteTransactions;
 import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.internal.IgniteKernal;
+import org.apache.ignite.internal.util.typedef.G;
 import org.apache.ignite.lang.IgniteFuture;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
 import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
 import org.apache.ignite.transactions.Transaction;
 import org.apache.ignite.transactions.TransactionConcurrency;
@@ -35,26 +40,63 @@ import static 
org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
  *
  */
 public class IgniteCacheThreadLocalTxTest extends GridCommonAbstractTest {
+    /** */
+    private static final TcpDiscoveryIpFinder ipFinder = new 
TcpDiscoveryVmIpFinder(true);
+
+    /** */
+    private boolean client;
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String 
igniteInstanceName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
+
+        ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(ipFinder);
+
+        cfg.setClientMode(client);
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+
+        super.afterTest();
+    }
+
     /**
-     *
+     * @throws Exception If failed.
      */
-    public IgniteCacheThreadLocalTxTest() {
-        super(true);
+    public void testSingleNode() throws Exception {
+        threadLocalTx(startGrid(0));
     }
 
     /**
      * @throws Exception If failed.
      */
+    public void testMultiNode() throws Exception {
+        startGridsMultiThreaded(4);
+
+        client = true;
+
+        startGrid(4);
+
+        for (Ignite node : G.allGrids())
+            threadLocalTx(node);
+    }
+
+    /**
+     * @param node Node.
+     * @throws Exception If failed.
+     */
     @SuppressWarnings("unchecked")
-    public void testThreadLocalTx() throws Exception {
+    private void threadLocalTx(Ignite node) throws Exception {
         CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
 
         ccfg.setAtomicityMode(TRANSACTIONAL);
+        ccfg.setBackups(2);
 
-        Ignite node = grid();
-
-        IgniteCache<Object, Object> cache = node.createCache(ccfg);
-        IgniteTransactions txs = node.transactions();
+        IgniteCache<Object, Object> cache = node.getOrCreateCache(ccfg);
 
         checkNoTx(node);
 
@@ -73,7 +115,11 @@ public class IgniteCacheThreadLocalTxTest extends 
GridCommonAbstractTest {
             }
         }
 
-        assertNull(txs.tx());
+        checkNoTx(node);
+
+        cache.put(1, 1);
+
+        checkNoTx(node);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/8e89ff29/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutNearCacheTest.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutNearCacheTest.java
 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutNearCacheTest.java
new file mode 100644
index 0000000..7c1a6dd
--- /dev/null
+++ 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxRollbackOnTimeoutNearCacheTest.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.transactions;
+
+/**
+ *
+ */
+public class TxRollbackOnTimeoutNearCacheTest extends TxRollbackOnTimeoutTest {
+    /** {@inheritDoc} */
+    @Override protected boolean nearCacheEnabled() {
+        return true;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/8e89ff29/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 caa1545..5dcd4b5 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,10 +25,12 @@ 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.NearCacheConfiguration;
 import org.apache.ignite.internal.IgniteEx;
 import org.apache.ignite.internal.IgniteInternalFuture;
 import 
org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal;
 import org.apache.ignite.internal.util.GridConcurrentSkipListSet;
+import org.apache.ignite.internal.util.typedef.F;
 import org.apache.ignite.internal.util.typedef.G;
 import org.apache.ignite.internal.util.typedef.X;
 import org.apache.ignite.internal.util.typedef.internal.U;
@@ -45,6 +47,7 @@ import 
org.apache.ignite.transactions.TransactionTimeoutException;
 import org.jsr166.ThreadLocalRandom8;
 
 import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
 import static 
org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC;
 import static 
org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ;
 
@@ -68,20 +71,35 @@ public class TxRollbackOnTimeoutTest extends 
GridCommonAbstractTest {
     @Override protected IgniteConfiguration getConfiguration(String 
igniteInstanceName) throws Exception {
         IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
 
-        cfg.setClientMode("client".equals(igniteInstanceName));
-
         ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(IP_FINDER);
 
-        CacheConfiguration ccfg = new CacheConfiguration(CACHE_NAME);
+        boolean client = "client".equals(igniteInstanceName);
+
+        cfg.setClientMode(client);
+
+        if (!client) {
+            CacheConfiguration ccfg = new CacheConfiguration(CACHE_NAME);
+
+            if (nearCacheEnabled())
+                ccfg.setNearConfiguration(new NearCacheConfiguration());
 
-        ccfg.setAtomicityMode(TRANSACTIONAL);
-        ccfg.setBackups(2);
+            ccfg.setAtomicityMode(TRANSACTIONAL);
+            ccfg.setBackups(2);
+            ccfg.setWriteSynchronizationMode(FULL_SYNC);
 
-        cfg.setCacheConfiguration(ccfg);
+            cfg.setCacheConfiguration(ccfg);
+        }
 
         return cfg;
     }
 
+    /**
+     * @return Near cache flag.
+     */
+    protected boolean nearCacheEnabled() {
+        return false;
+    }
+
     /** {@inheritDoc} */
     @Override protected void beforeTest() throws Exception {
         super.beforeTest();
@@ -97,6 +115,23 @@ public class TxRollbackOnTimeoutTest extends 
GridCommonAbstractTest {
     }
 
     /**
+     * @throws Exception If f nodeailed.
+     * @return Started client.
+     */
+    private Ignite startClient() throws Exception {
+        Ignite client = startGrid("client");
+
+        assertTrue(client.configuration().isClientMode());
+
+        if (nearCacheEnabled())
+            client.createNearCache(CACHE_NAME, new NearCacheConfiguration<>());
+        else
+            assertNotNull(client.cache(CACHE_NAME));
+
+        return client;
+    }
+
+    /**
      * @param e Exception.
      */
     protected void validateDeadlockException(Exception e) {
@@ -108,7 +143,7 @@ public class TxRollbackOnTimeoutTest extends 
GridCommonAbstractTest {
      * @throws Exception If failed.
      */
     public void testLockAndConcurrentTimeout() throws Exception {
-        startGrid("client");
+        startClient();
 
         for (Ignite node : G.allGrids()) {
             log.info("Test with node: " + node.name());
@@ -169,7 +204,7 @@ public class TxRollbackOnTimeoutTest extends 
GridCommonAbstractTest {
                     }
                 }
             }
-        }, 8, "tx-thread");
+        }, Runtime.getRuntime().availableProcessors(), "tx-thread");
     }
 
     /**
@@ -182,7 +217,7 @@ public class TxRollbackOnTimeoutTest extends 
GridCommonAbstractTest {
 
         waitingTxUnblockedOnTimeout(grid(0), grid(1));
 
-        Ignite client = startGrid("client");
+        Ignite client = startClient();
 
         waitingTxUnblockedOnTimeout(grid(0), client);
 
@@ -205,7 +240,7 @@ public class TxRollbackOnTimeoutTest extends 
GridCommonAbstractTest {
 
         waitingTxUnblockedOnThreadDeath(grid(0), grid(1));
 
-        Ignite client = startGrid("client");
+        Ignite client = startClient();
 
         waitingTxUnblockedOnThreadDeath(grid(0), client);
 
@@ -228,7 +263,7 @@ public class TxRollbackOnTimeoutTest extends 
GridCommonAbstractTest {
 
         deadlockUnblockedOnTimeout(ignite(0), ignite(0));
 
-        Ignite client = startGrid("client");
+        Ignite client = startClient();
 
         deadlockUnblockedOnTimeout(ignite(0), client);
 
@@ -290,8 +325,10 @@ public class TxRollbackOnTimeoutTest extends 
GridCommonAbstractTest {
         fut1.get();
         fut2.get();
 
-        assertTrue("Expecting committed key 2", 
node1.cache(CACHE_NAME).containsKey(2));
-        assertTrue("Expecting committed key 1", 
node1.cache(CACHE_NAME).containsKey(1));
+        assertTrue("Expecting committed key 2", node1.cache(CACHE_NAME).get(2) 
!= null);
+        assertTrue("Expecting committed key 1", node1.cache(CACHE_NAME).get(1) 
!= null);
+
+        node1.cache(CACHE_NAME).removeAll(F.asSet(1, 2));
     }
 
     /**
@@ -300,7 +337,7 @@ public class TxRollbackOnTimeoutTest extends 
GridCommonAbstractTest {
      * @throws Exception If failed.
      */
     public void testTimeoutRemoval() throws Exception {
-        IgniteEx client = (IgniteEx)startGrid("client");
+        IgniteEx client = (IgniteEx)startClient();
 
         final long TX_TIMEOUT = 250;
 
@@ -423,6 +460,18 @@ public class TxRollbackOnTimeoutTest extends 
GridCommonAbstractTest {
      * @throws Exception If failed.
      */
     private void waitingTxUnblockedOnTimeout(final Ignite near, final Ignite 
other) throws Exception {
+        waitingTxUnblockedOnTimeout(near, other, 1000);
+
+        waitingTxUnblockedOnTimeout(near, other, 50);
+    }
+
+    /**
+     * @param near Node starting tx which is timed out.
+     * @param other Node starting second tx.
+     * @param timeout Timeout.
+     * @throws Exception If failed.
+     */
+    private void waitingTxUnblockedOnTimeout(final Ignite near, final Ignite 
other, final long timeout) throws Exception {
         info("Start test [node1=" + near.name() + ", node2=" + other.name() + 
']');
 
         final CountDownLatch blocked = new CountDownLatch(1);
@@ -433,7 +482,7 @@ public class TxRollbackOnTimeoutTest extends 
GridCommonAbstractTest {
 
         IgniteInternalFuture<?> fut1 = GridTestUtils.runAsync(new Runnable() {
             @Override public void run() {
-                try (Transaction tx = near.transactions().txStart(PESSIMISTIC, 
REPEATABLE_READ, 1000, 0)) {
+                try (Transaction tx = near.transactions().txStart(PESSIMISTIC, 
REPEATABLE_READ, timeout, 0)) {
                     try {
                         for (int i = 0; i < recordsCnt; i++)
                             near.cache(CACHE_NAME).put(i, i);

http://git-wip-us.apache.org/repos/asf/ignite/blob/8e89ff29/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 99de6c8..260dffa 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
@@ -135,6 +135,7 @@ import 
org.apache.ignite.internal.processors.cache.distributed.replicated.GridCa
 import 
org.apache.ignite.internal.processors.cache.local.GridCacheLocalTxExceptionSelfTest;
 import 
org.apache.ignite.internal.processors.cache.query.continuous.CacheEntryProcessorExternalizableFailedTest;
 import 
org.apache.ignite.internal.processors.cache.query.continuous.CacheEntryProcessorNonSerializableTest;
+import 
org.apache.ignite.internal.processors.cache.transactions.TxRollbackOnTimeoutNearCacheTest;
 import 
org.apache.ignite.internal.processors.cache.transactions.TxRollbackOnTimeoutNoDeadlockDetectionTest;
 import 
org.apache.ignite.internal.processors.cache.transactions.TxRollbackOnTimeoutTest;
 import 
org.apache.ignite.internal.processors.datastreamer.DataStreamProcessorSelfTest;
@@ -318,6 +319,7 @@ public class IgniteCacheTestSuite extends TestSuite {
         suite.addTestSuite(IgniteIncompleteCacheObjectSelfTest.class);
 
         suite.addTestSuite(TxRollbackOnTimeoutTest.class);
+        suite.addTestSuite(TxRollbackOnTimeoutNearCacheTest.class);
         suite.addTestSuite(TxRollbackOnTimeoutNoDeadlockDetectionTest.class);
         suite.addTestSuite(IgniteCacheThreadLocalTxTest.class);
 

Reply via email to