ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [03/25] incubator-ignite git commit: # ignite-57
Date Mon, 09 Feb 2015 20:39:20 GMT
# ignite-57


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

Branch: refs/heads/sprint-1
Commit: 20f93d6c82e0d57035271f880a1fe3c465e37e46
Parents: bf22498
Author: sboikov <sboikov@gridgain.com>
Authored: Thu Feb 5 17:59:04 2015 +0300
Committer: sboikov <sboikov@gridgain.com>
Committed: Thu Feb 5 18:03:04 2015 +0300

----------------------------------------------------------------------
 .../apache/ignite/cache/CacheProjection.java    |  15 +-
 .../swapspace/GridSwapSpaceManager.java         |  17 ++
 .../processors/cache/GridCacheAdapter.java      | 237 +++++++++++++++-
 .../cache/GridCacheProjectionImpl.java          |  15 +
 .../processors/cache/GridCacheProxyImpl.java    |  36 +++
 .../processors/cache/GridCacheSwapManager.java  |  46 ++++
 .../processors/cache/IgniteCacheProxy.java      |  12 +-
 .../offheap/GridOffHeapProcessor.java           |  15 +
 .../util/offheap/GridOffHeapPartitionedMap.java |  11 +
 .../unsafe/GridUnsafePartitionedMap.java        |  10 +
 .../ignite/spi/swapspace/SwapSpaceSpi.java      |  11 +
 .../spi/swapspace/file/FileSwapSpaceSpi.java    |  27 ++
 .../spi/swapspace/noop/NoopSwapSpaceSpi.java    |   5 +
 .../cache/IgniteCacheAtomicLocalSizeTest.java   |  43 +++
 .../IgniteCacheAtomicReplicatedSizeTest.java    |  32 +++
 .../cache/IgniteCacheAtomicSizeTest.java        |  49 ++++
 .../cache/IgniteCachePeekAbstractTest.java      |   6 +-
 .../cache/IgniteCacheSizeAbstractTest.java      | 274 +++++++++++++++++++
 .../cache/IgniteCacheTxLocalSizeTest.java       |  43 +++
 .../cache/IgniteCacheTxReplicatedSizeTest.java  |  32 +++
 .../processors/cache/IgniteCacheTxSizeTest.java |  49 ++++
 .../inmemory/GridTestSwapSpaceSpi.java          |  41 +++
 .../ignite/testsuites/IgniteCacheTestSuite.java |   7 +
 23 files changed, 1015 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/20f93d6c/modules/core/src/main/java/org/apache/ignite/cache/CacheProjection.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/CacheProjection.java b/modules/core/src/main/java/org/apache/ignite/cache/CacheProjection.java
index 1c30f7b..9049807 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/CacheProjection.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/CacheProjection.java
@@ -1865,7 +1865,20 @@ public interface CacheProjection<K, V> extends Iterable<CacheEntry<K, V>> {
      * @return Local cache size.
      * @throws IgniteCheckedException If failed.
      */
-    public int localSize(CachePeekMode... peekModes) throws IgniteCheckedException;
+    public int localSize(CachePeekMode[] peekModes) throws IgniteCheckedException;
+
+    /**
+     * @param peekModes Peek modes.
+     * @return Global cache size.
+     * @throws IgniteCheckedException If failed.
+     */
+    public int size(CachePeekMode[] peekModes) throws IgniteCheckedException;
+
+    /**
+     * @param peekModes Peek modes.
+     * @return Future.
+     */
+    public IgniteInternalFuture<Integer> sizeAsync(CachePeekMode[] peekModes);
 
     /**
      * Gets the number of all entries cached across all nodes.

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/20f93d6c/modules/core/src/main/java/org/apache/ignite/internal/managers/swapspace/GridSwapSpaceManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/swapspace/GridSwapSpaceManager.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/swapspace/GridSwapSpaceManager.java
index e97cbc1..84e3588 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/swapspace/GridSwapSpaceManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/swapspace/GridSwapSpaceManager.java
@@ -322,6 +322,23 @@ public class GridSwapSpaceManager extends GridManagerAdapter<SwapSpaceSpi> {
     }
 
     /**
+     * Gets number of swap entries for given partitions.
+     *
+     * @param spaceName Space name.
+     * @param parts Partitions.
+     * @return Number of swap entries for given partitions.
+     * @throws IgniteCheckedException If failed.
+     */
+    public long swapKeys(@Nullable String spaceName, Set<Integer> parts) throws IgniteCheckedException {
+        try {
+            return getSpi().count(spaceName, parts);
+        }
+        catch (IgniteSpiException e) {
+            throw new IgniteCheckedException("Failed to get swap keys count for space: " + spaceName, e);
+        }
+    }
+
+    /**
      * @param spaceName Space name.
      * @throws IgniteCheckedException If failed.
      */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/20f93d6c/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 581a6e6..abd5360 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
@@ -4079,16 +4079,163 @@ public abstract class GridCacheAdapter<K, V> implements GridCache<K, V>,
     }
 
     /** {@inheritDoc} */
