Repository: incubator-ignite Updated Branches: refs/heads/ignite-45 852b03525 -> 8eb79a74d
#ignite-45-client-tests: Remove client cache tests. Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/242eaa51 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/242eaa51 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/242eaa51 Branch: refs/heads/ignite-45 Commit: 242eaa51cd5e52174962642945de7a1dc51129a9 Parents: 8656001 Author: ivasilinets <ivasilin...@gridgain.com> Authored: Thu Mar 19 16:38:59 2015 +0300 Committer: ivasilinets <ivasilin...@gridgain.com> Committed: Thu Mar 19 16:38:59 2015 +0300 ---------------------------------------------------------------------- .../ClientAbstractMultiThreadedSelfTest.java | 102 +--- .../client/ClientDefaultCacheSelfTest.java | 48 -- .../ClientAbstractMultiNodeSelfTest.java | 199 ------ .../integration/ClientAbstractSelfTest.java | 599 ------------------- .../loadtests/client/ClientTcpSslLoadTest.java | 108 ++++ 5 files changed, 109 insertions(+), 947 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/242eaa51/modules/clients/src/test/java/org/apache/ignite/internal/client/ClientAbstractMultiThreadedSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/client/ClientAbstractMultiThreadedSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/internal/client/ClientAbstractMultiThreadedSelfTest.java index bb5b246..e9064b3 100644 --- a/modules/clients/src/test/java/org/apache/ignite/internal/client/ClientAbstractMultiThreadedSelfTest.java +++ b/modules/clients/src/test/java/org/apache/ignite/internal/client/ClientAbstractMultiThreadedSelfTest.java @@ -18,14 +18,11 @@ package org.apache.ignite.internal.client; import org.apache.ignite.*; -import org.apache.ignite.cache.*; import org.apache.ignite.cache.affinity.rendezvous.*; -import org.apache.ignite.cluster.*; import org.apache.ignite.compute.*; import org.apache.ignite.configuration.*; import org.apache.ignite.internal.*; import org.apache.ignite.internal.client.balancer.*; -import org.apache.ignite.internal.client.impl.*; import org.apache.ignite.internal.client.ssl.*; import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.internal.*; @@ -43,7 +40,6 @@ import java.util.concurrent.*; import java.util.concurrent.atomic.*; import static org.apache.ignite.cache.CacheAtomicityMode.*; -import static org.apache.ignite.cache.CacheDistributionMode.*; import static org.apache.ignite.cache.CacheMode.*; import static org.apache.ignite.cache.CacheWriteSynchronizationMode.*; @@ -95,7 +91,7 @@ public abstract class ClientAbstractMultiThreadedSelfTest extends GridCommonAbst } /** Client instance for each test. */ - private GridClient client; + protected GridClient client; /** * @return Client protocol that should be used. @@ -379,102 +375,6 @@ public abstract class ClientAbstractMultiThreadedSelfTest extends GridCommonAbst info(">>>>>>> " + e.getKey() + " run " + e.getValue().get() + " tasks"); } - /** - * @throws Exception If failed. - */ - public void test6Affinity() throws Exception { - GridClientData cache = client.data(PARTITIONED_CACHE_NAME); - UUID nodeId = cache.affinity("6"); - - info("Affinity node: " + nodeId); - } - - /** - * @throws Exception If failed. - */ - public void testMultithreadedCachePut() throws Exception { - final AtomicLong keyCnt = new AtomicLong(); - - final AtomicReference<Exception> err = new AtomicReference<>(); - - final ConcurrentMap<String, T2<UUID, String>> puts = new ConcurrentHashMap<>(); - - final Map<UUID, Ignite> gridMap = new HashMap<>(); - - for (int i = 0; i < NODES_CNT; i++) { - Ignite g = grid(i); - - gridMap.put(g.cluster().localNode().id(), g); - } - - final Ignite ignite = F.first(gridMap.values()); - - assertEquals(NODES_CNT, client.compute().refreshTopology(false, false).size()); - - IgniteInternalFuture<?> fut = multithreadedAsync(new Runnable() { - @SuppressWarnings("OverlyStrongTypeCast") - @Override public void run() { - try { - GridClientData cache = client.data(PARTITIONED_CACHE_NAME); - - assertEquals(NODES_CNT, ((GridClientDataImpl)cache).projectionNodes().size()); - - long rawKey; - - while ((rawKey = keyCnt.getAndIncrement()) < cachePutCount()) { - String key = String.valueOf(rawKey); - - UUID nodeId = cache.affinity(key); - - String val = "val" + rawKey; - - if (cache.put(key, val)) { - T2<UUID, String> old = puts.putIfAbsent(key, new T2<>(nodeId, val)); - - assert old == null : "Map contained entry [key=" + rawKey + ", entry=" + old + ']'; - } - } - } - catch (Exception e) { - err.compareAndSet(null, e); - } - } - }, THREAD_CNT, "client-cache-put"); - - fut.get(); - - if (err.get() != null) - throw new Exception(err.get()); - - assertEquals(cachePutCount(), puts.size()); - - // Now check that all puts went to primary nodes. - for (long i = 0; i < cachePutCount(); i++) { - String key = String.valueOf(i); - - ClusterNode node = ignite.cluster().mapKeyToNode(PARTITIONED_CACHE_NAME, key); - - if (!puts.get(key).get2().equals(gridMap.get(node.id()).jcache(PARTITIONED_CACHE_NAME).localPeek(key, CachePeekMode.ONHEAP))) { - // printAffinityState(gridMap.values()); - - failNotEquals("Node don't have value for key [nodeId=" + node.id() + ", key=" + key + "]", - puts.get(key).get2(), gridMap.get(node.id()).jcache(PARTITIONED_CACHE_NAME).localPeek(key, CachePeekMode.ONHEAP)); - } - - - UUID curAffNode = client.data(PARTITIONED_CACHE_NAME).affinity(key); - - // Check that no other nodes see this key. - for (UUID id : gridMap.keySet()) { - if (!id.equals(curAffNode) && !id.equals(node.id())) - assertNull("Got value in near cache.", gridMap.get(id).jcache(PARTITIONED_CACHE_NAME).localPeek(key, CachePeekMode.ONHEAP)); - } - } - - for (Ignite g : gridMap.values()) - g.jcache(PARTITIONED_CACHE_NAME).clear(); - } - /** {@inheritDoc} */ @Override protected long getTestTimeout() { return 5 * 60 * 1000; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/242eaa51/modules/clients/src/test/java/org/apache/ignite/internal/client/ClientDefaultCacheSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/client/ClientDefaultCacheSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/internal/client/ClientDefaultCacheSelfTest.java index 59b4c53..c8a92b5 100644 --- a/modules/clients/src/test/java/org/apache/ignite/internal/client/ClientDefaultCacheSelfTest.java +++ b/modules/clients/src/test/java/org/apache/ignite/internal/client/ClientDefaultCacheSelfTest.java @@ -19,8 +19,6 @@ package org.apache.ignite.internal.client; import org.apache.ignite.cache.*; import org.apache.ignite.configuration.*; -import org.apache.ignite.internal.util.typedef.*; -import org.apache.ignite.lang.*; import org.apache.ignite.spi.discovery.tcp.*; import org.apache.ignite.spi.discovery.tcp.ipfinder.*; import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*; @@ -31,7 +29,6 @@ import java.net.*; import java.nio.charset.*; import java.util.*; -import static org.apache.ignite.internal.client.GridClientProtocol.*; import static org.apache.ignite.IgniteSystemProperties.*; /** @@ -47,9 +44,6 @@ public class ClientDefaultCacheSelfTest extends GridCommonAbstractTest { /** Host. */ private static final String HOST = "127.0.0.1"; - /** Port. */ - private static final int TCP_PORT = 11211; - /** Cached local node id. */ private UUID locNodeId; @@ -116,28 +110,6 @@ public class ClientDefaultCacheSelfTest extends GridCommonAbstractTest { } /** - * @return Client. - * @throws GridClientException In case of error. - */ - private GridClient clientTcp() throws GridClientException { - GridClientConfiguration cfg = new GridClientConfiguration(); - - cfg.setProtocol(TCP); - cfg.setServers(getServerList(TCP_PORT)); - cfg.setDataConfigurations(Collections.singleton(new GridClientDataConfiguration())); - - GridClient gridClient = GridClientFactory.start(cfg); - - assert F.exist(gridClient.compute().nodes(), new IgnitePredicate<GridClientNode>() { - @Override public boolean apply(GridClientNode n) { - return n.nodeId().equals(locNodeId); - } - }); - - return gridClient; - } - - /** * Builds list of connection strings with few different ports. * Used to avoid possible failures in case of port range active. * @@ -182,26 +154,6 @@ public class ClientDefaultCacheSelfTest extends GridCommonAbstractTest { } /** - * @throws Exception If failed. - */ - public void testTcp() throws Exception { - try { - jcache().put("key", 1); - - GridClient client = clientTcp(); - - Integer val = client.data().<String, Integer>get("key"); - - assert val != null; - - assert val == 1; - } - finally { - GridClientFactory.stopAll(); - } - } - - /** * Json format string in cache should not transform to Json object on get request. */ public void testSkipString2JsonTransformation() { http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/242eaa51/modules/clients/src/test/java/org/apache/ignite/internal/client/integration/ClientAbstractMultiNodeSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/client/integration/ClientAbstractMultiNodeSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/internal/client/integration/ClientAbstractMultiNodeSelfTest.java index 43d13e7..8c4794d 100644 --- a/modules/clients/src/test/java/org/apache/ignite/internal/client/integration/ClientAbstractMultiNodeSelfTest.java +++ b/modules/clients/src/test/java/org/apache/ignite/internal/client/integration/ClientAbstractMultiNodeSelfTest.java @@ -18,7 +18,6 @@ package org.apache.ignite.internal.client.integration; import org.apache.ignite.*; -import org.apache.ignite.cache.*; import org.apache.ignite.cache.affinity.rendezvous.*; import org.apache.ignite.cluster.*; import org.apache.ignite.compute.*; @@ -51,7 +50,6 @@ import java.util.concurrent.atomic.*; import static java.util.concurrent.TimeUnit.*; import static org.apache.ignite.cache.CacheAtomicityMode.*; -import static org.apache.ignite.cache.CacheDistributionMode.*; import static org.apache.ignite.cache.CacheMode.*; import static org.apache.ignite.cache.CacheWriteSynchronizationMode.*; @@ -330,85 +328,6 @@ public abstract class ClientAbstractMultiNodeSelfTest extends GridCommonAbstract /** * @throws Exception If failed. */ - public void testAffinityExecute() throws Exception { - GridClientCompute dflt = client.compute(); - - GridClientData data = client.data(PARTITIONED_CACHE_NAME); - - Collection<? extends GridClientNode> nodes = dflt.nodes(); - - assertEquals(NODES_CNT, nodes.size()); - - for (int i = 0; i < NODES_CNT; i++) { - Ignite g = grid(i); - - assert g != null; - - int affinityKey = -1; - - for (int key = 0; key < 10000; key++) { - if (g.cluster().localNode().id().equals(data.affinity(key))) { - affinityKey = key; - - break; - } - } - - if (affinityKey == -1) - throw new Exception("Unable to found key for which node is primary: " + g.cluster().localNode().id()); - - GridClientNode clientNode = dflt.node(g.cluster().localNode().id()); - - assertNotNull("Client node for " + g.cluster().localNode().id() + " was not found", clientNode); - - String res = dflt.affinityExecute(TestTask.class.getName(), PARTITIONED_CACHE_NAME, affinityKey, null); - - assertNotNull(res); - - assertEquals(g.cluster().localNode().id().toString(), res); - } - } - - /** - * @throws Exception If failed. - */ - public void testInvalidateFlag() throws Exception { - IgniteEx g0 = grid(0); - - IgniteCache<String, String> cache = g0.jcache(PARTITIONED_CACHE_NAME); - - String key = null; - - for (int i = 0; i < 10_000; i++) { - if (!affinity(cache).isPrimaryOrBackup(g0.localNode(), String.valueOf(i))) { - key = String.valueOf(i); - - break; - } - } - - assertNotNull(key); - - cache.put(key, key); // Create entry in near cache, it is invalidated if INVALIDATE flag is set. - - assertNotNull(cache.localPeek(key, CachePeekMode.ONHEAP)); - - GridClientData d = client.data(PARTITIONED_CACHE_NAME); - - d.flagsOn(GridClientCacheFlag.INVALIDATE).put(key, "zzz"); - - for (Ignite g : G.allGrids()) { - cache = g.jcache(PARTITIONED_CACHE_NAME); - - if (affinity(cache).isPrimaryOrBackup(g.cluster().localNode(), key)) - assertEquals("zzz", cache.localPeek(key, CachePeekMode.ONHEAP)); - } - } - - - /** - * @throws Exception If failed. - */ public void testTopologyListener() throws Exception { final Collection<UUID> added = new ArrayList<>(1); final Collection<UUID> rmvd = new ArrayList<>(1); @@ -459,124 +378,6 @@ public abstract class ClientAbstractMultiNodeSelfTest extends GridCommonAbstract } /** - * @throws Exception If failed. - */ - public void testDisabledRest() throws Exception { - restEnabled = false; - - final Ignite g = startGrid("disabled-rest"); - - try { - Thread.sleep(2 * TOP_REFRESH_FREQ); - - // As long as we have round robin load balancer this will cause every node to be queried. - for (int i = 0; i < NODES_CNT + 1; i++) - assertEquals(NODES_CNT + 1, client.compute().refreshTopology(false, false).size()); - - final GridClientData data = client.data(PARTITIONED_CACHE_NAME); - - // Check rest-disabled node is unavailable. - try { - String affKey; - - do { - affKey = UUID.randomUUID().toString(); - } while (!data.affinity(affKey).equals(g.cluster().localNode().id())); - - data.put(affKey, "asdf"); - - assertEquals("asdf", cache(0, PARTITIONED_CACHE_NAME).get(affKey)); - } - catch (GridServerUnreachableException e) { - // Thrown for direct client-node connections. - assertTrue("Unexpected exception message: " + e.getMessage(), - e.getMessage().startsWith("No available endpoints to connect (is rest enabled for this node?)")); - } - catch (GridClientException e) { - // Thrown for routed client-router-node connections. - String msg = e.getMessage(); - - assertTrue("Unexpected exception message: " + msg, protocol() == GridClientProtocol.TCP ? - msg.contains("No available endpoints to connect (is rest enabled for this node?)") : // TCP router. - msg.startsWith("No available nodes on the router for destination node ID")); // HTTP router. - } - - // Check rest-enabled nodes are available. - String affKey; - - do { - affKey = UUID.randomUUID().toString(); - } while (data.affinity(affKey).equals(g.cluster().localNode().id())); - - data.put(affKey, "fdsa"); - - assertEquals("fdsa", cache(0, PARTITIONED_CACHE_NAME).get(affKey)); - } - finally { - restEnabled = true; - - G.stop(g.name(), true); - } - } - - /** - * @throws Exception If failed. - */ - public void testAffinityPut() throws Exception { - Thread.sleep(2 * TOP_REFRESH_FREQ); - - assertEquals(NODES_CNT, client.compute().refreshTopology(false, false).size()); - - Map<UUID, Ignite> gridsByLocNode = new HashMap<>(NODES_CNT); - - GridClientData partitioned = client.data(PARTITIONED_CACHE_NAME); - - GridClientCompute compute = client.compute(); - - for (int i = 0; i < NODES_CNT; i++) - gridsByLocNode.put(grid(i).localNode().id(), grid(i)); - - for (int i = 0; i < 100; i++) { - String key = "key" + i; - - UUID primaryNodeId = grid(0).cluster().mapKeyToNode(PARTITIONED_CACHE_NAME, key).id(); - - partitioned.put(key, "val" + key); - - for (Map.Entry<UUID, Ignite> entry : gridsByLocNode.entrySet()) { - Object val = entry.getValue().jcache(PARTITIONED_CACHE_NAME).localPeek(key, CachePeekMode.ONHEAP); - - if (primaryNodeId.equals(entry.getKey()) || partitioned.affinity(key).equals(entry.getKey())) - assertEquals("val" + key, val); - else - assertNull(val); - } - } - - // Now check that we will see value in near cache in pinned mode. - for (int i = 100; i < 200; i++) { - String pinnedKey = "key" + i; - - UUID primaryNodeId = grid(0).cluster().mapKeyToNode(PARTITIONED_CACHE_NAME, pinnedKey).id(); - - UUID pinnedNodeId = F.first(F.view(gridsByLocNode.keySet(), F.notEqualTo(primaryNodeId))); - - GridClientNode node = compute.node(pinnedNodeId); - - partitioned.pinNodes(node).put(pinnedKey, "val" + pinnedKey); - - for (Map.Entry<UUID, Ignite> entry : gridsByLocNode.entrySet()) { - Object val = entry.getValue().jcache(PARTITIONED_CACHE_NAME).localPeek(pinnedKey, CachePeekMode.ONHEAP); - - if (primaryNodeId.equals(entry.getKey()) || pinnedNodeId.equals(entry.getKey())) - assertEquals("val" + pinnedKey, val); - else - assertNull(val); - } - } - } - - /** * @return Client configuration for the test. */ protected GridClientConfiguration clientConfiguration() throws GridClientException { http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/242eaa51/modules/clients/src/test/java/org/apache/ignite/internal/client/integration/ClientAbstractSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/client/integration/ClientAbstractSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/internal/client/integration/ClientAbstractSelfTest.java index 0173da6..a07c1b0 100644 --- a/modules/clients/src/test/java/org/apache/ignite/internal/client/integration/ClientAbstractSelfTest.java +++ b/modules/clients/src/test/java/org/apache/ignite/internal/client/integration/ClientAbstractSelfTest.java @@ -20,7 +20,6 @@ package org.apache.ignite.internal.client.integration; import junit.framework.*; import net.sf.json.*; import org.apache.ignite.*; -import org.apache.ignite.cache.*; import org.apache.ignite.cache.store.*; import org.apache.ignite.compute.*; import org.apache.ignite.configuration.*; @@ -486,43 +485,6 @@ public abstract class ClientAbstractSelfTest extends GridCommonAbstractTest { /** * @throws Exception If failed. */ - public void testCacheFlags() throws Exception { - /* Note! Only 'SKIP_STORE' flag is validated. */ - final GridClientData data = client.data(CACHE_NAME); - final GridClientData readData = data.flagsOn(GridClientCacheFlag.SKIP_STORE); - final GridClientData writeData = readData.flagsOff(GridClientCacheFlag.SKIP_STORE); - - assertEquals(Collections.singleton(GridClientCacheFlag.SKIP_STORE), readData.flags()); - assertTrue(writeData.flags().isEmpty()); - - for (int i = 0; i < 100; i++) { - String key = UUID.randomUUID().toString(); - Object val = UUID.randomUUID().toString(); - - // Put entry into cache & store. - assertTrue(writeData.put(key, val)); - - assertEquals(val, readData.get(key)); - assertEquals(val, writeData.get(key)); - - // Remove from cache, skip store. - assertTrue(readData.remove(key)); - - assertNull(readData.get(key)); - assertEquals(val, writeData.get(key)); - assertEquals(val, readData.get(key)); - - // Remove from cache and from store. - assertTrue(writeData.remove(key)); - - assertNull(readData.get(key)); - assertNull(writeData.get(key)); - } - } - - /** - * @throws Exception If failed. - */ public void testPutAll() throws Exception { GridClientData dfltData = client.data(); @@ -611,384 +573,6 @@ public abstract class ClientAbstractSelfTest extends GridCommonAbstractTest { /** * @throws Exception If failed. */ - public void testGet() throws Exception { - GridClientData dfltData = client.data(); - - assertNotNull(dfltData); - - GridClientData namedData = client.data(CACHE_NAME); - - assertNotNull(namedData); - - grid().jcache(null).put("key", "val"); - - Assert.assertEquals("val", dfltData.get("key")); - Assert.assertEquals("val", dfltData.getAsync("key").get()); - - grid().jcache(CACHE_NAME).put("key", "val"); - - Assert.assertEquals("val", namedData.get("key")); - Assert.assertEquals("val", namedData.getAsync("key").get()); - } - - /** - * @throws Exception If failed. - */ - public void testGetAll() throws Exception { - GridClientData dfltData = client.data(); - - assertNotNull(dfltData); - - GridClientData namedData = client.data(CACHE_NAME); - - assertNotNull(namedData); - - grid().jcache(null).put("key1", "val1"); - grid().jcache(null).put("key2", "val2"); - - Map<String, String> map = dfltData.getAll(F.asList("key1", "key2")); - - assertEquals(2, map.size()); - assertEquals("val1", map.get("key1")); - assertEquals("val2", map.get("key2")); - - grid().jcache(null).put("key3", "val3"); - grid().jcache(null).put("key4", "val4"); - - map = dfltData.getAll(F.asList("key3", "key4")); - - assertEquals(2, map.size()); - assertEquals("val3", map.get("key3")); - assertEquals("val4", map.get("key4")); - - map = dfltData.getAll(F.asList("key1")); - - assertEquals(1, map.size()); - assertEquals("val1", map.get("key1")); - - grid().jcache(CACHE_NAME).put("key1", "val1"); - grid().jcache(CACHE_NAME).put("key2", "val2"); - - map = namedData.getAll(F.asList("key1", "key2")); - - assertEquals(2, map.size()); - assertEquals("val1", map.get("key1")); - assertEquals("val2", map.get("key2")); - - grid().jcache(CACHE_NAME).put("key3", "val3"); - grid().jcache(CACHE_NAME).put("key4", "val4"); - - map = namedData.getAll(F.asList("key3", "key4")); - - assertEquals(2, map.size()); - assertEquals("val3", map.get("key3")); - assertEquals("val4", map.get("key4")); - - map = namedData.getAll(F.asList("key1")); - - assertEquals(1, map.size()); - assertEquals("val1", map.get("key1")); - - } - - /** - * @throws Exception If failed. - */ - public void testRemove() throws Exception { - GridClientData dfltData = client.data(); - - assertNotNull(dfltData); - - GridClientData namedData = client.data(CACHE_NAME); - - assertNotNull(namedData); - - grid().jcache(null).put("key1", "val1"); - grid().jcache(null).put("key2", "val2"); - - assertTrue(dfltData.remove("key1")); - assertTrue(dfltData.removeAsync("key2").get()); - assertFalse(dfltData.remove("wrongKey")); - assertFalse(dfltData.removeAsync("wrongKey").get()); - - assertNull(grid().jcache(null).get("key1")); - assertNull(grid().jcache(null).get("key2")); - - grid().jcache(CACHE_NAME).put("key1", "val1"); - grid().jcache(CACHE_NAME).put("key2", "val2"); - - assertTrue(namedData.remove("key1")); - assertTrue(namedData.removeAsync("key2").get()); - assertFalse(namedData.remove("wrongKey")); - assertFalse(namedData.removeAsync("wrongKey").get()); - - assertNull(grid().jcache(CACHE_NAME).get("key1")); - assertNull(grid().jcache(CACHE_NAME).get("key2")); - } - - /** - * @throws Exception If failed. - */ - public void testSkipStoreFlag() throws Exception { - GridClientData namedData = client.data(CACHE_NAME).flagsOn(GridClientCacheFlag.SKIP_STORE); - - // test keyA - grid().jcache(CACHE_NAME).put("keyA", "valA"); - assertTrue(namedData.remove("keyA")); - assertEquals("valA", cacheStores.get(CACHE_NAME).map.get("keyA")); - assertNull(namedData.get("keyA")); - - // test keyX - assertTrue(namedData.put("keyX", "valX")); - assertEquals("valX", namedData.get("keyX")); - assertNull(cacheStores.get(CACHE_NAME).map.get("keyX")); - } - - /** - * @throws Exception If failed. - */ - public void testSkipSwapFlag() throws Exception { - GridClientData namedData = client.data(CACHE_NAME); - - assertTrue(namedData.put("k", "v")); - - grid().jcache(CACHE_NAME).localEvict(Collections.<Object>singleton("k")); - - assertNull(namedData.flagsOn(GridClientCacheFlag.SKIP_SWAP, GridClientCacheFlag.SKIP_STORE).get("k")); - assertEquals("v", namedData.flagsOn(GridClientCacheFlag.SKIP_STORE).get("k")); - } - - /** - * @throws Exception If failed. - */ - public void testRemoveAll() throws Exception { - GridClientData dfltData = client.data(); - - assertNotNull(dfltData); - - GridClientData namedData = client.data(CACHE_NAME); - - assertNotNull(namedData); - - grid().jcache(null).put("key1", "val1"); - grid().jcache(null).put("key2", "val2"); - grid().jcache(null).put("key3", "val3"); - grid().jcache(null).put("key4", "val4"); - - dfltData.removeAll(F.asList("key1", "key2")); - dfltData.removeAllAsync(F.asList("key3", "key4")).get(); - - assertNull(grid().jcache(null).get("key1")); - assertNull(grid().jcache(null).get("key2")); - assertNull(grid().jcache(null).get("key3")); - assertNull(grid().jcache(null).get("key4")); - - grid().jcache(CACHE_NAME).put("key1", "val1"); - grid().jcache(CACHE_NAME).put("key2", "val2"); - grid().jcache(CACHE_NAME).put("key3", "val3"); - grid().jcache(CACHE_NAME).put("key4", "val4"); - - namedData.removeAll(F.asList("key1", "key2")); - namedData.removeAllAsync(F.asList("key3", "key4")).get(); - - assertNull(grid().jcache(CACHE_NAME).get("key1")); - assertNull(grid().jcache(CACHE_NAME).get("key2")); - assertNull(grid().jcache(CACHE_NAME).get("key3")); - assertNull(grid().jcache(CACHE_NAME).get("key4")); - } - - /** - * @throws Exception If failed. - */ - public void testReplace() throws Exception { - GridClientData dfltData = client.data(); - - assertNotNull(dfltData); - - GridClientData namedData = client.data(CACHE_NAME); - - assertNotNull(namedData); - - assertFalse(dfltData.replace("key1", "val1")); - grid().jcache(null).put("key1", "val1"); - assertTrue(dfltData.replace("key1", "val2")); - assertEquals("val2", grid().jcache(null).get("key1")); - - assertFalse(dfltData.replace("key2", "val1")); - grid().jcache(null).put("key2", "val1"); - assertTrue(dfltData.replace("key2", "val2")); - assertEquals("val2", grid().jcache(null).get("key2")); - - grid().jcache(null).removeAll(F.asSet("key1", "key2")); - - assertFalse(dfltData.replaceAsync("key1", "val1").get()); - grid().jcache(null).put("key1", "val1"); - assertTrue(dfltData.replaceAsync("key1", "val2").get()); - assertEquals("val2", grid().jcache(null).get("key1")); - - assertFalse(dfltData.replaceAsync("key2", "val1").get()); - grid().jcache(null).put("key2", "val1"); - assertTrue(dfltData.replaceAsync("key2", "val2").get()); - assertEquals("val2", grid().jcache(null).get("key2")); - - assertFalse(namedData.replace("key1", "val1")); - IgniteCache<Object, Object> cache = grid().jcache(CACHE_NAME); - - cache.put("key1", "val1"); - assertTrue(namedData.replace("key1", "val2")); - assertEquals("val2", cache.get("key1")); - - assertFalse(namedData.replaceAsync("key2", "val1").get()); - cache.put("key2", "val1"); - assertTrue(namedData.replaceAsync("key2", "val2").get()); - assertEquals("val2", cache.get("key2")); - - cache.removeAll(F.asSet("key1", "key2")); - - assertFalse(namedData.replaceAsync("key1", "val1").get()); - cache.put("key1", "val1"); - assertTrue(namedData.replaceAsync("key1", "val2").get()); - assertEquals("val2", cache.get("key1")); - - assertFalse(namedData.replaceAsync("key2", "val1").get()); - cache.put("key2", "val1"); - assertTrue(namedData.replaceAsync("key2", "val2").get()); - } - - /** - * @throws Exception If failed. - */ - @SuppressWarnings("NullableProblems") - public void testCompareAndSet() throws Exception { - GridClientData[] datas = new GridClientData[] { - client.data(), - client.data(CACHE_NAME) - }; - - assertNotNull(datas[0]); - assertNotNull(datas[1]); - - IgniteCache[] caches = new IgniteCache[] { - grid().jcache(null), - grid().jcache(CACHE_NAME) - }; - - for (int i = 0; i < datas.length; i++) { - GridClientData data = datas[i]; - IgniteCache<String, String> cache = (IgniteCache<String, String>)caches[i]; - - assertFalse(data.cas("key", null, null)); - cache.put("key", "val"); - assertTrue(data.cas("key", null, null)); - assertNull(cache.get("key")); - - assertFalse(data.cas("key", null, "val")); - cache.put("key", "val"); - assertFalse(data.cas("key", null, "wrongVal")); - assertEquals("val", cache.get("key")); - assertTrue(data.cas("key", null, "val")); - assertNull(cache.get("key")); - - assertTrue(data.cas("key", "val", null)); - assertEquals("val", cache.get("key")); - assertFalse(data.cas("key", "newVal", null)); - assertEquals("val", cache.get("key")); - cache.remove("key"); - - assertFalse(data.cas("key", "val1", "val2")); - cache.put("key", "val2"); - assertFalse(data.cas("key", "val1", "wrongVal")); - assertEquals("val2", cache.get("key")); - assertTrue(data.cas("key", "val1", "val2")); - assertEquals("val1", cache.get("key")); - cache.remove("key"); - - assertFalse(data.casAsync("key", null, null).get()); - cache.put("key", "val"); - assertTrue(data.casAsync("key", null, null).get()); - assertNull(cache.get("key")); - - assertFalse(data.casAsync("key", null, "val").get()); - cache.put("key", "val"); - assertFalse(data.casAsync("key", null, "wrongVal").get()); - assertEquals("val", cache.get("key")); - assertTrue(data.casAsync("key", null, "val").get()); - assertNull(cache.get("key")); - - assertTrue(data.casAsync("key", "val", null).get()); - assertEquals("val", cache.get("key")); - assertFalse(data.casAsync("key", "newVal", null).get()); - assertEquals("val", cache.get("key")); - cache.remove("key"); - - assertFalse(data.casAsync("key", "val1", "val2").get()); - cache.put("key", "val2"); - assertFalse(data.casAsync("key", "val1", "wrongVal").get()); - assertEquals("val2", cache.get("key")); - assertTrue(data.casAsync("key", "val1", "val2").get()); - assertEquals("val1", cache.get("key")); - cache.remove("key"); - } - } - - /** - * @throws Exception If failed. - */ - public void testMetrics() throws Exception { - GridClientData dfltData = client.data(); - GridClientData namedData = client.data(CACHE_NAME); - - grid().jcache(null).mxBean().clear(); - grid().jcache(CACHE_NAME).mxBean().clear(); - - grid().jcache(null).put("key1", "val1"); - grid().jcache(null).put("key2", "val2"); - grid().jcache(null).put("key2", "val3"); - - assertEquals("val1", grid().jcache(null).get("key1")); - assertEquals("val3", grid().jcache(null).get("key2")); - assertEquals("val3", grid().jcache(null).get("key2")); - - grid().jcache(CACHE_NAME).put("key1", "val1"); - grid().jcache(CACHE_NAME).put("key2", "val2"); - grid().jcache(CACHE_NAME).put("key2", "val3"); - - assertEquals("val1", grid().jcache(CACHE_NAME).get("key1")); - assertEquals("val3", grid().jcache(CACHE_NAME).get("key2")); - assertEquals("val3", grid().jcache(CACHE_NAME).get("key2")); - - GridClientDataMetrics m = dfltData.metrics(); - - CacheMetrics metrics = grid().jcache(null).metrics(); - - assertNotNull(m); - assertEquals(metrics.getCacheGets(), m.reads()); - assertEquals(metrics.getCachePuts(), m.writes()); - - m = dfltData.metricsAsync().get(); - - assertNotNull(m); - assertEquals(metrics.getCacheGets(), m.reads()); - assertEquals(metrics.getCachePuts(), m.writes()); - - m = namedData.metrics(); - - metrics = grid().jcache(CACHE_NAME).metrics(); - - assertNotNull(m); - assertEquals(metrics.getCacheGets(), m.reads()); - assertEquals(metrics.getCachePuts(), m.writes()); - - m = namedData.metricsAsync().get(); - - assertNotNull(m); - assertEquals(metrics.getCacheGets(), m.reads()); - assertEquals(metrics.getCachePuts(), m.writes()); - } - - /** - * @throws Exception If failed. - */ public void testAppendPrepend() throws Exception { List<GridClientData> datas = Arrays.asList(client.data(), client.data(CACHE_NAME)); @@ -1075,154 +659,6 @@ public abstract class ClientAbstractSelfTest extends GridCommonAbstractTest { /** * @throws Exception If failed. */ - public void testNode() throws Exception { - GridClientCompute compute = client.compute(); - - assertNull(compute.refreshNode(UUID.randomUUID(), true, false)); - assertNull(compute.refreshNode(UUID.randomUUID(), false, false)); - - GridClientNode node = compute.refreshNode(grid().localNode().id(), true, false); - - assertNotNull(node); - assertFalse(node.attributes().isEmpty()); - assertTrue(node.metrics() == null); - assertNotNull(node.tcpAddresses()); - assertEquals(grid().localNode().id(), node.nodeId()); - assertEquals(4, node.caches().size()); - - Map<String, GridClientCacheMode> caches = node.caches(); - - for (Map.Entry<String, GridClientCacheMode> e : caches.entrySet()) { - if (e.getKey() == null || CACHE_NAME.equals(e.getKey())) - assertEquals(GridClientCacheMode.LOCAL, e.getValue()); - else if ("replicated".equals(e.getKey())) - assertEquals(GridClientCacheMode.REPLICATED, e.getValue()); - else if ("partitioned".equals(e.getKey())) - assertEquals(GridClientCacheMode.PARTITIONED, e.getValue()); - else - fail("Unexpected cache name: " + e.getKey()); - } - - node = compute.refreshNode(grid().localNode().id(), false, false); - - assertNotNull(node); - assertTrue(node.attributes().isEmpty()); - assertTrue(node.metrics() == null); - assertNotNull(node.tcpAddresses()); - assertEquals(grid().localNode().id(), node.nodeId()); - assertEquals(4, node.caches().size()); - - caches = node.caches(); - - for (Map.Entry<String, GridClientCacheMode> e : caches.entrySet()) { - if (e.getKey() == null || CACHE_NAME.equals(e.getKey())) - assertEquals(GridClientCacheMode.LOCAL, e.getValue()); - else if ("replicated".equals(e.getKey())) - assertEquals(GridClientCacheMode.REPLICATED, e.getValue()); - else if ("partitioned".equals(e.getKey())) - assertEquals(GridClientCacheMode.PARTITIONED, e.getValue()); - else - fail("Unexpected cache name: " + e.getKey()); - } - - node = compute.refreshNode(grid().localNode().id(), false, true); - - assertNotNull(node); - assertTrue(node.attributes().isEmpty()); - assertFalse(node.metrics() == null); - assertTrue(node.metrics().getCurrentActiveJobs() != -1); - assertTrue(node.metrics().getCurrentIdleTime() != -1); - assertTrue(node.metrics().getLastUpdateTime() != -1); - assertNotNull(node.tcpAddresses()); - assertEquals(grid().localNode().id(), node.nodeId()); - assertEquals(4, node.caches().size()); - - caches = node.caches(); - - for (Map.Entry<String, GridClientCacheMode> e : caches.entrySet()) { - if (e.getKey() == null || CACHE_NAME.equals(e.getKey())) - assertEquals(GridClientCacheMode.LOCAL, e.getValue()); - else if ("replicated".equals(e.getKey())) - assertEquals(GridClientCacheMode.REPLICATED, e.getValue()); - else if ("partitioned".equals(e.getKey())) - assertEquals(GridClientCacheMode.PARTITIONED, e.getValue()); - else - fail("Unexpected cache name: " + e.getKey()); - } - - assertNull(compute.refreshNodeAsync(UUID.randomUUID(), true, false).get()); - assertNull(compute.refreshNodeAsync(UUID.randomUUID(), false, false).get()); - - node = compute.refreshNodeAsync(grid().localNode().id(), true, false).get(); - - assertNotNull(node); - assertFalse(node.attributes().isEmpty()); - assertTrue(node.metrics() == null); - assertNotNull(node.tcpAddresses()); - assertEquals(grid().localNode().id(), node.nodeId()); - assertEquals(4, node.caches().size()); - - caches = node.caches(); - - for (Map.Entry<String, GridClientCacheMode> e : caches.entrySet()) { - if (e.getKey() == null || CACHE_NAME.equals(e.getKey())) - assertEquals(GridClientCacheMode.LOCAL, e.getValue()); - else if ("replicated".equals(e.getKey())) - assertEquals(GridClientCacheMode.REPLICATED, e.getValue()); - else if ("partitioned".equals(e.getKey())) - assertEquals(GridClientCacheMode.PARTITIONED, e.getValue()); - else - fail("Unexpected cache name: " + e.getKey()); - } - - node = compute.refreshNodeAsync(grid().localNode().id(), false, false).get(); - - assertNotNull(node); - assertTrue(node.attributes().isEmpty()); - assertTrue(node.metrics() == null); - assertNotNull(node.tcpAddresses()); - assertEquals(grid().localNode().id(), node.nodeId()); - assertEquals(4, node.caches().size()); - - caches = node.caches(); - - for (Map.Entry<String, GridClientCacheMode> e : caches.entrySet()) { - if (e.getKey() == null || CACHE_NAME.equals(e.getKey())) - assertEquals(GridClientCacheMode.LOCAL, e.getValue()); - else if ("replicated".equals(e.getKey())) - assertEquals(GridClientCacheMode.REPLICATED, e.getValue()); - else if ("partitioned".equals(e.getKey())) - assertEquals(GridClientCacheMode.PARTITIONED, e.getValue()); - else - fail("Unexpected cache name: " + e.getKey()); - } - - node = compute.refreshNodeAsync(grid().localNode().id(), false, true).get(); - - assertNotNull(node); - assertTrue(node.attributes().isEmpty()); - assertFalse(node.metrics() == null); - assertNotNull(node.tcpAddresses()); - assertEquals(grid().localNode().id(), node.nodeId()); - assertEquals(4, node.caches().size()); - - caches = node.caches(); - - for (Map.Entry<String, GridClientCacheMode> e : caches.entrySet()) { - if (e.getKey() == null || CACHE_NAME.equals(e.getKey())) - assertEquals(GridClientCacheMode.LOCAL, e.getValue()); - else if ("replicated".equals(e.getKey())) - assertEquals(GridClientCacheMode.REPLICATED, e.getValue()); - else if ("partitioned".equals(e.getKey())) - assertEquals(GridClientCacheMode.PARTITIONED, e.getValue()); - else - fail("Unexpected cache name: " + e.getKey()); - } - } - - /** - * @throws Exception If failed. - */ public void testTopology() throws Exception { GridClientCompute compute = client.compute(); @@ -1284,41 +720,6 @@ public abstract class ClientAbstractSelfTest extends GridCommonAbstractTest { } /** - * Test if all user objects passed interception. - * - * @throws Exception If failed. - */ - public void testInterception() throws Exception { - grid().jcache(null).put("rem1", "rem1"); - - GridClientData data = client.data(); - - assertNotNull(data); - - overwriteIntercepted = true; - - data.put("key1", "val1"); - data.putAll(F.asMap("key2", "val2", "key3", "val3")); - data.remove("rem1"); - data.replace("key1", "nval1"); - - client.compute().execute(getTaskName(), getTaskArgument()); - - for (Object obj : Arrays.asList( - "rem1", "rem1", "key1", "key2", "key2", "val2", "key3", "val3", "rem1", "key1", "nval1", - getTaskArgument())) { - - assert INTERCEPTED_OBJECTS.containsKey(obj); - } - - assert ("nval1" + INTERCEPTED_SUF).equals(grid().jcache(null).get("key1" + INTERCEPTED_SUF)); - assert ("val2" + INTERCEPTED_SUF).equals(grid().jcache(null).get("key2" + INTERCEPTED_SUF)); - assert "rem1".equals(grid().jcache(null).get("rem1")); - - overwriteIntercepted = false; - } - - /** * Test task. */ private static class TestTask extends ComputeTaskSplitAdapter<List<Object>, Integer> { http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/242eaa51/modules/clients/src/test/java/org/apache/ignite/loadtests/client/ClientTcpSslLoadTest.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/loadtests/client/ClientTcpSslLoadTest.java b/modules/clients/src/test/java/org/apache/ignite/loadtests/client/ClientTcpSslLoadTest.java index fddad08..17e0a8d 100644 --- a/modules/clients/src/test/java/org/apache/ignite/loadtests/client/ClientTcpSslLoadTest.java +++ b/modules/clients/src/test/java/org/apache/ignite/loadtests/client/ClientTcpSslLoadTest.java @@ -18,9 +18,18 @@ package org.apache.ignite.loadtests.client; import org.apache.ignite.*; +import org.apache.ignite.cache.*; +import org.apache.ignite.cluster.*; +import org.apache.ignite.internal.*; import org.apache.ignite.internal.client.*; +import org.apache.ignite.internal.client.impl.*; +import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.internal.*; +import java.util.*; +import java.util.concurrent.*; +import java.util.concurrent.atomic.*; + /** * Makes a long run to ensure stability and absence of memory leaks. */ @@ -34,6 +43,9 @@ public class ClientTcpSslLoadTest extends ClientTcpSslMultiThreadedSelfTest { /** Time to let connections closed by idle. */ private static final long RELAX_INTERVAL = 60 * 1000; + /** Thread count to run tests. */ + private static final int THREAD_CNT = 20; + /** * @throws Exception If failed. */ @@ -85,4 +97,100 @@ public class ClientTcpSslLoadTest extends ClientTcpSslMultiThreadedSelfTest { log.error("Cache clear failed.", e); } } + + /** + * @throws Exception If failed. + */ + public void test6Affinity() throws Exception { + GridClientData cache = client.data(PARTITIONED_CACHE_NAME); + UUID nodeId = cache.affinity("6"); + + info("Affinity node: " + nodeId); + } + + /** + * @throws Exception If failed. + */ + public void testMultithreadedCachePut() throws Exception { + final AtomicLong keyCnt = new AtomicLong(); + + final AtomicReference<Exception> err = new AtomicReference<>(); + + final ConcurrentMap<String, T2<UUID, String>> puts = new ConcurrentHashMap<>(); + + final Map<UUID, Ignite> gridMap = new HashMap<>(); + + for (int i = 0; i < NODES_CNT; i++) { + Ignite g = grid(i); + + gridMap.put(g.cluster().localNode().id(), g); + } + + final Ignite ignite = F.first(gridMap.values()); + + assertEquals(NODES_CNT, client.compute().refreshTopology(false, false).size()); + + IgniteInternalFuture<?> fut = multithreadedAsync(new Runnable() { + @SuppressWarnings("OverlyStrongTypeCast") + @Override public void run() { + try { + GridClientData cache = client.data(PARTITIONED_CACHE_NAME); + + assertEquals(NODES_CNT, ((GridClientDataImpl)cache).projectionNodes().size()); + + long rawKey; + + while ((rawKey = keyCnt.getAndIncrement()) < cachePutCount()) { + String key = String.valueOf(rawKey); + + UUID nodeId = cache.affinity(key); + + String val = "val" + rawKey; + + if (cache.put(key, val)) { + T2<UUID, String> old = puts.putIfAbsent(key, new T2<>(nodeId, val)); + + assert old == null : "Map contained entry [key=" + rawKey + ", entry=" + old + ']'; + } + } + } + catch (Exception e) { + err.compareAndSet(null, e); + } + } + }, THREAD_CNT, "client-cache-put"); + + fut.get(); + + if (err.get() != null) + throw new Exception(err.get()); + + assertEquals(cachePutCount(), puts.size()); + + // Now check that all puts went to primary nodes. + for (long i = 0; i < cachePutCount(); i++) { + String key = String.valueOf(i); + + ClusterNode node = ignite.cluster().mapKeyToNode(PARTITIONED_CACHE_NAME, key); + + if (!puts.get(key).get2().equals(gridMap.get(node.id()).jcache(PARTITIONED_CACHE_NAME).localPeek(key, CachePeekMode.ONHEAP))) { + // printAffinityState(gridMap.values()); + + failNotEquals("Node don't have value for key [nodeId=" + node.id() + ", key=" + key + "]", + puts.get(key).get2(), gridMap.get(node.id()).jcache(PARTITIONED_CACHE_NAME).localPeek(key, CachePeekMode.ONHEAP)); + } + + + UUID curAffNode = client.data(PARTITIONED_CACHE_NAME).affinity(key); + + // Check that no other nodes see this key. + for (UUID id : gridMap.keySet()) { + if (!id.equals(curAffNode) && !id.equals(node.id())) + assertNull("Got value in near cache.", gridMap.get(id).jcache(PARTITIONED_CACHE_NAME).localPeek(key, CachePeekMode.ONHEAP)); + } + } + + for (Ignite g : gridMap.values()) + g.jcache(PARTITIONED_CACHE_NAME).clear(); + } }