IGNITE-45 - getOrCreate methods.
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/4e4feb84 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/4e4feb84 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/4e4feb84 Branch: refs/heads/ignite-541 Commit: 4e4feb841a16e313d7304129da74596145b00057 Parents: b9a1e83 Author: Alexey Goncharuk <agoncha...@gridgain.com> Authored: Fri Mar 20 17:09:27 2015 -0700 Committer: Alexey Goncharuk <agoncha...@gridgain.com> Committed: Fri Mar 20 17:09:27 2015 -0700 ---------------------------------------------------------------------- .../src/main/java/org/apache/ignite/Ignite.java | 20 ++- .../configuration/NearCacheConfiguration.java | 23 ---- .../apache/ignite/internal/IgniteKernal.java | 60 ++++++--- .../processors/cache/GridCacheProcessor.java | 51 ++++---- ...CacheJdbcBlobStoreMultithreadedSelfTest.java | 2 +- .../GridProjectionForCachesSelfTest.java | 15 +-- .../discovery/GridDiscoveryManagerSelfTest.java | 8 +- .../cache/GridCacheClearLocallySelfTest.java | 6 +- .../cache/IgniteDynamicCacheStartSelfTest.java | 125 +++++++++++-------- .../GridCacheClientModesAbstractSelfTest.java | 2 +- ...idCacheNearOnlyMultiNodeFullApiSelfTest.java | 2 +- .../near/GridCacheNearOnlyTopologySelfTest.java | 8 +- ...heNearOnlyLruNearEvictionPolicySelfTest.java | 2 +- .../ignite/testframework/junits/IgniteMock.java | 12 +- .../igfs/IgfsNearOnlyMultiNodeSelfTest.java | 12 +- .../org/apache/ignite/IgniteSpringBean.java | 18 ++- 16 files changed, 208 insertions(+), 158 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4e4feb84/modules/core/src/main/java/org/apache/ignite/Ignite.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/Ignite.java b/modules/core/src/main/java/org/apache/ignite/Ignite.java index 5e8d7d7..c2aa6bd 100644 --- a/modules/core/src/main/java/org/apache/ignite/Ignite.java +++ b/modules/core/src/main/java/org/apache/ignite/Ignite.java @@ -219,6 +219,15 @@ public interface Ignite extends AutoCloseable { NearCacheConfiguration<K, V> nearCfg); /** + * Gets existing cache with the given cache configuration or creates one if it does not exist. + * + * @param cacheCfg Cache configuration. + * @param nearCfg Near cache configuration for client. + * @return {@code IgniteCache} instance. + */ + public <K, V> IgniteCache<K, V> getOrCreateCache(CacheConfiguration<K, V> cacheCfg, NearCacheConfiguration<K, V> nearCfg); + + /** * Starts a near cache on local node if cache was previously started with one of the * {@link #createCache(CacheConfiguration)} or {@link #createCache(CacheConfiguration, NearCacheConfiguration)} * methods. @@ -226,7 +235,16 @@ public interface Ignite extends AutoCloseable { * @param nearCfg Near cache configuration. * @return Cache instance. */ - public <K, V> IgniteCache<K, V> createCache(NearCacheConfiguration<K, V> nearCfg); + public <K, V> IgniteCache<K, V> createCache(@Nullable String cacheName, NearCacheConfiguration<K, V> nearCfg); + + /** + * Gets existing near cache with the given name or creates a new one. + * + * @param cacheName Cache name. + * @param nearCfg Near configuration. + * @return {@code IgniteCache} instance. + */ + public <K, V> IgniteCache<K, V> getOrCreateCache(@Nullable String cacheName, NearCacheConfiguration<K, V> nearCfg); /** * Stops dynamically started cache. http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4e4feb84/modules/core/src/main/java/org/apache/ignite/configuration/NearCacheConfiguration.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/NearCacheConfiguration.java b/modules/core/src/main/java/org/apache/ignite/configuration/NearCacheConfiguration.java index 7e42b56..12c5e22 100644 --- a/modules/core/src/main/java/org/apache/ignite/configuration/NearCacheConfiguration.java +++ b/modules/core/src/main/java/org/apache/ignite/configuration/NearCacheConfiguration.java @@ -17,7 +17,6 @@ package org.apache.ignite.configuration; -import org.apache.ignite.*; import org.apache.ignite.cache.*; import org.apache.ignite.cache.eviction.*; @@ -32,9 +31,6 @@ public class NearCacheConfiguration<K, V> extends MutableConfiguration<K, V> { /** */ private static final long serialVersionUID = 0L; - /** Cache name. */ - private String name; - /** Near cache eviction policy. */ private CacheEvictionPolicy<K, V> nearEvictPlc; @@ -54,30 +50,11 @@ public class NearCacheConfiguration<K, V> extends MutableConfiguration<K, V> { public NearCacheConfiguration(NearCacheConfiguration<K, V> ccfg) { super(ccfg); - name = ccfg.getName(); nearEvictPlc = ccfg.getNearEvictionPolicy(); nearStartSize = ccfg.getNearStartSize(); } /** - * Gets cache name. The cache can be accessed via {@link Ignite#jcache(String)} method. - * - * @return Cache name. - */ - public String getName() { - return name; - } - - /** - * Sets cache name. - * - * @param name Cache name. - */ - public void setName(String name) { - this.name = name; - } - - /** * @return Near eviction policy. */ public CacheEvictionPolicy<K, V> getNearEvictionPolicy() { http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4e4feb84/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java index fd4fce7..4e6897d 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java @@ -451,7 +451,8 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable { assert cfg != null; return F.transform(cfg.getUserAttributes().entrySet(), new C1<Map.Entry<String, ?>, String>() { - @Override public String apply(Map.Entry<String, ?> e) { + @Override + public String apply(Map.Entry<String, ?> e) { return e.getKey() + ", " + e.getValue().toString(); } }); @@ -2255,7 +2256,7 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable { guard(); try { - ctx.cache().dynamicStartCache(cacheCfg, null).get(); + ctx.cache().dynamicStartCache(cacheCfg, cacheCfg.getName(), null, true).get(); return ctx.cache().publicJCache(cacheCfg.getName()); } @@ -2274,14 +2275,7 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable { guard(); try { - try { - ctx.cache().dynamicStartCache(cacheCfg, null).get(); - } - catch (IgniteCheckedException e) { - // Ignore error if cache exists. - if (!e.hasCause(IgniteCacheExistsException.class)) - throw e; - } + ctx.cache().dynamicStartCache(cacheCfg, cacheCfg.getName(), null, false).get(); return ctx.cache().publicJCache(cacheCfg.getName()); } @@ -2304,7 +2298,7 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable { guard(); try { - ctx.cache().dynamicStartCache(cacheCfg, nearCfg).get(); + ctx.cache().dynamicStartCache(cacheCfg, cacheCfg.getName(), nearCfg, true).get(); return ctx.cache().publicJCache(cacheCfg.getName()); } @@ -2314,19 +2308,57 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable { finally { unguard(); } + } + + /** {@inheritDoc} */ + @Override public <K, V> IgniteCache<K, V> getOrCreateCache(CacheConfiguration<K, V> cacheCfg, NearCacheConfiguration<K, V> nearCfg) { + A.notNull(cacheCfg, "cacheCfg"); + A.notNull(nearCfg, "nearCfg"); + guard(); + + try { + ctx.cache().dynamicStartCache(cacheCfg, cacheCfg.getName(), nearCfg, false).get(); + + return ctx.cache().publicJCache(cacheCfg.getName()); + } + catch (IgniteCheckedException e) { + throw CU.convertToCacheException(e); + } + finally { + unguard(); + } } /** {@inheritDoc} */ - @Override public <K, V> IgniteCache<K, V> createCache(@Nullable NearCacheConfiguration<K, V> nearCfg) { + @Override public <K, V> IgniteCache<K, V> createCache(String cacheName, NearCacheConfiguration<K, V> nearCfg) { + A.notNull(nearCfg, "nearCfg"); + + guard(); + + try { + ctx.cache().dynamicStartCache(null, cacheName, nearCfg, true).get(); + + return ctx.cache().publicJCache(cacheName); + } + catch (IgniteCheckedException e) { + throw CU.convertToCacheException(e); + } + finally { + unguard(); + } + } + + @Override + public <K, V> IgniteCache<K, V> getOrCreateCache(@Nullable String cacheName, NearCacheConfiguration<K, V> nearCfg) { A.notNull(nearCfg, "nearCfg"); guard(); try { - ctx.cache().dynamicStartCache(null, nearCfg).get(); + ctx.cache().dynamicStartCache(null, cacheName, nearCfg, false).get(); - return ctx.cache().publicJCache(nearCfg.getName()); + return ctx.cache().publicJCache(cacheName); } catch (IgniteCheckedException e) { throw CU.convertToCacheException(e); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4e4feb84/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java index 792436a..278e2c8 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java @@ -1531,38 +1531,47 @@ public class GridCacheProcessor extends GridProcessorAdapter { */ public IgniteInternalFuture<?> dynamicStartCache( @Nullable CacheConfiguration ccfg, - @Nullable NearCacheConfiguration nearCfg + String cacheName, + @Nullable NearCacheConfiguration nearCfg, + boolean failIfExists ) { assert ccfg != null || nearCfg != null; - String cacheName = ccfg == null ? nearCfg.getName() : ccfg.getName(); - DynamicCacheDescriptor desc = registeredCaches.get(maskNull(cacheName)); DynamicCacheChangeRequest req = new DynamicCacheChangeRequest(ctx.localNodeId()); if (ccfg != null) { - if (desc != null) - return new GridFinishedFuture<>(new IgniteCacheExistsException("Failed to start cache " + - "(a cache with the same name is already started): " + cacheName)); - - req.deploymentId(IgniteUuid.randomUuid()); + if (desc != null) { + if (failIfExists) + return new GridFinishedFuture<>(new IgniteCacheExistsException("Failed to start cache " + + "(a cache with the same name is already started): " + cacheName)); + else { + // Check if we were asked to start a near cache. + if (nearCfg != null) + req.clientStartOnly(true); + else + return new GridFinishedFuture<>(); + + req.deploymentId(desc.deploymentId()); + req.startCacheConfiguration(ccfg); + } + } + else { + req.deploymentId(IgniteUuid.randomUuid()); - try { - CacheConfiguration cfg = new CacheConfiguration(ccfg); + try { + CacheConfiguration cfg = new CacheConfiguration(ccfg); - CacheObjectContext cacheObjCtx = ctx.cacheObjects().contextForCache(null, cfg.getName(), cfg); + CacheObjectContext cacheObjCtx = ctx.cacheObjects().contextForCache(null, cfg.getName(), cfg); - initialize(cfg, cacheObjCtx); + initialize(cfg, cacheObjCtx); - req.startCacheConfiguration(cfg); - } - catch (IgniteCheckedException e) { - return new GridFinishedFuture(e); + req.startCacheConfiguration(cfg); + } catch (IgniteCheckedException e) { + return new GridFinishedFuture(e); + } } - - if (nearCfg != null) - nearCfg.setName(ccfg.getName()); } else { req.clientStartOnly(true); @@ -1572,11 +1581,11 @@ public class GridCacheProcessor extends GridProcessorAdapter { if (ccfg == null) return new GridFinishedFuture<>(new IgniteCacheExistsException("Failed to start near cache " + - "(a cache with the given name is not started): " + nearCfg.getName())); + "(a cache with the given name is not started): " + cacheName)); if (ccfg.getNodeFilter().apply(ctx.discovery().localNode())) return new GridFinishedFuture<>(new IgniteCheckedException("Failed to start near cache " + - "(local node is an affinity node for cache): " + nearCfg.getName())); + "(local node is an affinity node for cache): " + cacheName)); req.deploymentId(desc.deploymentId()); req.startCacheConfiguration(ccfg); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4e4feb84/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/GridCacheJdbcBlobStoreMultithreadedSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/GridCacheJdbcBlobStoreMultithreadedSelfTest.java b/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/GridCacheJdbcBlobStoreMultithreadedSelfTest.java index b1b63de..a21d130 100644 --- a/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/GridCacheJdbcBlobStoreMultithreadedSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/GridCacheJdbcBlobStoreMultithreadedSelfTest.java @@ -64,7 +64,7 @@ public class GridCacheJdbcBlobStoreMultithreadedSelfTest extends GridCommonAbstr Ignite grid = startGrid(GRID_CNT - 2); - grid.createCache(new NearCacheConfiguration()); + grid.createCache((String)null, new NearCacheConfiguration()); grid = startGrid(GRID_CNT - 1); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4e4feb84/modules/core/src/test/java/org/apache/ignite/internal/GridProjectionForCachesSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/GridProjectionForCachesSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/GridProjectionForCachesSelfTest.java index 992aa04..d0a01ec 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/GridProjectionForCachesSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/GridProjectionForCachesSelfTest.java @@ -84,13 +84,8 @@ public class GridProjectionForCachesSelfTest extends GridCommonAbstractTest { cfg.setName(cacheName); cfg.setCacheMode(PARTITIONED); - if (nearEnabled) { - NearCacheConfiguration nearCfg = new NearCacheConfiguration(); - - nearCfg.setName(cacheName); - - cfg.setNearConfiguration(nearCfg); - } + if (nearEnabled) + cfg.setNearConfiguration(new NearCacheConfiguration()); cfg.setNodeFilter(nodeFilter); @@ -104,11 +99,7 @@ public class GridProjectionForCachesSelfTest extends GridCommonAbstractTest { for (int i = 0; i < 5; i++) startGrid(i); - NearCacheConfiguration nearCfg = new NearCacheConfiguration(); - - nearCfg.setName(CACHE_NAME); - - grid(1).createCache(nearCfg); + grid(1).createCache(CACHE_NAME, new NearCacheConfiguration()); grid(2).jcache(null); grid(3).jcache(null); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4e4feb84/modules/core/src/test/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManagerSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManagerSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManagerSelfTest.java index eb8d3fa..7307438 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManagerSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManagerSelfTest.java @@ -99,13 +99,9 @@ public class GridDiscoveryManagerSelfTest extends GridCommonAbstractTest { IgniteKernal g1 = (IgniteKernal)startGrid(1); // NEAR_ONLY cache. - grid(1).createCache(new NearCacheConfiguration()); + grid(1).createCache((String)null, new NearCacheConfiguration()); - NearCacheConfiguration near = new NearCacheConfiguration(); - - near.setName(CACHE_NAME); - - grid(1).createCache(near); + grid(1).createCache(CACHE_NAME, new NearCacheConfiguration()); assertFalse(g0.context().discovery().hasNearCache(CACHE_NAME, one)); assertTrue(g0.context().discovery().hasNearCache(CACHE_NAME, two)); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4e4feb84/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheClearLocallySelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheClearLocallySelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheClearLocallySelfTest.java index 9c3596d..11e31e9 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheClearLocallySelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheClearLocallySelfTest.java @@ -89,8 +89,6 @@ public class GridCacheClearLocallySelfTest extends GridCommonAbstractTest { ccfgPartitioned.setWriteSynchronizationMode(FULL_SYNC); NearCacheConfiguration nearCfg = new NearCacheConfiguration(); - nearCfg.setName(CACHE_PARTITIONED); - ccfgPartitioned.setNearConfiguration(nearCfg); ccfgPartitioned.setNodeFilter(new AttributeFilter(getTestGridName(0))); @@ -150,9 +148,7 @@ public class GridCacheClearLocallySelfTest extends GridCommonAbstractTest { if (i == 1) { NearCacheConfiguration nearCfg = new NearCacheConfiguration(); - nearCfg.setName(CACHE_PARTITIONED); - - ignite.createCache(nearCfg); + ignite.createCache(CACHE_PARTITIONED, nearCfg); } if (i == 2) http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4e4feb84/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteDynamicCacheStartSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteDynamicCacheStartSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteDynamicCacheStartSelfTest.java index d554966..3f82cbd 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteDynamicCacheStartSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteDynamicCacheStartSelfTest.java @@ -49,7 +49,8 @@ public class IgniteDynamicCacheStartSelfTest extends GridCommonAbstractTest { /** */ public static final IgnitePredicate<ClusterNode> NODE_FILTER = new IgnitePredicate<ClusterNode>() { /** {@inheritDoc} */ - @Override public boolean apply(ClusterNode n) { + @Override + public boolean apply(ClusterNode n) { Boolean val = n.attribute(TEST_ATTRIBUTE_NAME); return val != null && val; @@ -66,8 +67,11 @@ public class IgniteDynamicCacheStartSelfTest extends GridCommonAbstractTest { return 3; } - /** {@inheritDoc} */ - @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + /** + * {@inheritDoc} + */ + @Override + protected IgniteConfiguration getConfiguration(String gridName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(gridName); cfg.setUserAttributes(F.asMap(TEST_ATTRIBUTE_NAME, testAttribute)); @@ -85,13 +89,19 @@ public class IgniteDynamicCacheStartSelfTest extends GridCommonAbstractTest { return cfg; } - /** {@inheritDoc} */ - @Override protected void beforeTestsStarted() throws Exception { + /** + * {@inheritDoc} + */ + @Override + protected void beforeTestsStarted() throws Exception { startGridsMultiThreaded(nodeCount()); } - /** {@inheritDoc} */ - @Override protected void afterTestsStopped() throws Exception { + /** + * {@inheritDoc} + */ + @Override + protected void afterTestsStopped() throws Exception { stopAllGrids(); } @@ -99,19 +109,20 @@ public class IgniteDynamicCacheStartSelfTest extends GridCommonAbstractTest { * @throws Exception If failed. */ public void testStartStopCacheMultithreadedSameNode() throws Exception { - final IgniteKernal kernal = (IgniteKernal)grid(0); + final IgniteKernal kernal = (IgniteKernal) grid(0); final Collection<IgniteInternalFuture<?>> futs = new ConcurrentLinkedDeque<>(); int threadNum = 20; GridTestUtils.runMultiThreaded(new Callable<Object>() { - @Override public Object call() throws Exception { + @Override + public Object call() throws Exception { CacheConfiguration ccfg = new CacheConfiguration(); ccfg.setName(DYNAMIC_CACHE_NAME); - futs.add(kernal.context().cache().dynamicStartCache(ccfg, null)); + futs.add(kernal.context().cache().dynamicStartCache(ccfg, ccfg.getName(), null, true)); return null; } @@ -129,8 +140,7 @@ public class IgniteDynamicCacheStartSelfTest extends GridCommonAbstractTest { info("Succeeded: " + System.identityHashCode(fut)); succeeded++; - } - catch (IgniteCheckedException e) { + } catch (IgniteCheckedException e) { info(e.getMessage()); failed++; @@ -143,7 +153,8 @@ public class IgniteDynamicCacheStartSelfTest extends GridCommonAbstractTest { futs.clear(); GridTestUtils.runMultiThreaded(new Callable<Object>() { - @Override public Object call() throws Exception { + @Override + public Object call() throws Exception { futs.add(kernal.context().cache().dynamicStopCache(DYNAMIC_CACHE_NAME)); return null; @@ -165,14 +176,15 @@ public class IgniteDynamicCacheStartSelfTest extends GridCommonAbstractTest { int threadNum = 20; GridTestUtils.runMultiThreaded(new Callable<Object>() { - @Override public Object call() throws Exception { + @Override + public Object call() throws Exception { CacheConfiguration ccfg = new CacheConfiguration(); ccfg.setName(DYNAMIC_CACHE_NAME); - IgniteKernal kernal = (IgniteKernal)grid(ThreadLocalRandom.current().nextInt(nodeCount())); + IgniteKernal kernal = (IgniteKernal) grid(ThreadLocalRandom.current().nextInt(nodeCount())); - futs.add(kernal.context().cache().dynamicStartCache(ccfg, null)); + futs.add(kernal.context().cache().dynamicStartCache(ccfg, ccfg.getName(), null, true)); return null; } @@ -190,8 +202,7 @@ public class IgniteDynamicCacheStartSelfTest extends GridCommonAbstractTest { info("Succeeded: " + System.identityHashCode(fut)); succeeded++; - } - catch (IgniteCheckedException e) { + } catch (IgniteCheckedException e) { info(e.getMessage()); failed++; @@ -204,8 +215,9 @@ public class IgniteDynamicCacheStartSelfTest extends GridCommonAbstractTest { futs.clear(); GridTestUtils.runMultiThreaded(new Callable<Object>() { - @Override public Object call() throws Exception { - IgniteKernal kernal = (IgniteKernal)grid(ThreadLocalRandom.current().nextInt(nodeCount())); + @Override + public Object call() throws Exception { + IgniteKernal kernal = (IgniteKernal) grid(ThreadLocalRandom.current().nextInt(nodeCount())); futs.add(kernal.context().cache().dynamicStopCache(DYNAMIC_CACHE_NAME)); @@ -237,7 +249,7 @@ public class IgniteDynamicCacheStartSelfTest extends GridCommonAbstractTest { * @throws Exception If failed. */ private void checkStartStopCacheSimple(CacheAtomicityMode mode) throws Exception { - final IgniteKernal kernal = (IgniteKernal)grid(0); + final IgniteKernal kernal = (IgniteKernal) grid(0); CacheConfiguration ccfg = new CacheConfiguration(); ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); @@ -245,10 +257,10 @@ public class IgniteDynamicCacheStartSelfTest extends GridCommonAbstractTest { ccfg.setName(DYNAMIC_CACHE_NAME); - kernal.context().cache().dynamicStartCache(ccfg, null).get(); + kernal.createCache(ccfg, null); for (int g = 0; g < nodeCount(); g++) { - IgniteKernal kernal0 = (IgniteKernal)grid(g); + IgniteKernal kernal0 = (IgniteKernal) grid(g); for (IgniteInternalFuture f : kernal0.context().cache().context().exchange().exchangeFutures()) f.get(); @@ -272,7 +284,7 @@ public class IgniteDynamicCacheStartSelfTest extends GridCommonAbstractTest { kernal.context().cache().dynamicStopCache(DYNAMIC_CACHE_NAME).get(); for (int g = 0; g < nodeCount(); g++) { - final IgniteKernal kernal0 = (IgniteKernal)grid(g); + final IgniteKernal kernal0 = (IgniteKernal) grid(g); final int idx = g; @@ -280,13 +292,15 @@ public class IgniteDynamicCacheStartSelfTest extends GridCommonAbstractTest { f.get(); GridTestUtils.assertThrows(log, new Callable<Object>() { - @Override public Object call() throws Exception { + @Override + public Object call() throws Exception { return kernal0.jcache(DYNAMIC_CACHE_NAME); } }, IllegalArgumentException.class, null); GridTestUtils.assertThrows(log, new Callable<Object>() { - @Override public Object call() throws Exception { + @Override + public Object call() throws Exception { return caches[idx].get("1"); } }, IllegalStateException.class, null); @@ -297,7 +311,7 @@ public class IgniteDynamicCacheStartSelfTest extends GridCommonAbstractTest { * @throws Exception If failed. */ public void testStartStopCacheAddNode() throws Exception { - final IgniteKernal kernal = (IgniteKernal)grid(0); + final IgniteKernal kernal = (IgniteKernal) grid(0); CacheConfiguration ccfg = new CacheConfiguration(); ccfg.setCacheMode(CacheMode.REPLICATED); @@ -305,7 +319,7 @@ public class IgniteDynamicCacheStartSelfTest extends GridCommonAbstractTest { ccfg.setName(DYNAMIC_CACHE_NAME); - kernal.context().cache().dynamicStartCache(ccfg, null).get(); + kernal.createCache(ccfg, null); info(">>>>>>> Deployed dynamic cache"); @@ -332,19 +346,19 @@ public class IgniteDynamicCacheStartSelfTest extends GridCommonAbstractTest { // Check that cache is not deployed on new node after undeploy. for (int g = 0; g < nodeCount() + 2; g++) { - final IgniteKernal kernal0 = (IgniteKernal)grid(g); + final IgniteKernal kernal0 = (IgniteKernal) grid(g); for (IgniteInternalFuture f : kernal0.context().cache().context().exchange().exchangeFutures()) f.get(); GridTestUtils.assertThrows(log, new Callable<Object>() { - @Override public Object call() throws Exception { + @Override + public Object call() throws Exception { return kernal0.jcache(DYNAMIC_CACHE_NAME); } }, IllegalArgumentException.class, null); } - } - finally { + } finally { stopGrid(nodeCount() + 1); stopGrid(nodeCount()); } @@ -359,7 +373,7 @@ public class IgniteDynamicCacheStartSelfTest extends GridCommonAbstractTest { startGrid(nodeCount()); - final IgniteKernal kernal = (IgniteKernal)grid(0); + final IgniteKernal kernal = (IgniteKernal) grid(0); CacheConfiguration ccfg = new CacheConfiguration(); ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); @@ -368,7 +382,7 @@ public class IgniteDynamicCacheStartSelfTest extends GridCommonAbstractTest { ccfg.setNodeFilter(NODE_FILTER); - kernal.context().cache().dynamicStartCache(ccfg, null).get(); + kernal.createCache(ccfg, null); startGrid(nodeCount() + 1); @@ -383,16 +397,16 @@ public class IgniteDynamicCacheStartSelfTest extends GridCommonAbstractTest { for (int g = 0; g < nodeCount(); g++) { for (int i = 0; i < 100; i++) { assertFalse(grid(g).affinity(DYNAMIC_CACHE_NAME).mapKeyToPrimaryAndBackups(i) - .contains(grid(nodeCount()).cluster().localNode())); + .contains(grid(nodeCount()).cluster().localNode())); assertFalse(grid(g).affinity(DYNAMIC_CACHE_NAME).mapKeyToPrimaryAndBackups(i) - .contains(grid(nodeCount() + 1).cluster().localNode())); + .contains(grid(nodeCount() + 1).cluster().localNode())); } } // Check that cache is not deployed on new node after undeploy. for (int g = 0; g < nodeCount() + 2; g++) { - final IgniteKernal kernal0 = (IgniteKernal)grid(g); + final IgniteKernal kernal0 = (IgniteKernal) grid(g); for (IgniteInternalFuture f : kernal0.context().cache().context().exchange().exchangeFutures()) f.get(); @@ -401,7 +415,8 @@ public class IgniteDynamicCacheStartSelfTest extends GridCommonAbstractTest { assertNotNull(grid(g).jcache(DYNAMIC_CACHE_NAME)); else GridTestUtils.assertThrows(log, new Callable<Object>() { - @Override public Object call() throws Exception { + @Override + public Object call() throws Exception { return kernal0.cache(DYNAMIC_CACHE_NAME); } }, IllegalArgumentException.class, null); @@ -411,8 +426,7 @@ public class IgniteDynamicCacheStartSelfTest extends GridCommonAbstractTest { stopGrid(nodeCount() + 1); stopGrid(nodeCount()); - } - finally { + } finally { testAttribute = true; } } @@ -422,8 +436,9 @@ public class IgniteDynamicCacheStartSelfTest extends GridCommonAbstractTest { */ public void testFailWhenConfiguredCacheExists() throws Exception { GridTestUtils.assertThrows(log, new Callable<Object>() { - @Override public Object call() throws Exception { - final IgniteKernal kernal = (IgniteKernal)grid(0); + @Override + public Object call() throws Exception { + final IgniteKernal kernal = (IgniteKernal) grid(0); CacheConfiguration ccfg = new CacheConfiguration(); ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); @@ -433,7 +448,7 @@ public class IgniteDynamicCacheStartSelfTest extends GridCommonAbstractTest { ccfg.setNodeFilter(NODE_FILTER); - return kernal.context().cache().dynamicStartCache(ccfg, null).get(); + return kernal.createCache(ccfg, null); } }, IgniteCheckedException.class, null); } @@ -447,7 +462,7 @@ public class IgniteDynamicCacheStartSelfTest extends GridCommonAbstractTest { startGrid(nodeCount()); - final IgniteKernal kernal = (IgniteKernal)grid(0); + final IgniteKernal kernal = (IgniteKernal) grid(0); CacheConfiguration ccfg = new CacheConfiguration(); ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); @@ -456,11 +471,12 @@ public class IgniteDynamicCacheStartSelfTest extends GridCommonAbstractTest { ccfg.setNodeFilter(NODE_FILTER); - kernal.context().cache().dynamicStartCache(ccfg, null).get(); + kernal.createCache(ccfg, null); GridTestUtils.assertThrows(log, new Callable<Object>() { - @Override public Object call() throws Exception { - IgniteKernal ignite = (IgniteKernal)grid(nodeCount()); + @Override + public Object call() throws Exception { + IgniteKernal ignite = (IgniteKernal) grid(nodeCount()); return ignite.cache(DYNAMIC_CACHE_NAME); } @@ -475,8 +491,7 @@ public class IgniteDynamicCacheStartSelfTest extends GridCommonAbstractTest { assertEquals("1", ignite(g).jcache(DYNAMIC_CACHE_NAME).get("1")); kernal.context().cache().dynamicStopCache(DYNAMIC_CACHE_NAME).get(); - } - finally { + } finally { stopGrid(nodeCount()); } } @@ -490,7 +505,7 @@ public class IgniteDynamicCacheStartSelfTest extends GridCommonAbstractTest { startGrid(nodeCount()); - final IgniteKernal kernal = (IgniteKernal)grid(0); + final IgniteKernal kernal = (IgniteKernal) grid(0); CacheConfiguration ccfg = new CacheConfiguration(); ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); @@ -499,9 +514,9 @@ public class IgniteDynamicCacheStartSelfTest extends GridCommonAbstractTest { ccfg.setNodeFilter(NODE_FILTER); - final IgniteKernal started = (IgniteKernal)grid(nodeCount()); + final IgniteKernal started = (IgniteKernal) grid(nodeCount()); - started.context().cache().dynamicStartCache(ccfg, null).get(); + started.createCache(ccfg, null); GridCacheAdapter<Object, Object> cache = started.internalCache(DYNAMIC_CACHE_NAME); @@ -517,12 +532,12 @@ public class IgniteDynamicCacheStartSelfTest extends GridCommonAbstractTest { assertEquals("1", ignite(g).jcache(DYNAMIC_CACHE_NAME).get("1")); kernal.context().cache().dynamicStopCache(DYNAMIC_CACHE_NAME).get(); - } - finally { + } finally { stopGrid(nodeCount()); } } + /** * @throws Exception If failed. */ @@ -545,7 +560,7 @@ public class IgniteDynamicCacheStartSelfTest extends GridCommonAbstractTest { NearCacheConfiguration nearCfg = new NearCacheConfiguration(); - started.context().cache().dynamicStartCache(ccfg, nearCfg).get(); + started.createCache(ccfg, nearCfg); GridCacheAdapter<Object, Object> cache = started.internalCache(DYNAMIC_CACHE_NAME); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4e4feb84/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheClientModesAbstractSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheClientModesAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheClientModesAbstractSelfTest.java index 557cb41..f82b47c 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheClientModesAbstractSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheClientModesAbstractSelfTest.java @@ -51,7 +51,7 @@ public abstract class GridCacheClientModesAbstractSelfTest extends GridCacheAbst super.beforeTestsStarted(); if (!clientOnly()) { - grid(nearOnlyGridName).createCache(new NearCacheConfiguration()); + grid(nearOnlyGridName).createCache((String)null, new NearCacheConfiguration()); } } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4e4feb84/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearOnlyMultiNodeFullApiSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearOnlyMultiNodeFullApiSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearOnlyMultiNodeFullApiSelfTest.java index c1a83e0..b744ed3 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearOnlyMultiNodeFullApiSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearOnlyMultiNodeFullApiSelfTest.java @@ -59,7 +59,7 @@ public class GridCacheNearOnlyMultiNodeFullApiSelfTest extends GridCachePartitio for (int i = 0; i < gridCount(); i++) { if (ignite(i).configuration().isClientMode()) { if (clientHasNearCache()) - ignite(i).createCache(new NearCacheConfiguration<>()); + ignite(i).createCache((String)null, new NearCacheConfiguration<>()); else ignite(i).jcache(null); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4e4feb84/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearOnlyTopologySelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearOnlyTopologySelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearOnlyTopologySelfTest.java index b2c8e0f..9c99910 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearOnlyTopologySelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheNearOnlyTopologySelfTest.java @@ -113,7 +113,7 @@ public class GridCacheNearOnlyTopologySelfTest extends GridCommonAbstractTest { Ignite ignite = startGrid(i); if (cilent) - ignite.createCache(new NearCacheConfiguration()); + ignite.createCache((String)null, new NearCacheConfiguration()); } for (int i = 0; i < 100; i++) @@ -135,7 +135,7 @@ public class GridCacheNearOnlyTopologySelfTest extends GridCommonAbstractTest { Ignite ignite = startGrid(i); if (cilent) - ignite.createCache(new NearCacheConfiguration()); + ignite.createCache((String)null, new NearCacheConfiguration()); } cache = false; @@ -166,7 +166,7 @@ public class GridCacheNearOnlyTopologySelfTest extends GridCommonAbstractTest { Ignite ignite = startGrid(i); if (cilent) - ignite.createCache(new NearCacheConfiguration()); + ignite.createCache((String)null, new NearCacheConfiguration()); } for (int i = 0; i < 10; i++) @@ -239,7 +239,7 @@ public class GridCacheNearOnlyTopologySelfTest extends GridCommonAbstractTest { Ignite ignite = startGrid(i); if (cilent) - ignite.createCache(new NearCacheConfiguration()); + ignite.createCache((String)null, new NearCacheConfiguration()); } } finally { http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4e4feb84/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/lru/GridCacheNearOnlyLruNearEvictionPolicySelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/lru/GridCacheNearOnlyLruNearEvictionPolicySelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/lru/GridCacheNearOnlyLruNearEvictionPolicySelfTest.java index 3ed07ff..85cd049 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/lru/GridCacheNearOnlyLruNearEvictionPolicySelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/lru/GridCacheNearOnlyLruNearEvictionPolicySelfTest.java @@ -139,7 +139,7 @@ public class GridCacheNearOnlyLruNearEvictionPolicySelfTest extends GridCommonAb NearCacheConfiguration nearCfg = new NearCacheConfiguration(); nearCfg.setNearEvictionPolicy(new CacheLruEvictionPolicy(EVICTION_MAX_SIZE)); - grid(0).createCache(nearCfg); + grid(0).createCache((String)null, nearCfg); int cnt = 1000; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4e4feb84/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java index d2135ed..dfcf487 100644 --- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java +++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java @@ -182,7 +182,17 @@ public class IgniteMock implements Ignite { } /** {@inheritDoc} */ - @Override public <K, V> IgniteCache<K, V> createCache(@Nullable NearCacheConfiguration<K, V> nearCfg) { + @Override public <K, V> IgniteCache<K, V> createCache(String cacheName, NearCacheConfiguration<K, V> nearCfg) { + return null; + } + + /** {@inheritDoc} */ + @Override public <K, V> IgniteCache<K, V> getOrCreateCache(CacheConfiguration<K, V> cacheCfg, NearCacheConfiguration<K, V> nearCfg) { + return null; + } + + /** {@inheritDoc} */ + @Override public <K, V> IgniteCache<K, V> getOrCreateCache(@Nullable String cacheName, NearCacheConfiguration<K, V> nearCfg) { return null; } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4e4feb84/modules/hadoop/src/test/java/org/apache/ignite/igfs/IgfsNearOnlyMultiNodeSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/hadoop/src/test/java/org/apache/ignite/igfs/IgfsNearOnlyMultiNodeSelfTest.java b/modules/hadoop/src/test/java/org/apache/ignite/igfs/IgfsNearOnlyMultiNodeSelfTest.java index 84f70be..510d3a7 100644 --- a/modules/hadoop/src/test/java/org/apache/ignite/igfs/IgfsNearOnlyMultiNodeSelfTest.java +++ b/modules/hadoop/src/test/java/org/apache/ignite/igfs/IgfsNearOnlyMultiNodeSelfTest.java @@ -59,17 +59,9 @@ public class IgfsNearOnlyMultiNodeSelfTest extends GridCommonAbstractTest { @Override protected void beforeTestsStarted() throws Exception { startGrids(nodeCount()); - NearCacheConfiguration nearCfg = new NearCacheConfiguration(); + grid(0).createCache("data", new NearCacheConfiguration()); - nearCfg.setName("data"); - - grid(0).createCache(nearCfg); - - nearCfg = new NearCacheConfiguration(); - - nearCfg.setName("meta"); - - grid(0).createCache(nearCfg); + grid(0).createCache("meta", new NearCacheConfiguration()); } /** {@inheritDoc} */ http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4e4feb84/modules/spring/src/main/java/org/apache/ignite/IgniteSpringBean.java ---------------------------------------------------------------------- diff --git a/modules/spring/src/main/java/org/apache/ignite/IgniteSpringBean.java b/modules/spring/src/main/java/org/apache/ignite/IgniteSpringBean.java index 0e72daa..c8db3bd 100644 --- a/modules/spring/src/main/java/org/apache/ignite/IgniteSpringBean.java +++ b/modules/spring/src/main/java/org/apache/ignite/IgniteSpringBean.java @@ -255,10 +255,24 @@ public class IgniteSpringBean implements Ignite, DisposableBean, InitializingBea } /** {@inheritDoc} */ - @Override public <K, V> IgniteCache<K, V> createCache(NearCacheConfiguration<K, V> nearCfg) { + @Override public <K, V> IgniteCache<K, V> getOrCreateCache(CacheConfiguration<K, V> cacheCfg, NearCacheConfiguration<K, V> nearCfg) { assert g != null; - return g.createCache(nearCfg); + return g.getOrCreateCache(cacheCfg, nearCfg); + } + + /** {@inheritDoc} */ + @Override public <K, V> IgniteCache<K, V> createCache(String cacheName, NearCacheConfiguration<K, V> nearCfg) { + assert g != null; + + return g.createCache(cacheName, nearCfg); + } + + /** {@inheritDoc} */ + @Override public <K, V> IgniteCache<K, V> getOrCreateCache(@Nullable String cacheName, NearCacheConfiguration<K, V> nearCfg) { + assert g != null; + + return g.getOrCreateCache(cacheName, nearCfg); } /** {@inheritDoc} */