-    @Override public int localSize(CachePeekMode... peekModes) throws IgniteCheckedException {
-        boolean primary;
-        boolean backup;
-        boolean near;
+    @Override public int size(CachePeekMode[] peekModes) throws IgniteCheckedException {
+        if (isLocal())
+            return localSize(peekModes);
 
-        boolean heap;
-        boolean offheap;
-        boolean swap;
+        return sizeAsync(peekModes).get();
+    }
 
-        return 0;
+    /** {@inheritDoc} */
+    @Override public IgniteInternalFuture<Integer> sizeAsync(CachePeekMode[] peekModes) {
+        assert peekModes != null;
+
+        Collection<ClusterNode> nodes = ctx.grid().forDataNodes(name()).nodes();
+
+        if (nodes.isEmpty())
+            return new GridFinishedFuture<>(ctx.kernalContext(), 0);
+
+        IgniteInternalFuture<Collection<Integer>> fut =
+            ctx.closures().broadcastNoFailover(new SizeCallable(ctx.name(), peekModes), null, nodes);
+
+        return fut.chain(new CX1<IgniteInternalFuture<Collection<Integer>>, Integer>() {
+            @Override public Integer applyx(IgniteInternalFuture<Collection<Integer>> fut) throws IgniteCheckedException {
+                Collection<Integer> res = fut.get();
+
+                int totalSize = 0;
+
+                for (Integer size : res)
+                    totalSize += size;
+
+                return totalSize;
+            }
+        });
+    }
+
+    /** {@inheritDoc} */
+    @SuppressWarnings("ForLoopReplaceableByForEach")
+    @Override public int localSize(CachePeekMode[] peekModes) throws IgniteCheckedException {
+        assert peekModes != null;
+
+        boolean near = false;
+        boolean primary = false;
+        boolean backup = false;
+
+        boolean heap = false;
+        boolean offheap = false;
+        boolean swap = false;
+
+        if (peekModes.length == 0) {
+            near = true;
+            primary = true;
+            backup = true;
+
+            heap = true;
+            offheap = true;
+            swap = true;
+        }
+        else {
+            for (int i = 0; i < peekModes.length; i++) {
+                CachePeekMode peekMode = peekModes[i];
+
+                A.notNull(peekMode, "peekMode");
+
+                switch (peekMode) {
+                    case ALL:
+                        near = true;
+                        primary = true;
+                        backup = true;
+
+                        heap = true;
+                        offheap = true;
+                        swap = true;
+
+                        break;
+
+                    case BACKUP:
+                        backup = true;
+
+                        break;
+
+                    case PRIMARY:
+                        primary = true;
+
+                        break;
+
+                    case NEAR:
+                        near = true;
+
+                        break;
+
+                    case ONHEAP:
+                        heap = true;
+
+                        break;
+
+                    case OFFHEAP:
+                        offheap = true;
+
+                        break;
+
+                    case SWAP:
+                        swap = true;
+
+                        break;
+
+                    default:
+                        assert false : peekMode;
+                }
+            }
+        }
+
+        if (!(heap || offheap || swap)) {
+            heap = true;
+            offheap = true;
+            swap = true;
+        }
+
+        if (!(primary || backup || near)) {
+            primary = true;
+            backup = true;
+            near = true;
+        }
+
+        assert heap || offheap || swap;
+        assert primary || backup || near;
+
+        int size = 0;
+
+        if (heap) {
+            if (near)
+                size += nearSize();
+
+            GridCacheAdapter cache = ctx.isNear() ? ctx.near().dht() : ctx.cache();
+
+            if (!(primary && backup)) {
+                if (primary)
+                    size += cache.primarySize();
+
+                if (backup)
+                    size += (cache.size() - cache.primarySize());
+            }
+            else
+                size += cache.size();
+        }
+
+        // Swap and offheap are disabled for near cache.
+        if (primary || backup) {
+            long topVer = ctx.affinity().affinityTopologyVersion();
+
+            GridCacheSwapManager<K, V> swapMgr = ctx.isNear() ? ctx.near().dht().context().swap() : ctx.swap();
+
+            if (swap)
+                size += swapMgr.swapEntriesCount(primary, backup, topVer);
+
+            if (offheap)
+                size += swapMgr.offheapEntriesCount(primary, backup, topVer);
+        }
+
+        return size;
     }
 
     /** {@inheritDoc} */
@@ -5460,7 +5607,79 @@ public abstract class GridCacheAdapter<K, V> implements GridCache<K, V>,
     }
 
     /**
-     * Internal callable which performs {@link org.apache.ignite.cache.CacheProjection#size()} or {@link org.apache.ignite.cache.CacheProjection#primarySize()}
+     * Internal callable for global size calculation.
+     */
+    @GridInternal
+    private static class SizeCallable extends IgniteClosureX<Object, Integer> implements Externalizable {
+        /** */
+        private static final long serialVersionUID = 0L;
+
+        /** Cache name. */
+        private String cacheName;
+
+        /** Peek modes. */
+        private CachePeekMode[] peekModes;
+
+        /** Injected grid instance. */
+        @IgniteInstanceResource
+        private Ignite ignite;
+
+        /**
+         * Required by {@link Externalizable}.
+         */
+        public SizeCallable() {
+            // No-op.
+        }
+
+        /**
+         * @param cacheName Cache name.
+         * @param peekModes Cache peek modes.
+         */
+        private SizeCallable(String cacheName, CachePeekMode[] peekModes) {
+            this.cacheName = cacheName;
+            this.peekModes = peekModes;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Integer applyx(Object o) throws IgniteCheckedException {
+            GridCache<Object, Object> cache = ((IgniteEx)ignite).cachex(cacheName);
+
+            assert cache != null : cacheName;
+
+            return cache.localSize(peekModes);
+        }
+
+        /** {@inheritDoc} */
+        @SuppressWarnings("ForLoopReplaceableByForEach")
+        @Override public void writeExternal(ObjectOutput out) throws IOException {
+            U.writeString(out, cacheName);
+
+            out.writeInt(peekModes.length);
+
+            for (int i = 0; i < peekModes.length; i++)
+                U.writeEnum(out, peekModes[i]);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+            cacheName = U.readString(in);
+
+            int len = in.readInt();
+
+            peekModes = new CachePeekMode[len];
+
+            for (int i = 0; i < len; i++)
+                peekModes[i] = CachePeekMode.fromOrdinal(in.readByte());
+        }
+
+        /** {@inheritDoc} */
+        public String toString() {
+            return S.toString(SizeCallable.class, this);
+        }
+    }
+
+    /**
+     * Internal callable which performs {@link CacheProjection#size()} or {@link CacheProjection#primarySize()}
      * operation on a cache with the given name.
      */
     @GridInternal

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/20f93d6c/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProjectionImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProjectionImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProjectionImpl.java
index 241c3c7..5ed1b7d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProjectionImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProjectionImpl.java
@@ -585,6 +585,21 @@ public class GridCacheProjectionImpl<K, V> implements GridCacheProjectionEx<K, V
     }
 
     /** {@inheritDoc} */
