# sprint-2 Fixed test.

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

Branch: refs/heads/ignite-424
Commit: f860b80adf61574d789fe045cfa69325f2e26be4
Parents: 71c6939
Author: sboikov <sboi...@gridgain.com>
Authored: Fri Mar 27 10:10:49 2015 +0300
Committer: sboikov <sboi...@gridgain.com>
Committed: Fri Mar 27 10:19:00 2015 +0300

----------------------------------------------------------------------
 ...idCacheValueConsistencyAbstractSelfTest.java |  3 +-
 .../IgniteClientAffinityAssignmentSelfTest.java | 99 ++++++++++++++++----
 2 files changed, 85 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f860b80a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheValueConsistencyAbstractSelfTest.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheValueConsistencyAbstractSelfTest.java
 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheValueConsistencyAbstractSelfTest.java
index 4c684c4..7875402 100644
--- 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheValueConsistencyAbstractSelfTest.java
+++ 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheValueConsistencyAbstractSelfTest.java
@@ -292,7 +292,8 @@ public abstract class 
GridCacheValueConsistencyAbstractSelfTest extends GridCach
                         boolean primary = 
aff.isPrimary(ignite.cluster().localNode(), i);
                         boolean backup = 
aff.isBackup(ignite.cluster().localNode(), i);
 
-                        log.error("Invalid value detected [val=" + val +
+                        log.error("Invalid value detected [key=" + i +
+                            ", val=" + val +
                             ", firstVal=" + firstVal +
                             ", node=" + g +
                             ", primary=" + primary +

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f860b80a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteClientAffinityAssignmentSelfTest.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteClientAffinityAssignmentSelfTest.java
 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteClientAffinityAssignmentSelfTest.java
index c87a878..5c52cca 100644
--- 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteClientAffinityAssignmentSelfTest.java
+++ 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteClientAffinityAssignmentSelfTest.java
@@ -24,17 +24,24 @@ import org.apache.ignite.cache.affinity.fair.*;
 import org.apache.ignite.cache.affinity.rendezvous.*;
 import org.apache.ignite.configuration.*;
 import org.apache.ignite.internal.*;
+import org.apache.ignite.internal.util.lang.*;
+import org.apache.ignite.spi.discovery.tcp.*;
+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 java.util.concurrent.*;
+
 /**
  * Tests affinity assignment for different affinity types.
  */
 public class IgniteClientAffinityAssignmentSelfTest extends 
GridCommonAbstractTest {
     /** */
-    public static final int PARTS = 256;
+    private static final TcpDiscoveryIpFinder ipFinder = new 
TcpDiscoveryVmIpFinder(true);
 
     /** */
-    private boolean client;
+    public static final int PARTS = 256;
 
     /** */
     private boolean cache;
@@ -46,7 +53,9 @@ public class IgniteClientAffinityAssignmentSelfTest extends 
GridCommonAbstractTe
     @Override protected IgniteConfiguration getConfiguration(String gridName) 
throws Exception {
         IgniteConfiguration cfg = super.getConfiguration(gridName);
 
-        if (cache && !client) {
+        ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(ipFinder);
+
+        if (cache) {
             CacheConfiguration ccfg = new CacheConfiguration();
 
             ccfg.setCacheMode(CacheMode.PARTITIONED);
@@ -62,6 +71,8 @@ public class IgniteClientAffinityAssignmentSelfTest extends 
GridCommonAbstractTe
 
             cfg.setCacheConfiguration(ccfg);
         }
+        else
+            cfg.setClientMode(true);
 
         return cfg;
     }
@@ -92,36 +103,68 @@ public class IgniteClientAffinityAssignmentSelfTest 
extends GridCommonAbstractTe
 
         startGrids(3);
 
+        long topVer = 3;
+
         try {
-            checkAffinity();
+            checkAffinity(topVer++);
 
-            client = true;
+            cache = false;
 
-            startGrid(3);
+            final Ignite ignite3 = startGrid(3);
 
-            checkAffinity();
+            GridTestUtils.assertThrows(log, new Callable<Object>() {
+                @Override public Object call() throws Exception {
+                    ((IgniteKernal)ignite3).getCache(null);
 
-            startGrid(4);
+                    return null;
+                }
+            }, IllegalArgumentException.class, null);
 
-            checkAffinity();
+            assertNotNull(ignite3.cache(null)); // Start client cache.
 
-            cache = false;
+            ((IgniteKernal)ignite3).getCache(null);
+
+            checkAffinity(topVer++);
+
+            final Ignite ignite4 = startGrid(4);
+
+            GridTestUtils.assertThrows(log, new Callable<Object>() {
+                @Override public Object call() throws Exception {
+                    ((IgniteKernal)ignite4).getCache(null);
+
+                    return null;
+                }
+            }, IllegalArgumentException.class, null);
+
+            assertNotNull(ignite4.cache(null)); // Start client cache.
+
+            ((IgniteKernal)ignite4).getCache(null);
+
+            checkAffinity(topVer++);
 
-            startGrid(5);
+            final Ignite ignite5 = startGrid(5); // Node without cache.
 
-            checkAffinity();
+            GridTestUtils.assertThrows(log, new Callable<Object>() {
+                @Override public Object call() throws Exception {
+                    ((IgniteKernal)ignite5).getCache(null);
+
+                    return null;
+                }
+            }, IllegalArgumentException.class, null);
+
+            checkAffinity(topVer++);
 
             stopGrid(5);
 
-            checkAffinity();
+            checkAffinity(topVer++);
 
             stopGrid(4);
 
-            checkAffinity();
+            checkAffinity(topVer++);
 
             stopGrid(3);
 
-            checkAffinity();
+            checkAffinity(topVer);
         }
         finally {
             stopAllGrids();
@@ -129,9 +172,12 @@ public class IgniteClientAffinityAssignmentSelfTest 
extends GridCommonAbstractTe
     }
 
     /**
+     * @param topVer Topology version.
      * @throws Exception If failed.
      */
-    private void checkAffinity() throws Exception {
+    private void checkAffinity(long topVer) throws Exception {
+        awaitTopology(topVer);
+
         Affinity<Object> aff = 
((IgniteKernal)grid(0)).getCache(null).affinity();
 
         for (Ignite grid : Ignition.allGrids()) {
@@ -149,4 +195,25 @@ public class IgniteClientAffinityAssignmentSelfTest 
extends GridCommonAbstractTe
             }
         }
     }
+
+    /**
+     * @param topVer Topology version.
+     * @throws Exception If failed.
+     */
+    private void awaitTopology(final long topVer) throws Exception {
+        for (Ignite grid : Ignition.allGrids()) {
+            final GridCacheAdapter cache = 
((IgniteKernal)grid).internalCache(null);
+
+            if (cache == null)
+                continue;
+
+            GridTestUtils.waitForCondition(new GridAbsPredicate() {
+                @Override public boolean apply() {
+                    return 
cache.context().affinity().affinityTopologyVersion().topologyVersion() == 
topVer;
+                }
+            }, 5000);
+
+            assertEquals(topVer, 
cache.context().affinity().affinityTopologyVersion().topologyVersion());
+        }
+    }
 }

Reply via email to