You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2015/07/03 16:27:58 UTC

incubator-ignite git commit: # ignite-648: improve framework (refactoring)

Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-648 8d267a2d5 -> 9edd54ecb


# ignite-648: improve framework (refactoring)


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/9edd54ec
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/9edd54ec
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/9edd54ec

Branch: refs/heads/ignite-648
Commit: 9edd54ecb21051169912fa4ffa5518753337d09c
Parents: 8d267a2
Author: ashutak <as...@gridgain.com>
Authored: Fri Jul 3 17:27:56 2015 +0300
Committer: ashutak <as...@gridgain.com>
Committed: Fri Jul 3 17:27:56 2015 +0300

----------------------------------------------------------------------
 .../testframework/junits/GridAbstractTest.java  | 12 +--
 .../junits/common/GridCommonAbstractTest.java   | 85 ++++++--------------
 2 files changed, 29 insertions(+), 68 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9edd54ec/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java
index db1b7dd..0f34149 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java
@@ -1416,7 +1416,7 @@ public abstract class GridAbstractTest extends TestCase {
     }
 
     /**
-     * Runs job on local jvm or on remote jvm in multi jvm case.
+     * Calls job on local jvm or on remote jvm in multi jvm case.
      *
      * @param idx Grid index.
      * @param job Job.
@@ -1436,12 +1436,12 @@ public abstract class GridAbstractTest extends TestCase {
     }
 
     /**
-     * Runs job on local jvm or on remote jvm in multi jvm case.
+     * Calls job on local jvm or on remote jvm in multi jvm case.
      *
      * @param ignite Ignite.
      * @param job Job.
      */
