# ignite-157 added simplified putAll restart test

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

Branch: refs/heads/ignite-837
Commit: 9ac0e96545edd85b513c6d0490354f00a7e1089b
Parents: 7013c2b
Author: sboikov <sboi...@gridgain.com>
Authored: Thu Apr 23 17:47:44 2015 +0300
Committer: sboikov <sboi...@gridgain.com>
Committed: Thu Apr 23 18:10:09 2015 +0300

----------------------------------------------------------------------
 .../cache/distributed/dht/GridDhtTxLocal.java   |   2 +-
 .../cache/IgniteCachePutAllRestartTest.java     | 203 +++++++++++++++++++
 .../testsuites/IgniteCacheRestartTestSuite.java |   1 +
 3 files changed, 205 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9ac0e965/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxLocal.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxLocal.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxLocal.java
index f3266df..176ffbb 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxLocal.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxLocal.java
@@ -603,7 +603,7 @@ public class GridDhtTxLocal extends GridDhtTxLocalAdapter 
implements GridCacheMa
             }
         }
         else {
-            prepFut.complete();
+            // prepFut.complete();
 
             prepFut.listen(new CI1<IgniteInternalFuture<IgniteInternalTx>>() {
                 @Override public void 
apply(IgniteInternalFuture<IgniteInternalTx> f) {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9ac0e965/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePutAllRestartTest.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePutAllRestartTest.java
 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePutAllRestartTest.java
new file mode 100644
index 0000000..93b42c1
--- /dev/null
+++ 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePutAllRestartTest.java
@@ -0,0 +1,203 @@
+/*
+ * 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;
+
+import org.apache.ignite.*;
+import org.apache.ignite.cache.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.internal.*;
+import org.apache.ignite.spi.discovery.tcp.*;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.*;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*;
+import org.apache.ignite.testframework.*;
+import org.apache.ignite.testframework.junits.common.*;
+
+import javax.cache.*;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.*;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.*;
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.*;
+
+/**
+ *
+ */
+public class IgniteCachePutAllRestartTest extends GridCommonAbstractTest {
+    /** Cache name. */
+    private static final String CACHE_NAME = "partitioned";
+
+    /** IP finder. */
+    private static TcpDiscoveryIpFinder ipFinder = new 
TcpDiscoveryVmIpFinder(true);
+
+    /** */
+    private static final int NODES = 4;
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) 
throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        cfg.setPeerClassLoadingEnabled(false);
+
+        ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(ipFinder);
+
+        CacheConfiguration cacheCfg = defaultCacheConfiguration();
+
+        cacheCfg.setName(CACHE_NAME);
+        cacheCfg.setWriteSynchronizationMode(FULL_SYNC);
+        cacheCfg.setCacheMode(CacheMode.PARTITIONED);
+        cacheCfg.setBackups(1);
+        cacheCfg.setAtomicityMode(TRANSACTIONAL);
+
+        cacheCfg.setNearConfiguration(null);
+
+        cfg.setCacheConfiguration(cacheCfg);
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected long getTestTimeout() {
+        return 5 * 60_000;
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testStopNode() throws Exception {
+        startGrids(NODES);
+
+        final AtomicBoolean stop = new AtomicBoolean();
+
+        IgniteInternalFuture<?> fut = GridTestUtils.runAsync(new 
Callable<Object>() {
+            @Override public Object call() throws Exception {
+                Thread.currentThread().setName("put-thread");
+
+                IgniteCache<Integer, Integer> cache = 
ignite(0).cache(CACHE_NAME);
+
+                Random rnd = new Random();
+
+                int iter = 0;
+
+                while (!stop.get()) {
+                    Map<Integer, Integer> map = new HashMap<>();
+
+                    for (int i = 0; i < 10; i++)
+                        map.put(rnd.nextInt(1000), i);
+
+                    try {
+                        cache.putAll(map);
+                    }
+                    catch (CacheException e) {
+                        log.info("Update failed: " + e);
+                    }
+
+                    iter++;
+
+                    if (iter % 10 == 0)
+                        log.info("Iteration: " + iter);
+                }
+
+                return null;
+            }
+        });
+
+        try {
+            ThreadLocalRandom rnd = ThreadLocalRandom.current();
+
+            long endTime = System.currentTimeMillis() + 2 * 60_000;
+
+            while (System.currentTimeMillis() < endTime) {
+                int node = rnd.nextInt(1, NODES);
+
+                stopGrid(node);
+
+                startGrid(node);
+            }
+        }
+        finally {
+            stop.set(true);
+        }
+
+        fut.get();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testStopOriginatingNode() throws Exception {
+        startGrids(NODES);
+
+        ThreadLocalRandom rnd = ThreadLocalRandom.current();
+
+        long endTime = System.currentTimeMillis() + 2 * 60_000;
+
+        while (System.currentTimeMillis() < endTime) {
+            int node = rnd.nextInt(0, NODES);
+
+            final Ignite ignite = ignite(node);
+
+            IgniteInternalFuture<?> fut = GridTestUtils.runAsync(new 
Callable<Void>() {
+                @Override public Void call() throws Exception {
+                    Thread.currentThread().setName("put-thread");
+
+                    IgniteCache<Integer, Integer> cache = 
ignite.cache(CACHE_NAME);
+
+                    Random rnd = new Random();
+
+                    long endTime = System.currentTimeMillis() + 60_000;
+
+                    try {
+                        int iter = 0;
+
+                        while (System.currentTimeMillis() < endTime) {
+                            Map<Integer, Integer> map = new HashMap<>();
+
+                            for (int i = 0; i < 10; i++)
+                                map.put(rnd.nextInt(1000), i);
+
+                            cache.putAll(map);
+
+                            iter++;
+
+                            log.info("Iteration: " + iter);
+                        }
+
+                        fail("Should fail.");
+                    }
+                    catch (CacheException | IllegalStateException e) {
+                        log.info("Expected error: " + e);
+                    }
+
+                    return null;
+                }
+            });
+
+            ignite.close();
+
+            fut.get();
+
+            startGrid(node);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9ac0e965/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheRestartTestSuite.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheRestartTestSuite.java
 
b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheRestartTestSuite.java
index 5b406c6..5682f67 100644
--- 
a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheRestartTestSuite.java
+++ 
b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheRestartTestSuite.java
@@ -47,6 +47,7 @@ public class IgniteCacheRestartTestSuite extends TestSuite {
 
         suite.addTestSuite(IgniteCacheAtomicPutAllFailoverSelfTest.class);
         // suite.addTestSuite(GridCachePutAllFailoverSelfTest.class); TODO 
IGNITE-157
+        // suite.addTestSuite(IgniteCacheAtomicNodeRestartTest.class); TODO 
IGNITE-157
 
         return suite;
     }

Reply via email to