ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [25/31] incubator-ignite git commit: # ignite-648: fix testUnswapShort and good refactoring
Date Fri, 26 Jun 2015 13:53:28 GMT
# ignite-648: fix testUnswapShort and good 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/7cf3a66f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/7cf3a66f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/7cf3a66f

Branch: refs/heads/ignite-648
Commit: 7cf3a66f8daef34de6a4450f407686d6461241fe
Parents: ff4f257
Author: ashutak <ashutak@gridgain.com>
Authored: Fri Jun 26 11:30:16 2015 +0300
Committer: ashutak <ashutak@gridgain.com>
Committed: Fri Jun 26 11:30:16 2015 +0300

----------------------------------------------------------------------
 .../affinity/fair/FairAffinityFunction.java     |  4 +--
 .../cache/GridCacheAbstractFullApiSelfTest.java | 37 +++++++-------------
 .../cache/GridCacheAbstractSelfTest.java        | 16 ++++-----
 ...achePartitionedMultiNodeFullApiSelfTest.java | 12 ++++---
 .../testframework/junits/GridAbstractTest.java  | 31 +++++++++-------
 .../junits/multijvm/IgniteNodeRunner.java       | 20 ++++++++++-
 .../junits/multijvm/IgniteProcessProxy.java     |  2 +-
 7 files changed, 66 insertions(+), 56 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7cf3a66f/modules/core/src/main/java/org/apache/ignite/cache/affinity/fair/FairAffinityFunction.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/affinity/fair/FairAffinityFunction.java
b/modules/core/src/main/java/org/apache/ignite/cache/affinity/fair/FairAffinityFunction.java
index 0253e62..15c5a3d 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/affinity/fair/FairAffinityFunction.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/affinity/fair/FairAffinityFunction.java
@@ -19,7 +19,7 @@ package org.apache.ignite.cache.affinity.fair;
 
 import org.apache.ignite.cache.affinity.*;
 import org.apache.ignite.cluster.*;
-import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.*;
 import org.apache.ignite.events.*;
 import org.apache.ignite.internal.util.typedef.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
@@ -31,7 +31,7 @@ import java.util.*;
  * Fair affinity function which tries to ensure that all nodes get equal number of partitions
with
  * minimum amount of reassignments between existing nodes.
  * <p>
- * Cache affinity can be configured for individual caches via {@link CacheConfiguration#getAffinity()}
method.
+ * Cache affinity can be configured for individual caches via {@link CacheConfiguration#setAffinity(AffinityFunction)}
method.
  */
 @AffinityCentralizedFunction
 public class FairAffinityFunction implements AffinityFunction {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7cf3a66f/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 606f64a..2986e02 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
@@ -288,7 +288,6 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
             assert jcache(i).localSize() != 0 || F.isEmpty(keysCol);
         }
 
-        // TODO
         for (int i = 0; i < gridCount(); i++) {
             if (!isMultiJvmAndNodeIsRemote(i)) {
                 GridCacheContext<String, Integer> ctx = context(i);
@@ -302,23 +301,20 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
                 assertEquals("Incorrect key size on cache #" + i, sum, jcache(i).localSize(ALL));
             }
             else {
-                final int finalI = i;
-                final UUID id = grid(i).localNode().id();
+                final int iCopy = i;
 
                 ((IgniteProcessProxy)grid(i)).remoteCompute().run(new IgniteRunnable() {
                     @Override public void run() {
-                        Ignite grid = Ignition.ignite(id);
-
-                        GridCacheContext<String, Integer> ctx =
-                            ((IgniteKernal)grid).<String, Integer>internalCache().context();
+                        GridCacheContext<String, Integer> ctx = context(iCopy);
 
                         int sum = 0;
 
                         for (String key : map.keySet())
-                            if (ctx.affinity().localNode(key, new AffinityTopologyVersion(ctx.discovery().topologyVersion())))
+                            if (ctx.affinity().localNode(key,
+                                new AffinityTopologyVersion(ctx.discovery().topologyVersion())))
                                 sum++;
 
-                        assertEquals("Incorrect key size on cache #" + finalI, sum, grid.cache(null).localSize(ALL));
+                        assertEquals("Incorrect key size on cache #" + iCopy, sum, jcache(iCopy).localSize(ALL));
                     }
                 });
             }
@@ -3885,15 +3881,11 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
                     assertEquals("Incorrect size on cache #" + i, size, jcache(i).localSize(ALL));
                 }
                 else {
-                    final UUID id = grid(i).localNode().id();
+                    final int iCopy = i;
 
-                    final int finalI = i;
                     ((IgniteProcessProxy)grid(i)).remoteCompute().run(new IgniteRunnable()
{
                         @Override public void run() {
-                            Ignite grid = Ignition.ignite(id);
-
-                            GridCacheContext<String, Integer> ctx =
-                                ((IgniteKernal)grid).<String, Integer>internalCache().context();
+                            GridCacheContext<String, Integer> ctx = context(iCopy);
 
                             if (ctx.cache().configuration().getMemoryMode() == OFFHEAP_TIERED)
                                 return;
@@ -3905,14 +3897,15 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
                                     GridCacheEntryEx e =
                                         ctx.isNear() ? ctx.near().dht().peekEx(key) : ctx.cache().peekEx(key);
 
-                                    assert e != null : "Entry is null [idx=" + finalI + ",
key=" + key + ", ctx=" + ctx + ']';
+                                    assert e != null : "Entry is null [idx=" + iCopy + ",
key=" + key
+                                        + ", ctx=" + ctx + ']';
                                     assert !e.deleted() : "Entry is deleted: " + e;
 
                                     size++;
                                 }
                             }
 
-                            assertEquals("Incorrect size on cache #" + finalI, size, grid.cache(null).localSize(ALL));
+                            assertEquals("Incorrect size on cache #" + iCopy, size, jcache(iCopy).localSize(ALL));
                         }
                     });
                 }