-    public <R> R executeOnLocalOrRemoteJvm(Ignite ignite, final TestIgniteCallable<R> job) {
+    public static <R> R executeOnLocalOrRemoteJvm(Ignite ignite, final TestIgniteCallable<R> job) {
         if (!isMultiJvmObject(ignite))
             try {
                 return job.call(ignite);
@@ -1459,7 +1459,7 @@ public abstract class GridAbstractTest extends TestCase {
      * @param cache Cache.
      * @param job Job.
      */
-    public <K,V,R> R executeOnLocalOrRemoteJvm(IgniteCache<K,V> cache, TestCacheCallable<K,V,R> job) {
+    public static <K,V,R> R executeOnLocalOrRemoteJvm(IgniteCache<K,V> cache, TestCacheCallable<K,V,R> job) {
         Ignite ignite = cache.unwrap(Ignite.class);
 
         if (!isMultiJvmObject(ignite))
@@ -1474,7 +1474,7 @@ public abstract class GridAbstractTest extends TestCase {
     }
 
     /**
-     * Runs job on remote jvm.
+     * Calls job on remote jvm.
      *
      * @param idx Grid index.
      * @param job Job.
@@ -1495,7 +1495,7 @@ public abstract class GridAbstractTest extends TestCase {
     }
 
     /**
-     * Runs job on remote jvm.
+     * Calls job on remote jvm.
      *
      * @param proxy Ignite.
      * @param job Job.

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9edd54ec/modules/core/src/test/java/org/apache/ignite/testframework/junits/common/GridCommonAbstractTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/common/GridCommonAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/common/GridCommonAbstractTest.java
index 4764de0..8698b4a 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/common/GridCommonAbstractTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/common/GridCommonAbstractTest.java
@@ -36,7 +36,6 @@ import org.apache.ignite.internal.util.typedef.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
 import org.apache.ignite.lang.*;
 import org.apache.ignite.testframework.junits.*;
-import org.apache.ignite.testframework.junits.multijvm.*;
 import org.jetbrains.annotations.*;
 
 import javax.cache.*;
@@ -117,7 +116,7 @@ public abstract class GridCommonAbstractTest extends GridAbstractTest {
      * @return Cache.
      */
     protected <K, V> GridCacheAdapter<K, V> internalCache(IgniteCache<K, V> cache) {
-        if (cache instanceof IgniteCacheProcessProxy)
+        if (isMultiJvmObject(cache))
             throw new UnsupportedOperationException("Oparetion can't be supported automatically for multi jvm " +
                 "(send closure instead).");
 
@@ -207,23 +206,12 @@ public abstract class GridCommonAbstractTest extends GridAbstractTest {
      * @return {@code True} if near cache is enabled.
      */
     protected static <K, V> boolean nearEnabled(final IgniteCache<K,V> cache) {
-        final Ignite ignite = cache.unwrap(Ignite.class);
-
-        CacheConfiguration cfg;
-
-        if (!(ignite instanceof IgniteProcessProxy))
-            cfg = ((IgniteKernal)ignite).<K, V>internalCache(cache.getName()).context().config();
-        else {
-            final String cacheName = cache.getName();
-
-            cfg = ((IgniteProcessProxy)ignite).remoteCompute().call(new IgniteCallable<CacheConfiguration>() {
-                @Override public CacheConfiguration call() throws Exception {
-                    IgniteEx grid = IgniteNodeRunner.startedInstance();
-
-                    return ((IgniteKernal)grid).<K, V>internalCache(cacheName).context().config();
-                }
-            });
-        }
+        CacheConfiguration cfg = GridAbstractTest.executeOnLocalOrRemoteJvm(cache,
+            new TestCacheCallable<K, V, CacheConfiguration>() {
+            @Override public CacheConfiguration call(Ignite ignite, IgniteCache<K, V> cache) throws Exception {
+                return ((IgniteKernal)ignite).<K, V>internalCache(cache.getName()).context().config();
+            }
+        });
 
         return isNearEnabled(cfg);
     }
@@ -259,59 +247,32 @@ public abstract class GridCommonAbstractTest extends GridAbstractTest {
      * @throws Exception If failed.
      */
     protected static <K> void loadAll(Cache<K, ?> cache, final Set<K> keys, final boolean replaceExistingValues) throws Exception {
-        Ignite ignite = cache.unwrap(Ignite.class);
-
-        if (!(ignite instanceof IgniteProcessProxy))
-            loadAll0(cache, keys, replaceExistingValues);
-        else {
-            IgniteProcessProxy proxy = (IgniteProcessProxy)ignite;
-
-            final UUID id = proxy.getId();
+        IgniteCache<K, Object> cacheCp = (IgniteCache<K, Object>)cache;
 
-            final String cacheName = cache.getName();
+        GridAbstractTest.executeOnLocalOrRemoteJvm(cacheCp, new TestCacheRunnable<K, Object>() {
+            @Override public void run(Ignite ignite, IgniteCache<K, Object> cache) throws Exception {
+                final AtomicReference<Exception> ex = new AtomicReference<>();
 
-            final Set<Object> keysCp = (Set<Object>)keys;
+                final CountDownLatch latch = new CountDownLatch(1);
 
-            proxy.remoteCompute().run(new CAX() {
-                @Override public void applyx() throws IgniteCheckedException {
-                    try {
-                        loadAll0(Ignition.ignite(id).cache(cacheName), keysCp, replaceExistingValues);
+                cache.loadAll(keys, replaceExistingValues, new CompletionListener() {
+                    @Override public void onCompletion() {
+                        latch.countDown();
                     }
-                    catch (Exception e) {
-                        throw new IgniteCheckedException(e);
-                    }
-                }
-            });
-        }
-    }
-
-    /**
-     * @param cache Cache.
-     * @param keys Keys.
-     * @param replaceExistingValues Replace existing values.
-     * @throws Exception If failed.
-     */
-    private static <K> void loadAll0(Cache<K, ?> cache, Set<K> keys, boolean replaceExistingValues) throws Exception {
-        final AtomicReference<Exception> ex = new AtomicReference<>();
 
-        final CountDownLatch latch = new CountDownLatch(1);
+                    @Override public void onException(Exception e) {
+                        ex.set(e);
 
-        cache.loadAll(keys, replaceExistingValues, new CompletionListener() {
-            @Override public void onCompletion() {
-                latch.countDown();
-            }
+                        latch.countDown();
+                    }
+                });
 
-            @Override public void onException(Exception e) {
-                ex.set(e);
+                latch.await();
 
-                latch.countDown();
+                if (ex.get() != null)
+                    throw ex.get();
             }
         });
-
-        latch.await();
-
-        if (ex.get() != null)
-            throw ex.get();
     }
 
     /**