IGNITE-45 - Fixing tests.

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

Branch: refs/heads/ignite-45
Commit: 5ac2673b6fb0a5af1c68bad07b8776441a001494
Parents: 489d1b8
Author: Alexey Goncharuk <agoncha...@gridgain.com>
Authored: Wed Mar 18 16:28:21 2015 -0700
Committer: Alexey Goncharuk <agoncha...@gridgain.com>
Committed: Wed Mar 18 16:28:21 2015 -0700

----------------------------------------------------------------------
 .../distributed/dht/GridDhtTxPrepareFuture.java |  9 ++++++
 .../distributed/near/GridNearCacheEntry.java    |  1 +
 .../distributed/near/GridNearTxRemote.java      |  3 +-
 .../cache/GridCacheClearAllSelfTest.java        | 29 +++++++++++++++++++
 ...GridCacheMixedPartitionExchangeSelfTest.java | 21 ++++++++++----
 .../GridCacheReturnValueTransferSelfTest.java   | 17 +++++------
 .../GridCacheAbstractJobExecutionTest.java      | 30 ++++++++++++++------
 ...idCachePartitionedPreloadEventsSelfTest.java | 10 +++----
 8 files changed, 92 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5ac2673b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareFuture.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareFuture.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareFuture.java
index 5edddd0..db2742e 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareFuture.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareFuture.java
@@ -49,6 +49,7 @@ import static 
org.apache.ignite.transactions.TransactionState.*;
 /**
  *
  */
+@SuppressWarnings("unchecked")
 public final class GridDhtTxPrepareFuture<K, V> extends 
