ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject incubator-ignite git commit: # ignite-648: improve framework
Date Fri, 03 Jul 2015 10:23:06 GMT
Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-648 69e44129f -> 1d4949d39


# ignite-648: improve framework


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

Branch: refs/heads/ignite-648
Commit: 1d4949d39c3b4be4a6b5194c883d5b7304041dcb
Parents: 69e4412
Author: ashutak <ashutak@gridgain.com>
Authored: Fri Jul 3 13:23:02 2015 +0300
Committer: ashutak <ashutak@gridgain.com>
Committed: Fri Jul 3 13:23:02 2015 +0300

----------------------------------------------------------------------
 .../cache/GridCacheAbstractFullApiSelfTest.java |  87 +++++----
 ...idCacheNearOnlyMultiNodeFullApiSelfTest.java |   8 -
 ...ReplicatedAtomicMultiJvmFullApiSelfTest.java |   2 +-
 .../testframework/junits/GridAbstractTest.java  | 189 +++++++++++++++++++
 4 files changed, 232 insertions(+), 54 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1d4949d3/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 4e31771..43202b4 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
@@ -385,7 +385,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
      */
     public void testRemoveAllSkipStore() throws Exception {
         if (isMultiJvm())
-            return;
+            fail("https://issues.apache.org/jira/browse/IGNITE-648");
 
         IgniteCache<String, Integer> jcache = jcache();
 
@@ -3188,6 +3188,9 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
      * @throws Exception If failed.
      */
     protected void checkTtl(boolean inTx, boolean oldEntry) throws Exception {
+        if (isMultiJvm())
+            fail("https://issues.apache.org/jira/browse/IGNITE-648");
+
         if (memoryMode() == OFFHEAP_TIERED)
             return;
 
@@ -3256,20 +3259,18 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
 
         for (int i = 0; i < gridCount(); i++) {
             if (grid(i).affinity(null).isPrimaryOrBackup(grid(i).localNode(), key)) {
-                if (!isMultiJvmAndNodeIsRemote(i)) {
-                    GridCacheAdapter<String, Integer> cache = internalCache(jcache(i));
+                GridCacheAdapter<String, Integer> cache = internalCache(jcache(i));
 
-                    if (cache.context().isNear())
-                        cache = cache.context().near().dht();
+                if (cache.context().isNear())
+                    cache = cache.context().near().dht();
 
-                    GridCacheEntryEx curEntry = cache.peekEx(key);
+                GridCacheEntryEx curEntry = cache.peekEx(key);
 
-                    assertEquals(ttl, curEntry.ttl());
+                assertEquals(ttl, curEntry.ttl());
 
-                    assert curEntry.expireTime() > startTime;
+                assert curEntry.expireTime() > startTime;
 
-                    expireTimes[i] = curEntry.expireTime();
-                }
+                expireTimes[i] = curEntry.expireTime();
             }
         }
 
@@ -3291,20 +3292,18 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
 
         for (int i = 0; i < gridCount(); i++) {
             if (grid(i).affinity(null).isPrimaryOrBackup(grid(i).localNode(), key)) {
-                if (!isMultiJvmAndNodeIsRemote(i)) {
-                    GridCacheAdapter<String, Integer> cache = internalCache(jcache(i));
+                GridCacheAdapter<String, Integer> cache = internalCache(jcache(i));
 
-                    if (cache.context().isNear())
-                        cache = cache.context().near().dht();
+                if (cache.context().isNear())
+                    cache = cache.context().near().dht();
 
-                    GridCacheEntryEx curEntry = cache.peekEx(key);
+                GridCacheEntryEx curEntry = cache.peekEx(key);
 
-                    assertEquals(ttl, curEntry.ttl());
+                assertEquals(ttl, curEntry.ttl());
 
-                    assert curEntry.expireTime() > startTime;
+                assert curEntry.expireTime() > startTime;
 
-                    expireTimes[i] = curEntry.expireTime();
-                }
+                expireTimes[i] = curEntry.expireTime();
             }
         }
 
@@ -3326,20 +3325,18 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
 
         for (int i = 0; i < gridCount(); i++) {
             if (grid(i).affinity(null).isPrimaryOrBackup(grid(i).localNode(), key)) {
-                if (!isMultiJvmAndNodeIsRemote(i)) {
-                    GridCacheAdapter<String, Integer> cache = internalCache(jcache(i));
+                GridCacheAdapter<String, Integer> cache = internalCache(jcache(i));
 
-                    if (cache.context().isNear())
-                        cache = cache.context().near().dht();
+                if (cache.context().isNear())
+                    cache = cache.context().near().dht();
 
-                    GridCacheEntryEx curEntry = cache.peekEx(key);
+                GridCacheEntryEx curEntry = cache.peekEx(key);
 
-                    assertEquals(ttl, curEntry.ttl());
+                assertEquals(ttl, curEntry.ttl());
 
-                    assert curEntry.expireTime() > startTime;
+                assert curEntry.expireTime() > startTime;
 
-                    expireTimes[i] = curEntry.expireTime();
-                }
+                expireTimes[i] = curEntry.expireTime();
             }
         }
 
@@ -3365,17 +3362,15 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
 
         for (int i = 0; i < gridCount(); i++) {
             if (grid(i).affinity(null).isPrimaryOrBackup(grid(i).localNode(), key)) {
-                if (!isMultiJvmAndNodeIsRemote(i)) {
-                    GridCacheAdapter<String, Integer> cache = internalCache(jcache(i));
+                GridCacheAdapter<String, Integer> cache = internalCache(jcache(i));
 
-                    if (cache.context().isNear())
-                        cache = cache.context().near().dht();
+                if (cache.context().isNear())
+                    cache = cache.context().near().dht();
 
-                    GridCacheEntryEx curEntry = cache.peekEx(key);
+                GridCacheEntryEx curEntry = cache.peekEx(key);
 
-                    assertEquals(ttl, curEntry.ttl());
-                    assertEquals(expireTimes[i], curEntry.expireTime());
-                }
+                assertEquals(ttl, curEntry.ttl());
+                assertEquals(expireTimes[i], curEntry.expireTime());
             }
         }
 
@@ -4152,8 +4147,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
 
         checkIteratorRemove(cache, entries);
 
-        if(!isMultiJvm())
-            checkIteratorEmpty(cache);
+        checkIteratorEmpty(cache);
     }
 
     /**
@@ -4261,13 +4255,16 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
      */
     private void checkIteratorsCleared() {
         for (int j = 0; j < gridCount(); j++) {
+            runOnLocalOrRemoteJvm(j, new IndexSerializableJob() {
+                @Override public void run(int i) throws Exception {
+                    GridCacheQueryManager queries = context(i).queries();
 
-            GridCacheQueryManager queries = context(j).queries();
+                    Map map = GridTestUtils.getFieldValue(queries, GridCacheQueryManager.class,
"qryIters");
 
-            Map map = GridTestUtils.getFieldValue(queries, GridCacheQueryManager.class, "qryIters");
-
-            for (Object obj : map.values())
-                assertEquals("Iterators not removed for grid " + j, 0, ((Map) obj).size());
+                    for (Object obj : map.values())
+                        assertEquals("Iterators not removed for grid " + i, 0, ((Map)obj).size());
+                }
+            });
         }
     }
 
@@ -4515,7 +4512,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
      */
     public void testWithSkipStore() throws Exception {
         if(isMultiJvm())
-            return;
+            fail("https://issues.apache.org/jira/browse/IGNITE-648");
 
         IgniteCache<String, Integer> cache = grid(0).cache(null);
 
@@ -4727,7 +4724,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
      */
     public void testWithSkipStoreRemoveAll() throws Exception {
         if (isMultiJvm())
-            return;
+            fail("https://issues.apache.org/jira/browse/IGNITE-648");
 
         if (atomicityMode() == TRANSACTIONAL || (atomicityMode() == ATOMIC && nearEnabled()))
// TODO IGNITE-373.
             return;

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1d4949d3/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 3d9364b..23d78f4 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
@@ -137,14 +137,6 @@ public class GridCacheNearOnlyMultiNodeFullApiSelfTest extends GridCachePartitio
         return nearIdx == 0 ? jcache(1) : jcache(0);
     }
 
-    /** {@inheritDoc} */
-    @Override protected void checkTtl(boolean inTx, boolean oldEntry) throws Exception {
-        if (isMultiJvm())
-            fail("https://issues.apache.org/jira/browse/IGNITE-648");
-
-        super.checkTtl(inTx, oldEntry);
-    }
-
     /**
      * @return For the purpose of this test returns the near-only instance.
      */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1d4949d3/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/multijvm/GridCacheReplicatedAtomicMultiJvmFullApiSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/multijvm/GridCacheReplicatedAtomicMultiJvmFullApiSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/multijvm/GridCacheReplicatedAtomicMultiJvmFullApiSelfTest.java
index 1a92030..a4a50a4 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/multijvm/GridCacheReplicatedAtomicMultiJvmFullApiSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/multijvm/GridCacheReplicatedAtomicMultiJvmFullApiSelfTest.java
@@ -22,7 +22,7 @@ import org.apache.ignite.internal.processors.cache.distributed.replicated.*;
 /**
  * Multy Jvm tests.
  */
-public class GridCacheReplicatedAtomicMultiJvmFullApiSelfTest extends 
+public class GridCacheReplicatedAtomicMultiJvmFullApiSelfTest extends
     GridCacheReplicatedAtomicMultiNodeFullApiSelfTest {
     /** {@inheritDoc} */
     protected boolean isMultiJvm() {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1d4949d3/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 732af54..94fa248 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
@@ -1366,6 +1366,14 @@ public abstract class GridAbstractTest extends TestCase {
      * Gets flag whether nodes will run in one jvm or in separate jvms.
      *
      * @return <code>True</code> to run nodes in separate jvms.
+     * @see IgniteNodeRunner
+     * @see IgniteProcessProxy
+     * @see #runRemotely(int, IndexSerializableJob)
+     * @see #runRemotely(IgniteProcessProxy, IgniteSerializableJob)
+     * @see #runRemotely(IgniteCacheProcessProxy, CacheSerializiableJob)
+     * @see #runOnLocalOrRemoteJvm(int, IndexSerializableJob)
+     * @see #runOnLocalOrRemoteJvm(Ignite, IgniteSerializableJob)
+     * @see #runOnLocalOrRemoteJvm(IgniteCache, CacheSerializiableJob)
      */
     protected boolean isMultiJvm() {
         return false;
@@ -1395,6 +1403,156 @@ public abstract class GridAbstractTest extends TestCase {
     }
 
     /**
+     * @param cache Cache.
+     * @return <code>True</code> if cache is an instance of {@link IgniteCacheProcessProxy}
+     */
+    public static boolean isMultiJvmObject(IgniteCache cache) {
+        return cache instanceof IgniteCacheProcessProxy;
+    }
+
+    /**
+     * @param ignite Ignite.
+     * @return <code>True</code> if cache is an instance of {@link IgniteProcessProxy}
+     */
+    public static boolean isMultiJvmObject(Ignite ignite) {
+        return ignite instanceof IgniteProcessProxy;
+    }
+
+    /**
+     * Runs job on local jvm or on remote jvm in multi jvm case.
+     *
+     * @param idx Grid index.
+     * @param job Job.
+     */
+    public void runOnLocalOrRemoteJvm(final int idx, final IndexSerializableJob job) {
+        IgniteEx ignite = grid(idx);
+
+        if (!isMultiJvmObject(ignite))
+            try {
+                job.run(idx);
+            }
+            catch (Exception e) {
+                throw new IgniteException(e);
+            }
+        else
+            runRemotely(idx, job);
+    }
+
+    /**
+     * Runs job on local jvm or on remote jvm in multi jvm case.
+     *
+     * @param ignite Ignite.
+     * @param job Job.
+     */
+    public void runOnLocalOrRemoteJvm(Ignite ignite, final IgniteSerializableJob job) {
+        if (!isMultiJvmObject(ignite))
+            try {
+                job.run(ignite);
+            }
+            catch (Exception e) {
+                throw new IgniteException(e);
+            }
+        else
+            runRemotely((IgniteProcessProxy)ignite, job);
+    }
+
+    /**
+     * Runs job on local jvm or on remote jvm in multi jvm case.
+     *
+     * @param cache Cache.
+     * @param job Job.
+     */
+    public <K,V> void runOnLocalOrRemoteJvm(IgniteCache<K,V> cache, CacheSerializiableJob<K,V>
job) {
+        Ignite ignite = cache.unwrap(Ignite.class);
+
+        if (!isMultiJvmObject(ignite))
+            try {
+                job.run(ignite, cache);
+            }
+            catch (Exception e) {
+                throw new IgniteException(e);
+            }
+        else
+            runRemotely((IgniteCacheProcessProxy<K, V>)cache, job);
+    }
+
+    /**
+     * Runs job on remote jvm.
+     *
+     * @param idx Grid index.
+     * @param job Job.
+     */
+    public void runRemotely(final int idx, final IndexSerializableJob job) {
+        IgniteEx ignite = grid(idx);
+
+        if (!isMultiJvmObject(ignite))
+            throw new IllegalArgumentException("Ignite have to be process proxy.");
+
+        IgniteProcessProxy proxy = (IgniteProcessProxy)ignite;
+
+        proxy.remoteCompute().run(new CAX() {
+            @Override public void applyx() throws IgniteCheckedException {
+                try {
+                    job.run(idx);
+                }
+                catch (Exception e) {
+                    throw new IgniteCheckedException(e);
+                }
+            }
+        });
+    }
+
+    /**
+     * Runs job on remote jvm.
+     *
+     * @param proxy Ignite.
+     * @param job Job.
+     */
+    public static void runRemotely(IgniteProcessProxy proxy, final IgniteSerializableJob
job) {
+        final UUID id = proxy.getId();
+
+        proxy.remoteCompute().run(new CAX() {
+            @Override public void applyx() throws IgniteCheckedException {
+                Ignite ignite = Ignition.ignite(id);
+
+                try {
+                    job.run(ignite);
+                }
+                catch (Exception e) {
+                    throw new IgniteCheckedException(e);
+                }
+            }
+        });
+    }
+
+    /**
+     * Runs job on remote jvm.
+     *
+     * @param cache Cache.
+     * @param job Job.
+     */
+    public static <K, V> void runRemotely(IgniteCacheProcessProxy<K, V> cache,
final CacheSerializiableJob<K,V> job) {
+        IgniteProcessProxy proxy = (IgniteProcessProxy)cache.unwrap(Ignite.class);
+
+        final UUID id = proxy.getId();
+        final String cacheName = cache.getName();
+
+        proxy.remoteCompute().run(new CAX() {
+            @Override public void applyx() throws IgniteCheckedException {
+                Ignite ignite = Ignition.ignite(id);
+                IgniteCache<K,V> cache = ignite.cache(cacheName);
+
+                try {
+                    job.run(ignite, cache);
+                }
+                catch (Exception e) {
+                    throw new IgniteCheckedException(e);
+                }
+            }
+        });
+    }
+
+    /**
      * @return Test counters.
      */
     protected synchronized TestCounters getTestCounters() throws IgniteCheckedException {
@@ -1707,4 +1865,35 @@ public abstract class GridAbstractTest extends TestCase {
             return numOfTests;
         }
     }
+
+    /**
+     * Serializable runnable.
+     */
+    public static interface IgniteSerializableJob extends Serializable {
+        /**
+         * @param ignite Ignite.
+         */
+        void run(Ignite ignite) throws Exception;
+    }
+
+    /**
+     * Serializiable runnable.
+     */
+    public static interface IndexSerializableJob extends Serializable {
+        /**
+         * @param idx Grid index.
+         */
+        void run(int idx) throws Exception;
+    }
+
+    /**
+     * Serializiable runnable.
+     */
+    public static interface CacheSerializiableJob<K, V> extends Serializable {
+        /**
+         * @param ignite Ignite.
+         * @param cache Cache.
+         */
+        void run(Ignite ignite, IgniteCache<K, V> cache) throws Exception;
+    }
 }


Mime
View raw message