From 41333302ac4c86113530d56d8aa0455125fe609d Mon Sep 17 00:00:00 2001 From: alpert Date: Wed, 20 Apr 2016 17:31:33 +0300 Subject: [PATCH] # IGNITE-2394 --- .../processors/cache/GridCacheAdapter.java | 4 +- .../processors/cache/IgniteCacheProxy.java | 16 ++- .../distributed/dht/GridCacheClientLoadTest.java | 159 +++++++++++++++++++++ 3 files changed, 173 insertions(+), 6 deletions(-) create mode 100644 modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheClientLoadTest.java diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java index d807e26..9d850ce 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java @@ -3657,14 +3657,14 @@ public abstract class GridCacheAdapter implements IgniteInternalCache globalLoadCacheAsync(@Nullable IgniteBiPredicate p, @Nullable Object... args) throws IgniteCheckedException { - ClusterGroup oldNodes = ctx.kernalContext().grid().cluster().forCacheNodes(ctx.name()) + ClusterGroup oldNodes = ctx.kernalContext().grid().cluster().forDataNodes(ctx.name()) .forPredicate(new IgnitePredicate() { @Override public boolean apply(ClusterNode node) { return node.version().compareToIgnoreTimestamp(LOAD_CACHE_JOB_SINCE) < 0; } }); - ClusterGroup newNodes = ctx.kernalContext().grid().cluster().forCacheNodes(ctx.name()) + ClusterGroup newNodes = ctx.kernalContext().grid().cluster().forDataNodes(ctx.name()) .forPredicate(new IgnitePredicate() { @Override public boolean apply(ClusterNode node) { return node.version().compareToIgnoreTimestamp(LOAD_CACHE_JOB_SINCE) >= 0; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java index 5b78271..1411d0f 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java @@ -374,10 +374,18 @@ public class IgniteCacheProxy extends AsyncSupportAdapter(TestStore.class)); + + return cfg; + } + + public void testLocalLoadClient() throws Exception { + String localCacheName = "localCache1"; + + CacheConfiguration localCache = cacheConfiguration(getTestGridName(clientGridId), localCacheName, LOCAL); + IgniteCache cache = grid(clientGridId).createCache(localCache); + cache.loadCache(null); + + assertEquals(cache.localSize(), 10) ; + assertEquals(grid(serverGridId).cache(localCacheName).localSize(), 0) ; + } + + + public void testLocalLoadServer() throws Exception { + String localCacheName = "localCache2"; + + CacheConfiguration localCache = cacheConfiguration(getTestGridName(clientGridId), localCacheName, LOCAL); + grid(clientGridId).createCache(localCache); + + IgniteCache cache = grid(serverGridId).cache(localCacheName); + cache.loadCache(null); + + assertEquals(grid(clientGridId).cache(localCacheName).localSize(), 0) ; + assertEquals(cache.localSize(), 10) ; + } + + public void testLocalLoadCreateServer() throws Exception { + String localCacheName = "localCache3"; + + CacheConfiguration localCache = cacheConfiguration(getTestGridName(serverGridId), localCacheName, LOCAL); + grid(serverGridId).createCache(localCache); + + IgniteCache cache = grid(clientGridId).cache(localCacheName); + cache.loadCache(null); + + assertEquals(grid(serverGridId).cache(localCacheName).localSize(), 0) ; + assertEquals(cache.localSize(), 10) ; + } + + public void testReplicatedLoadFromClient() throws Exception { + String replicatedCacheName = "replicatedCache1"; + + CacheConfiguration localCache = cacheConfiguration(getTestGridName(clientGridId), replicatedCacheName, REPLICATED); + IgniteCache cache = grid(clientGridId).createCache(localCache); + cache.loadCache(null); + + assertEquals(cache.localSize(), 0) ; + assertEquals(grid(serverGridId).cache(replicatedCacheName).localSize(), 10) ; + } + + public void testReplicatedLoadFromServer() throws Exception { + String replicatedCacheName = "replicatedCache2"; + + CacheConfiguration localCache = cacheConfiguration(getTestGridName(serverGridId), replicatedCacheName, REPLICATED); + grid(serverGridId).createCache(localCache); + + IgniteCache cache = grid(clientGridId).cache(replicatedCacheName); + cache.loadCache(null); + + assertEquals(cache.localSize(), 0) ; + assertEquals(grid(serverGridId).cache(replicatedCacheName).localSize(), 10) ; + } + + public static class TestStore extends CacheStoreAdapter { + + @Override + public Integer load(Object key) throws CacheLoaderException { + return null; + } + + @Override + public void write(Cache.Entry entry) throws CacheWriterException { + } + + @Override + public void delete(Object key) throws CacheWriterException { + } + + @Override + public void loadCache(IgniteBiInClosure clo, Object... args) { + U.dumpStack(); + + for (int i = 0; i < 10; i++) + clo.apply(i, i); + } + } + +} -- 2.6.4 (Apple Git-63)