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:12:58 UTC

[47/51] incubator-ignite git commit: ignite-709

ignite-709


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

Branch: refs/heads/ignite-709
Commit: b28e6fec675899080a27cbab21f01f4cec1718df
Parents: c412dd0
Author: Denis Magda <dm...@gridgain.com>
Authored: Fri Apr 10 13:02:02 2015 +0300
Committer: Denis Magda <dm...@gridgain.com>
Committed: Fri Apr 10 13:02:02 2015 +0300

----------------------------------------------------------------------
 ...acheTcpClientDiscoveryMultithreadedTest.java |   7 -
 ...acheTcpClientDiscoveryMultiThreadedTest.java | 138 +++++++++++++++----
 2 files changed, 113 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b28e6fec/modules/core/src/test/java/org/apache/ignite/internal/processors/GridCacheTcpClientDiscoveryMultithreadedTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/GridCacheTcpClientDiscoveryMultithreadedTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/GridCacheTcpClientDiscoveryMultithreadedTest.java
deleted file mode 100644
index 94f6ae7..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/GridCacheTcpClientDiscoveryMultithreadedTest.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package org.apache.ignite.internal.processors;
-
-/**
- * Created by GridAdmin1234 on 4/10/2015.
- */
-public class GridCacheTcpClientDiscoveryMultithreadedTest {
-}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b28e6fec/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 1c7ce3d..06aa3b8 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
@@ -1,27 +1,25 @@
 /*
- * 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;
 
-import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.processors.cache.GridCacheAbstractSelfTest;
+import org.apache.ignite.*;
+import org.apache.ignite.cache.*;
+import org.apache.ignite.cache.affinity.rendezvous.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.spi.discovery.tcp.*;
 
-import java.util.concurrent.atomic.AtomicInteger;
+import java.util.Arrays;
+import java.util.concurrent.Callable;
+import java.util.concurrent.atomic.*;
+
+import static org.apache.ignite.cache.CacheMode.*;
 
 /**
  * Tests TcpClientDiscovery SPI with multiple client nodes that interact with a cache concurrently.
@@ -31,10 +29,13 @@ public class GridCacheTcpClientDiscoveryMultiThreadedTest extends GridCacheAbstr
     private final static int SERVER_NODES_COUNT = 3;
 
     /** Client nodes count. */
-    private final static int CLIENT_NODES_COUNT = 5;
+    private final static int CLIENT_NODES_COUNT = 3;
+
+    /** Array to hold info on whether a client node has a near cache or not */
+    private static boolean[] nearCacheNode;
 
     /** Grids counter. */
-    private static AtomicInteger gridsCounter;
+    private static AtomicInteger gridsCnt;
 
     /** {@inheritDoc} */
     @Override protected int gridCount() {
@@ -43,18 +44,105 @@ public class GridCacheTcpClientDiscoveryMultiThreadedTest extends GridCacheAbstr
     
     /** {@inheritDoc} */
     @Override protected void beforeTestsStarted() throws Exception {
-        gridsCounter = new AtomicInteger();
-        
-        startGridsMultiThreaded(gridCount());
+        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();
+
+        // 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 IgniteConfiguration getConfiguration(String gridName) throws Exception {
-        return super.getConfiguration(gridName);
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+        int nodesCount = gridsCnt.incrementAndGet();
+
+        // Filling configuration for client nodes
+        if (nodesCount > SERVER_NODES_COUNT) {
+            TcpClientDiscoverySpi disco = new TcpClientDiscoverySpi();
+            disco.setIpFinder(ipFinder);
+
+            cfg.setClientMode(true);
+            //cfg.setDiscoverySpi(disco);
+        }
+
+        return cfg;
     }
 
     /** {@inheritDoc} */
+    @SuppressWarnings("unchecked")
     @Override protected CacheConfiguration cacheConfiguration(String gridName) throws Exception {
-        return super.cacheConfiguration(gridName);
+        CacheConfiguration cfg = super.cacheConfiguration(gridName);
+
+        cfg.setCacheStoreFactory(null);
+        cfg.setReadThrough(false);
+        cfg.setWriteThrough(false);
+        cfg.setAffinity(new RendezvousAffinityFunction(false, 32));
+        cfg.setBackups(1);
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        super.afterTestsStopped();
+
+        gridsCnt.set(0);
+        Arrays.fill(nearCacheNode, false);
     }
+
+    /** {@inheritDoc} */
+    @Override protected CacheMode cacheMode() {
+        return PARTITIONED;
+    }
+
+
+    public void testCacheConcurrentlyWithMultipleClientNodes() throws Exception {
+        AtomicInteger threadsCnt = new AtomicInteger();
+
+        IgniteInternalFuture<?> f = multithreadedAsync(
+                new Callable<Object>() {
+                    @Override public Object call() throws Exception {
+                        int clientIdx = SERVER_NODES_COUNT + threadsCnt.getAndIncrement();
+                        Ignite node = grid(clientIdx);
+
+                        assert node.configuration().isClientMode();
+
+                        IgniteCache<Integer, Integer> cache = node.cache(null);
+                        boolean isNearCacheNode = nearCacheNode[clientIdx - SERVER_NODES_COUNT];
+
+                        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));
+
+                            if (isNearCacheNode)
+                                assertEquals(i, (int) cache.localPeek(i, CachePeekMode.ONHEAP));
+                        }
+
+                        //stopGrid(clientIdx);
+
+                        return null;
+                    }
+                },
+                CLIENT_NODES_COUNT
+        );
+
+        f.get();
+    }
+
 }