You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2017/07/13 14:36:04 UTC

[35/50] ignite git commit: ignite-5578 Affinity for local join

ignite-5578 Affinity for local join


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

Branch: refs/heads/ignite-5578
Commit: d72ff5909517f06bfb63d9eee020e341811cb1ba
Parents: 4a46272
Author: sboikov <sb...@gridgain.com>
Authored: Wed Jul 12 19:06:11 2017 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Wed Jul 12 19:06:11 2017 +0300

----------------------------------------------------------------------
 .../db/IgnitePdsCacheRestoreTest.java           | 208 +++++++++++++++++++
 .../ignite/testsuites/IgnitePdsTestSuite.java   |   5 +-
 2 files changed, 212 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/d72ff590/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgnitePdsCacheRestoreTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgnitePdsCacheRestoreTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgnitePdsCacheRestoreTest.java
new file mode 100644
index 0000000..25626f4
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgnitePdsCacheRestoreTest.java
@@ -0,0 +1,208 @@
+/*
+ * 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.persistence.db;
+
+import java.util.Arrays;
+import java.util.List;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.MemoryConfiguration;
+import org.apache.ignite.configuration.PersistentStoreConfiguration;
+import org.apache.ignite.configuration.WALMode;
+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.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
+
+/**
+ *
+ */
+public class IgnitePdsCacheRestoreTest extends GridCommonAbstractTest {
+    /** */
+    private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
+
+    /** */
+    private CacheConfiguration[] ccfgs;
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
+
+        ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(IP_FINDER);
+
+        if (ccfgs != null) {
+            cfg.setCacheConfiguration(ccfgs);
+
+            ccfgs = null;
+        }
+
+        MemoryConfiguration memCfg = new MemoryConfiguration();
+        memCfg.setPageSize(1024);
+        memCfg.setDefaultMemoryPolicySize(10 * 1024 * 1024);
+
+        cfg.setMemoryConfiguration(memCfg);
+
+        PersistentStoreConfiguration pCfg = new PersistentStoreConfiguration();
+
+        pCfg.setWalMode(WALMode.LOG_ONLY);
+
+        cfg.setPersistentStoreConfiguration(pCfg);
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        super.beforeTest();
+
+        GridTestUtils.deleteDbFiles();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+
+        GridTestUtils.deleteDbFiles();
+
+        super.afterTest();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testRestoreAndNewCache1() throws Exception {
+        restoreAndNewCache(false);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testRestoreAndNewCache2() throws Exception {
+        restoreAndNewCache(true);
+    }
+
+    /**
+     * @param createNew If {@code true} need cache is added while node is stopped.
+     * @throws Exception If failed.
+     */
+    private void restoreAndNewCache(boolean createNew) throws Exception {
+        for (int i = 0; i < 3; i++) {
+            ccfgs = configurations1();
+
+            startGrid(i);
+        }
+
+        ignite(0).active(true);
+
+        IgniteCache<Object, Object> cache1 = ignite(2).cache("c1");
+
+        List<Integer> keys = primaryKeys(cache1, 10);
+
+        for (Integer key : keys)
+            cache1.put(key, key);
+
+        stopGrid(2);
+
+        if (createNew) {
+            // New cache is added when node is stopped.
+            ignite(0).getOrCreateCaches(Arrays.asList(configurations2()));
+        }
+        else {
+            // New cache is added on node restart.
+            ccfgs = configurations2();
+        }
+
+        startGrid(2);
+
+        cache1 = ignite(2).cache("c1");
+
+        IgniteCache<Object, Object> cache2 = ignite(2).cache("c2");
+
+        for (Integer key : keys) {
+            assertEquals(key, cache1.get(key));
+
+            assertNull(cache2.get(key));
+
+            cache2.put(key, key);
+
+            assertEquals(key, cache2.get(key));
+        }
+
+        List<Integer> nearKeys = nearKeys(cache1, 10, 0);
+
+        for (Integer key : nearKeys) {
+            assertNull(cache1.get(key));
+            assertNull(cache2.get(key));
+
+            cache2.put(key, key);
+            assertEquals(key, cache2.get(key));
+
+            cache1.put(key, key);
+            assertEquals(key, cache1.get(key));
+        }
+
+        startGrid(3);
+
+        awaitPartitionMapExchange();
+
+        for (Integer key : nearKeys) {
+            assertEquals(key, cache2.get(key));
+
+            assertEquals(key, cache1.get(key));
+        }
+    }
+
+    /**
+     * @return Configurations set 1.
+     */
+    private CacheConfiguration[] configurations1() {
+        CacheConfiguration[] ccfgs = new CacheConfiguration[1];
+
+        ccfgs[0] = cacheConfiguration("c1");
+
+        return ccfgs;
+    }
+
+    /**
+     * @return Configurations set 1.
+     */
+    private CacheConfiguration[] configurations2() {
+        CacheConfiguration[] ccfgs = new CacheConfiguration[2];
+
+        ccfgs[0] = cacheConfiguration("c1");
+        ccfgs[1] = cacheConfiguration("c2");
+
+        return ccfgs;
+    }
+
+    /**
+     * @param name Cache name.
+     * @return Cache configuration.
+     */
+    private CacheConfiguration cacheConfiguration(String name) {
+        CacheConfiguration ccfg = new CacheConfiguration(name);
+
+        ccfg.setWriteSynchronizationMode(FULL_SYNC);
+
+        return ccfg;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/d72ff590/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite.java
index f09973b..eaf4a01 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite.java
@@ -21,8 +21,9 @@ import junit.framework.TestSuite;
 import org.apache.ignite.internal.processors.cache.persistence.IgnitePdsClientNearCachePutGetTest;
 import org.apache.ignite.internal.processors.cache.persistence.IgnitePdsDynamicCacheTest;
 import org.apache.ignite.internal.processors.cache.persistence.IgnitePdsSingleNodePutGetPersistenceTest;
-import org.apache.ignite.internal.processors.cache.persistence.db.file.IgnitePdsEvictionTest;
+import org.apache.ignite.internal.processors.cache.persistence.db.IgnitePdsCacheRestoreTest;
 import org.apache.ignite.internal.processors.cache.persistence.db.file.IgnitePdsCheckpointSimulationWithRealCpDisabledTest;
+import org.apache.ignite.internal.processors.cache.persistence.db.file.IgnitePdsEvictionTest;
 import org.apache.ignite.internal.processors.cache.persistence.pagemem.BPlusTreePageMemoryImplTest;
 import org.apache.ignite.internal.processors.cache.persistence.pagemem.BPlusTreeReuseListPageMemoryImplTest;
 import org.apache.ignite.internal.processors.cache.persistence.pagemem.MetadataStoragePageMemoryImplTest;
@@ -71,6 +72,8 @@ public class IgnitePdsTestSuite extends TestSuite {
         suite.addTestSuite(IgnitePdsDynamicCacheTest.class);
         suite.addTestSuite(IgnitePdsClientNearCachePutGetTest.class);
 
+        suite.addTestSuite(IgnitePdsCacheRestoreTest.class);
+
         return suite;
     }
 }