GridCompoundIdentityFuture<IgniteInternalTx>
     implements GridCacheMvccFuture<IgniteInternalTx> {
     /** */
@@ -125,6 +126,9 @@ public final class GridDhtTxPrepareFuture<K, V> extends 
GridCompoundIdentityFutu
     private volatile boolean locksReady;
 
     /** */
+    private boolean invoke;
+
+    /** */
     private IgniteInClosure<GridNearTxPrepareResponse> completeCb;
 
     /**
@@ -307,6 +311,8 @@ public final class GridDhtTxPrepareFuture<K, V> extends 
GridCompoundIdentityFutu
 
                     if (retVal) {
                         if (!F.isEmpty(txEntry.entryProcessors())) {
+                            invoke = true;
+
                             KeyCacheObject key = txEntry.key();
 
                             Object procRes = null;
@@ -1232,6 +1238,9 @@ public final class GridDhtTxPrepareFuture<K, V> extends 
GridCompoundIdentityFutu
                                     
cacheCtx.events().addEvent(entry.partition(), entry.key(), cctx.localNodeId(),
                                         (IgniteUuid)null, null, 
EVT_CACHE_REBALANCE_OBJECT_LOADED, info.value(), true, null,
                                         false, null, null, null);
+
+                                if (retVal && !invoke)
+                                    ret.value(cacheCtx, info.value());
                             }
 
                             break;

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5ac2673b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheEntry.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheEntry.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheEntry.java
index 2db8743..3d8a188 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheEntry.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheEntry.java
@@ -601,6 +601,7 @@ public class GridNearCacheEntry extends 
GridDistributedCacheEntry {
 
     /** {@inheritDoc} */
     @Override protected void onInvalidate() {
+        primaryNodeId = null;
         dhtVer = null;
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5ac2673b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxRemote.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxRemote.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxRemote.java
index 363f601..9969f65 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxRemote.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxRemote.java
@@ -116,12 +116,13 @@ public class GridNearTxRemote extends 
GridDistributedTxRemoteAdapter {
         writeMap = new LinkedHashMap<>(
             writeEntries != null ? Math.max(txSize, writeEntries.size()) : 
txSize, 1.0f);
 
-        if (writeEntries != null)
+        if (writeEntries != null) {
             for (IgniteTxEntry entry : writeEntries) {
                 entry.unmarshal(ctx, true, ldr);
 
                 addEntry(entry);
             }
+        }
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5ac2673b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheClearAllSelfTest.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheClearAllSelfTest.java
 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheClearAllSelfTest.java
index 0aa6a91..cf7557c 100644
--- 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheClearAllSelfTest.java
+++ 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheClearAllSelfTest.java
@@ -19,7 +19,10 @@ package org.apache.ignite.internal.processors.cache;
 
 import org.apache.ignite.*;
 import org.apache.ignite.cache.*;
+import org.apache.ignite.cluster.*;
 import org.apache.ignite.configuration.*;
+import org.apache.ignite.internal.util.typedef.*;
+import org.apache.ignite.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.*;
@@ -48,6 +51,9 @@ public class GridCacheClearAllSelfTest extends 
GridCommonAbstractTest {
     /** Cache name which differs from the default one. */
     private static final String CACHE_NAME_OTHER = "cache_name_other";
 
+    /** Test attribute name. */
+    private static final String TEST_ATTRIBUTE = "TestAttribute";
+
     /** VM IP finder for TCP discovery SPI. */
     private static final TcpDiscoveryIpFinder IP_FINDER = new 
TcpDiscoveryVmIpFinder(true);
 
@@ -66,12 +72,15 @@ public class GridCacheClearAllSelfTest extends 
GridCommonAbstractTest {
         ccfg.setName(cacheName);
         ccfg.setCacheMode(cacheMode);
         ccfg.setAtomicityMode(TRANSACTIONAL);
+        ccfg.setNodeFilter(new AttributeFilter(cacheName));
 
         if (cacheMode == PARTITIONED)
             ccfg.setBackups(1);
 
         cfg.setCacheConfiguration(ccfg);
 
+        cfg.setUserAttributes(F.asMap(TEST_ATTRIBUTE, cacheName));
+
         TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();
 
         discoSpi.setIpFinder(IP_FINDER);
@@ -101,6 +110,8 @@ public class GridCacheClearAllSelfTest extends 
GridCommonAbstractTest {
         cacheName = CACHE_NAME_OTHER;
 
         startGrid(GRID_CNT - 1);
+
+        awaitPartitionMapExchange();
     }
 
     /**
@@ -163,4 +174,22 @@ public class GridCacheClearAllSelfTest extends 
GridCommonAbstractTest {
         // ... but cache with another name should remain untouched.
         assert grid(GRID_CNT - 1).jcache(CACHE_NAME_OTHER).localSize() == 
KEY_CNT_OTHER;
     }
+
+    /** {@inheritDoc} */
+    private static class AttributeFilter implements 
IgnitePredicate<ClusterNode> {
+        /** */
+        private String attrValue;
+
+        /**
+         * @param attrValue Attribute value.
+         */
+        private AttributeFilter(String attrValue) {
+            this.attrValue = attrValue;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean apply(ClusterNode clusterNode) {
+            return F.eq(attrValue, clusterNode.attribute(TEST_ATTRIBUTE));
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5ac2673b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheMixedPartitionExchangeSelfTest.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheMixedPartitionExchangeSelfTest.java
 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheMixedPartitionExchangeSelfTest.java
index 51d8543..f00222d 100644
--- 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheMixedPartitionExchangeSelfTest.java
+++ 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheMixedPartitionExchangeSelfTest.java
@@ -20,7 +20,9 @@ package org.apache.ignite.internal.processors.cache;
 import org.apache.ignite.*;
 import org.apache.ignite.configuration.*;
 import org.apache.ignite.internal.*;
+import org.apache.ignite.internal.cluster.*;
 import org.apache.ignite.internal.processors.affinity.*;
+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.*;
@@ -39,6 +41,7 @@ import static 
org.apache.ignite.transactions.TransactionIsolation.*;
  * Test case checks partition exchange when non-cache node joins topology 
(partition
  * exchange should be skipped in this case).
  */
+@SuppressWarnings("unchecked")
 public class GridCacheMixedPartitionExchangeSelfTest extends 
GridCommonAbstractTest {
     /** Flag indicating whether to include cache to the node configuration. */
     private boolean cache;
@@ -49,6 +52,8 @@ public class GridCacheMixedPartitionExchangeSelfTest extends 
GridCommonAbstractT
 
         if (cache)
             cfg.setCacheConfiguration(cacheConfiguration());
+        else
+            cfg.setClientMode(true);
 
         return cfg;
     }
@@ -93,14 +98,20 @@ public class GridCacheMixedPartitionExchangeSelfTest 
extends GridCommonAbstractT
 
                         IgniteCache<Integer, Integer> prj = 
grid(g).jcache(null);
 
-                        try (Transaction tx = 
grid(g).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
-                            Integer val = prj.get(key);
+                        try {
+                            try (Transaction tx = 
grid(g).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
+                                Integer val = prj.get(key);
 
-                            val = val == null ? 1 : val + 1;
+                                val = val == null ? 1 : val + 1;
 
-                            prj.put(key, val);
+                                prj.put(key, val);
 
-                            tx.commit();
+                                tx.commit();
+                            }
+                        }
+                        catch (Exception e) {
+                            if (!X.hasCause(e, 
ClusterTopologyCheckedException.class))
+                                throw e;
                         }
                     }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5ac2673b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheReturnValueTransferSelfTest.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheReturnValueTransferSelfTest.java
 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheReturnValueTransferSelfTest.java
index a79ebc5..ec3b507 100644
--- 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheReturnValueTransferSelfTest.java
+++ 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheReturnValueTransferSelfTest.java
@@ -55,16 +55,17 @@ public class GridCacheReturnValueTransferSelfTest extends 
GridCommonAbstractTest
     @Override protected IgniteConfiguration getConfiguration(String gridName) 
throws Exception {
         IgniteConfiguration cfg = super.getConfiguration(gridName);
 
-        if (cache) {
-            CacheConfiguration ccfg = new CacheConfiguration();
+        CacheConfiguration ccfg = new CacheConfiguration();
 
-            ccfg.setBackups(backups);
-            ccfg.setCacheMode(PARTITIONED);
-            ccfg.setAtomicityMode(atomicityMode);
-            ccfg.setAtomicWriteOrderMode(writeOrderMode);
+        ccfg.setBackups(backups);
+        ccfg.setCacheMode(PARTITIONED);
+        ccfg.setAtomicityMode(atomicityMode);
+        ccfg.setAtomicWriteOrderMode(writeOrderMode);
 
-            cfg.setCacheConfiguration(ccfg);
-        }
+        cfg.setCacheConfiguration(ccfg);
+
+        if (!cache)
+            cfg.setClientMode(true);
 
         return cfg;
     }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5ac2673b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheAbstractJobExecutionTest.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheAbstractJobExecutionTest.java
 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheAbstractJobExecutionTest.java
index 45f92ca..d2cef6e 100644
--- 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheAbstractJobExecutionTest.java
+++ 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheAbstractJobExecutionTest.java
@@ -18,7 +18,6 @@
 package org.apache.ignite.internal.processors.cache.distributed;
 
 import org.apache.ignite.*;
-import org.apache.ignite.cache.*;
 import org.apache.ignite.compute.*;
 import org.apache.ignite.configuration.*;
 import org.apache.ignite.internal.*;
@@ -85,7 +84,14 @@ public abstract class GridCacheAbstractJobExecutionTest 
extends GridCommonAbstra
 
             IgniteCache<String, int[]> c = g.jcache(null);
 
-            assertEquals("Cache is not empty, node: " + g.name(), 0, c.size());
+            GridCacheAdapter<Object, Object> cache = 
((IgniteEx)g).context().cache().internalCache();
+
+            info("Node: " + g.cluster().localNode().id());
+            info("Entries: " + cache.entries());
+            info("DHT entries: " + cache.context().near().dht().entries());
+
+            assertEquals("Cache is not empty, node [entries=" + 
c.localEntries() + ", grid=" + g.name() + ']',
+                0, c.localSize());
         }
     }
 
@@ -109,9 +115,11 @@ public abstract class GridCacheAbstractJobExecutionTest 
extends GridCommonAbstra
      * @param jobCnt Job count.
      * @throws Exception If fails.
      */
-    private void checkTransactions(final TransactionConcurrency concur, final 
TransactionIsolation isolation,
-        final int jobCnt) throws Exception {
-
+    private void checkTransactions(
+        final TransactionConcurrency concur,
+        final TransactionIsolation isolation,
+        final int jobCnt
+    ) throws Exception {
         info("Grid 0: " + grid(0).localNode().id());
         info("Grid 1: " + grid(1).localNode().id());
         info("Grid 2: " + grid(2).localNode().id());
@@ -121,6 +129,10 @@ public abstract class GridCacheAbstractJobExecutionTest 
extends GridCommonAbstra
 
         Collection<ComputeTaskFuture<?>> futs = new LinkedList<>();
 
+        final String key = "TestKey";
+
+        info("Primary node for test key: " + 
grid(0).affinity(null).mapKeyToNode(key));
+
         IgniteCompute comp = ignite.compute().withAsync();
 
         for (int i = 0; i < jobCnt; i++) {
@@ -132,14 +144,14 @@ public abstract class GridCacheAbstractJobExecutionTest 
extends GridCommonAbstra
                     IgniteCache<String, int[]> cache = ignite.jcache(null);
 
                     try (Transaction tx = 
ignite.transactions().txStart(concur, isolation)) {
-                        int[] arr = cache.get("TestKey");
+                        int[] arr = cache.get(key);
 
                         if (arr == null)
                             arr = new int[jobCnt];
 
                         arr[i] = 1;
 
-                        cache.put("TestKey", arr);
+                        cache.put(key, arr);
 
                         int c = cntr.getAndIncrement();
 
@@ -165,7 +177,7 @@ public abstract class GridCacheAbstractJobExecutionTest 
extends GridCommonAbstra
             for (int g = 0; g < GRID_CNT; g++) {
                 info("Will check grid: " + g);
 
-                info("Value: " + grid(i).jcache(null).localPeek("TestKey"));
+                info("Value: " + grid(i).jcache(null).localPeek(key));
             }
 
             IgniteCache<String, int[]> c = grid(i).jcache(null);
@@ -173,7 +185,7 @@ public abstract class GridCacheAbstractJobExecutionTest 
extends GridCommonAbstra
             // Do within transaction to make sure that lock is acquired
             // which means that all previous transactions have committed.
             try (Transaction tx = grid(i).transactions().txStart(concur, 
isolation)) {
-                int[] arr = c.get("TestKey");
+                int[] arr = c.get(key);
 
                 assertNotNull(arr);
                 assertEquals(jobCnt, arr.length);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5ac2673b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCachePartitionedPreloadEventsSelfTest.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCachePartitionedPreloadEventsSelfTest.java
 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCachePartitionedPreloadEventsSelfTest.java
index c7f5ee1..75f5f07 100644
--- 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCachePartitionedPreloadEventsSelfTest.java
+++ 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCachePartitionedPreloadEventsSelfTest.java
@@ -30,7 +30,6 @@ import org.apache.ignite.internal.util.typedef.*;
 import java.util.*;
 
 import static org.apache.ignite.cache.CacheMode.*;
-import static org.apache.ignite.cache.CacheRebalanceMode.*;
 import static org.apache.ignite.events.EventType.*;
 
 /**
@@ -41,7 +40,7 @@ public class GridCachePartitionedPreloadEventsSelfTest 
extends GridCachePreloadE
     private boolean replicatedAffinity = true;
 
     /** */
-    private CacheRebalanceMode preloadMode = SYNC;
+    private long rebalanceDelay;
 
     /** {@inheritDoc} */
     @Override protected CacheConfiguration cacheConfiguration() {
@@ -76,7 +75,7 @@ public class GridCachePartitionedPreloadEventsSelfTest 
extends GridCachePreloadE
                 }
             }, CacheAffinityFunction.class));
 
-        cacheCfg.setRebalanceMode(preloadMode);
+        cacheCfg.setRebalanceDelay(rebalanceDelay);
 
         return cacheCfg;
     }
@@ -94,7 +93,7 @@ public class GridCachePartitionedPreloadEventsSelfTest 
extends GridCachePreloadE
      */
     public void testForcePreload() throws Exception {
         replicatedAffinity = false;
-        preloadMode = NONE;
+        rebalanceDelay = -1;
 
         Ignite g1 = startGrid("g1");
 
@@ -116,7 +115,8 @@ public class GridCachePartitionedPreloadEventsSelfTest 
extends GridCachePreloadE
         assertFalse("There are no keys assigned to g2", g2Keys.isEmpty());
 
         for (Object key : g2Keys)
-            g2.jcache(null).put(key, "changed val");
+            // Need to force keys loading.
+            assertEquals("val", g2.jcache(null).getAndPut(key, "changed val"));
 
         Collection<Event> evts = g2.events().localQuery(F.<Event>alwaysTrue(), 
EVT_CACHE_REBALANCE_OBJECT_LOADED);
 

Reply via email to