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 2015/04/10 14:13:01 UTC
[50/51] incubator-ignite git commit: ignite-709: new test is added
ignite-709: new test is added
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/6f55baaa
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/6f55baaa
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/6f55baaa
Branch: refs/heads/ignite-709
Commit: 6f55baaa43d94235d8a6052cac9778a43e6f1bbe
Parents: 46ae32b
Author: Denis Magda <dm...@gridgain.com>
Authored: Fri Apr 10 15:02:59 2015 +0300
Committer: Denis Magda <dm...@gridgain.com>
Committed: Fri Apr 10 15:02:59 2015 +0300
----------------------------------------------------------------------
...acheTcpClientDiscoveryMultiThreadedTest.java | 191 +++++++++++++------
1 file changed, 132 insertions(+), 59 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6f55baaa/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTcpClientDiscoveryMultiThreadedTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTcpClientDiscoveryMultiThreadedTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTcpClientDiscoveryMultiThreadedTest.java
index 0ce34e8..b523420 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTcpClientDiscoveryMultiThreadedTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTcpClientDiscoveryMultiThreadedTest.java
@@ -27,51 +27,35 @@ import static org.apache.ignite.cache.CacheMode.*;
*/
public class GridCacheTcpClientDiscoveryMultiThreadedTest extends GridCacheAbstractSelfTest {
/** Server nodes count. */
- private final static int SERVER_NODES_COUNT = 3;
+ private volatile static int serverNodesCount;
/** Client nodes count. */
- private final static int CLIENT_NODES_COUNT = 4;
+ private volatile static int clientNodesCount;
- /** Array to hold info on whether a client node has a near cache or not */
- private static boolean[] nearCacheNode;
-
- /** Grids counter. */
- private static AtomicInteger gridsCnt;
+ /** Client node or not. */
+ private volatile static boolean client;
/** {@inheritDoc} */
@Override protected int gridCount() {
- return SERVER_NODES_COUNT + CLIENT_NODES_COUNT;
+ return serverNodesCount + clientNodesCount;
}
/** {@inheritDoc} */
@Override protected void beforeTestsStarted() throws Exception {
- gridsCnt = new AtomicInteger();
- nearCacheNode = new boolean[CLIENT_NODES_COUNT];
-
- for (int i = 0; i < SERVER_NODES_COUNT; i++)
- startGrid(i);
-
- startGridsMultiThreaded(SERVER_NODES_COUNT, CLIENT_NODES_COUNT);
-
- checkTopology(gridCount());
- awaitPartitionMapExchange();
+ // No-op.
+ }
- // Explicitly create near cache for even client nodes
- for (int i = SERVER_NODES_COUNT; i < gridCount(); i++) {
- if (i % 2 == 0) {
- grid(i).createNearCache(null, new NearCacheConfiguration<>());
- nearCacheNode[i - SERVER_NODES_COUNT] = true;
- }
- }
+ /** {@inheritDoc} */
+ @Override protected void beforeTest() throws Exception {
+ // No-op.
}
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(gridName);
- int nodesCount = gridsCnt.incrementAndGet();
// Filling configuration for client nodes
- if (nodesCount > SERVER_NODES_COUNT) {
+ if (client) {
TcpDiscoveryVmIpFinder clientFinder = new TcpDiscoveryVmIpFinder();
ArrayList<String> addresses = new ArrayList<>(ipFinder.getRegisteredAddresses().size());
@@ -108,53 +92,142 @@ public class GridCacheTcpClientDiscoveryMultiThreadedTest extends GridCacheAbstr
}
/** {@inheritDoc} */
- @Override protected void afterTestsStopped() throws Exception {
- super.afterTestsStopped();
-
- gridsCnt.set(0);
- Arrays.fill(nearCacheNode, false);
- }
-
- /** {@inheritDoc} */
@Override protected CacheMode cacheMode() {
return PARTITIONED;
}
-
+ /**
+ * @throws Exception If failed.
+ */
public void testCacheConcurrentlyWithMultipleClientNodes() throws Exception {
- AtomicInteger threadsCnt = new AtomicInteger();
+ try {
+ serverNodesCount = 3;
+ clientNodesCount = 4;
- IgniteInternalFuture<?> f = multithreadedAsync(
- new Callable<Object>() {
- @Override public Object call() throws Exception {
- int clientIdx = SERVER_NODES_COUNT + threadsCnt.getAndIncrement();
- Ignite node = grid(clientIdx);
+ startServerNodes();
- assert node.configuration().isClientMode();
+ client = true;
+ startGridsMultiThreaded(serverNodesCount, clientNodesCount);
- IgniteCache<Integer, Integer> cache = node.cache(null);
- boolean isNearCacheNode = nearCacheNode[clientIdx - SERVER_NODES_COUNT];
+ checkTopology(gridCount());
+ awaitPartitionMapExchange();
- for (int i = 100 * clientIdx; i < 100 * (clientIdx + 1); i++) {
- cache.put(i, i);
- }
+ // Explicitly create near cache for even client nodes
+ final boolean[] nearCacheNode = new boolean[clientNodesCount];
+ for (int i = serverNodesCount; i < gridCount(); i++) {
+ if (i % 2 == 0) {
+ grid(i).createNearCache(null, new NearCacheConfiguration<>());
+ nearCacheNode[i - serverNodesCount] = true;
+ }
+ }
+
+ super.beforeTest();
+
+ final AtomicInteger threadsCnt = new AtomicInteger();
+
+ IgniteInternalFuture<?> f = multithreadedAsync(
+ new Callable<Object>() {
+ @Override
+ public Object call() throws Exception {
+ int clientIdx = serverNodesCount + threadsCnt.getAndIncrement();
+ Ignite node = grid(clientIdx);
+
+ assert node.configuration().isClientMode();
+
+ IgniteCache<Integer, Integer> cache = node.cache(null);
+ boolean isNearCacheNode = nearCacheNode[clientIdx - serverNodesCount];
+
+ for (int i = 100 * clientIdx; i < 100 * (clientIdx + 1); i++) {
+ cache.put(i, i);
+ }
+
+ for (int i = 100 * clientIdx; i < 100 * (clientIdx + 1); i++) {
+ assertEquals(i, (int) cache.get(i));
- for (int i = 100 * clientIdx; i < 100 * (clientIdx + 1); i++) {
- assertEquals(i, (int)cache.get(i));
+ if (isNearCacheNode)
+ assertEquals(i, (int) cache.localPeek(i, CachePeekMode.ONHEAP));
+ }
- if (isNearCacheNode)
- assertEquals(i, (int) cache.localPeek(i, CachePeekMode.ONHEAP));
+ stopGrid(clientIdx);
+
+ return null;
}
+ },
+ clientNodesCount
+ );
+
+ f.get();
+
+ }
+ finally {
+ afterTestsStopped();
+ }
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testCacheWithServerNodesRestart() throws Exception {
+ try {
+ serverNodesCount = 3;
+ clientNodesCount = 1;
+
+ startServerNodes();
+
+ client = true;
+ Ignite client = startGrid(serverNodesCount);
+
+ checkTopology(gridCount());
+ awaitPartitionMapExchange();
+ super.beforeTest();
+
+ IgniteCache<Integer, Integer> cache = client.cache(null);
- stopGrid(clientIdx);
+ performSimpleOperationsOnCache(cache);
- return null;
- }
- },
- CLIENT_NODES_COUNT
- );
+ // Restart server nodes, client node should reconnect automatically.
+ stopServerNodes();
+ startServerNodes();
+ checkTopology(gridCount());
+ awaitPartitionMapExchange();
+ super.beforeTest();
- f.get();
+ performSimpleOperationsOnCache(cache);
+ }
+ finally {
+ afterTestsStopped();
+ }
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ private void startServerNodes() throws Exception {
+ client = false;
+ for (int i = 0; i < serverNodesCount; i++)
+ startGrid(i);
}
+ /**
+ * @throws Exception
+ */
+ private void stopServerNodes() throws Exception {
+ for (int i = 0; i < serverNodesCount; i++)
+ stopGrid(i);
+ }
+
+ /**
+ * Executes simple operation on the cache.
+ *
+ * @param cache Cache instance to use.
+ */
+ private void performSimpleOperationsOnCache(IgniteCache<Integer, Integer> cache) {
+ for (int i = 100; i < 200; i++) {
+ cache.put(i, i);
+ }
+
+ for (int i = 100; i < 200; i++) {
+ assertEquals(i, (int) cache.get(i));
+ }
+ }
}