ignite-45 - Fixed Full API suite.

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

Branch: refs/heads/ignite-45
Commit: 41dd7379c76607b18088159ea2cdc8248656a90d
Parents: f68fa57
Author: Alexey Goncharuk <agoncha...@gridgain.com>
Authored: Sun Mar 15 18:58:59 2015 -0700
Committer: Alexey Goncharuk <agoncha...@gridgain.com>
Committed: Sun Mar 15 18:58:59 2015 -0700

----------------------------------------------------------------------
 .../discovery/GridDiscoveryManager.java         | 58 ++++++++++++++++----
 .../affinity/AffinityTopologyVersion.java       |  8 ---
 .../affinity/GridAffinityAssignmentCache.java   | 11 +++-
 .../cache/DynamicCacheChangeBatch.java          | 18 ++++++
 .../processors/cache/GridCacheAdapter.java      |  2 +-
 .../GridCachePartitionExchangeManager.java      | 32 ++++++++---
 .../processors/cache/GridCacheProcessor.java    | 18 +++++-
 .../distributed/dht/GridDhtCacheAdapter.java    | 14 ++---
 .../dht/GridDhtPartitionTopologyImpl.java       |  3 +-
 .../transactions/IgniteTxLocalAdapter.java      | 11 +++-
 .../cache/GridCacheAbstractFullApiSelfTest.java | 23 ++++++--
 .../cache/GridCacheAbstractSelfTest.java        |  2 +
 .../cache/IgniteDynamicCacheStartSelfTest.java  | 47 +++++++++++++++-
 ...tomicClientOnlyMultiNodeFullApiSelfTest.java | 11 ++--
 ...eAtomicNearOnlyMultiNodeFullApiSelfTest.java |  4 +-
 ...idCacheNearOnlyMultiNodeFullApiSelfTest.java | 22 +++++++-
 ...ionedClientOnlyNoPrimaryFullApiSelfTest.java | 10 +++-
 ...achePartitionedMultiNodeFullApiSelfTest.java | 25 ++++++---
 18 files changed, 250 insertions(+), 69 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/41dd7379/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManager.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManager.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManager.java
