ignite-648: refactor
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/d5fe1f75 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/d5fe1f75 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/d5fe1f75 Branch: refs/heads/ignite-648 Commit: d5fe1f75d0282835061d410fd3348e896587ce16 Parents: 36d9487 Author: Artem Shutak <ashu...@gridgain.com> Authored: Mon Apr 27 18:44:31 2015 +0300 Committer: Artem Shutak <ashu...@gridgain.com> Committed: Mon Apr 27 18:44:31 2015 +0300 ---------------------------------------------------------------------- .../cache/GridCacheAbstractFullApiSelfTest.java | 41 ++++++++++++--- ...CachePartitionedMultiJvmFullApiSelfTest.java | 53 ++------------------ .../cache/multijvm/IgniteCacheProcessProxy.java | 5 +- .../cache/multijvm/IgniteExProcessProxy.java | 25 +++++++++ 4 files changed, 66 insertions(+), 58 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d5fe1f75/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java index 7587951..4b042d1 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java @@ -197,22 +197,51 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract // info("Grid " + i + ": " + grid(i).localNode().id()); } + /** + * Gets flag whether nodes will run in one jvm or in separate jvms. + * + * @return <code>True</code> to run nodes in separate jvms. + */ protected boolean isMultiJvm() { return false; } /** {@inheritDoc} */ @Override protected Ignite startGrid(String gridName, GridSpringResourceContext ctx) throws Exception { - if (cacheCfgMap == null) - return super.startGrid(gridName, ctx); + if (!isMultiJvm() || gridName.endsWith("0")) { + if (cacheCfgMap == null) + return super.startGrid(gridName, ctx); + + IgniteConfiguration cfg = getConfiguration(gridName); + + cacheCfgMap.put(gridName, cfg.getCacheConfiguration()); - IgniteConfiguration cfg = getConfiguration(gridName); + cfg.setCacheConfiguration(); - cacheCfgMap.put(gridName, cfg.getCacheConfiguration()); + return IgnitionEx.start(optimize(cfg), ctx); + } + + startingGrid.set(gridName); + + try { + IgniteConfiguration cfg = optimize(getConfiguration(gridName)); + + return new IgniteExProcessProxy(cfg, log, grid(0)); + } + finally { + startingGrid.set(null); + } + + } + + /** {@inheritDoc} */ + @Override protected IgniteEx grid(int idx) { + if (!isMultiJvm() || idx == 0) + return super.grid(idx); - cfg.setCacheConfiguration(); + String name = getTestGridName(idx); - return IgnitionEx.start(optimize(cfg), ctx); + return IgniteExProcessProxy.get(name); } /** {@inheritDoc} */ http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d5fe1f75/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/multijvm/GridCachePartitionedMultiJvmFullApiSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/multijvm/GridCachePartitionedMultiJvmFullApiSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/multijvm/GridCachePartitionedMultiJvmFullApiSelfTest.java index 7cb4c08..2a3d07d 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/multijvm/GridCachePartitionedMultiJvmFullApiSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/multijvm/GridCachePartitionedMultiJvmFullApiSelfTest.java @@ -20,9 +20,7 @@ package org.apache.ignite.internal.processors.cache.multijvm; import org.apache.ignite.*; import org.apache.ignite.configuration.*; import org.apache.ignite.events.*; -import org.apache.ignite.internal.*; import org.apache.ignite.internal.processors.cache.distributed.near.*; -import org.apache.ignite.internal.processors.resource.*; import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; import org.apache.ignite.spi.discovery.tcp.*; @@ -49,9 +47,6 @@ public class GridCachePartitionedMultiJvmFullApiSelfTest extends GridCachePartit } }; - /** Proces name to process map. */ - private final Map<String, IgniteExProcessProxy> ignites = new HashMap<>(); - /** {@inheritDoc} */ @Override protected void beforeTestsStarted() throws Exception { allNodesJoinLatch = new CountDownLatch(gridCount() - 1); @@ -63,10 +58,7 @@ public class GridCachePartitionedMultiJvmFullApiSelfTest extends GridCachePartit /** {@inheritDoc} */ @Override protected void afterTestsStopped() throws Exception { - for (IgniteExProcessProxy ignite : ignites.values()) - ignite.getProcess().kill(); - - ignites.clear(); + IgniteExProcessProxy.killAll(); locIgnite = null; @@ -75,16 +67,14 @@ public class GridCachePartitionedMultiJvmFullApiSelfTest extends GridCachePartit /** {@inheritDoc} */ @Override protected void beforeTest() throws Exception { - super.beforeTest(); // TODO: CODE: implement. + super.beforeTest(); } /** {@inheritDoc} */ @Override protected void afterTest() throws Exception { - // TODO: remove processes killing from here. - for (IgniteExProcessProxy ignite : ignites.values()) - ignite.getProcess().kill(); + IgniteExProcessProxy.killAll(); // TODO: remove processes killing from here. - super.afterTest(); // TODO: CODE: implement. + super.afterTest(); } /** {@inheritDoc} */ @@ -117,44 +107,11 @@ public class GridCachePartitionedMultiJvmFullApiSelfTest extends GridCachePartit return true; } - /** {@inheritDoc} */ - protected Ignite startGrid(String gridName, GridSpringResourceContext ctx) throws Exception { - if (!isMultiJvm() || gridName.endsWith("0")) { - locIgnite = super.startGrid(gridName, ctx); - - return locIgnite; - } - - startingGrid.set(gridName); - - try { - IgniteConfiguration cfg = optimize(getConfiguration(gridName)); - - IgniteExProcessProxy proxy = new IgniteExProcessProxy(cfg, log, grid(0)); - - ignites.put(gridName, proxy); - - return proxy; - } - finally { - startingGrid.set(null); - } - } - - /** {@inheritDoc} */ - @Override protected IgniteEx grid(int idx) { - if (!isMultiJvm() || idx == 0) - return super.grid(idx); - - String name = getTestGridName(idx); - - return ignites.get(name); - } - /** * @throws Exception If failed. */ public void testPutAllRemoveAll() throws Exception { + // TODO: uncomment. // for (int i = 0; i < gridCount(); i++) { // IgniteEx grid0 = grid0(i); // http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d5fe1f75/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/multijvm/IgniteCacheProcessProxy.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/multijvm/IgniteCacheProcessProxy.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/multijvm/IgniteCacheProcessProxy.java index ea03f5d..fd49042 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/multijvm/IgniteCacheProcessProxy.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/multijvm/IgniteCacheProcessProxy.java @@ -29,10 +29,7 @@ import java.util.*; import java.util.concurrent.locks.*; /** - * TODO: Add class description. - * - * @author @java.author - * @version @java.version + * Ignite cache proxy for ignite instance at another JVM. */ public class IgniteCacheProcessProxy<K, V> implements IgniteCache<K, V> { /** Compute. */ http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d5fe1f75/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/multijvm/IgniteExProcessProxy.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/multijvm/IgniteExProcessProxy.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/multijvm/IgniteExProcessProxy.java index f7c8a4c..286232b 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/multijvm/IgniteExProcessProxy.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/multijvm/IgniteExProcessProxy.java @@ -99,6 +99,31 @@ public class IgniteExProcessProxy implements IgniteEx { } /** + * @param gridName Grid name. + * @return Instance by name or <code>null</code>. + */ + public static IgniteExProcessProxy get(String gridName) { + return gridProxies.get(gridName); + } + + /** + * Kill all running processes. + * + * @throws Exception if failed. + */ + public static void killAll() throws Exception { + for (IgniteExProcessProxy ignite : gridProxies.values()) + try { + ignite.getProcess().kill(); + } + catch (Exception e) { + U.error(ignite.log, "Killing failed.", e); + } + + gridProxies.clear(); + } + + /** * @return Local JVM grid instance. */ public Ignite localJvmGrid() {