Repository: incubator-ignite Updated Branches: refs/heads/ignite-929 637017ec3 -> 98f4c6082
# ignite-929 Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/98f4c608 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/98f4c608 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/98f4c608 Branch: refs/heads/ignite-929 Commit: 98f4c6082983ecbe837188d8f1877c736adc0f37 Parents: 637017e Author: sboikov <sboi...@gridgain.com> Authored: Thu Jul 9 17:30:11 2015 +0300 Committer: sboikov <sboi...@gridgain.com> Committed: Thu Jul 9 17:30:11 2015 +0300 ---------------------------------------------------------------------- .../apache/ignite/internal/IgniteKernal.java | 7 +- .../cache/CacheStopAndDestroySelfTest.java | 186 ++++++------------- 2 files changed, 58 insertions(+), 135 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/98f4c608/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 aca938c..024dc7b 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 @@ -2249,12 +2249,7 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable { guard(); try { - IgniteCache<K, V> cache = ctx.cache().publicJCache(name, false); - - if (cache == null) - throw new IllegalArgumentException("Cache is not started: " + name); - - return cache; + return ctx.cache().publicJCache(name, false); } catch (IgniteCheckedException e) { throw CU.convertToCacheException(e); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/98f4c608/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheStopAndDestroySelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheStopAndDestroySelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheStopAndDestroySelfTest.java index 79c2a2a..20284a8 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheStopAndDestroySelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheStopAndDestroySelfTest.java @@ -67,6 +67,20 @@ public class CacheStopAndDestroySelfTest extends GridCommonAbstractTest { /** */ private static volatile boolean stop; + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + super.beforeTest(); + + startGridsMultiThreaded(gridCount()); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + super.afterTest(); + + stopAllGrids(); + } + /** * @return Grids count to start. */ @@ -201,30 +215,11 @@ public class CacheStopAndDestroySelfTest extends GridCommonAbstractTest { // DHT Destroy. Cache should be removed from each node. - grid(0).cache(CACHE_NAME_DHT).destroy(); - - try { - grid(0).cache(CACHE_NAME_DHT).get(KEY_VAL); + IgniteCache<Object, Object> cache = grid(0).cache(CACHE_NAME_DHT); - fail(); - } - catch (IllegalArgumentException | IllegalStateException ignored0) { - try { - grid(1).cache(CACHE_NAME_DHT).get(KEY_VAL); + cache.destroy(); - fail(); - } - catch (IllegalArgumentException | IllegalStateException ignored1) { - try { - grid(2).cache(CACHE_NAME_DHT).get(KEY_VAL); - - fail(); - } - catch (IllegalArgumentException | IllegalStateException ignored2) { - // No-op - } - } - } + checkDestroyed(cache); } /** @@ -258,30 +253,11 @@ public class CacheStopAndDestroySelfTest extends GridCommonAbstractTest { assertTrue(grid(2).configuration().isClientMode()); - grid(2).cache(CACHE_NAME_CLIENT).destroy();// Client node. - - try { - grid(0).cache(CACHE_NAME_CLIENT).get(KEY_VAL); - - fail(); - } - catch (IllegalArgumentException | IllegalStateException ignored0) { - try { - grid(1).cache(CACHE_NAME_CLIENT).get(KEY_VAL); + IgniteCache<Object, Object> cache = grid(2).cache(CACHE_NAME_CLIENT); - fail(); - } - catch (IllegalArgumentException | IllegalStateException ignored1) { - try { - grid(2).cache(CACHE_NAME_CLIENT).get(KEY_VAL); + cache.destroy(); // Client node. - fail(); - } - catch (IllegalArgumentException | IllegalStateException ignored2) { - // No-op - } - } - } + checkDestroyed(cache); } /** @@ -313,32 +289,13 @@ public class CacheStopAndDestroySelfTest extends GridCommonAbstractTest { assertEquals("near-test", grid(2).cache(CACHE_NAME_NEAR).localPeek(KEY_VAL)); - // Local destroy. Cache should be removed from each node. + // Near cache destroy. Cache should be removed from each node. - grid(2).cache(CACHE_NAME_NEAR).destroy(); + IgniteCache<Object, Object> cache = grid(2).cache(CACHE_NAME_NEAR); - try { - grid(0).cache(CACHE_NAME_NEAR).get(KEY_VAL); + cache.destroy(); - fail(); - } - catch (IllegalArgumentException | IllegalStateException ignored0) { - try { - grid(1).cache(CACHE_NAME_NEAR).get(KEY_VAL); - - fail(); - } - catch (IllegalArgumentException | IllegalStateException ignored1) { - try { - grid(2).cache(CACHE_NAME_NEAR).get(KEY_VAL); - - fail(); - } - catch (IllegalArgumentException | IllegalStateException ignored2) { - // No-op - } - } - } + checkDestroyed(cache); } /** @@ -369,32 +326,9 @@ public class CacheStopAndDestroySelfTest extends GridCommonAbstractTest { assert grid(0).cache(CACHE_NAME_LOC).get(KEY_VAL).equals(KEY_VAL + 0); assert grid(1).cache(CACHE_NAME_LOC).get(KEY_VAL).equals(KEY_VAL + 1); - //Local destroy. Cache should be removed from each node. - grid(0).cache(CACHE_NAME_LOC).destroy(); - try { - grid(0).cache(CACHE_NAME_LOC).get(KEY_VAL); - - fail(); - } - catch (IllegalArgumentException | IllegalStateException ignored0) { - try { - grid(1).cache(CACHE_NAME_LOC).get(KEY_VAL); - - fail(); - } - catch (IllegalArgumentException | IllegalStateException ignored1) { - try { - grid(2).cache(CACHE_NAME_LOC).get(KEY_VAL); - - fail(); - } - catch (IllegalArgumentException | IllegalStateException ignored2) { - // No-op - } - } - } + assertNull(grid(0).cache(CACHE_NAME_LOC)); } /** @@ -726,30 +660,13 @@ public class CacheStopAndDestroySelfTest extends GridCommonAbstractTest { // Local close. Same as Local destroy. - grid(1).cache(CACHE_NAME_LOC).close(); - - try { - grid(0).cache(CACHE_NAME_LOC).get(KEY_VAL); + IgniteCache<Object, Object> cache = grid(1).cache(CACHE_NAME_LOC); - fail(); - } - catch (IllegalArgumentException | IllegalStateException ignored0) { - try { - grid(1).cache(CACHE_NAME_LOC).get(KEY_VAL); + cache.close(); - fail(); - } - catch (IllegalArgumentException | IllegalStateException ignored1) { - try { - grid(2).cache(CACHE_NAME_LOC).get(KEY_VAL); + checkUsageFails(cache); - fail(); - } - catch (IllegalArgumentException | IllegalStateException ignored2) { - // No-op - } - } - } + assertNull(grid(1).cache(CACHE_NAME_LOC)); // Local creation after closed. @@ -834,7 +751,7 @@ public class CacheStopAndDestroySelfTest extends GridCommonAbstractTest { } }); - IgniteCache cache = grid(0).getOrCreateCache(getDhtConfig()); + IgniteCache<Object, Object> cache = grid(0).getOrCreateCache(getDhtConfig()); cache.close(); @@ -860,12 +777,7 @@ public class CacheStopAndDestroySelfTest extends GridCommonAbstractTest { assert a3.get() > 1; assert a4.get() > 1; - try { - cache.get(KEY_VAL); - } - catch (IllegalStateException e) { - // No-op - } + checkUsageFails(cache); } /** @@ -898,7 +810,7 @@ public class CacheStopAndDestroySelfTest extends GridCommonAbstractTest { mgr.destroyCache(cacheName); - Cache cache = mgr.createCache(cacheName, + Cache<Integer, String> cache = mgr.createCache(cacheName, new MutableConfiguration<Integer, String>().setTypes(Integer.class, String.class)); cache.close(); @@ -906,7 +818,7 @@ public class CacheStopAndDestroySelfTest extends GridCommonAbstractTest { cache.close(); try { - cache.get("key"); + cache.get(1); fail(); } @@ -915,17 +827,33 @@ public class CacheStopAndDestroySelfTest extends GridCommonAbstractTest { } } - /** {@inheritDoc} */ - @Override protected void beforeTest() throws Exception { - super.beforeTest(); + /** + * @param cache Cache. + * @throws Exception If failed. + */ + private void checkDestroyed(IgniteCache<Object, Object> cache) throws Exception { + checkUsageFails(cache); - startGridsMultiThreaded(gridCount()); + awaitPartitionMapExchange(); + + String cacheName = cache.getName(); + + for (int i = 0; i < 3; i++) + assertNull("Unexpected cache for node: " + i, grid(i).cache(cacheName)); } - /** {@inheritDoc} */ - @Override protected void afterTest() throws Exception { - super.afterTest(); + /** + * @param cache Cache. + * @throws Exception If failed. + */ + private void checkUsageFails(IgniteCache<Object, Object> cache) throws Exception { + try { + cache.get(0); - stopAllGrids(); + fail(); + } + catch (IllegalStateException e) { + // No-op. + } } }