ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject ignite git commit: Added new test: IgniteCachePartitionedBackupNodeFailureRecoveryTest.
Date Tue, 08 Nov 2016 08:21:48 GMT
Repository: ignite
Updated Branches:
  refs/heads/master 45bb1ac95 -> e031498d8


Added new test: IgniteCachePartitionedBackupNodeFailureRecoveryTest.


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

Branch: refs/heads/master
Commit: e031498d872a5f1552b26a859b9ee79d3568ff9b
Parents: 45bb1ac
Author: sboikov <sboikov@gridgain.com>
Authored: Tue Nov 8 11:21:37 2016 +0300
Committer: sboikov <sboikov@gridgain.com>
Committed: Tue Nov 8 11:21:37 2016 +0300

----------------------------------------------------------------------
 ...artitionedBackupNodeFailureRecoveryTest.java | 193 +++++++++++++++++++
 .../testsuites/IgniteCacheTestSuite2.java       |   2 +
 2 files changed, 195 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/e031498d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/IgniteCachePartitionedBackupNodeFailureRecoveryTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/IgniteCachePartitionedBackupNodeFailureRecoveryTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/IgniteCachePartitionedBackupNodeFailureRecoveryTest.java
new file mode 100644
index 0000000..6654fd9
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/IgniteCachePartitionedBackupNodeFailureRecoveryTest.java
@@ -0,0 +1,193 @@
+/*
+* 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.distributed.dht;
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.locks.ReentrantLock;
+import javax.cache.processor.EntryProcessor;
+import javax.cache.processor.MutableEntry;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.CacheAtomicWriteOrderMode;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.cache.affinity.Affinity;
+import org.apache.ignite.configuration.CacheConfiguration;
+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.IgniteCacheAbstractTest;
+
+import static org.apache.ignite.cache.CacheAtomicWriteOrderMode.PRIMARY;
+import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
+import static org.apache.ignite.cache.CacheMode.PARTITIONED;
+import static org.apache.ignite.cache.CacheRebalanceMode.SYNC;
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.PRIMARY_SYNC;
+import static org.apache.ignite.testframework.GridTestUtils.runAsync;
+
+/**
+ */
+public class IgniteCachePartitionedBackupNodeFailureRecoveryTest extends IgniteCacheAbstractTest
{
+    /** {@inheritDoc}*/
+    @Override protected int gridCount() {
+        return 3;
+    }
+
+    /** {@inheritDoc}*/
+    @Override protected CacheMode cacheMode() {
+        return PARTITIONED;
+    }
+
+    /** {@inheritDoc}*/
+    @Override protected CacheAtomicityMode atomicityMode() {
+        return ATOMIC;
+    }
+
+    /** {@inheritDoc}*/
+    @Override protected CacheAtomicWriteOrderMode atomicWriteOrderMode() {
+        return PRIMARY;
+    }
+
+    /** {@inheritDoc}*/
+    @Override protected NearCacheConfiguration nearConfiguration() {
+        return new NearCacheConfiguration();
+    }
+
+    /** {@inheritDoc}*/
+    @Override protected CacheConfiguration cacheConfiguration(String gridName) throws Exception
{
+        CacheConfiguration ccfg = super.cacheConfiguration(gridName);
+
+        ccfg.setBackups(1);
+        ccfg.setWriteSynchronizationMode(PRIMARY_SYNC);
+        ccfg.setRebalanceMode(SYNC);
+
+        return ccfg;
+    }
+
+    /**
+     * Test stops and restarts backup node.
+     *
+     * @throws Exception If failed.
+     */
+    public void testBackUpFail() throws Exception {
+        final IgniteEx node1 = grid(0);
+        final IgniteEx node2 = grid(1);
+        final IgniteEx node3 = grid(2);
+
+        awaitPartitionMapExchange();
+
+        final IgniteCache<Integer, Integer> cache1 = node1.cache(null);
+
+        Affinity<Integer> aff = node1.affinity(null);
+
+        Integer key0 = null;
+
+        for (int key = 0; key < 10_000; key++) {
+            if (aff.isPrimary(node2.cluster().localNode(), key) && aff.isBackup(node3.cluster().localNode(),
key)) {
+                key0 = key;
+
+                break;
+            }
+        }
+
+        assertNotNull(key0);
+
+        cache1.put(key0, 0);
+
+        final AtomicBoolean finished = new AtomicBoolean();
+
+        final ReentrantLock lock = new ReentrantLock();
+
+        final AtomicInteger cntr = new AtomicInteger();
+
+        final Integer finalKey = key0;
+
+        IgniteInternalFuture<Void> primaryFut;
+        IgniteInternalFuture<Void> backupFut;
+
+        try {
+            primaryFut = runAsync(new Callable<Void>() {
+                @Override public Void call() throws Exception {
+                    while (!finished.get()) {
+                        lock.lock();
+
+                        try {
+                            cache1.invoke(finalKey, new TestEntryProcessor());
+
+                            cntr.getAndIncrement();
+                        }
+                        finally {
+                            lock.unlock();
+                        }
+                    }
+
+                    return null;
+                }
+            });
+
+            backupFut = runAsync(new Callable<Void>() {
+                @Override public Void call() throws Exception {
+                    while (!finished.get()) {
+                        stopGrid(2);
+
+                        IgniteEx backUp = startGrid(2);
+
+                        IgniteCache<Integer, Integer> cache3 = backUp.cache(null);
+
+                        lock.lock();
+
+                        try {
+                            Integer backUpVal = cache3.localPeek(finalKey);
+
+                            Integer exp = cntr.get();
+
+                            assertEquals(exp, backUpVal);
+                        }
+                        finally {
+                            lock.unlock();
+                        }
+                    }
+                    return null;
+                }
+            });
+
+            Thread.sleep(30_000);
+        }
+        finally {
+            finished.set(true);
+        }
+
+        primaryFut.get();
+        backupFut.get();
+    }
+
+    /**
+     *
+     */
+    static class TestEntryProcessor implements EntryProcessor<Integer, Integer, Void>
{
+        /** {@inheritDoc}*/
+        @Override public Void process(MutableEntry<Integer, Integer> entry, Object...
args) {
+            Integer v = entry.getValue() + 1;
+
+            entry.setValue(v);
+
+            return null;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/e031498d/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite2.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite2.java
b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite2.java
index dc412a9..3fc27de 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite2.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite2.java
@@ -72,6 +72,7 @@ import org.apache.ignite.internal.processors.cache.distributed.dht.GridCachePart
 import org.apache.ignite.internal.processors.cache.distributed.dht.GridCachePartitionedPreloadEventsSelfTest;
 import org.apache.ignite.internal.processors.cache.distributed.dht.GridCachePartitionedTopologyChangeSelfTest;
 import org.apache.ignite.internal.processors.cache.distributed.dht.GridCachePartitionedUnloadEventsSelfTest;
+import org.apache.ignite.internal.processors.cache.distributed.dht.IgniteCachePartitionedBackupNodeFailureRecoveryTest;
 import org.apache.ignite.internal.processors.cache.distributed.near.GridCacheAtomicNearEvictionEventSelfTest;
 import org.apache.ignite.internal.processors.cache.distributed.near.GridCacheAtomicNearMultiNodeSelfTest;
 import org.apache.ignite.internal.processors.cache.distributed.near.GridCacheAtomicNearReadersSelfTest;
@@ -259,6 +260,7 @@ public class IgniteCacheTestSuite2 extends TestSuite {
         suite.addTest(new TestSuite(CacheEnumOperationsSingleNodeTest.class));
         suite.addTest(new TestSuite(CacheEnumOperationsTest.class));
         suite.addTest(new TestSuite(IgniteCacheIncrementTxTest.class));
+        suite.addTest(new TestSuite(IgniteCachePartitionedBackupNodeFailureRecoveryTest.class));
 
         suite.addTest(new TestSuite(IgniteNoCustomEventsOnNodeStart.class));
 


Mime
View raw message