You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ag...@apache.org on 2016/01/27 11:24:50 UTC

[06/21] ignite git commit: ignite-2407 Added test.

ignite-2407 Added test.


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

Branch: refs/heads/sql-store
Commit: 7a660d7683c8d77c5156ca6c959c83935de77a0c
Parents: 4fa85a1
Author: sboikov <sb...@gridgain.com>
Authored: Thu Jan 21 16:15:18 2016 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Thu Jan 21 16:15:18 2016 +0300

----------------------------------------------------------------------
 .../distributed/IgniteCachePrimarySyncTest.java | 129 +++++++++++++++++++
 1 file changed, 129 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/7a660d76/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCachePrimarySyncTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCachePrimarySyncTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCachePrimarySyncTest.java
new file mode 100644
index 0000000..cef73fd
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCachePrimarySyncTest.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.distributed;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+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 static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.PRIMARY_SYNC;
+
+/**
+ *
+ */
+public class IgniteCachePrimarySyncTest extends GridCommonAbstractTest {
+    /** */
+    private static final TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true);
+
+    /** */
+    private static final int SRVS = 4;
+
+    /** */
+    private boolean clientMode;
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(ipFinder);
+
+        CacheConfiguration<Object, Object> ccfg1 = new CacheConfiguration<>();
+        ccfg1.setName("cache1");
+        ccfg1.setAtomicityMode(ATOMIC);
+        ccfg1.setBackups(2);
+        ccfg1.setWriteSynchronizationMode(PRIMARY_SYNC);
+
+        CacheConfiguration<Object, Object> ccfg2 = new CacheConfiguration<>();
+        ccfg2.setName("cache2");
+        ccfg2.setAtomicityMode(TRANSACTIONAL);
+        ccfg2.setBackups(2);
+        ccfg2.setWriteSynchronizationMode(PRIMARY_SYNC);
+
+        cfg.setCacheConfiguration(ccfg1, ccfg2);
+
+        cfg.setClientMode(clientMode);
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        super.beforeTestsStarted();
+
+        startGrids(SRVS);
+
+        clientMode = true;
+
+        Ignite client = startGrid(SRVS);
+
+        assertTrue(client.configuration().isClientMode());
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        super.afterTestsStopped();
+
+        stopAllGrids();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPutGet() throws Exception {
+        checkPutGet(ignite(SRVS).cache("cache1"));
+
+        checkPutGet(ignite(SRVS).cache("cache2"));
+    }
+
+    /**
+     * @param cache Cache.
+     */
+    private void checkPutGet(IgniteCache<Object, Object> cache) {
+        log.info("Check cache: " + cache.getName());
+
+        final int KEYS = 50;
+
+        for (int iter = 0; iter < 100; iter++) {
+            log.info("Iteration: " + iter);
+
+            for (int i = 0; i < KEYS; i++)
+                cache.remove(i);
+
+            Map<Integer, Integer> putBatch = new HashMap<>();
+
+            for (int i = 0; i < KEYS; i++)
+                putBatch.put(i, iter);
+
+            cache.putAll(putBatch);
+
+            Map<Object, Object> vals = cache.getAll(putBatch.keySet());
+
+            for (int i = 0; i < KEYS; i++)
+                assertNotNull(vals.get(i));
+        }
+    }
+}