+    @Override public int localSize(CachePeekMode[] peekModes) throws IgniteCheckedException {
+        return cache.localSize(peekModes);
+    }
+
+    /** {@inheritDoc} */
+    @Override public int size(CachePeekMode[] peekModes) throws IgniteCheckedException {
+        return cache.size(peekModes);
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteInternalFuture<Integer> sizeAsync(CachePeekMode[] peekModes) {
+        return cache.sizeAsync(peekModes);
+    }
+
+    /** {@inheritDoc} */
     @Override public int globalSize() throws IgniteCheckedException {
         return cache.globalSize();
     }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/20f93d6c/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProxyImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProxyImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProxyImpl.java
index 6fba463..81617d4 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProxyImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProxyImpl.java
@@ -1714,6 +1714,42 @@ public class GridCacheProxyImpl<K, V> implements GridCacheProxy<K, V>, Externali
     }
 
     /** {@inheritDoc} */
+    @Override public int size(CachePeekMode[] peekModes) throws IgniteCheckedException {
+        GridCacheProjectionImpl<K, V> prev = gate.enter(prj);
+
+        try {
+            return delegate.size(peekModes);
+        }
+        finally {
+            gate.leave(prev);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteInternalFuture<Integer> sizeAsync(CachePeekMode[] peekModes) {
+        GridCacheProjectionImpl<K, V> prev = gate.enter(prj);
+
+        try {
+            return delegate.sizeAsync(peekModes);
+        }
+        finally {
+            gate.leave(prev);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public int localSize(CachePeekMode[] peekModes) throws IgniteCheckedException {
+        GridCacheProjectionImpl<K, V> prev = gate.enter(prj);
+
+        try {
+            return delegate.localSize(peekModes);
+        }
+        finally {
+            gate.leave(prev);
+        }
+    }
+
+    /** {@inheritDoc} */
     @Override public int globalSize() throws IgniteCheckedException {
         GridCacheProjectionImpl<K, V> prev = gate.enter(prj);
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/20f93d6c/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java
index a0b1ecb..419fdf5 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java
@@ -171,6 +171,52 @@ public class GridCacheSwapManager<K, V> extends GridCacheManagerAdapter<K, V> {
     }
 
     /**
+     * @param primary If {@code true} includes primary entries.
+     * @param backup If {@code true} includes backup entries.
+     * @param topVer Topology version.
+     * @return Number of swap entries.
+     * @throws IgniteCheckedException If failed.
+     */
+    public int swapEntriesCount(boolean primary, boolean backup, long topVer) throws IgniteCheckedException {
+        assert primary || backup;
+
+        if (!swapEnabled)
+            return 0;
+
+        if (!(primary && backup)) {
+            Set<Integer> parts = primary ? cctx.affinity().primaryPartitions(cctx.localNodeId(), topVer) :
+                cctx.affinity().backupPartitions(cctx.localNodeId(), topVer);
+
+            return (int)swapMgr.swapKeys(spaceName, parts);
+        }
+        else
+            return (int)swapMgr.swapKeys(spaceName);
+    }
+
+    /**
+     * @param primary If {@code true} includes primary entries.
+     * @param backup If {@code true} includes backup entries.
+     * @param topVer Topology version.
+     * @return Number of offheap entries.
+     * @throws IgniteCheckedException If failed.
+     */
+    public int offheapEntriesCount(boolean primary, boolean backup, long topVer) throws IgniteCheckedException {
+        assert primary || backup;
+
+        if (!offheapEnabled)
+            return 0;
+
+        if (!(primary && backup)) {
+            Set<Integer> parts = primary ? cctx.affinity().primaryPartitions(cctx.localNodeId(), topVer) :
+                cctx.affinity().backupPartitions(cctx.localNodeId(), topVer);
+
+            return (int)offheap.entriesCount(spaceName, parts);
+        }
+        else
+            return (int)offheap.entriesCount(spaceName);
+    }
+
+    /**
      * Gets number of swap entries (keys).
      *
      * @return Swap keys count.

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/20f93d6c/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
index 093f17b..e022a94 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
@@ -303,14 +303,16 @@ public class IgniteCacheProxy<K, V> extends IgniteAsyncSupportAdapter<IgniteCach
 
     /** {@inheritDoc} */
     @Override public int size(CachePeekMode... peekModes) throws CacheException {
-        // TODO IGNITE-1.
-        if (peekModes.length != 0)
-            throw new UnsupportedOperationException();
-
         GridCacheProjectionImpl<K, V> prev = gate.enter(prj);
 
         try {
-            return ctx.cache().globalSize();
+            if (isAsync()) {
+                setFuture(delegate.sizeAsync(peekModes));
+
+                return 0;
+            }
+            else
+                return delegate.size(peekModes);
         }
         catch (IgniteCheckedException e) {
             throw cacheException(e);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/20f93d6c/modules/core/src/main/java/org/apache/ignite/internal/processors/offheap/GridOffHeapProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/offheap/GridOffHeapProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/offheap/GridOffHeapProcessor.java
index 5e0e559..1238171 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/offheap/GridOffHeapProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/offheap/GridOffHeapProcessor.java
@@ -30,6 +30,8 @@ import org.apache.ignite.marshaller.*;
 import org.jdk8.backport.*;
 import org.jetbrains.annotations.*;
 
+import java.util.*;
+
 /**
  * Manages offheap memory caches.
  */
@@ -300,6 +302,19 @@ public class GridOffHeapProcessor extends GridProcessorAdapter {
     }
 
     /**
+     * Gets number of elements in the given space.
+     *
+     * @param spaceName Space name. Optional.
+     * @param parts Partitions.
+     * @return Number of elements or {@code -1} if no space with the given name has been found.
+     */
+    public long entriesCount(@Nullable String spaceName, Set<Integer> parts) {
+        GridOffHeapPartitionedMap m = offheap(spaceName);
+
+        return m == null ? -1 : m.size(parts);
+    }
+
+    /**
      * Gets size of a memory allocated for the entries of the given space.
      *
      * @param spaceName Space name. Optional.

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/20f93d6c/modules/core/src/main/java/org/apache/ignite/internal/util/offheap/GridOffHeapPartitionedMap.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/offheap/GridOffHeapPartitionedMap.java b/modules/core/src/main/java/org/apache/ignite/internal/util/offheap/GridOffHeapPartitionedMap.java
index 06a83a7..49850ab 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/offheap/GridOffHeapPartitionedMap.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/offheap/GridOffHeapPartitionedMap.java
@@ -22,6 +22,8 @@ import org.apache.ignite.internal.util.typedef.*;
 import org.apache.ignite.lang.*;
 import org.jetbrains.annotations.*;
 
+import java.util.*;
+
 /**
  * Off-heap map.
  */
@@ -141,6 +143,15 @@ public interface GridOffHeapPartitionedMap {
      */
     public long size();
 
+
+    /**
+     * Gets number of elements in the map.
+     *
+     * @param parts Partitions.
+     * @return Number of elements in the map.
+     */
+    public long size(Set<Integer> parts);
+
     /**
      * Gets total available memory size.
      *

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/20f93d6c/modules/core/src/main/java/org/apache/ignite/internal/util/offheap/unsafe/GridUnsafePartitionedMap.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/offheap/unsafe/GridUnsafePartitionedMap.java b/modules/core/src/main/java/org/apache/ignite/internal/util/offheap/unsafe/GridUnsafePartitionedMap.java
index 343c08b..4d4ba61 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/offheap/unsafe/GridUnsafePartitionedMap.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/offheap/unsafe/GridUnsafePartitionedMap.java
@@ -209,6 +209,16 @@ public class GridUnsafePartitionedMap implements GridOffHeapPartitionedMap {
     }
 
     /** {@inheritDoc} */
+    @Override public long size(Set<Integer> parts) {
+        int cnt = 0;
+
+        for (Integer part : parts)
+            cnt += mapFor(part).size();
+
+        return cnt;
+    }
+
+    /** {@inheritDoc} */
     @Override public long memorySize() {
         return mem.totalSize();
     }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/20f93d6c/modules/core/src/main/java/org/apache/ignite/spi/swapspace/SwapSpaceSpi.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/swapspace/SwapSpaceSpi.java b/modules/core/src/main/java/org/apache/ignite/spi/swapspace/SwapSpaceSpi.java
index 0277407..7ff51cf 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/swapspace/SwapSpaceSpi.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/swapspace/SwapSpaceSpi.java
@@ -82,6 +82,17 @@ public interface SwapSpaceSpi extends IgniteSpi {
     public long count(@Nullable String spaceName) throws IgniteSpiException;
 
     /**
+     * Gets number of stored entries (keys) in data space with given name. If specified
+     * space does not exist this method returns {@code 0}.
+     *
+     * @param spaceName Space name to get number of entries for.
+     * @param parts Partitions.
+     * @return Number of stored entries in specified space.
+     * @throws org.apache.ignite.spi.IgniteSpiException In case of any errors.
+     */
+    public long count(@Nullable String spaceName, Set<Integer> parts) throws IgniteSpiException;
+
+    /**
      * Reads stored value as array of bytes by key from data space with given name.
      * If specified space does not exist this method returns {@code null}.
      *

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/20f93d6c/modules/core/src/main/java/org/apache/ignite/spi/swapspace/file/FileSwapSpaceSpi.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/swapspace/file/FileSwapSpaceSpi.java b/modules/core/src/main/java/org/apache/ignite/spi/swapspace/file/FileSwapSpaceSpi.java
index fd7048d..cab688a 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/swapspace/file/FileSwapSpaceSpi.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/swapspace/file/FileSwapSpaceSpi.java
@@ -325,6 +325,16 @@ public class FileSwapSpaceSpi extends IgniteSpiAdapter implements SwapSpaceSpi,
     }
 
     /** {@inheritDoc} */
+    @Override public long count(@Nullable String spaceName, Set<Integer> parts) throws IgniteSpiException {
+        Space space = space(spaceName, false);
+
+        if (space == null)
+            return 0;
+
+        return space.count(parts);
+    }
+
+    /** {@inheritDoc} */
     @Nullable @Override public byte[] read(@Nullable String spaceName, SwapKey key, SwapContext ctx)
         throws IgniteSpiException {
         assert key != null;
@@ -1529,6 +1539,23 @@ public class FileSwapSpaceSpi extends IgniteSpiAdapter implements SwapSpaceSpi,
         }
 
         /**
+         * @param parts Partitions.
+         * @return Total count of keys for given partitions.
+         */
+        public long count(Set<Integer> parts) {
+            long cnt = 0;
+
+            for (Integer part : parts) {
+                ConcurrentMap<SwapKey, SwapValue> map = partition(part, false);
+
+                if (map != null)
+                    cnt += map.size();
+            }
+
+            return cnt;
+        }
+
+        /**
          * Clears space.
          *
          * @throws org.apache.ignite.spi.IgniteSpiException If failed.

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/20f93d6c/modules/core/src/main/java/org/apache/ignite/spi/swapspace/noop/NoopSwapSpaceSpi.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/swapspace/noop/NoopSwapSpaceSpi.java b/modules/core/src/main/java/org/apache/ignite/spi/swapspace/noop/NoopSwapSpaceSpi.java
index 008e2c1..9c7fd94 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/swapspace/noop/NoopSwapSpaceSpi.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/swapspace/noop/NoopSwapSpaceSpi.java
@@ -64,6 +64,11 @@ public class NoopSwapSpaceSpi extends IgniteSpiAdapter implements SwapSpaceSpi {
     }
 
     /** {@inheritDoc} */
+    @Override public long count(@Nullable String spaceName, Set<Integer> parts) throws IgniteSpiException {
+        return 0;
+    }
+
+    /** {@inheritDoc} */
     @Override @Nullable public byte[] read(@Nullable String spaceName, SwapKey key, SwapContext ctx)
         throws IgniteSpiException {
         return null;

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/20f93d6c/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicLocalSizeTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicLocalSizeTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicLocalSizeTest.java
new file mode 100644
index 0000000..aaf5a5a
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicLocalSizeTest.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache;
+
+import org.apache.ignite.cache.*;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.*;
+import static org.apache.ignite.cache.CacheMode.*;
+
+/**
+ *
+ */
+public class IgniteCacheAtomicLocalSizeTest extends IgniteCacheSizeAbstractTest {
+    /** {@inheritDoc} */
+    @Override protected CacheAtomicityMode atomicityMode() {
+        return ATOMIC;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected int gridCount() {
+        return 1;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheMode cacheMode() {
+        return LOCAL;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/20f93d6c/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicReplicatedSizeTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicReplicatedSizeTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicReplicatedSizeTest.java
new file mode 100644
index 0000000..f4b466a
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicReplicatedSizeTest.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache;
+
+import org.apache.ignite.cache.*;
+
+import static org.apache.ignite.cache.CacheMode.*;
+
+/**
+ *
+ */
+public class IgniteCacheAtomicReplicatedSizeTest extends IgniteCacheAtomicSizeTest {
+    /** {@inheritDoc} */
+    @Override protected CacheMode cacheMode() {
+        return REPLICATED;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/20f93d6c/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicSizeTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicSizeTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicSizeTest.java
new file mode 100644
index 0000000..62b52ff
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAtomicSizeTest.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache;
+
+import org.apache.ignite.cache.*;
+
+import static org.apache.ignite.cache.CacheAtomicWriteOrderMode.*;
+import static org.apache.ignite.cache.CacheAtomicityMode.*;
+import static org.apache.ignite.cache.CacheMode.*;
+
+/**
+ *
+ */
+public class IgniteCacheAtomicSizeTest extends IgniteCacheSizeAbstractTest {
+    /** {@inheritDoc} */
+    @Override protected CacheAtomicityMode atomicityMode() {
+        return ATOMIC;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected int gridCount() {
+        return 4;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheMode cacheMode() {
+        return PARTITIONED;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheAtomicWriteOrderMode atomicWriteOrderMode() {
+        return PRIMARY;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/20f93d6c/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePeekAbstractTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePeekAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePeekAbstractTest.java
index 006cb8b..80fec09 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePeekAbstractTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePeekAbstractTest.java
@@ -24,7 +24,7 @@ import org.apache.ignite.cache.eviction.fifo.*;
 import org.apache.ignite.configuration.*;
 import org.apache.ignite.internal.*;
 import org.apache.ignite.spi.*;
-import org.apache.ignite.spi.swapspace.inmemory.*;
+import org.apache.ignite.spi.swapspace.file.*;
 
 import java.util.*;
 
@@ -43,7 +43,7 @@ public abstract class IgniteCachePeekAbstractTest extends IgniteCacheAbstractTes
     @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
         IgniteConfiguration cfg = super.getConfiguration(gridName);
 
-        cfg.setSwapSpaceSpi(new GridTestSwapSpaceSpi());
+        cfg.setSwapSpaceSpi(new FileSwapSpaceSpi());
 
         return cfg;
     }
@@ -215,7 +215,7 @@ public abstract class IgniteCachePeekAbstractTest extends IgniteCacheAbstractTes
             for (Integer key : keys)
                 cache0.put(key, val);
 
-            GridTestSwapSpaceSpi swap = (GridTestSwapSpaceSpi)ignite(nodeIdx).configuration().getSwapSpaceSpi();
+            FileSwapSpaceSpi swap = (FileSwapSpaceSpi)ignite(nodeIdx).configuration().getSwapSpaceSpi();
 
             Set<Integer> swapKeys = new HashSet<>();
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/20f93d6c/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheSizeAbstractTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheSizeAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheSizeAbstractTest.java
new file mode 100644
index 0000000..35c3c86
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheSizeAbstractTest.java
@@ -0,0 +1,274 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache;
+
+import org.apache.ignite.*;
+import org.apache.ignite.cache.*;
+import org.apache.ignite.cache.affinity.*;
+import org.apache.ignite.cache.eviction.fifo.*;
+import org.apache.ignite.cluster.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.spi.swapspace.file.*;
+
+import java.util.*;
+
+import static org.apache.ignite.cache.CacheDistributionMode.*;
+import static org.apache.ignite.cache.CacheMode.*;
+import static org.apache.ignite.cache.CachePeekMode.*;
+
+/**
+ *
+ */
+public abstract class IgniteCacheSizeAbstractTest extends IgniteCacheAbstractTest {
+    /** */
+    private static final int HEAP_ENTRIES = 10;
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        cfg.setSwapSpaceSpi(new FileSwapSpaceSpi());
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheDistributionMode distributionMode() {
+        return PARTITIONED_ONLY;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheConfiguration cacheConfiguration(String gridName) throws Exception {
+        CacheConfiguration ccfg = super.cacheConfiguration(gridName);
+
+        ccfg.setMemoryMode(CacheMemoryMode.ONHEAP_TIERED);
+
+        ccfg.setOffHeapMaxMemory(512);
+
+        ccfg.setBackups(1);
+
+        if (gridName.equals(getTestGridName(0)))
+            ccfg.setDistributionMode(NEAR_PARTITIONED);
+
+        ccfg.setEvictionPolicy(new CacheFifoEvictionPolicy(HEAP_ENTRIES));
+
+        return ccfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected boolean swapEnabled() {
+        return true;
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testSize() throws Exception {
+        for (int i = 0; i < gridCount(); i++) {
+            IgniteCache<Integer, String> cache = jcache(i);
+
+            assertEquals(0, cache.localSize());
+
+            assertEquals(0, cache.size());
+
+            for (CachePeekMode peekMode : CachePeekMode.values()) {
+                assertEquals(0, cache.localSize(peekMode));
+
+                assertEquals(0, cache.size(peekMode));
+            }
+        }
+
+        if (cacheMode() == LOCAL) {
+            IgniteCache<Integer, String> cache0 = jcache(0);
+
+            IgniteCache<Integer, String> cacheAsync0 = cache0.withAsync();
+
+            for (int i = 0; i < HEAP_ENTRIES; i++) {
+                cache0.put(i, String.valueOf(i));
+
+                final int size = i + 1;
+
+                assertEquals(size, cache0.localSize());
+                assertEquals(size, cache0.localSize(PRIMARY));
+                assertEquals(size, cache0.localSize(BACKUP));
+                assertEquals(size, cache0.localSize(NEAR));
+                assertEquals(size, cache0.localSize(ALL));
+
+                assertEquals(size, cache0.size());
+                assertEquals(size, cache0.size(PRIMARY));
+                assertEquals(size, cache0.size(BACKUP));
+                assertEquals(size, cache0.size(NEAR));
+                assertEquals(size, cache0.size(ALL));
+
+                cacheAsync0.size();
+
+                assertEquals(size, cacheAsync0.future().get());
+
+                cacheAsync0.size(PRIMARY);
+
+                assertEquals(size, cacheAsync0.future().get());
+            }
+        }
+        else {
+            checkSizeAffinityFilter(0);
+
+            checkSizeAffinityFilter(1);
+        }
+    }
+
+    /**
+     * @param nodeIdx Node index.
+     * @throws Exception If failed.
+     */
+    private void checkSizeAffinityFilter(int nodeIdx) throws Exception {
+        IgniteCache<Integer, String> cache0 = jcache(nodeIdx);
+
+        final int PUT_KEYS = 10;
+
+        List<Integer> keys = null;
+
+        try {
+            if (cacheMode() == REPLICATED) {
+                keys = backupKeys(cache0, 10, 0);
+
+                for (Integer key : keys)
+                    cache0.put(key, String.valueOf(key));
+
+                assertEquals(PUT_KEYS, cache0.localSize());
+                assertEquals(PUT_KEYS, cache0.localSize(BACKUP));
+                assertEquals(PUT_KEYS, cache0.localSize(ALL));
+                assertEquals(0, cache0.localSize(PRIMARY));
+                assertEquals(0, cache0.localSize(NEAR));
+
+                for (int i = 0; i < gridCount(); i++) {
+                    IgniteCache<Integer, String> cache = jcache(i);
+
+                    assertEquals(0, cache.size(NEAR));
+                    assertEquals(PUT_KEYS, cache.size(PRIMARY));
+                    assertEquals(PUT_KEYS * (gridCount() - 1), cache.size(BACKUP));
+                    assertEquals(PUT_KEYS * gridCount(), cache.size(PRIMARY, BACKUP));
+                    assertEquals(PUT_KEYS * gridCount(), cache.size()); // Primary + backups.
+                }
+            }
+            else {
+                keys = nearKeys(cache0, PUT_KEYS, 0);
+
+                for (Integer key : keys)
+                    cache0.put(key, String.valueOf(key));
+
+                boolean hasNearCache = nodeIdx == 0 ;
+
+                if (hasNearCache) {
+                    assertEquals(PUT_KEYS, cache0.localSize());
+                    assertEquals(PUT_KEYS, cache0.localSize(ALL));
+                    assertEquals(PUT_KEYS, cache0.localSize(NEAR));
+
+                    for (int i = 0; i < gridCount(); i++) {
+                        IgniteCache<Integer, String> cache = jcache(i);
+
+                        assertEquals(PUT_KEYS, cache.size(NEAR));
+                        assertEquals(PUT_KEYS, cache.size(BACKUP));
+                        assertEquals(PUT_KEYS * 2, cache.size(PRIMARY, BACKUP));
+                        assertEquals(PUT_KEYS * 2 + PUT_KEYS, cache.size()); // Primary + backups + near.
+                    }
+                }
+                else {
+                    assertEquals(0, cache0.localSize());
+                    assertEquals(0, cache0.localSize(ALL));
+                    assertEquals(0, cache0.localSize(NEAR));
+
+                    for (int i = 0; i < gridCount(); i++) {
+                        IgniteCache<Integer, String> cache = jcache(i);
+
+                        assertEquals(0, cache.size(NEAR));
+                        assertEquals(PUT_KEYS, cache.size(BACKUP));
+                        assertEquals(PUT_KEYS * 2, cache.size(PRIMARY, BACKUP));
+                        assertEquals(PUT_KEYS * 2, cache.size()); // Primary + backups.
+                    }
+                }
+
+                assertEquals(0, cache0.localSize(BACKUP));
+                assertEquals(0, cache0.localSize(PRIMARY));
+            }
+
+            checkPrimarySize(PUT_KEYS);
+
+            CacheAffinity<Integer> aff = ignite(0).affinity(null);
+
+            for (int i = 0; i < gridCount(); i++) {
+                if (i == nodeIdx)
+                    continue;
+
+                ClusterNode node = ignite(i).cluster().localNode();
+
+                int primary = 0;
+                int backups = 0;
+
+                for (Integer key : keys) {
+                    if (aff.isPrimary(node, key))
+                        primary++;
+                    else if (aff.isBackup(node, key))
+                        backups++;
+                }
+
+                IgniteCache<Integer, String> cache = jcache(i);
+
+                assertEquals(primary, cache.localSize(PRIMARY));
+                assertEquals(backups, cache.localSize(BACKUP));
+                assertEquals(primary + backups, cache.localSize(PRIMARY, BACKUP));
+                assertEquals(primary + backups, cache.localSize(BACKUP, PRIMARY));
+                assertEquals(primary + backups, cache.localSize(ALL));
+            }
+        }
+        finally {
+            if (keys != null)
+                cache0.removeAll(new HashSet<>(keys));
+        }
+    }
+
+    /**
+     * @param nodeIdx Node index.
+     * @throws Exception If failed.
+     */
+    private void checkSizeStorageFilter(int nodeIdx) throws Exception {
+
+    }
+
+    /**
+     * @param exp Expected size.
+     */
+    private void checkPrimarySize(int exp) {
+        int size = 0;
+
+        for (int i = 0; i < gridCount(); i++) {
+            IgniteCache<Integer, String> cache = jcache(i);
+
+            IgniteCache<Integer, String> cacheAsync = cache.withAsync();
+
+            assertEquals(exp, cache.size(PRIMARY));
+
+            size += cache.localSize(PRIMARY);
+
+            cacheAsync.size(PRIMARY);
+
+            assertEquals(exp, cacheAsync.future().get());
+        }
+
+        assertEquals(exp, size);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/20f93d6c/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTxLocalSizeTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTxLocalSizeTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTxLocalSizeTest.java
new file mode 100644
index 0000000..5b0ddf7
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTxLocalSizeTest.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache;
+
+import org.apache.ignite.cache.*;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.*;
+import static org.apache.ignite.cache.CacheMode.*;
+
+/**
+ *
+ */
+public class IgniteCacheTxLocalSizeTest extends IgniteCacheSizeAbstractTest {
+    /** {@inheritDoc} */
+    @Override protected CacheAtomicityMode atomicityMode() {
+        return TRANSACTIONAL;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected int gridCount() {
+        return 1;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheMode cacheMode() {
+        return LOCAL;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/20f93d6c/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTxReplicatedSizeTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTxReplicatedSizeTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTxReplicatedSizeTest.java
new file mode 100644
index 0000000..a971bb8
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTxReplicatedSizeTest.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache;
+
+import org.apache.ignite.cache.*;
+
+import static org.apache.ignite.cache.CacheMode.*;
+
+/**
+ *
+ */
+public class IgniteCacheTxReplicatedSizeTest extends IgniteCacheTxSizeTest {
+    /** {@inheritDoc} */
+    @Override protected CacheMode cacheMode() {
+        return REPLICATED;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/20f93d6c/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTxSizeTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTxSizeTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTxSizeTest.java
new file mode 100644
index 0000000..70ff8b5
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTxSizeTest.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache;
+
+import org.apache.ignite.cache.*;
+
+import static org.apache.ignite.cache.CacheAtomicWriteOrderMode.*;
+import static org.apache.ignite.cache.CacheAtomicityMode.*;
+import static org.apache.ignite.cache.CacheMode.*;
+
+/**
+ *
+ */
+public class IgniteCacheTxSizeTest extends IgniteCacheSizeAbstractTest {
+    /** {@inheritDoc} */
+    @Override protected CacheAtomicityMode atomicityMode() {
+        return TRANSACTIONAL;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected int gridCount() {
+        return 4;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheMode cacheMode() {
+        return PARTITIONED;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheAtomicWriteOrderMode atomicWriteOrderMode() {
+        return PRIMARY;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/20f93d6c/modules/core/src/test/java/org/apache/ignite/spi/swapspace/inmemory/GridTestSwapSpaceSpi.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/spi/swapspace/inmemory/GridTestSwapSpaceSpi.java b/modules/core/src/test/java/org/apache/ignite/spi/swapspace/inmemory/GridTestSwapSpaceSpi.java
index 5545848..456b277 100644
--- a/modules/core/src/test/java/org/apache/ignite/spi/swapspace/inmemory/GridTestSwapSpaceSpi.java
+++ b/modules/core/src/test/java/org/apache/ignite/spi/swapspace/inmemory/GridTestSwapSpaceSpi.java
@@ -73,6 +73,13 @@ public class GridTestSwapSpaceSpi extends IgniteSpiAdapter implements SwapSpaceS
     }
 
     /** {@inheritDoc} */
+    @Override public long count(@Nullable String spaceName, Set<Integer> parts) throws IgniteSpiException {
+        Space space = space(spaceName);
+
+        return space.count(parts);
+    }
+
+    /** {@inheritDoc} */
     @Override public byte[] read(@Nullable String spaceName, SwapKey key, SwapContext ctx)
         throws IgniteSpiException {
         Space space = space(spaceName);
@@ -171,6 +178,11 @@ public class GridTestSwapSpaceSpi extends IgniteSpiAdapter implements SwapSpaceS
         return space;
     }
 
+    /**
+     * @param evtType Event type.
+     * @param spaceName Space name.
+     * @param key Key bytes.
+     */
     private void fireEvent(int evtType, String spaceName, @Nullable byte[] key) {
         SwapSpaceSpiListener lsnr0 = lsnr;
 
@@ -178,10 +190,14 @@ public class GridTestSwapSpaceSpi extends IgniteSpiAdapter implements SwapSpaceS
             lsnr0.onSwapEvent(evtType, spaceName, key);
     }
 
+    /**
+     *
+     */
     private class Space {
         /** Data storage. */
         private ConcurrentMap<SwapKey, byte[]> data = new ConcurrentHashMap8<>();
 
+        /** */
         private final String name;
 
         /**
@@ -215,6 +231,21 @@ public class GridTestSwapSpaceSpi extends IgniteSpiAdapter implements SwapSpaceS
         }
 
         /**
+         * @param parts Partitions.
+         * @return Number of entries for given partitions.
+         */
+        public long count(Set<Integer> parts) {
+            int cnt = 0;
+
+            for (SwapKey key : data.keySet()) {
+                if (parts.contains(key.partition()))
+                    cnt++;
+            }
+
+            return cnt;
+        }
+
+        /**
          * @param key Key to read.
          * @return Read bytes.
          */
@@ -318,6 +349,9 @@ public class GridTestSwapSpaceSpi extends IgniteSpiAdapter implements SwapSpaceS
             return parts;
         }
 
+        /**
+         * @return Iterator.
+         */
         public <K> IgniteSpiCloseableIterator<K> keyIterator() {
             final Iterator<SwapKey> it = data.keySet().iterator();
 
@@ -342,6 +376,9 @@ public class GridTestSwapSpaceSpi extends IgniteSpiAdapter implements SwapSpaceS
             };
         }
 
+        /**
+         * @return Raw iterator.
+         */
         public IgniteSpiCloseableIterator<Map.Entry<byte[], byte[]>> rawIterator() {
             final Iterator<Map.Entry<SwapKey, byte[]>> it = data.entrySet().iterator();
 
@@ -378,6 +415,10 @@ public class GridTestSwapSpaceSpi extends IgniteSpiAdapter implements SwapSpaceS
             };
         }
 
+        /**
+         * @param part Partition.
+         * @return Raw iterator for partition.
+         */
         public IgniteSpiCloseableIterator<Map.Entry<byte[], byte[]>> rawIterator(final int part) {
             final Iterator<Map.Entry<SwapKey, byte[]>> it = data.entrySet().iterator();
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/20f93d6c/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
index eb4e7ea..d992295 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
@@ -374,6 +374,13 @@ public class IgniteCacheTestSuite extends TestSuite {
         suite.addTestSuite(IgniteCacheTxLocalPeekTest.class);
         suite.addTestSuite(IgniteCacheTxReplicatedPeekTest.class);
 
+        suite.addTestSuite(IgniteCacheAtomicSizeTest.class);
+        suite.addTestSuite(IgniteCacheAtomicReplicatedSizeTest.class);
+        suite.addTestSuite(IgniteCacheAtomicLocalSizeTest.class);
+        suite.addTestSuite(IgniteCacheTxSizeTest.class);
+        suite.addTestSuite(IgniteCacheTxReplicatedSizeTest.class);
+        suite.addTestSuite(IgniteCacheTxLocalSizeTest.class);
+
         // TODO: IGNITE-114.
         // suite.addTestSuite(IgniteCacheInvokeReadThroughTest.class);
 


Mime
View raw message