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 2016/07/29 14:12:06 UTC
[2/4] ignite git commit: ignite-3547
ignite-3547
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/f53d26b9
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/f53d26b9
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/f53d26b9
Branch: refs/heads/ignite-3547
Commit: f53d26b931bb99ccbaaeabff8f2544a34fee9d7c
Parents: 3691079
Author: sboikov <sb...@gridgain.com>
Authored: Fri Jul 29 15:02:30 2016 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Fri Jul 29 15:02:30 2016 +0300
----------------------------------------------------------------------
.../IgniteCacheConnectionRecoveryTest.java | 148 +++++++++++++++++++
.../IgniteCacheMessageRecoveryAbstractTest.java | 14 +-
2 files changed, 156 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/f53d26b9/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCacheConnectionRecoveryTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCacheConnectionRecoveryTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCacheConnectionRecoveryTest.java
new file mode 100644
index 0000000..826b0e7
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCacheConnectionRecoveryTest.java
@@ -0,0 +1,148 @@
+/*
+ * 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 java.util.concurrent.Callable;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.util.typedef.G;
+import org.apache.ignite.internal.util.typedef.internal.U;
+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 java.util.concurrent.TimeUnit.SECONDS;
+import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static org.apache.ignite.cache.CacheMode.REPLICATED;
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
+
+/**
+ *
+ */
+public class IgniteCacheConnectionRecoveryTest extends GridCommonAbstractTest {
+ /** */
+ private static TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
+
+ /** */
+ private boolean client;
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+ ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(IP_FINDER);
+
+ cfg.setClientMode(client);
+
+ return cfg;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ super.beforeTestsStarted();
+
+ startGridsMultiThreaded(5);
+
+ client = true;
+
+ startGridsMultiThreaded(5, 5);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTestsStopped() throws Exception {
+ stopAllGrids();
+
+ super.afterTestsStopped();
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testConnectionRecovery() throws Exception {
+ ignite(0).createCache(cacheConfiguration("cache1", TRANSACTIONAL));
+ ignite(0).createCache(cacheConfiguration("cache2", ATOMIC));
+
+ final Map<Integer, Integer> data = new HashMap<>();
+
+ for (int i = 0; i < 500; i++)
+ data.put(i, i);
+
+ final AtomicInteger idx = new AtomicInteger();
+
+ final long stopTime = U.currentTimeMillis() + 10_000;
+
+ IgniteInternalFuture<?> fut = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
+ @Override public Object call() throws Exception {
+ Ignite node = ignite(idx.incrementAndGet() % 10);
+
+ IgniteCache cache1 = node.cache("cache1").withAsync();
+ IgniteCache cache2 = node.cache("cache2").withAsync();
+
+ int cnt = 0;
+
+ while (U.currentTimeMillis() < stopTime) {
+ cache1.putAll(data);
+ cache1.future().get(30, SECONDS);
+
+
+ cache2.putAll(data);
+ cache2.future().get(5, SECONDS);
+
+ log.info("Iteration: " + cnt++);
+ }
+
+ return null;
+ }
+ }, 30, "test-thread");
+
+ while (System.currentTimeMillis() < stopTime) {
+ for (Ignite node : G.allGrids())
+ IgniteCacheMessageRecoveryAbstractTest.closeSessions(node);
+
+ U.sleep(500);
+ }
+
+ fut.get();
+ }
+
+ /**
+ * @param name Cache name.
+ * @param atomicityMode Cache atomicity mode.
+ * @return Configuration.
+ */
+ private CacheConfiguration cacheConfiguration(String name, CacheAtomicityMode atomicityMode) {
+ CacheConfiguration ccfg = new CacheConfiguration();
+
+ ccfg.setName(name);
+ ccfg.setAtomicityMode(atomicityMode);
+ ccfg.setCacheMode(REPLICATED);
+ ccfg.setWriteSynchronizationMode(FULL_SYNC);
+
+ return ccfg;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/f53d26b9/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCacheMessageRecoveryAbstractTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCacheMessageRecoveryAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCacheMessageRecoveryAbstractTest.java
index 16d7e5d..0460a8f 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCacheMessageRecoveryAbstractTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCacheMessageRecoveryAbstractTest.java
@@ -150,7 +150,11 @@ public abstract class IgniteCacheMessageRecoveryAbstractTest extends GridCommonA
for (int i = 0; i < 30; i++) {
Thread.sleep(1000);
- closed |= closeSessions();
+ Ignite node0 = ignite(ThreadLocalRandom.current().nextInt(0, GRID_CNT));
+
+ log.info("Close sessions for: " + ignite.name());
+
+ closed |= closeSessions(node0);
}
assertTrue(closed);
@@ -163,13 +167,11 @@ public abstract class IgniteCacheMessageRecoveryAbstractTest extends GridCommonA
}
/**
+ * @param ignite Node.
* @throws Exception If failed.
+ * @return {@code True} if closed at least one session.
*/
- private boolean closeSessions() throws Exception {
- Ignite ignite = ignite(ThreadLocalRandom.current().nextInt(0, GRID_CNT));
-
- log.info("Close sessions for: " + ignite.name());
-
+ static boolean closeSessions(Ignite ignite) throws Exception {
TcpCommunicationSpi commSpi = (TcpCommunicationSpi)ignite.configuration().getCommunicationSpi();
Map<UUID, GridCommunicationClient> clients = U.field(commSpi, "clients");