ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vkuliche...@apache.org
Subject [12/50] incubator-ignite git commit: # ignite-45 added specific test for near reader update
Date Tue, 24 Mar 2015 17:47:23 GMT
# ignite-45 added specific test for near reader update


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

Branch: refs/heads/ignite-45-ipc-debug
Commit: 5d46399b7c8463ec4c11f824e42552ff9e30e4fc
Parents: 8aff704
Author: sboikov <sboikov@gridgain.com>
Authored: Tue Mar 24 13:41:28 2015 +0300
Committer: sboikov <sboikov@gridgain.com>
Committed: Tue Mar 24 13:41:28 2015 +0300

----------------------------------------------------------------------
 ...cheNearUpdateTopologyChangeAbstractTest.java | 129 +++++++++++++++++++
 ...CacheAtomicNearUpdateTopologyChangeTest.java |  39 ++++++
 .../CacheTxNearUpdateTopologyChangeTest.java    |  33 +++++
 ...GridCacheDhtEvictionNearReadersSelfTest.java |   8 --
 .../dht/GridCacheDhtEvictionSelfTest.java       |   8 --
 .../dht/GridCacheDhtInternalEntrySelfTest.java  |   8 --
 .../testframework/junits/GridAbstractTest.java  |   8 ++
 .../junits/common/GridCommonAbstractTest.java   |  53 ++++++++
 8 files changed, 262 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5d46399b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheNearUpdateTopologyChangeAbstractTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheNearUpdateTopologyChangeAbstractTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheNearUpdateTopologyChangeAbstractTest.java