index 4be1ee6..fe3dc1b 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManager.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManager.java
@@ -234,13 +234,44 @@ public class GridDiscoveryManager extends 
GridManagerAdapter<DiscoverySpi> {
      * Adds near node ID to cache filter.
      *
      * @param cacheName Cache name.
-     * @param nearNodeId Near node ID.
+     * @param clientNodeId Near node ID.
      */
-    public void addNearNode(String cacheName, UUID nearNodeId) {
+    public void addClientNode(String cacheName, UUID clientNodeId, boolean 
nearEnabled) {
         CachePredicate predicate = registeredCaches.get(cacheName);
 
         if (predicate != null)
-            predicate.addNearNode(nearNodeId);
+            predicate.addClientNode(clientNodeId, nearEnabled);
+    }
+
+    /**
+     * @return Client nodes map.
+     */
+    public Map<String, Map<UUID, Boolean>> clientNodesMap() {
+        Map<String, Map<UUID, Boolean>> res = null;
+
+        for (Map.Entry<String, CachePredicate> entry : 
registeredCaches.entrySet()) {
+            CachePredicate pred = entry.getValue();
+
+            if (!F.isEmpty(pred.clientNodes)) {
+                if (res == null)
+                    res = U.newHashMap(registeredCaches.size());
+
+                res.put(entry.getKey(), new HashMap<>(pred.clientNodes));
+            }
+        }
+
+        return res;
+    }
+
+    /**
+     * @param leftNodeId Left node ID.
+     */
+    private void updateClientNodes(UUID leftNodeId) {
+        for (Map.Entry<String, CachePredicate> entry : 
registeredCaches.entrySet()) {
+            CachePredicate pred = entry.getValue();
+
+            pred.onNodeLeft(leftNodeId);
+        }
     }
 
     /**
@@ -332,6 +363,8 @@ public class GridDiscoveryManager extends 
GridManagerAdapter<DiscoverySpi> {
                 if (type == EVT_NODE_FAILED || type == EVT_NODE_LEFT) {
                     for (DiscoCache c : discoCacheHist.values())
                         c.updateAlives(node);
+
+                    updateClientNodes(node.id());
                 }
 
                 if (type == DiscoveryCustomEvent.EVT_DISCOVERY_CUSTOM_EVT) {
@@ -1440,6 +1473,7 @@ public class GridDiscoveryManager extends 
GridManagerAdapter<DiscoverySpi> {
          * @param node Remote node this event is connected with.
          * @param topSnapshot Topology snapshot.
          */
+        @SuppressWarnings("RedundantTypeArguments")
         private void recordEvent(int type, long topVer, ClusterNode node, 
Collection<ClusterNode> topSnapshot) {
             assert node != null;
 
@@ -1806,7 +1840,7 @@ public class GridDiscoveryManager extends 
GridManagerAdapter<DiscoverySpi> {
         private long awaitVer;
 
         /** Empty constructor required by {@link Externalizable}. */
-        public DiscoTopologyFuture() {
+        private DiscoTopologyFuture() {
             // No-op.
         }
 
@@ -2345,22 +2379,22 @@ public class GridDiscoveryManager extends 
GridManagerAdapter<DiscoverySpi> {
         /**
          * @param nodeId Near node ID to add.
          */
-        public void addNearNode(UUID nodeId) {
-            clientNodes.put(nodeId, true);
+        public void addClientNode(UUID nodeId, boolean nearEnabled) {
+            clientNodes.put(nodeId, nearEnabled);
         }
 
         /**
-         * @param nodeId Near node ID to add.
+         * @param nodeId Near node ID to remove.
          */
-        public void addClientNode(UUID nodeId) {
-            clientNodes.put(nodeId, false);
+        public void removeNearNode(UUID nodeId) {
+            clientNodes.remove(nodeId);
         }
 
         /**
-         * @param nodeId Near node ID to remove.
+         * @param leftNodeId Left node ID.
          */
-        public void removeNearNode(UUID nodeId) {
-            clientNodes.remove(nodeId);
+        public void onNodeLeft(UUID leftNodeId) {
+            clientNodes.remove(leftNodeId);
         }
 
         /**

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/41dd7379/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/AffinityTopologyVersion.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/AffinityTopologyVersion.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/AffinityTopologyVersion.java
index 9ff02f7..6faa6bf 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/AffinityTopologyVersion.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/AffinityTopologyVersion.java
@@ -82,14 +82,6 @@ public class AffinityTopologyVersion implements 
Comparable<AffinityTopologyVersi
         this.topVer = topVer;
     }
 
-    /**
-     *
-     */
-    public AffinityTopologyVersion previous() {
-        // TODO IGNITE-45.
-        return new AffinityTopologyVersion(topVer - 1, 0);
-    }
-
     /** {@inheritDoc} */
     @Override public int compareTo(AffinityTopologyVersion o) {
         int cmp = Long.compare(topVer, o.topVer);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/41dd7379/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityAssignmentCache.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityAssignmentCache.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityAssignmentCache.java
index dc103ac..a008315 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityAssignmentCache.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityAssignmentCache.java
@@ -55,7 +55,7 @@ public class GridAffinityAssignmentCache {
     private final CacheAffinityKeyMapper affMapper;
 
     /** Affinity calculation results cache: topology version => partition => 
nodes. */
-    private final ConcurrentMap<AffinityTopologyVersion, 
GridAffinityAssignment> affCache;
+    private final ConcurrentLinkedHashMap<AffinityTopologyVersion, 
GridAffinityAssignment> affCache;
 
     /** Cache item corresponding to the head topology version. */
     private final AtomicReference<GridAffinityAssignment> head;
@@ -150,7 +150,14 @@ public class GridAffinityAssignmentCache {
             log.debug("Calculating affinity [topVer=" + topVer + ", 
locNodeId=" + ctx.localNodeId() +
                 ", discoEvt=" + discoEvt + ']');
 
-        GridAffinityAssignment prev = affCache.get(topVer.previous());
+        Iterator<AffinityTopologyVersion> it = 
affCache.descendingKeySet().iterator();
+
+        AffinityTopologyVersion prevVer = null;
+
+        if (it.hasNext())
+            prevVer = it.next();
+
+        GridAffinityAssignment prev = prevVer == null ? null : 
affCache.get(prevVer);
 
         List<ClusterNode> sorted;
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/41dd7379/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheChangeBatch.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheChangeBatch.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheChangeBatch.java
index 3de9a99..ac3660e 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheChangeBatch.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheChangeBatch.java
@@ -34,6 +34,10 @@ public class DynamicCacheChangeBatch implements Serializable 
{
     @GridToStringInclude
     private Collection<DynamicCacheChangeRequest> reqs;
 
+    /** Client nodes map. Used in discovery data exchange. */
+    @GridToStringInclude
+    private Map<String, Map<UUID, Boolean>> clientNodes;
+
     /**
      * @param reqs Requests.
      */
@@ -50,6 +54,20 @@ public class DynamicCacheChangeBatch implements Serializable 
{
         return reqs;
     }
 
+    /**
+     * @return Client nodes map.
+     */
+    public Map<String, Map<UUID, Boolean>> clientNodes() {
+        return clientNodes;
+    }
+
+    /**
+     * @param clientNodes Client nodes map.
+     */
+    public void clientNodes(Map<String, Map<UUID, Boolean>> clientNodes) {
+        this.clientNodes = clientNodes;
+    }
+
     /** {@inheritDoc} */
     @Override public String toString() {
         return S.toString(DynamicCacheChangeBatch.class, this);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/41dd7379/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
index 81aa5eb..09bb1f1 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
@@ -1420,7 +1420,7 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
             if (entry != null)
                 return entry.clear(obsoleteVer, false, filter);
         }
-        catch (GridDhtInvalidPartitionException e) {
+        catch (GridDhtInvalidPartitionException ignored) {
             return false;
         }
         catch (IgniteCheckedException ex) {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/41dd7379/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCachePartitionExchangeManager.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCachePartitionExchangeManager.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCachePartitionExchangeManager.java
index f094e35..3e236bf 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCachePartitionExchangeManager.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCachePartitionExchangeManager.java
@@ -566,8 +566,17 @@ public class GridCachePartitionExchangeManager<K, V> 
extends GridCacheSharedMana
         GridDhtPartitionsSingleMessage m = new 
GridDhtPartitionsSingleMessage(id, cctx.versions().last());
 
         for (GridCacheContext cacheCtx : cctx.cacheContexts()) {
-            if (!cacheCtx.isLocal())
-                m.addLocalPartitionMap(cacheCtx.cacheId(), 
cacheCtx.topology().localPartitionMap());
+            if (!cacheCtx.isLocal()) {
+                GridDhtPartitionMap locMap = 
cacheCtx.topology().localPartitionMap();
+
+                m.addLocalPartitionMap(cacheCtx.cacheId(), locMap);
+            }
+        }
+
+        for (GridClientPartitionTopology top : clientTops.values()) {
+            GridDhtPartitionMap locMap = top.localPartitionMap();
+
+            m.addLocalPartitionMap(top.cacheId(), locMap);
         }
 
         if (log.isDebugEnabled())
@@ -701,15 +710,20 @@ public class GridCachePartitionExchangeManager<K, V> 
extends GridCacheSharedMana
 
                 boolean updated = false;
 
-                for (GridCacheContext cacheCtx : cctx.cacheContexts()) {
-                    if (!cacheCtx.isLocal()) {
-                        GridDhtPartitionTopology top = cacheCtx.topology();
+                for (Map.Entry<Integer, GridDhtPartitionMap> entry : 
msg.partitions().entrySet()) {
+                    Integer cacheId = entry.getKey();
 
-                        GridDhtPartitionMap parts = 
msg.partitions().get(cacheCtx.cacheId());
+                    GridCacheContext<K, V> cacheCtx = 
cctx.cacheContext(cacheId);
 
-                        if (parts != null)
-                            updated |= top.update(null, parts) != null;
-                    }
+                    GridDhtPartitionTopology top = null;
+
+                    if (cacheCtx == null)
+                        top = clientTops.get(cacheId);
+                    else if (!cacheCtx.isLocal())
+                        top = cacheCtx.topology();
+
+                    if (top != null)
+                        updated |= top.update(null, entry.getValue()) != null;
                 }
 
                 if (updated)

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/41dd7379/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
index ea0afd2..993e50b 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
@@ -1392,7 +1392,11 @@ public class GridCacheProcessor extends 
GridProcessorAdapter {
             }
         }
 
-        return new DynamicCacheChangeBatch(reqs);
+        DynamicCacheChangeBatch req = new DynamicCacheChangeBatch(reqs);
+
+        req.clientNodes(ctx.discovery().clientNodesMap());
+
+        return req;
     }
 
     /** {@inheritDoc} */
@@ -1431,6 +1435,15 @@ public class GridCacheProcessor extends 
GridProcessorAdapter {
                     existing.validationFailed(e);
                 }
             }
+
+            if (!F.isEmpty(batch.clientNodes())) {
+                for (Map.Entry<String, Map<UUID, Boolean>> entry : 
batch.clientNodes().entrySet()) {
+                    String cacheName = entry.getKey();
+
+                    for (Map.Entry<UUID, Boolean> tup : 
entry.getValue().entrySet())
+                        ctx.discovery().addClientNode(cacheName, tup.getKey(), 
tup.getValue());
+                }
+            }
         }
     }
 
@@ -1622,8 +1635,7 @@ public class GridCacheProcessor extends 
GridProcessorAdapter {
                         ccfg.getCacheMode() == LOCAL);
                 }
 
-                if (req.nearCacheConfiguration() != null)
-                    ctx.discovery().addNearNode(req.cacheName(), 
req.initiatingNodeId());
+                ctx.discovery().addClientNode(req.cacheName(), 
req.initiatingNodeId(), req.nearCacheConfiguration() != null);
             }
             else {
                 if (desc == null) {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/41dd7379/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheAdapter.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheAdapter.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheAdapter.java
index be711a8..91a543f 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheAdapter.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheAdapter.java
@@ -18,7 +18,6 @@
 package org.apache.ignite.internal.processors.cache.distributed.dht;
 
 import org.apache.ignite.*;
-import org.apache.ignite.cache.*;
 import org.apache.ignite.cluster.*;
 import org.apache.ignite.internal.*;
 import org.apache.ignite.internal.processors.affinity.*;
@@ -42,8 +41,6 @@ import java.io.*;
 import java.util.*;
 import java.util.concurrent.*;
 
-import static org.apache.ignite.cache.CacheDistributionMode.*;
-import static org.apache.ignite.internal.processors.cache.GridCacheUtils.*;
 import static org.apache.ignite.internal.processors.dr.GridDrType.*;
 
 /**
@@ -497,7 +494,7 @@ public abstract class GridDhtCacheAdapter<K, V> extends 
GridDistributedCacheAdap
 
     /**
      * This method is used internally. Use
-     * {@link #getDhtAsync(UUID, long, LinkedHashMap, boolean, boolean, 
AffinityTopologyVersion, UUID, int, boolean, IgniteCacheExpiryPolicy, boolean)}
+     * {@link #getDhtAsync(UUID, long, LinkedHashMap, boolean, boolean, 
AffinityTopologyVersion, UUID, int, IgniteCacheExpiryPolicy, boolean)}
      * method instead to retrieve DHT value.
      *
      * @param keys {@inheritDoc}
@@ -683,7 +680,7 @@ public abstract class GridDhtCacheAdapter<K, V> extends 
GridDistributedCacheAdap
                     AffinityTopologyVersion topVer = new 
AffinityTopologyVersion(ctx.discovery().topologyVersion());
 
                     for (Map.Entry<KeyCacheObject, GridCacheVersion> e : 
entries.entrySet()) {
-                        List<ClusterNode> nodes = 
ctx.affinity().nodes((K)e.getKey(), topVer);
+                        List<ClusterNode> nodes = 
ctx.affinity().nodes(e.getKey(), topVer);
 
                         for (int i = 0; i < nodes.size(); i++) {
                             ClusterNode node = nodes.get(i);
@@ -831,11 +828,11 @@ public abstract class GridDhtCacheAdapter<K, V> extends 
GridDistributedCacheAdap
         /** {@inheritDoc} */
         @NotNull @Override public Iterator<Cache.Entry<K, V>> iterator() {
             final GridDhtLocalPartition part = 
ctx.topology().localPartition(partId,
-                new 
AffinityTopologyVersion(ctx.discovery().topologyVersion()), false);
+                ctx.discovery().topologyVersionEx(), false);
 
             Iterator<GridDhtCacheEntry> partIt = part == null ? null : 
part.entries().iterator();
 
-            return new PartitionEntryIterator<>(partIt);
+            return new PartitionEntryIterator(partIt);
         }
 
         /** {@inheritDoc} */
@@ -1000,7 +997,7 @@ public abstract class GridDhtCacheAdapter<K, V> extends 
GridDistributedCacheAdap
     /**
      * Complex partition iterator for both partition and swap iteration.
      */
-    private class PartitionEntryIterator<K, V> extends 
GridIteratorAdapter<Cache.Entry<K, V>> {
+    private class PartitionEntryIterator extends 
GridIteratorAdapter<Cache.Entry<K, V>> {
         /** */
         private static final long serialVersionUID = 0L;
 
@@ -1071,6 +1068,7 @@ public abstract class GridDhtCacheAdapter<K, V> extends 
GridDistributedCacheAdap
     /**
      * Multi update future.
      */
+    @SuppressWarnings("TypeMayBeWeakened")
     private static class MultiUpdateFuture extends 
GridFutureAdapter<IgniteUuid> {
         /** */
         private static final long serialVersionUID = 0L;

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/41dd7379/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java
index d410521..7a172cd 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java
@@ -262,7 +262,8 @@ class GridDhtPartitionTopologyImpl<K, V> implements 
GridDhtPartitionTopology {
             if (cctx.rebalanceEnabled()) {
                 for (int p = 0; p < num; p++) {
                     // If this is the first node in grid.
-                    if ((oldest.id().equals(loc.id()) && 
oldest.id().equals(exchId.nodeId())) || exchId.isCacheAdded(cctx.cacheId())) {
+                    if ((oldest.id().equals(loc.id()) && 
oldest.id().equals(exchId.nodeId())) || exchId.isCacheAdded(
+                        cctx.cacheId())) {
                         assert exchId.isJoined() || 
exchId.isCacheAdded(cctx.cacheId());
 
                         try {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/41dd7379/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java
index 24e421d..ca85838 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java
@@ -18,7 +18,6 @@
 package org.apache.ignite.internal.processors.cache.transactions;
 
 import org.apache.ignite.*;
-import org.apache.ignite.cluster.*;
 import org.apache.ignite.internal.processors.affinity.*;
 import org.apache.ignite.internal.*;
 import org.apache.ignite.internal.cluster.*;
@@ -2697,6 +2696,16 @@ public abstract class IgniteTxLocalAdapter extends 
IgniteTxAdapter
                     });
             }
         }
+        catch (RuntimeException e) {
+            for (IgniteTxEntry txEntry : txMap.values()) {
+                GridCacheEntryEx cached0 = txEntry.cached();
+
+                if (cached0 != null)
+                    txEntry.context().evicts().touch(cached0, 
topologyVersion());
+            }
+
+            throw e;
+        }
         catch (IgniteCheckedException e) {
             setRollbackOnly();
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/41dd7379/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 186bd46..54ff90c 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
@@ -3626,6 +3626,9 @@ public abstract class GridCacheAbstractFullApiSelfTest 
extends GridCacheAbstract
         assertNull(cache.localPeek(key, CachePeekMode.ONHEAP));
 
         assert cache.localSize() == 0;
+
+        // Clear readers, if any.
+        cache.remove(key);
     }
 
     /**
@@ -3820,7 +3823,7 @@ public abstract class GridCacheAbstractFullApiSelfTest 
extends GridCacheAbstract
                 int size = 0;
 
                 for (String key : keys) {
-                    if (ctx.affinity().localNode(key, new 
AffinityTopologyVersion(ctx.discovery().topologyVersion()))) {
+                    if (ctx.affinity().localNode(key, 
ctx.discovery().topologyVersionEx())) {
                         GridCacheEntryEx e =
                             ctx.isNear() ? ctx.near().dht().peekEx(key) : 
ctx.cache().peekEx(key);
 
@@ -3850,7 +3853,7 @@ public abstract class GridCacheAbstractFullApiSelfTest 
extends GridCacheAbstract
                 int size = 0;
 
                 for (String key : keys)
-                    if (ctx.affinity().localNode(key, new 
AffinityTopologyVersion(ctx.discovery().topologyVersion())))
+                    if (ctx.affinity().localNode(key, 
ctx.discovery().topologyVersionEx()))
                         size++;
 
                 assertEquals("Incorrect key size on cache #" + i, size, 
jcache(i).localSize());
@@ -3949,7 +3952,12 @@ public abstract class GridCacheAbstractFullApiSelfTest 
extends GridCacheAbstract
     public void testIgniteCacheIterator() throws Exception {
         IgniteCache<String, Integer> cache = jcache(0);
 
-        assertFalse(cache.iterator().hasNext());
+        Iterator<Cache.Entry<String, Integer>> it = cache.iterator();
+
+        boolean hasNext = it.hasNext();
+
+        if (hasNext)
+            assertFalse("Cache has value: " + it.next(), hasNext);
 
         final int SIZE = 10_000;
 
@@ -4225,15 +4233,20 @@ public abstract class GridCacheAbstractFullApiSelfTest 
extends GridCacheAbstract
 
         assert keysToRmv.size() > 1;
 
+        info("Will clear keys on node: " + g.cluster().localNode().id());
+
         g.<String, Integer>jcache(null).localClearAll(keysToRmv);
 
         for (int i = 0; i < 500; ++i) {
             String key = "key" + i;
 
-            boolean found = primaryIgnite(key).jcache(null).localPeek(key) != 
null;
+            Ignite ignite = primaryIgnite(key);
+
+            boolean found = ignite.jcache(null).localPeek(key) != null;
 
             if (keysToRmv.contains(key))
-                assertFalse("Found removed key " + key, found);
+                assertFalse("Found removed key [key=" + key + ", node=" + 
ignite.cluster().localNode().id() + ']',
+                    found);
             else
                 assertTrue("Not found key " + key, found);
         }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/41dd7379/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 d3d83e2..6023e1a 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
@@ -77,6 +77,8 @@ public abstract class GridCacheAbstractSelfTest extends 
GridCommonAbstractTest {
         assert cnt >= 1 : "At least one grid must be started";
 
         startGrids(cnt);
+
+        awaitPartitionMapExchange();
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/41dd7379/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteDynamicCacheStartSelfTest.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteDynamicCacheStartSelfTest.java
 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteDynamicCacheStartSelfTest.java
index 60355f3..2d1d39f 100644
--- 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteDynamicCacheStartSelfTest.java
+++ 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteDynamicCacheStartSelfTest.java
@@ -22,6 +22,7 @@ import org.apache.ignite.cache.*;
 import org.apache.ignite.cluster.*;
 import org.apache.ignite.configuration.*;
 import org.apache.ignite.internal.*;
+import org.apache.ignite.internal.managers.discovery.*;
 import org.apache.ignite.internal.util.typedef.*;
 import org.apache.ignite.lang.*;
 import org.apache.ignite.testframework.*;
@@ -61,7 +62,7 @@ public class IgniteDynamicCacheStartSelfTest extends 
GridCommonAbstractTest {
      * @return Number of nodes for this test.
      */
     public int nodeCount() {
-        return 4;
+        return 3;
     }
 
     /** {@inheritDoc} */
@@ -558,4 +559,48 @@ public class IgniteDynamicCacheStartSelfTest extends 
GridCommonAbstractTest {
             stopGrid(nodeCount());
         }
     }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testNearNodesCache() throws Exception {
+        try {
+            testAttribute = false;
+
+            Ignite ig = startGrid(nodeCount());
+
+            CacheConfiguration ccfg = new CacheConfiguration();
+
+            ccfg.setName(DYNAMIC_CACHE_NAME);
+            ccfg.setCacheMode(CacheMode.PARTITIONED);
+            ccfg.setNodeFilter(NODE_FILTER);
+
+            try (IgniteCache cache = ig.createCache(ccfg, new 
NearCacheConfiguration())) {
+                assertNotNull(cache);
+
+                GridCacheAdapter<Object, Object> cacheAdapter =
+                    ((IgniteKernal)ig).internalCache(DYNAMIC_CACHE_NAME);
+
+                assertNotNull(cacheAdapter);
+                assertFalse(cacheAdapter.affinityNode());
+                assertTrue(cacheAdapter.context().isNear());
+
+                try {
+                    IgniteKernal grid = (IgniteKernal)startGrid(nodeCount() + 
1);
+
+                    // Check that new node sees near node.
+                    GridDiscoveryManager disco = grid.context().discovery();
+
+                    
assertTrue(disco.cacheNearNode(disco.node(ig.cluster().localNode().id()),
+                        DYNAMIC_CACHE_NAME));
+                }
+                finally {
+                    stopGrid(nodeCount() + 1);
+                }
+            }
+        }
+        finally {
+            stopGrid(nodeCount());
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/41dd7379/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicClientOnlyMultiNodeFullApiSelfTest.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicClientOnlyMultiNodeFullApiSelfTest.java
 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicClientOnlyMultiNodeFullApiSelfTest.java
index da86b9e..abb9a69 100644
--- 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicClientOnlyMultiNodeFullApiSelfTest.java
+++ 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicClientOnlyMultiNodeFullApiSelfTest.java
@@ -42,16 +42,17 @@ public class 
GridCacheAtomicClientOnlyMultiNodeFullApiSelfTest extends GridCache
     @Override protected CacheConfiguration cacheConfiguration(String gridName) 
throws Exception {
         CacheConfiguration cfg = super.cacheConfiguration(gridName);
 
-// TODO IGNITE-45
-//        if (cfg.getDistributionMode() == NEAR_ONLY)
-//            cfg.setDistributionMode(CLIENT_ONLY);
-//        else
-//            cfg.setDistributionMode(PARTITIONED_ONLY);
+        cfg.setNearConfiguration(null);
 
         return cfg;
     }
 
     /** {@inheritDoc} */
+    @Override protected boolean clientHasNearCache() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
     @Override protected CacheAtomicityMode atomicityMode() {
         return ATOMIC;
     }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/41dd7379/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicNearOnlyMultiNodeFullApiSelfTest.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicNearOnlyMultiNodeFullApiSelfTest.java
 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicNearOnlyMultiNodeFullApiSelfTest.java
index 2e2eada..9e947df 100644
--- 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicNearOnlyMultiNodeFullApiSelfTest.java
+++ 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCacheAtomicNearOnlyMultiNodeFullApiSelfTest.java
@@ -36,9 +36,7 @@ public class GridCacheAtomicNearOnlyMultiNodeFullApiSelfTest 
extends GridCacheNe
     @Override protected CacheConfiguration cacheConfiguration(String gridName) 
throws Exception {
         CacheConfiguration cfg = super.cacheConfiguration(gridName);
 
-        // TODO IGNITE-45.
-//        if (cfg.getDistributionMode() != NEAR_ONLY)
-//            cfg.setDistributionMode(PARTITIONED_ONLY);
+        cfg.setNearConfiguration(null);
 
         return cfg;
     }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/41dd7379/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 458d86f..1a056dd 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
@@ -55,6 +55,24 @@ public class GridCacheNearOnlyMultiNodeFullApiSelfTest 
extends GridCachePartitio
         cnt = new AtomicInteger();
 
         super.beforeTestsStarted();
+
+        for (int i = 0; i < gridCount(); i++) {
+            if (ignite(i).configuration().isClientMode()) {
+                if (clientHasNearCache())
+                    ignite(i).createCache(new NearCacheConfiguration<>());
+                else
+                    ignite(i).jcache(null);
+
+                break;
+            }
+        }
+    }
+
+    /**
+     * @return If client node has near cache.
+     */
+    protected boolean clientHasNearCache() {
+        return true;
     }
 
     @Override protected IgniteConfiguration getConfiguration(String gridName) 
throws Exception {
@@ -83,8 +101,6 @@ public class GridCacheNearOnlyMultiNodeFullApiSelfTest 
extends GridCachePartitio
     @Override protected void beforeTest() throws Exception {
         for (int i = 0; i < gridCount(); i++) {
             if (ignite(i).configuration().isClientMode()) {
-                ignite(i).createCache(new NearCacheConfiguration<>());
-
                 nearIdx = i;
 
                 break;
@@ -95,6 +111,8 @@ public class GridCacheNearOnlyMultiNodeFullApiSelfTest 
extends GridCachePartitio
 
         dfltIgnite = grid(nearIdx);
 
+        info("Near-only node: " + dfltIgnite.cluster().localNode().id());
+
         super.beforeTest(); // Doing initial asserts.
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/41dd7379/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedClientOnlyNoPrimaryFullApiSelfTest.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedClientOnlyNoPrimaryFullApiSelfTest.java
 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedClientOnlyNoPrimaryFullApiSelfTest.java
index c76ec71..c79c32a 100644
--- 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedClientOnlyNoPrimaryFullApiSelfTest.java
+++ 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedClientOnlyNoPrimaryFullApiSelfTest.java
@@ -31,10 +31,18 @@ import java.util.*;
 public class GridCachePartitionedClientOnlyNoPrimaryFullApiSelfTest extends 
GridCachePartitionedFullApiSelfTest {
     /** {@inheritDoc} */
     @Override protected NearCacheConfiguration nearConfiguration() {
-        // TODO IGNITE-45.
         return null;
     }
 
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) 
throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        cfg.setClientMode(true);
+
+        return cfg;
+    }
+
     /**
      *
      */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/41dd7379/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 ebe0ae7..dfafc5c 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
@@ -23,6 +23,7 @@ import org.apache.ignite.cache.affinity.*;
 import org.apache.ignite.cluster.*;
 import org.apache.ignite.configuration.*;
 import org.apache.ignite.events.*;
+import org.apache.ignite.internal.*;
 import org.apache.ignite.internal.processors.cache.*;
 import org.apache.ignite.internal.util.typedef.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
@@ -228,22 +229,32 @@ public class GridCachePartitionedMultiNodeFullApiSelfTest 
extends GridCacheParti
         jcache().put("key", 1);
 
         for (int i = 0; i < gridCount(); i++) {
-            boolean nearEnabled = nearEnabled(jcache(i));
+            IgniteCache<String, Integer> c = jcache(i);
+
+            assertEquals((Integer)1, c.get("key"));
+
+            boolean nearEnabled = nearEnabled(c);
+
+            if (nearEnabled)
+                
assertTrue(((IgniteKernal)ignite(i)).internalCache().context().isNear());
 
             Integer nearPeekVal = nearEnabled ? 1 : null;
 
-            IgniteCache<String, Integer> c = jcache(i);
+            CacheAffinity<Object> aff = ignite(i).affinity(null);
 
-            if 
(c.unwrap(Ignite.class).affinity(null).isBackup(grid(i).localNode(), "key")) {
+            info("Affinity nodes [nodes=" + 
F.nodeIds(aff.mapKeyToPrimaryAndBackups("key")) +
+                ", locNode=" + ignite(i).cluster().localNode().id() + ']');
+
+            if (aff.isBackup(grid(i).localNode(), "key")) {
                 assertNull(c.localPeek("key", NEAR));
 
                 assertEquals((Integer)1, c.localPeek("key", BACKUP));
             }
-            else if 
(!c.unwrap(Ignite.class).affinity(null).isPrimaryOrBackup(grid(i).localNode(), 
"key")) {
+            else if (!aff.isPrimaryOrBackup(grid(i).localNode(), "key")) {
                 // Initialize near reader.
-                assertEquals((Integer)1, jcache(i).get("key"));
+                assertEquals((Integer)1, c.get("key"));
 
-                assertEquals(nearPeekVal, c.localPeek("key", NEAR));
+                assertEquals("Failed to validate near value for node: " + i, 
nearPeekVal, c.localPeek("key", NEAR));
 
                 assertNull(c.localPeek("key", PRIMARY, BACKUP));
             }
@@ -323,7 +334,7 @@ public class GridCachePartitionedMultiNodeFullApiSelfTest 
extends GridCacheParti
         assertEquals(nearEnabled() ? 2 : 0, cache2.nearSize());
         assertEquals(0, cache2.size() - cache2.nearSize());
 
-        CacheEntryPredicateAdapter prjFilter = new 
CacheEntryPredicateAdapter() {
+        CacheEntryPredicate prjFilter = new CacheEntryPredicateAdapter() {
             @Override public boolean apply(GridCacheEntryEx e) {
                 try {
                     Integer val = CU.value(e.rawGetOrUnmarshal(false), 
e.context(), false);

Reply via email to