@@ -3942,15 +3935,11 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
                     assertEquals("Incorrect key size on cache #" + i, size, jcache(i).localSize(ALL));
                 }
                 else {
-                    final int finI = i;
-                    final UUID id = grid(i).localNode().id();
+                    final int iCopy = i;
 
                     ((IgniteProcessProxy)grid(i)).remoteCompute().run(new IgniteRunnable()
{
                         @Override public void run() {
-                            Ignite grid = Ignition.ignite(id);
-
-                            GridCacheContext<String, Integer> ctx =
-                                ((IgniteKernal)grid).<String, Integer>internalCache().context();
+                            GridCacheContext<String, Integer> ctx = context(iCopy);
 
                             int size = 0;
 
@@ -3958,7 +3947,7 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract
                                 if (ctx.affinity().localNode(key, ctx.discovery().topologyVersionEx()))
                                     size++;
 
-                            assertEquals("Incorrect key size on cache #" + finI, size, grid.cache(null).localSize(ALL));
+                            assertEquals("Incorrect key size on cache #" + iCopy, size, jcache(iCopy).localSize(ALL));
                         }
                     });
                 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7cf3a66f/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractSelfTest.java
index 2a84be9..bb207fc 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractSelfTest.java
@@ -32,7 +32,6 @@ import org.apache.ignite.spi.discovery.tcp.ipfinder.*;
 import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*;
 import org.apache.ignite.testframework.*;
 import org.apache.ignite.testframework.junits.common.*;
-import org.apache.ignite.testframework.junits.multijvm.*;
 import org.apache.ignite.transactions.*;
 import org.jetbrains.annotations.*;
 import org.jsr166.*;
@@ -357,11 +356,7 @@ public abstract class GridCacheAbstractSelfTest extends GridCommonAbstractTest
{
      */
     @SuppressWarnings({"unchecked"})
     @Override protected IgniteCache<String, Integer> jcache(int idx) {
-        if (!isMultiJvmAndNodeIsRemote(idx))
-            return ignite(idx).cache(null);
-        else
-            return IgniteProcessProxy.get(getTestGridName(idx)).cache(null);
-
+        return ignite(idx).cache(null);
     }
 
     /**
@@ -369,10 +364,11 @@ public abstract class GridCacheAbstractSelfTest extends GridCommonAbstractTest
{
      * @return Cache context.
      */
     protected GridCacheContext<String, Integer> context(final int idx) {
-        if (!isMultiJvmAndNodeIsRemote(idx))
-            return ((IgniteKernal)grid(idx)).<String, Integer>internalCache().context();
-        else
-            throw new UnsupportedOperationException("Operation cant be supported for multi
jvm mode.");
+        if (isMultiJvmAndNodeIsRemote(idx) && !weAreOnRemoteJvm())
+            throw new UnsupportedOperationException("Operation can't be done automatically
via proxy. " +
+                "Send task with this logic on remote jvm.");
+
+        return ((IgniteKernal)grid(idx)).<String, Integer>internalCache().context();
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7cf3a66f/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedMultiNodeFullApiSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedMultiNodeFullApiSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedMultiNodeFullApiSelfTest.java
index 9445f9c..6e694d9 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedMultiNodeFullApiSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedMultiNodeFullApiSelfTest.java
@@ -28,7 +28,6 @@ import org.apache.ignite.internal.util.typedef.*;
 import org.apache.ignite.lang.*;
 
 import java.util.*;
-import java.util.concurrent.atomic.*;
 
 import static org.apache.ignite.cache.CacheMode.*;
 import static org.apache.ignite.cache.CachePeekMode.*;
@@ -179,21 +178,24 @@ public class GridCachePartitionedMultiNodeFullApiSelfTest extends GridCacheParti
         if (memoryMode() == CacheMemoryMode.OFFHEAP_TIERED)
             return;
 
-        final AtomicInteger swapEvts = new AtomicInteger(0);
-        final AtomicInteger unswapEvts = new AtomicInteger(0);
+        final IgniteAtomicLong swapEvts = grid(0).atomicLong("swapEvts", 0, true);
+
+        final IgniteAtomicLong unswapEvts = grid(0).atomicLong("unswapEvts", 0, true);
 
         for (int i = 0; i < gridCount(); i++) {
+            final int iCopy = i;
+
             grid(i).events().localListen(new IgnitePredicate<Event>() {
                 @Override public boolean apply(Event evt) {
                     info("Received event: " + evt);
 
                     switch (evt.type()) {
                         case EVT_CACHE_OBJECT_SWAPPED:
-                            swapEvts.incrementAndGet();
+                            grid(iCopy).atomicLong("swapEvts", 0, false).incrementAndGet();
 
                             break;
                         case EVT_CACHE_OBJECT_UNSWAPPED:
-                            unswapEvts.incrementAndGet();
+                            grid(iCopy).atomicLong("unswapEvts", 0, false).incrementAndGet();
 
                             break;
                     }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7cf3a66f/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 8802362..2f52224 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
@@ -223,6 +223,9 @@ public abstract class GridAbstractTest extends TestCase {
      * @return logger.
      */
     protected IgniteLogger log() {
+        if (weAreOnRemoteJvm())
+            return IgniteNodeRunner.startedInstance().log();
+
         return log;
     }
 
@@ -878,8 +881,12 @@ public abstract class GridAbstractTest extends TestCase {
     protected IgniteEx grid(String name) {
         if (!isMultiJvmAndNodeIsRemote(name))
             return (IgniteEx)G.ignite(name);
-        else
-            return IgniteProcessProxy.get(name);
+        else {
+            if (weAreOnRemoteJvm())
+                return IgniteNodeRunner.startedInstance();
+            else
+                return IgniteProcessProxy.ignite(name);
+        }
     }
 
     /**
@@ -889,11 +896,7 @@ public abstract class GridAbstractTest extends TestCase {
      * @return Grid instance.
      */
     protected IgniteEx grid(int idx) {
-        if (!isMultiJvmAndNodeIsRemote(idx))
-            return (IgniteEx)G.ignite(getTestGridName(idx));
-        else
-            return IgniteProcessProxy.get(getTestGridName(idx));
-
+        return grid(getTestGridName(idx));
     }
 
     /**
@@ -901,12 +904,7 @@ public abstract class GridAbstractTest extends TestCase {
      * @return Ignite instance.
      */
     protected Ignite ignite(int idx) {
-        String gridName = getTestGridName(idx);
-
-        if (!isMultiJvmAndNodeIsRemote(idx))
-            return G.ignite(gridName);
-        else
-            return IgniteProcessProxy.get(gridName);
+        return grid(idx);
     }
 
     /**
@@ -1402,6 +1400,13 @@ public abstract class GridAbstractTest extends TestCase {
     }
 
     /**
+     * @return <code>True</code> if current jvm contains remote started node.
+     */
+    protected boolean weAreOnRemoteJvm() {
+        return IgniteNodeRunner.hasStartedInstance();
+    }
+
+    /**
      * @return Test counters.
      */
     protected synchronized TestCounters getTestCounters() throws IgniteCheckedException {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7cf3a66f/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteNodeRunner.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteNodeRunner.java
b/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteNodeRunner.java
index 0dec37b..e8b9be2 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteNodeRunner.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteNodeRunner.java
@@ -20,6 +20,7 @@ package org.apache.ignite.testframework.junits.multijvm;
 import com.thoughtworks.xstream.*;
 import org.apache.ignite.*;
 import org.apache.ignite.configuration.*;
+import org.apache.ignite.internal.*;
 import org.apache.ignite.internal.processors.cache.*;
 import org.apache.ignite.internal.util.*;
 import org.apache.ignite.internal.util.typedef.*;
@@ -38,6 +39,9 @@ public class IgniteNodeRunner {
     private static final String IGNITE_CONFIGURATION_FILE = System.getProperty("java.io.tmpdir")
+
         File.separator + "igniteConfiguration.tmp_";
 
+    /** */
+    private static volatile Ignite ignite;
+
     /**
      * Starts {@link Ignite} instance accorging to given arguments.
      *
@@ -51,7 +55,21 @@ public class IgniteNodeRunner {
 
         IgniteConfiguration cfg = readCfgFromFileAndDeleteFile(args[0]);
 
-        Ignition.start(cfg);
+        ignite = Ignition.start(cfg);
+    }
+
+    /**
+     * @return Ignite instance started at main.
+     */
+    public static IgniteEx startedInstance(){
+        return (IgniteEx)ignite;
+    }
+
+    /**
+     * @return <code>True</code> if there is ignite node started via {@link IgniteNodeRunner}
at this jvm.
+     */
+    public static boolean hasStartedInstance() {
+        return ignite != null;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7cf3a66f/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteProcessProxy.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteProcessProxy.java
b/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteProcessProxy.java
index 51b910a..42436e5 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteProcessProxy.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteProcessProxy.java
@@ -120,7 +120,7 @@ public class IgniteProcessProxy implements IgniteEx {
      * @param gridName Grid name.
      * @return Instance by name or exception wiil be thrown.
      */
-    public static IgniteProcessProxy get(String gridName) {
+    public static IgniteProcessProxy ignite(String gridName) {
         IgniteProcessProxy res = gridProxies.get(gridName);
 
         if (res == null)


Mime
View raw message