new file mode 100644
index 0000000..9200612
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheNearUpdateTopologyChangeAbstractTest.java
@@ -0,0 +1,129 @@
+/*
+ * 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.cache.affinity.*;
+import org.apache.ignite.cluster.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.internal.util.lang.*;
+import org.apache.ignite.testframework.*;
+
+import java.util.*;
+
+import static org.apache.ignite.cache.CacheMode.*;
+
+/**
+ *
+ */
+public abstract class CacheNearUpdateTopologyChangeAbstractTest extends IgniteCacheAbstractTest
{
+    /** {@inheritDoc} */
+    @Override protected int gridCount() {
+        return 3;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheMode cacheMode() {
+        return PARTITIONED;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected NearCacheConfiguration nearConfiguration() {
+        return new NearCacheConfiguration();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testNearUpdateTopologyChange() throws Exception {
+        final CacheAffinity<Integer> aff = grid(0).affinity(null);
+
+        final Integer key = 9;
+
+        IgniteCache<Integer, Integer> primaryCache = primaryCache(key, null);
+
+        final Ignite primaryIgnite = primaryCache.unwrap(Ignite.class);
+
+        log.info("Primary node: " + primaryIgnite.name());
+
+        primaryCache.put(key, 1);
+
+        IgniteCache<Integer, Integer> nearCache = nearCache(key);
+
+        log.info("Near node: " + nearCache.unwrap(Ignite.class).name());
+
+        assertEquals((Object)1, nearCache.get(key));
+
+        boolean gotNewPrimary = false;
+
+        List<Ignite> newNodes = new ArrayList<>();
+
+        for (int i = 0; i < 10; i++) {
+            int idx = gridCount() + i;
+
+            log.info("Start new node: " + i);
+
+            Ignite ignite = startGrid(idx);
+
+            awaitPartitionMapExchange();
+
+            newNodes.add(ignite);
+
+            ClusterNode primaryNode = aff.mapKeyToNode(key);
+
+            Ignite primary = grid(primaryNode);
+
+            log.info("Primary node on new topology: " + primary.name());
+
+            if (!primaryNode.equals(primaryIgnite.cluster().localNode())) {
+                log.info("Update from new primary: " + primary.name());
+
+                primary = grid(primaryNode);
+
+                gotNewPrimary = true;
+
+                primary.cache(null).put(key, 2);
+
+                break;
+            }
+        }
+
+        assertTrue(gotNewPrimary);
+
+        for (Ignite ignite : newNodes) {
+            log.info("Stop started node: " + ignite.name());
+
+            ignite.close();
+        }
+
+        awaitPartitionMapExchange();
+
+        GridTestUtils.waitForCondition(new GridAbsPredicate() {
+            @Override public boolean apply() {
+                return aff.isPrimary(primaryIgnite.cluster().localNode(), key);
+            }
+        }, 10_000);
+
+        log.info("Primary node: " + primaryNode(key, null).name());
+
+        assertTrue(aff.isPrimary(primaryIgnite.cluster().localNode(), key));
+
+        assertEquals((Object)2, nearCache.get(key));
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5d46399b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/CacheAtomicNearUpdateTopologyChangeTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/CacheAtomicNearUpdateTopologyChangeTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/CacheAtomicNearUpdateTopologyChangeTest.java
new file mode 100644
index 0000000..a69a9c3
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/CacheAtomicNearUpdateTopologyChangeTest.java
@@ -0,0 +1,39 @@
+/*
+ * 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;
+
+import org.apache.ignite.cache.*;
+import org.apache.ignite.internal.processors.cache.*;
+
+import static org.apache.ignite.cache.CacheAtomicWriteOrderMode.*;
+import static org.apache.ignite.cache.CacheAtomicityMode.*;
+
+/**
+ *
+ */
+public class CacheAtomicNearUpdateTopologyChangeTest extends CacheNearUpdateTopologyChangeAbstractTest
{
+    /** {@inheritDoc} */
+    @Override protected CacheAtomicityMode atomicityMode() {
+        return ATOMIC;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheAtomicWriteOrderMode atomicWriteOrderMode() {
+        return PRIMARY;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5d46399b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/CacheTxNearUpdateTopologyChangeTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/CacheTxNearUpdateTopologyChangeTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/CacheTxNearUpdateTopologyChangeTest.java
new file mode 100644
index 0000000..1eeb865
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/CacheTxNearUpdateTopologyChangeTest.java
@@ -0,0 +1,33 @@
+/*
+ * 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;
+
+import org.apache.ignite.cache.*;
+import org.apache.ignite.internal.processors.cache.*;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.*;
+
+/**
+ *
+ */
+public class CacheTxNearUpdateTopologyChangeTest extends CacheNearUpdateTopologyChangeAbstractTest
{
+    /** {@inheritDoc} */
+    @Override protected CacheAtomicityMode atomicityMode() {
+        return TRANSACTIONAL;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5d46399b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheDhtEvictionNearReadersSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheDhtEvictionNearReadersSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheDhtEvictionNearReadersSelfTest.java
index be4cef7..1252326 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheDhtEvictionNearReadersSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheDhtEvictionNearReadersSelfTest.java
@@ -139,14 +139,6 @@ public class GridCacheDhtEvictionNearReadersSelfTest extends GridCommonAbstractT
     }
 
     /**
-     * @param node Node.
-     * @return Grid for the given node.
-     */
-    private Ignite grid(ClusterNode node) {
-        return G.ignite(node.id());
-    }
-
-    /**
      * @param g Grid.
      * @return Near cache.
      */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5d46399b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheDhtEvictionSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheDhtEvictionSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheDhtEvictionSelfTest.java
index a177e00..64f26aa 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheDhtEvictionSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheDhtEvictionSelfTest.java
@@ -132,14 +132,6 @@ public class GridCacheDhtEvictionSelfTest extends GridCommonAbstractTest
{
     }
 
     /**
-     * @param node Node.
-     * @return Grid for the given node.
-     */
-    private Ignite grid(ClusterNode node) {
-        return G.ignite(node.id());
-    }
-
-    /**
      * @param g Grid.
      * @return Near cache.
      */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5d46399b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheDhtInternalEntrySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheDhtInternalEntrySelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheDhtInternalEntrySelfTest.java
index b944869..82bf5ae 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheDhtInternalEntrySelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheDhtInternalEntrySelfTest.java
@@ -198,12 +198,4 @@ public class GridCacheDhtInternalEntrySelfTest extends GridCommonAbstractTest
{
 
         return F.t(primary, other);
     }
-
-    /**
-     * @param node Node.
-     * @return Grid.
-     */
-    private Ignite grid(ClusterNode node) {
-        return G.ignite(node.id());
-    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5d46399b/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java
b/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java
index 29b832e..93d1d74 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java
@@ -836,6 +836,14 @@ public abstract class GridAbstractTest extends TestCase {
     }
 
     /**
+     * @param node Node.
+     * @return Ignite instance with given local node.
+     */
+    protected final Ignite grid(ClusterNode node) {
+        return G.ignite(node.id());
+    }
+
+    /**
      * Starts grid using provided grid name and spring config location.
      * <p>
      * Note that grids started this way should be stopped with {@code G.stop(..)} methods.

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5d46399b/modules/core/src/test/java/org/apache/ignite/testframework/junits/common/GridCommonAbstractTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/common/GridCommonAbstractTest.java
b/modules/core/src/test/java/org/apache/ignite/testframework/junits/common/GridCommonAbstractTest.java
index 9389018..143a3b7 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/common/GridCommonAbstractTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/common/GridCommonAbstractTest.java
@@ -731,4 +731,57 @@ public abstract class GridCommonAbstractTest extends GridAbstractTest
{
 
         return null;
     }
+
+    /**
+     * @param key Key.
+     * @return Near cache for key.
+     */
+    protected IgniteCache<Integer, Integer> nearCache(Integer key) {
+        List<Ignite> allGrids = Ignition.allGrids();
+
+        assertFalse("There are no alive nodes.", F.isEmpty(allGrids));
+
+        CacheAffinity<Integer> aff = allGrids.get(0).affinity(null);
+
+        Collection<ClusterNode> nodes = aff.mapKeyToPrimaryAndBackups(key);
+
+        for (Ignite ignite : allGrids) {
+            if (!nodes.contains(ignite.cluster().localNode()))
+                return ignite.cache(null);
+        }
+
+        fail();
+
+        return null;
+    }
+
+    /**
+     * @param key Key.
+     * @param cacheName Cache name.
+     * @return Near cache for key.
+     */
+    protected IgniteCache<Integer, Integer> primaryCache(Integer key, String cacheName)
{
+        return primaryNode(key, null).cache(null);
+    }
+
+    /**
+     * @param key Key.
+     * @param cacheName Cache name.
+     * @return Ignite instance which has primary cache for given key.
+     */
+    protected Ignite primaryNode(Object key, String cacheName) {
+        List<Ignite> allGrids = Ignition.allGrids();
+
+        assertFalse("There are no alive nodes.", F.isEmpty(allGrids));
+
+        Ignite ignite = allGrids.get(0);
+
+        CacheAffinity<Object> aff = ignite.affinity(cacheName);
+
+        ClusterNode node = aff.mapKeyToNode(key);
+
+        assertNotNull("There are no cache affinity nodes", node);
+
+        return grid(node);
+    }
 }


Mime
View raw message