Improved CacheStore + external class loader tests
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/bf3a5ea6 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/bf3a5ea6 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/bf3a5ea6 Branch: refs/heads/ignite-2542 Commit: bf3a5ea652a9c36e5ce8dd87dba72b5fafc3ce86 Parents: bad0420 Author: Denis Magda <[email protected]> Authored: Mon Feb 8 13:41:38 2016 +0300 Committer: Denis Magda <[email protected]> Committed: Mon Feb 8 13:41:38 2016 +0300 ---------------------------------------------------------------------- .../GridCacheReplicatedPreloadSelfTest.java | 120 +++++++++++++------ 1 file changed, 82 insertions(+), 38 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/bf3a5ea6/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/preloader/GridCacheReplicatedPreloadSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/preloader/GridCacheReplicatedPreloadSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/preloader/GridCacheReplicatedPreloadSelfTest.java index 523f641..887fea4 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/preloader/GridCacheReplicatedPreloadSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/preloader/GridCacheReplicatedPreloadSelfTest.java @@ -77,6 +77,9 @@ public class GridCacheReplicatedPreloadSelfTest extends GridCommonAbstractTest { private volatile boolean isClient = false; /** */ + private volatile boolean useExtClassLoader = false; + + /** */ private TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true); /** {@inheritDoc} */ @@ -108,7 +111,8 @@ public class GridCacheReplicatedPreloadSelfTest extends GridCommonAbstractTest { cfg.setEventStorageSpi(spi); - if (getTestGridName(1).equals(gridName) || cfg.getMarshaller() instanceof BinaryMarshaller) + if (getTestGridName(1).equals(gridName) || useExtClassLoader || + cfg.getMarshaller() instanceof BinaryMarshaller) cfg.setClassLoader(getExternalClassLoader()); if (isClient) @@ -187,7 +191,7 @@ public class GridCacheReplicatedPreloadSelfTest extends GridCommonAbstractTest { for (int i = 0; i < 3; i++) { evts = g2.events().localQuery(F.<Event>alwaysTrue(), - EVT_CACHE_REBALANCE_STARTED, EVT_CACHE_REBALANCE_STOPPED); + EVT_CACHE_REBALANCE_STARTED, EVT_CACHE_REBALANCE_STOPPED); if (evts.size() != 2) { info("Wrong events collection size (will retry in 1000 ms): " + evts.size()); @@ -284,7 +288,7 @@ public class GridCacheReplicatedPreloadSelfTest extends GridCommonAbstractTest { assert v3 != null; assert v3.toString().equals(v1.toString()); assert !v3.getClass().getClassLoader().equals(getClass().getClassLoader()); - assert v3.getClass().getClassLoader().getClass().getName().contains("GridDeploymentClassLoader")|| + assert v3.getClass().getClassLoader().getClass().getName().contains("GridDeploymentClassLoader") || grid(3).configuration().getMarshaller() instanceof BinaryMarshaller; } finally { @@ -297,70 +301,110 @@ public class GridCacheReplicatedPreloadSelfTest extends GridCommonAbstractTest { */ public void testStore() throws Exception { try { + needStore = true; + useExtClassLoader = true; + Ignite g1 = startGrid(1); - if (g1.configuration().getMarshaller() instanceof BinaryMarshaller) { - stopAllGrids(); + Ignite g2 = startGrid(2); // Checks deserialization at node join. - needStore = true; + isClient = true; - g1 = startGrid(1); + Ignite g3 = startGrid(3); + + IgniteCache<Integer, Object> cache1 = g1.cache(null); + IgniteCache<Integer, Object> cache2 = g2.cache(null); + IgniteCache<Integer, Object> cache3 = g3.cache(null); + + cache1.put(1, 1); + + assertEquals(1, cache2.get(1)); + assertEquals(1, cache3.get(1)); + } + finally { + needStore = false; + isClient = false; + useExtClassLoader = false; + } + } + + /** + * @throws Exception If test failed. + */ + public void testStoreDynamicStart() throws Exception { + try { + needStore = false; + useExtClassLoader = true; - ClassLoader ldr = grid(1).configuration().getClassLoader(); + Ignite g1 = startGrid(1); + Ignite g2 = startGrid(2); - CacheConfiguration cfg = defaultCacheConfiguration(); + isClient = true; - Ignite g2 = startGrid(2); // Checks deserialization at node join. + Ignite g3 = startGrid(3); - isClient = true; + Object sf = getExternalClassLoader().loadClass( + "org.apache.ignite.tests.p2p.CacheDeploymentTestStoreFactory").newInstance(); - Ignite g3 = startGrid(3); + CacheConfiguration cfg = defaultCacheConfiguration(); - isClient = false; + cfg.setCacheStoreFactory((Factory)sf); + cfg.setName("customStore"); - IgniteCache<Integer, Object> cache1 = g1.cache(null); - IgniteCache<Integer, Object> cache2 = g2.cache(null); - IgniteCache<Integer, Object> cache3 = g3.cache(null); + IgniteCache<Integer, Object> cache1 = g1.createCache(cfg); - cache1.put(1, 1); + IgniteCache<Integer, Object> cache2 = g2.getOrCreateCache(cfg); // Checks deserialization at cache creation. + IgniteCache<Integer, Object> cache3 = g3.getOrCreateCache(cfg); // Checks deserialization at cache creation. - assertEquals(1, cache2.get(1)); - assertEquals(1, cache3.get(1)); + cache1.put(1, 1); - needStore = false; + assertEquals(1, cache2.get(1)); + assertEquals(1, cache3.get(1)); + } + finally { + needStore = false; + isClient = false; + useExtClassLoader = false; + } + } - stopAllGrids(); + /** + * @throws Exception If test failed. + */ + public void testStoreDynamicStart2() throws Exception { + try { + needStore = false; + useExtClassLoader = true; - g1 = startGrid(1); - g2 = startGrid(2); + Ignite g1 = startGrid(1); + Ignite g2 = startGrid(2); - isClient = true; + isClient = true; - g3 = startGrid(3); + Ignite g3 = startGrid(3); - isClient = false; + Object sf = getExternalClassLoader().loadClass( + "org.apache.ignite.tests.p2p.CacheDeploymentTestStoreFactory").newInstance(); - Object sf = ldr.loadClass("org.apache.ignite.tests.p2p.CacheDeploymentTestStoreFactory").newInstance(); + CacheConfiguration cfg = defaultCacheConfiguration(); - cfg.setCacheStoreFactory((Factory)sf); - cfg.setName("customStore"); + cfg.setCacheStoreFactory((Factory)sf); + cfg.setName("customStore"); - cache1 = g1.createCache(cfg); + IgniteCache<Integer, Object> cache1 = g1.getOrCreateCache(cfg); - cache2 = g2.getOrCreateCache(cfg); // Checks deserialization at cache creation. - cache3 = g3.getOrCreateCache(cfg); // Checks deserialization at cache creation. + IgniteCache<Integer, Object> cache2 = g2.getOrCreateCache("customStore"); // Checks deserialization at cache creation. + IgniteCache<Integer, Object> cache3 = g3.getOrCreateCache("customStore"); // Checks deserialization at cache creation. - cache1.put(1, 1); + cache1.put(1, 1); - assertEquals(1, cache2.get(1)); - assertEquals(1, cache3.get(1)); - } + assertEquals(1, cache2.get(1)); + assertEquals(1, cache3.get(1)); } finally { needStore = false; isClient = false; - - stopAllGrids(); + useExtClassLoader = false; } }
