You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by nt...@apache.org on 2016/03/22 17:50:20 UTC
[44/50] [abbrv] ignite git commit: Added test.
Added test.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/43ff1488
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/43ff1488
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/43ff1488
Branch: refs/heads/ignite-2004
Commit: 43ff1488fba3c75ac9097c5374c0edd868131f23
Parents: cadc61fa
Author: sboikov <sb...@gridgain.com>
Authored: Mon Mar 21 18:11:40 2016 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Mon Mar 21 18:11:40 2016 +0300
----------------------------------------------------------------------
.../distributed/IgniteCacheCreatePutTest.java | 137 ++++++++++++++++++-
1 file changed, 130 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/43ff1488/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCacheCreatePutTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCacheCreatePutTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCacheCreatePutTest.java
index 8b3d9d3..efba34a 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCacheCreatePutTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/IgniteCacheCreatePutTest.java
@@ -18,12 +18,15 @@
package org.apache.ignite.internal.processors.cache.distributed;
import java.util.concurrent.Callable;
+import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
-import org.apache.ignite.cache.CacheMode;
+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.internal.U;
import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
@@ -31,6 +34,12 @@ 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.CacheAtomicityMode.ATOMIC;
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static org.apache.ignite.cache.CacheMode.PARTITIONED;
+import static org.apache.ignite.cache.CacheMode.REPLICATED;
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
+
/**
*
*/
@@ -41,6 +50,9 @@ public class IgniteCacheCreatePutTest extends GridCommonAbstractTest {
/** */
private static TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true);
+ /** */
+ private boolean client;
+
/** {@inheritDoc} */
protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(gridName);
@@ -60,11 +72,13 @@ public class IgniteCacheCreatePutTest extends GridCommonAbstractTest {
CacheConfiguration ccfg = new CacheConfiguration();
ccfg.setName("cache*");
- ccfg.setCacheMode(CacheMode.PARTITIONED);
+ ccfg.setCacheMode(PARTITIONED);
ccfg.setBackups(1);
cfg.setCacheConfiguration(ccfg);
+ cfg.setClientMode(client);
+
return cfg;
}
@@ -74,10 +88,10 @@ public class IgniteCacheCreatePutTest extends GridCommonAbstractTest {
}
/** {@inheritDoc} */
- @Override protected void afterTestsStopped() throws Exception {
- super.afterTestsStopped();
-
+ @Override protected void afterTest() throws Exception {
stopAllGrids();
+
+ super.afterTest();
}
/**
@@ -96,8 +110,7 @@ public class IgniteCacheCreatePutTest extends GridCommonAbstractTest {
final AtomicInteger idx = new AtomicInteger();
GridTestUtils.runMultiThreaded(new Callable<Void>() {
- @Override
- public Void call() throws Exception {
+ @Override public Void call() throws Exception {
int node = idx.getAndIncrement();
Ignite ignite = startGrid(node);
@@ -122,4 +135,114 @@ public class IgniteCacheCreatePutTest extends GridCommonAbstractTest {
stopAllGrids();
}
}
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testUpdatesAndCacheStart() throws Exception {
+ final int NODES = 4;
+
+ startGridsMultiThreaded(NODES);
+
+ Ignite ignite0 = ignite(0);
+
+ ignite0.createCache(cacheConfiguration("atomic-cache", ATOMIC));
+ ignite0.createCache(cacheConfiguration("tx-cache", TRANSACTIONAL));
+
+ final long stopTime = System.currentTimeMillis() + 60_000;
+
+ final AtomicInteger updateThreadIdx = new AtomicInteger();
+
+ IgniteInternalFuture<?> fut = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {
+ @Override public Void call() throws Exception {
+ int nodeIdx = updateThreadIdx.getAndIncrement() % NODES;
+
+ Ignite node = ignite(nodeIdx);
+
+ IgniteCache cache1 = node.cache("atomic-cache");
+ IgniteCache cache2 = node.cache("tx-cache");
+
+ ThreadLocalRandom rnd = ThreadLocalRandom.current();
+
+ int iter = 0;
+
+ while (System.currentTimeMillis() < stopTime) {
+ Integer key = rnd.nextInt(10_000);
+
+ cache1.put(key, key);
+
+ cache2.put(key, key);
+
+ if (iter++ % 1000 == 0)
+ log.info("Update iteration: " + iter);
+ }
+
+ return null;
+ }
+ }, NODES * 2, "update-thread");
+
+ final AtomicInteger cacheThreadIdx = new AtomicInteger();
+
+ IgniteInternalFuture<?> cacheFut = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {
+ @Override public Void call() throws Exception {
+ int nodeIdx = cacheThreadIdx.getAndIncrement() % NODES;
+
+ Ignite node = ignite(nodeIdx);
+
+ int iter = 0;
+
+ while (System.currentTimeMillis() < stopTime) {
+ String cacheName = "dynamic-cache-" + nodeIdx;
+
+ CacheConfiguration ccfg = new CacheConfiguration();
+
+ ccfg.setName(cacheName);
+
+ node.createCache(ccfg);
+
+ node.destroyCache(cacheName);
+
+ U.sleep(500);
+
+ if (iter++ % 1000 == 0)
+ log.info("Cache create iteration: " + iter);
+ }
+
+ return null;
+ }
+ }, NODES, "cache-thread");
+
+ while (!fut.isDone()) {
+ client = true;
+
+ startGrid(NODES);
+
+ stopGrid(NODES);
+
+ client = false;
+
+ startGrid(NODES);
+
+ stopGrid(NODES);
+ }
+
+ fut.get();
+ cacheFut.get();
+ }
+
+ /**
+ * @param name Cache name.
+ * @param atomicityMode Cache atomicity mode.
+ * @return Cache configuration.
+ */
+ private CacheConfiguration cacheConfiguration(String name, CacheAtomicityMode atomicityMode) {
+ CacheConfiguration ccfg = new CacheConfiguration();
+
+ ccfg.setName(name);
+ ccfg.setCacheMode(REPLICATED);
+ ccfg.setAtomicityMode(atomicityMode);
+ ccfg.setWriteSynchronizationMode(FULL_SYNC);
+
+ return ccfg;
+ }
}
\ No newline at end of file