You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2015/05/29 20:21:57 UTC

[48/50] [abbrv] incubator-ignite git commit: ignite-916 Eviction policy should evict cache entries when memory size limit is reached

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e5d5d08d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/fifo/GridCacheFifoEvictionPolicySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/fifo/GridCacheFifoEvictionPolicySelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/fifo/GridCacheFifoEvictionPolicySelfTest.java
deleted file mode 100644
index 64d3831..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/fifo/GridCacheFifoEvictionPolicySelfTest.java
+++ /dev/null
@@ -1,372 +0,0 @@
-/*
- * 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.eviction.fifo;
-
-import org.apache.ignite.*;
-import org.apache.ignite.cache.eviction.*;
-import org.apache.ignite.cache.eviction.fifo.*;
-import org.apache.ignite.internal.processors.cache.eviction.*;
-
-import java.util.*;
-
-import static org.apache.ignite.cache.CacheMode.*;
-
-/**
- * FIFO Eviction test.
- */
-@SuppressWarnings({"TypeMayBeWeakened"})
-public class GridCacheFifoEvictionPolicySelfTest extends
-    GridCacheEvictionAbstractTest<FifoEvictionPolicy<String, String>> {
-    /**
-     * @throws Exception If failed.
-     */
-    public void testPolicy() throws Exception {
-        try {
-            startGrid();
-
-            MockEntry e1 = new MockEntry("1", "1");
-            MockEntry e2 = new MockEntry("2", "2");
-            MockEntry e3 = new MockEntry("3", "3");
-            MockEntry e4 = new MockEntry("4", "4");
-            MockEntry e5 = new MockEntry("5", "5");
-
-            FifoEvictionPolicy<String, String> p = policy();
-
-            p.setMaxSize(3);
-
-            p.onEntryAccessed(false, e1);
-
-            check(p.queue(), e1);
-
-            p.onEntryAccessed(false, e2);
-
-            check(p.queue(), e1, e2);
-
-            p.onEntryAccessed(false, e3);
-
-            check(p.queue(), e1, e2, e3);
-
-            assert !e1.isEvicted();
-            assert !e2.isEvicted();
-            assert !e3.isEvicted();
-
-            assertEquals(3, p.getCurrentSize());
-
-            p.onEntryAccessed(false, e4);
-
-            check(p.queue(), e2, e3, e4);
-
-            assertEquals(3, p.getCurrentSize());
-
-            assert e1.isEvicted();
-            assert !e2.isEvicted();
-            assert !e3.isEvicted();
-            assert !e4.isEvicted();
-
-            p.onEntryAccessed(false, e5);
-
-            check(p.queue(), e3, e4, e5);
-
-            assertEquals(3, p.getCurrentSize());
-
-            assert e2.isEvicted();
-            assert !e3.isEvicted();
-            assert !e4.isEvicted();
-            assert !e5.isEvicted();
-
-            p.onEntryAccessed(false, e1 = new MockEntry("1", "1"));
-
-            check(p.queue(), e4, e5, e1);
-
-            assertEquals(3, p.getCurrentSize());
-
-            assert e3.isEvicted();
-            assert !e1.isEvicted();
-            assert !e4.isEvicted();
-            assert !e5.isEvicted();
-
-            p.onEntryAccessed(false, e5);
-
-            check(p.queue(), e4, e5, e1);
-
-            assert !e1.isEvicted();
-            assert !e4.isEvicted();
-            assert !e5.isEvicted();
-
-            p.onEntryAccessed(false, e1);
-
-            assertEquals(3, p.getCurrentSize());
-
-            check(p.queue(), e4, e5, e1);
-
-            assert !e1.isEvicted();
-            assert !e4.isEvicted();
-            assert !e5.isEvicted();
-
-            p.onEntryAccessed(false, e5);
-
-            assertEquals(3, p.getCurrentSize());
-
-            check(p.queue(), e4, e5, e1);
-
-            assert !e1.isEvicted();
-            assert !e4.isEvicted();
-            assert !e5.isEvicted();
-
-            p.onEntryAccessed(true, e1);
-
-            assertEquals(2, p.getCurrentSize());
-
-            assert !e1.isEvicted();
-            assert !e4.isEvicted();
-            assert !e5.isEvicted();
-
-            p.onEntryAccessed(true, e4);
-
-            assertEquals(1, p.getCurrentSize());
-
-            assert !e4.isEvicted();
-            assert !e5.isEvicted();
-
-            p.onEntryAccessed(true, e5);
-
-            assertEquals(0, p.getCurrentSize());
-
-            assert !e5.isEvicted();
-
-            info(p);
-        }
-        finally {
-            stopAllGrids();
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testMemory() throws Exception {
-        try {
-            startGrid();
-
-            FifoEvictionPolicy<String, String> p = policy();
-
-            int max = 10;
-
-            p.setMaxSize(max);
-
-            int cnt = 11;
-
-            for (int i = 0; i < cnt; i++)
-                p.onEntryAccessed(false, new MockEntry(Integer.toString(i), Integer.toString(i)));
-
-            info(p);
-
-            assertEquals(max, p.getCurrentSize());
-        }
-        finally {
-            stopAllGrids();
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testRandom() throws Exception {
-        try {
-            startGrid();
-
-            FifoEvictionPolicy<String, String> p = policy();
-
-            int max = 10;
-
-            p.setMaxSize(max);
-
-            Random rand = new Random();
-
-            int keys = 31;
-
-            MockEntry[] fifos = new MockEntry[keys];
-
-            for (int i = 0; i < fifos.length; i++)
-                fifos[i] = new MockEntry(Integer.toString(i));
-
-            int runs = 5000000;
-
-            for (int i = 0; i < runs; i++) {
-                boolean rmv = rand.nextBoolean();
-
-                int j = rand.nextInt(fifos.length);
-
-                MockEntry e = entry(fifos, j);
-
-                if (rmv)
-                    fifos[j] = new MockEntry(Integer.toString(j));
-
-                p.onEntryAccessed(rmv, e);
-            }
-
-            info(p);
-
-            int curSize = p.getCurrentSize();
-
-            assert curSize <= max : "curSize <= max [curSize=" + curSize + ", max=" + max + ']';
-        }
-        finally {
-            stopAllGrids();
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testAllowEmptyEntries() throws Exception {
-        try {
-            startGrid();
-
-            MockEntry e1 = new MockEntry("1");
-
-            MockEntry e2 = new MockEntry("2");
-
-            MockEntry e3 = new MockEntry("3");
-
-            MockEntry e4 = new MockEntry("4");
-
-            MockEntry e5 = new MockEntry("5");
-
-            FifoEvictionPolicy<String, String> p = policy();
-
-            p.setMaxSize(10);
-
-            p.onEntryAccessed(false, e1);
-
-            assertFalse(e1.isEvicted());
-
-            p.onEntryAccessed(false, e2);
-
-            assertFalse(e1.isEvicted());
-            assertFalse(e2.isEvicted());
-
-            p.onEntryAccessed(false, e3);
-
-            assertFalse(e1.isEvicted());
-            assertFalse(e3.isEvicted());
-
-            p.onEntryAccessed(false, e4);
-
-            assertFalse(e1.isEvicted());
-            assertFalse(e3.isEvicted());
-            assertFalse(e4.isEvicted());
-
-            p.onEntryAccessed(false, e5);
-
-            assertFalse(e1.isEvicted());
-            assertFalse(e3.isEvicted());
-            assertFalse(e5.isEvicted());
-        }
-        finally {
-            stopAllGrids();
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testPut() throws Exception {
-        mode = LOCAL;
-        syncCommit = true;
-        plcMax = 100;
-
-        Ignite ignite = startGrid();
-
-        try {
-            IgniteCache<Object, Object> cache = ignite.cache(null);
-
-            int cnt = 500;
-
-            int min = Integer.MAX_VALUE;
-
-            int minIdx = 0;
-
-            for (int i = 0; i < cnt; i++) {
-                cache.put(i, i);
-
-                int cacheSize = cache.size();
-
-                if (i > plcMax && cacheSize < min) {
-                    min = cacheSize;
-                    minIdx = i;
-                }
-            }
-
-            assert min >= plcMax : "Min cache size is too small: " + min;
-
-            info("Min cache size [min=" + min + ", idx=" + minIdx + ']');
-            info("Current cache size " + cache.size());
-            info("Current cache key size " + cache.size());
-
-            min = Integer.MAX_VALUE;
-
-            minIdx = 0;
-
-            // Touch.
-            for (int i = cnt; --i > cnt - plcMax;) {
-                cache.get(i);
-
-                int cacheSize = cache.size();
-
-                if (cacheSize < min) {
-                    min = cacheSize;
-                    minIdx = i;
-                }
-            }
-
-            info("----");
-            info("Min cache size [min=" + min + ", idx=" + minIdx + ']');
-            info("Current cache size " + cache.size());
-            info("Current cache key size " + cache.size());
-
-            assert min >= plcMax : "Min cache size is too small: " + min;
-        }
-        finally {
-            stopAllGrids();
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override protected FifoEvictionPolicy<String, String> createPolicy(int plcMax) {
-        return new FifoEvictionPolicy<>(plcMax);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected FifoEvictionPolicy<String, String> createNearPolicy(int nearMax) {
-        return new FifoEvictionPolicy<>(nearMax);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void checkNearPolicies(int endNearPlcSize) {
-        for (int i = 0; i < gridCnt; i++)
-            for (EvictableEntry<String, String> e : nearPolicy(i).queue())
-                assert !e.isCached() : "Invalid near policy size: " + nearPolicy(i).queue();
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void checkPolicies(int plcMax) {
-        for (int i = 0; i < gridCnt; i++)
-            assert policy(i).queue().size() <= plcMax;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e5d5d08d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/lru/GridCacheLruEvictionPolicySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/lru/GridCacheLruEvictionPolicySelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/lru/GridCacheLruEvictionPolicySelfTest.java
deleted file mode 100644
index c623b38..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/lru/GridCacheLruEvictionPolicySelfTest.java
+++ /dev/null
@@ -1,417 +0,0 @@
-/*
- * 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.eviction.lru;
-
-import org.apache.ignite.*;
-import org.apache.ignite.cache.*;
-import org.apache.ignite.cache.eviction.*;
-import org.apache.ignite.cache.eviction.lru.*;
-import org.apache.ignite.internal.processors.cache.eviction.*;
-
-import java.util.*;
-
-/**
- * LRU Eviction test.
- */
-@SuppressWarnings( {"TypeMayBeWeakened"})
-public class GridCacheLruEvictionPolicySelfTest extends
-    GridCacheEvictionAbstractTest<LruEvictionPolicy<String, String>> {
-    /**
-     * @throws Exception If failed.
-     */
-    public void testPolicy() throws Exception {
-        startGrid();
-
-        try {
-            MockEntry e1 = new MockEntry("1", "1");
-            MockEntry e2 = new MockEntry("2", "2");
-            MockEntry e3 = new MockEntry("3", "3");
-            MockEntry e4 = new MockEntry("4", "4");
-            MockEntry e5 = new MockEntry("5", "5");
-
-            LruEvictionPolicy<String, String> p = policy();
-
-            p.setMaxSize(3);
-
-            p.onEntryAccessed(false, e1);
-
-            check(p.queue(), e1);
-
-            p.onEntryAccessed(false, e2);
-
-            check(p.queue(), e1, e2);
-
-            p.onEntryAccessed(false, e3);
-
-            check(p.queue(), e1, e2, e3);
-
-            assert !e1.isEvicted();
-            assert !e2.isEvicted();
-            assert !e3.isEvicted();
-
-            assertEquals(3, p.getCurrentSize());
-
-            p.onEntryAccessed(false, e4);
-
-            check(p.queue(), e2, e3, e4);
-
-            assertEquals(3, p.getCurrentSize());
-
-            assert e1.isEvicted();
-            assert !e2.isEvicted();
-            assert !e3.isEvicted();
-            assert !e4.isEvicted();
-
-            p.onEntryAccessed(false, e5);
-
-            check(p.queue(), e3, e4, e5);
-
-            assertEquals(3, p.getCurrentSize());
-
-            assert e2.isEvicted();
-            assert !e3.isEvicted();
-            assert !e4.isEvicted();
-            assert !e5.isEvicted();
-
-            p.onEntryAccessed(false, e1 = new MockEntry("1", "1"));
-
-            check(p.queue(), e4, e5, e1);
-
-            assertEquals(3, p.getCurrentSize());
-
-            assert e3.isEvicted();
-            assert !e1.isEvicted();
-            assert !e4.isEvicted();
-            assert !e5.isEvicted();
-
-            p.onEntryAccessed(false, e5);
-
-            assertEquals(3, p.getCurrentSize());
-
-            check(p.queue(), e4, e1, e5);
-
-            assert !e1.isEvicted();
-            assert !e4.isEvicted();
-            assert !e5.isEvicted();
-
-            p.onEntryAccessed(false, e1);
-
-            assertEquals(3, p.getCurrentSize());
-
-            check(p.queue(), e4, e5, e1);
-
-            assert !e1.isEvicted();
-            assert !e4.isEvicted();
-            assert !e5.isEvicted();
-
-            p.onEntryAccessed(false, e5);
-
-            assertEquals(3, p.getCurrentSize());
-
-            check(p.queue(), e4, e1, e5);
-
-            assert !e1.isEvicted();
-            assert !e4.isEvicted();
-            assert !e5.isEvicted();
-
-            p.onEntryAccessed(true, e1);
-
-            assertEquals(2, p.getCurrentSize());
-
-            assert !e1.isEvicted();
-            assert !e4.isEvicted();
-            assert !e5.isEvicted();
-
-            p.onEntryAccessed(true, e4);
-
-            assertEquals(1, p.getCurrentSize());
-
-            assert !e4.isEvicted();
-            assert !e5.isEvicted();
-
-            p.onEntryAccessed(true, e5);
-
-            assertEquals(0, p.getCurrentSize());
-
-            assert !e5.isEvicted();
-
-            info(p);
-        }
-        finally {
-            stopGrid();
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testMemory() throws Exception {
-        startGrid();
-
-        try {
-            LruEvictionPolicy<String, String> p = policy();
-
-            int max = 10;
-
-            p.setMaxSize(max);
-
-            int cnt = 11;
-
-            for (int i = 0; i < cnt; i++)
-                p.onEntryAccessed(false, new MockEntry(Integer.toString(i), Integer.toString(i)));
-
-            info(p);
-
-            assertEquals(max, p.getCurrentSize());
-        }
-        finally {
-            stopGrid();
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testMiddleAccess() throws Exception {
-        startGrid();
-
-        try {
-            LruEvictionPolicy<String, String> p = policy();
-
-            int max = 8;
-
-            p.setMaxSize(max);
-
-            MockEntry entry1 = new MockEntry("1", "1");
-            MockEntry entry2 = new MockEntry("2", "2");
-            MockEntry entry3 = new MockEntry("3", "3");
-
-            p.onEntryAccessed(false, entry1);
-            p.onEntryAccessed(false, entry2);
-            p.onEntryAccessed(false, entry3);
-
-            MockEntry[] freqUsed = new MockEntry[] {
-                new MockEntry("4", "4"),
-                new MockEntry("5", "5"),
-                new MockEntry("6", "6"),
-                new MockEntry("7", "7"),
-                new MockEntry("8", "7")
-            };
-
-            for (MockEntry e : freqUsed)
-                p.onEntryAccessed(false, e);
-
-            for (MockEntry e : freqUsed)
-                assert !e.isEvicted();
-
-            int cnt = 1001;
-
-            for (int i = 0; i < cnt; i++)
-                p.onEntryAccessed(false, entry(freqUsed, i % freqUsed.length));
-
-            info(p);
-
-            assertEquals(max, p.getCurrentSize());
-        }
-        finally {
-            stopGrid();
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testRandom() throws Exception {
-        startGrid();
-
-        try {
-            LruEvictionPolicy<String, String> p = policy();
-
-            int max = 10;
-
-            p.setMaxSize(max);
-
-            Random rand = new Random();
-
-            int keys = 31;
-
-            MockEntry[] lrus = new MockEntry[keys];
-
-            for (int i = 0; i < lrus.length; i++)
-                lrus[i] = new MockEntry(Integer.toString(i));
-
-            int runs = 500000;
-
-            for (int i = 0; i < runs; i++) {
-                boolean rmv = rand.nextBoolean();
-
-                int j = rand.nextInt(lrus.length);
-
-                MockEntry e = entry(lrus, j);
-
-                if (rmv)
-                    lrus[j] = new MockEntry(Integer.toString(j));
-
-                p.onEntryAccessed(rmv, e);
-            }
-
-            info(p);
-
-            assert p.getCurrentSize() <= max;
-        }
-        finally {
-            stopGrid();
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testAllowEmptyEntries() throws Exception {
-        try {
-            startGrid();
-
-            MockEntry e1 = new MockEntry("1");
-
-            MockEntry e2 = new MockEntry("2");
-
-            MockEntry e3 = new MockEntry("3");
-
-            MockEntry e4 = new MockEntry("4");
-
-            MockEntry e5 = new MockEntry("5");
-
-            LruEvictionPolicy<String, String> p = policy();
-
-            p.setMaxSize(10);
-
-            p.onEntryAccessed(false, e1);
-
-            assertFalse(e1.isEvicted());
-
-            p.onEntryAccessed(false, e2);
-
-            assertFalse(e1.isEvicted());
-            assertFalse(e2.isEvicted());
-
-            p.onEntryAccessed(false, e3);
-
-            assertFalse(e1.isEvicted());
-            assertFalse(e3.isEvicted());
-
-            p.onEntryAccessed(false, e4);
-
-            assertFalse(e1.isEvicted());
-            assertFalse(e3.isEvicted());
-            assertFalse(e4.isEvicted());
-
-            p.onEntryAccessed(false, e5);
-
-            assertFalse(e1.isEvicted());
-            assertFalse(e3.isEvicted());
-            assertFalse(e5.isEvicted());
-        }
-        finally {
-            stopAllGrids();
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testPut() throws Exception {
-        mode = CacheMode.LOCAL;
-        syncCommit = true;
-        plcMax = 100;
-
-        Ignite ignite = startGrid();
-
-        try {
-            IgniteCache<Integer, Integer> cache = ignite.cache(null);
-
-            int cnt = 500;
-
-            int min = Integer.MAX_VALUE;
-
-            int minIdx = 0;
-
-            for (int i = 0; i < cnt; i++) {
-                cache.put(i, i);
-
-                int cacheSize = cache.size();
-
-                if (i > plcMax && cacheSize < min) {
-                    min = cacheSize;
-                    minIdx = i;
-                }
-            }
-
-            assert min >= plcMax : "Min cache size is too small: " + min;
-
-            info("Min cache size [min=" + min + ", idx=" + minIdx + ']');
-            info("Current cache size " + cache.size());
-
-            min = Integer.MAX_VALUE;
-
-            minIdx = 0;
-
-            // Touch.
-            for (int i = cnt; --i > cnt - plcMax;) {
-                cache.get(i);
-
-                int cacheSize = cache.size();
-
-                if (cacheSize < min) {
-                    min = cacheSize;
-                    minIdx = i;
-                }
-            }
-
-            info("----");
-            info("Min cache size [min=" + min + ", idx=" + minIdx + ']');
-            info("Current cache size " + cache.size());
-
-            assert min >= plcMax : "Min cache size is too small: " + min;
-        }
-        finally {
-            stopAllGrids();
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override protected LruEvictionPolicy<String, String> createPolicy(int plcMax) {
-        return new LruEvictionPolicy<>(plcMax);
-    }
-
-    @Override protected LruEvictionPolicy<String, String> createNearPolicy(int nearMax) {
-        return new LruEvictionPolicy<>(nearMax);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void checkNearPolicies(int endNearPlcSize) {
-        for (int i = 0; i < gridCnt; i++)
-            for (EvictableEntry<String, String> e : nearPolicy(i).queue())
-                assert !e.isCached() : "Invalid near policy size: " + nearPolicy(i).queue();
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void checkPolicies(int plcMax) {
-        for (int i = 0; i < gridCnt; i++)
-            assert policy(i).queue().size() <= plcMax;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e5d5d08d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/lru/GridCacheLruNearEvictionPolicySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/lru/GridCacheLruNearEvictionPolicySelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/lru/GridCacheLruNearEvictionPolicySelfTest.java
deleted file mode 100644
index e0606a7..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/lru/GridCacheLruNearEvictionPolicySelfTest.java
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * 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.eviction.lru;
-
-import org.apache.ignite.*;
-import org.apache.ignite.cache.*;
-import org.apache.ignite.cache.eviction.lru.*;
-import org.apache.ignite.configuration.*;
-import org.apache.ignite.spi.discovery.tcp.*;
-import org.apache.ignite.spi.discovery.tcp.ipfinder.*;
-import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*;
-import org.apache.ignite.testframework.junits.common.*;
-
-import java.util.*;
-
-import static org.apache.ignite.cache.CacheAtomicityMode.*;
-import static org.apache.ignite.cache.CacheMode.*;
-import static org.apache.ignite.cache.CacheRebalanceMode.*;
-import static org.apache.ignite.cache.CacheWriteSynchronizationMode.*;
-
-/**
- * LRU near eviction tests (GG-8884).
- */
-public class GridCacheLruNearEvictionPolicySelfTest extends GridCommonAbstractTest {
-    /** */
-    private static final TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true);
-
-    /** Maximum size for near eviction policy. */
-    private static final int EVICTION_MAX_SIZE = 10;
-
-    /** Grid count. */
-    private static final int GRID_COUNT = 2;
-
-    /** Cache atomicity mode specified by test. */
-    private CacheAtomicityMode atomicityMode;
-
-    /** {@inheritDoc} */
-    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
-        IgniteConfiguration c = super.getConfiguration(gridName);
-
-        CacheConfiguration cc = new CacheConfiguration();
-
-        cc.setAtomicityMode(atomicityMode);
-        cc.setCacheMode(PARTITIONED);
-        cc.setWriteSynchronizationMode(PRIMARY_SYNC);
-        cc.setRebalanceMode(SYNC);
-        cc.setStartSize(100);
-        cc.setBackups(0);
-
-        NearCacheConfiguration nearCfg = new NearCacheConfiguration();
-        nearCfg.setNearEvictionPolicy(new LruEvictionPolicy(EVICTION_MAX_SIZE));
-        cc.setNearConfiguration(nearCfg);
-
-        c.setCacheConfiguration(cc);
-
-        TcpDiscoverySpi disco = new TcpDiscoverySpi();
-
-        disco.setIpFinder(ipFinder);
-
-        c.setDiscoverySpi(disco);
-
-        return c;
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testAtomicNearEvictionMaxSize() throws Exception {
-        atomicityMode = ATOMIC;
-
-        checkNearEvictionMaxSize();
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testTransactionalNearEvictionMaxSize() throws Exception {
-        atomicityMode = TRANSACTIONAL;
-
-        checkNearEvictionMaxSize();
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    private void checkNearEvictionMaxSize() throws Exception {
-        startGridsMultiThreaded(GRID_COUNT);
-
-        try {
-            Random rand = new Random(0);
-
-            int cnt = 1000;
-
-            info("Inserting " + cnt + " keys to cache.");
-
-            try (IgniteDataStreamer<Integer, String> ldr = grid(0).dataStreamer(null)) {
-                for (int i = 0; i < cnt; i++)
-                    ldr.addData(i, Integer.toString(i));
-            }
-
-            for (int i = 0; i < GRID_COUNT; i++)
-                assertTrue("Near cache size " + near(i).nearSize() + ", but eviction maximum size " + EVICTION_MAX_SIZE,
-                    near(i).nearSize() <= EVICTION_MAX_SIZE);
-
-            info("Getting " + cnt + " keys from cache.");
-
-            for (int i = 0; i < cnt; i++) {
-                IgniteCache<Integer, String> cache = grid(rand.nextInt(GRID_COUNT)).cache(null);
-
-                assertTrue(cache.get(i).equals(Integer.toString(i)));
-            }
-
-            for (int i = 0; i < GRID_COUNT; i++)
-                assertTrue("Near cache size " + near(i).nearSize() + ", but eviction maximum size " + EVICTION_MAX_SIZE,
-                    near(i).nearSize() <= EVICTION_MAX_SIZE);
-        }
-        finally {
-            stopAllGrids();
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e5d5d08d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/lru/GridCacheNearOnlyLruNearEvictionPolicySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/lru/GridCacheNearOnlyLruNearEvictionPolicySelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/lru/GridCacheNearOnlyLruNearEvictionPolicySelfTest.java
deleted file mode 100644
index 5d4ff85..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/lru/GridCacheNearOnlyLruNearEvictionPolicySelfTest.java
+++ /dev/null
@@ -1,171 +0,0 @@
-/*
- * 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.eviction.lru;
-
-import org.apache.ignite.*;
-import org.apache.ignite.cache.*;
-import org.apache.ignite.cache.eviction.lru.*;
-import org.apache.ignite.configuration.*;
-import org.apache.ignite.spi.discovery.tcp.*;
-import org.apache.ignite.spi.discovery.tcp.ipfinder.*;
-import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*;
-import org.apache.ignite.testframework.junits.common.*;
-
-import static org.apache.ignite.cache.CacheAtomicityMode.*;
-import static org.apache.ignite.cache.CacheMode.*;
-import static org.apache.ignite.cache.CacheRebalanceMode.*;
-import static org.apache.ignite.cache.CacheWriteSynchronizationMode.*;
-
-/**
- * LRU near eviction tests for NEAR_ONLY distribution mode (GG-8884).
- */
-public class GridCacheNearOnlyLruNearEvictionPolicySelfTest extends GridCommonAbstractTest {
-    /** */
-    private static final TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true);
-
-    /** Grid count. */
-    private static final int GRID_COUNT = 2;
-
-    /** Maximum size for near eviction policy. */
-    private static final int EVICTION_MAX_SIZE = 10;
-
-    /** Node count. */
-    private int cnt;
-
-    /** Caching mode specified by test. */
-    private CacheMode cacheMode;
-
-    /** Cache atomicity mode specified by test. */
-    private CacheAtomicityMode atomicityMode;
-
-    /** {@inheritDoc} */
-    @Override protected void beforeTest() throws Exception {
-        super.beforeTest();
-
-        cnt = 0;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
-        IgniteConfiguration c = super.getConfiguration(gridName);
-
-        if (cnt == 0)
-            c.setClientMode(true);
-
-        CacheConfiguration cc = new CacheConfiguration();
-
-        cc.setAtomicityMode(atomicityMode);
-        cc.setCacheMode(cacheMode);
-        cc.setWriteSynchronizationMode(PRIMARY_SYNC);
-        cc.setRebalanceMode(SYNC);
-        cc.setStartSize(100);
-        cc.setBackups(0);
-
-        c.setCacheConfiguration(cc);
-
-        TcpDiscoverySpi disco = new TcpDiscoverySpi();
-
-        disco.setIpFinder(ipFinder);
-
-        c.setDiscoverySpi(disco);
-
-        cnt++;
-
-        return c;
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testPartitionedAtomicNearEvictionMaxSize() throws Exception {
-        atomicityMode = ATOMIC;
-        cacheMode = PARTITIONED;
-
-        checkNearEvictionMaxSize();
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testPartitionedTransactionalNearEvictionMaxSize() throws Exception {
-        atomicityMode = TRANSACTIONAL;
-        cacheMode = PARTITIONED;
-
-        checkNearEvictionMaxSize();
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testReplicatedAtomicNearEvictionMaxSize() throws Exception {
-        atomicityMode = ATOMIC;
-        cacheMode = REPLICATED;
-
-        checkNearEvictionMaxSize();
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testReplicatedTransactionalNearEvictionMaxSize() throws Exception {
-        atomicityMode = TRANSACTIONAL;
-        cacheMode = REPLICATED;
-
-        checkNearEvictionMaxSize();
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    private void checkNearEvictionMaxSize() throws Exception {
-        startGrids(GRID_COUNT);
-
-        try {
-            NearCacheConfiguration nearCfg = new NearCacheConfiguration();
-            nearCfg.setNearEvictionPolicy(new LruEvictionPolicy(EVICTION_MAX_SIZE));
-
-            grid(0).createNearCache(null, nearCfg);
-
-            int cnt = 1000;
-
-            info("Inserting " + cnt + " keys to cache.");
-
-            try (IgniteDataStreamer<Integer, String> ldr = grid(1).dataStreamer(null)) {
-                for (int i = 0; i < cnt; i++)
-                    ldr.addData(i, Integer.toString(i));
-            }
-
-            assertTrue("Near cache size " + near(0).nearSize() + ", but eviction maximum size " + EVICTION_MAX_SIZE,
-                near(0).nearSize() <= EVICTION_MAX_SIZE);
-
-            info("Getting " + cnt + " keys from cache.");
-
-            for (int i = 0; i < cnt; i++) {
-                IgniteCache<Integer, String> cache = grid(0).cache(null);
-
-                assertTrue(cache.get(i).equals(Integer.toString(i)));
-            }
-
-            assertTrue("Near cache size " + near(0).nearSize() + ", but eviction maximum size " + EVICTION_MAX_SIZE,
-                near(0).nearSize() <= EVICTION_MAX_SIZE);
-        }
-        finally {
-            stopAllGrids();
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e5d5d08d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/lru/LruEvictionPolicySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/lru/LruEvictionPolicySelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/lru/LruEvictionPolicySelfTest.java
new file mode 100644
index 0000000..8e1e8cf
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/lru/LruEvictionPolicySelfTest.java
@@ -0,0 +1,353 @@
+/*
+ * 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.eviction.lru;
+
+import org.apache.ignite.cache.eviction.*;
+import org.apache.ignite.cache.eviction.lru.*;
+import org.apache.ignite.internal.processors.cache.*;
+import org.apache.ignite.internal.processors.cache.eviction.*;
+
+/**
+ * LRU Eviction policy tests.
+ */
+public class LruEvictionPolicySelfTest extends
+    EvictionAbstractTest<LruEvictionPolicy<String, String>> {
+    /**
+     * @throws Exception If failed.
+     */
+    public void testMiddleAccess() throws Exception {
+        startGrid();
+
+        try {
+            LruEvictionPolicy<String, String> p = policy();
+
+            int max = 8;
+
+            p.setMaxSize(max * MockEntry.ENTRY_SIZE);
+
+            MockEntry entry1 = new MockEntry("1", "1");
+            MockEntry entry2 = new MockEntry("2", "2");
+            MockEntry entry3 = new MockEntry("3", "3");
+
+            p.onEntryAccessed(false, entry1);
+            p.onEntryAccessed(false, entry2);
+            p.onEntryAccessed(false, entry3);
+
+            MockEntry[] freqUsed = new MockEntry[] {
+                new MockEntry("4", "4"),
+                new MockEntry("5", "5"),
+                new MockEntry("6", "6"),
+                new MockEntry("7", "7"),
+                new MockEntry("8", "7")
+            };
+
+            for (MockEntry e : freqUsed)
+                p.onEntryAccessed(false, e);
+
+            for (MockEntry e : freqUsed)
+                assert !e.isEvicted();
+
+            int cnt = 1001;
+
+            for (int i = 0; i < cnt; i++)
+                p.onEntryAccessed(false, entry(freqUsed, i % freqUsed.length));
+
+            info(p);
+
+            check(max, MockEntry.ENTRY_SIZE);
+        }
+        finally {
+            stopGrid();
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void doTestPolicy() throws Exception {
+        startGrid();
+
+        try {
+            MockEntry e1 = new MockEntry("1", "1");
+            MockEntry e2 = new MockEntry("2", "2");
+            MockEntry e3 = new MockEntry("3", "3");
+            MockEntry e4 = new MockEntry("4", "4");
+            MockEntry e5 = new MockEntry("5", "5");
+
+            LruEvictionPolicy<String, String> p = policy();
+
+            p.onEntryAccessed(false, e1);
+
+            check(MockEntry.ENTRY_SIZE, p.queue(), e1);
+
+            p.onEntryAccessed(false, e2);
+
+            check(MockEntry.ENTRY_SIZE, p.queue(), e1, e2);
+
+            p.onEntryAccessed(false, e3);
+
+            check(MockEntry.ENTRY_SIZE, p.queue(), e1, e2, e3);
+
+            assertFalse(e1.isEvicted());
+            assertFalse(e2.isEvicted());
+            assertFalse(e3.isEvicted());
+
+            p.onEntryAccessed(false, e4);
+
+            check(p.queue(), e2, e3, e4);
+            check(MockEntry.ENTRY_SIZE, p.queue(), e2, e3, e4);
+
+            assertTrue(e1.isEvicted());
+            assertFalse(e2.isEvicted());
+            assertFalse(e3.isEvicted());
+            assertFalse(e4.isEvicted());
+
+            p.onEntryAccessed(false, e5);
+
+            check(MockEntry.ENTRY_SIZE, p.queue(), e3, e4, e5);
+
+            assertTrue(e2.isEvicted());
+            assertFalse(e3.isEvicted());
+            assertFalse(e4.isEvicted());
+            assertFalse(e5.isEvicted());
+
+            p.onEntryAccessed(false, e1 = new MockEntry("1", "1"));
+
+            check(MockEntry.ENTRY_SIZE, p.queue(), e4, e5, e1);
+
+            assertTrue(e3.isEvicted());
+            assertFalse(e1.isEvicted());
+            assertFalse(e4.isEvicted());
+            assertFalse(e5.isEvicted());
+
+            p.onEntryAccessed(false, e5);
+
+            assertEquals(3, p.getCurrentSize());
+
+            check(MockEntry.ENTRY_SIZE, p.queue(), e4, e1, e5);
+
+            assertFalse(e1.isEvicted());
+            assertFalse(e4.isEvicted());
+            assertFalse(e5.isEvicted());
+
+            p.onEntryAccessed(false, e1);
+
+            check(MockEntry.ENTRY_SIZE, p.queue(), e4, e5, e1);
+
+            assertFalse(e1.isEvicted());
+            assertFalse(e4.isEvicted());
+            assertFalse(e5.isEvicted());
+
+            p.onEntryAccessed(false, e5);
+
+            assertEquals(3, p.getCurrentSize());
+
+            check(MockEntry.ENTRY_SIZE, p.queue(), e4, e1, e5);
+
+            assertFalse(e1.isEvicted());
+            assertFalse(e4.isEvicted());
+            assertFalse(e5.isEvicted());
+
+            p.onEntryAccessed(true, e1);
+
+            check(MockEntry.ENTRY_SIZE, p.queue(), e4, e5);
+
+            assertFalse(e1.isEvicted());
+            assertFalse(e4.isEvicted());
+            assertFalse(e5.isEvicted());
+
+            p.onEntryAccessed(true, e4);
+
+            check(MockEntry.ENTRY_SIZE, p.queue(), e5);
+
+            assertFalse(e4.isEvicted());
+            assertFalse(e5.isEvicted());
+
+            p.onEntryAccessed(true, e5);
+
+            check(MockEntry.ENTRY_SIZE, p.queue());
+
+            assertFalse(e5.isEvicted());
+
+            info(p);
+        }
+        finally {
+            stopGrid();
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void doTestPolicyWithBatch() throws Exception {
+        startGrid();
+
+        try {
+            MockEntry e1 = new MockEntry("1", "1");
+            MockEntry e2 = new MockEntry("2", "2");
+            MockEntry e3 = new MockEntry("3", "3");
+            MockEntry e4 = new MockEntry("4", "4");
+            MockEntry e5 = new MockEntry("5", "5");
+
+            LruEvictionPolicy<String, String> p = policy();
+
+            p.onEntryAccessed(false, e1);
+
+            check(MockEntry.ENTRY_SIZE, p.queue(), e1);
+
+            p.onEntryAccessed(false, e2);
+
+            check(MockEntry.ENTRY_SIZE, p.queue(), e1, e2);
+
+            p.onEntryAccessed(false, e3);
+
+            check(MockEntry.ENTRY_SIZE, p.queue(), e1, e2, e3);
+
+            assertFalse(e1.isEvicted());
+            assertFalse(e2.isEvicted());
+            assertFalse(e3.isEvicted());
+
+            p.onEntryAccessed(false, e4);
+
+            check(MockEntry.ENTRY_SIZE, p.queue(), e1, e2, e3, e4);
+
+            assertFalse(e1.isEvicted());
+            assertFalse(e2.isEvicted());
+            assertFalse(e3.isEvicted());
+            assertFalse(e4.isEvicted());
+
+            p.onEntryAccessed(false, e5);
+
+            // Batch evicted
+            check(MockEntry.ENTRY_SIZE, p.queue(), e3, e4, e5);
+
+            assertTrue(e1.isEvicted());
+            assertTrue(e2.isEvicted());
+            assertFalse(e3.isEvicted());
+            assertFalse(e4.isEvicted());
+            assertFalse(e5.isEvicted());
+
+            p.onEntryAccessed(false, e1 = new MockEntry("1", "1"));
+
+            check(MockEntry.ENTRY_SIZE, p.queue(), e3, e4, e5, e1);
+
+            assertFalse(e3.isEvicted());
+            assertFalse(e4.isEvicted());
+            assertFalse(e5.isEvicted());
+            assertFalse(e1.isEvicted());
+
+            p.onEntryAccessed(false, e5);
+
+            check(MockEntry.ENTRY_SIZE, p.queue(), e3, e4, e1, e5);
+
+            assertFalse(e3.isEvicted());
+            assertFalse(e4.isEvicted());
+            assertFalse(e1.isEvicted());
+            assertFalse(e5.isEvicted());
+
+            p.onEntryAccessed(false, e1);
+
+            check(MockEntry.ENTRY_SIZE, p.queue(), e3, e4, e5, e1);
+
+            assertFalse(e3.isEvicted());
+            assertFalse(e4.isEvicted());
+            assertFalse(e5.isEvicted());
+            assertFalse(e1.isEvicted());
+
+            p.onEntryAccessed(false, e5);
+
+            check(MockEntry.ENTRY_SIZE, p.queue(), e3, e4, e1, e5);
+
+            assertFalse(e3.isEvicted());
+            assertFalse(e4.isEvicted());
+            assertFalse(e1.isEvicted());
+            assertFalse(e5.isEvicted());
+
+            p.onEntryAccessed(true, e1);
+
+            check(MockEntry.ENTRY_SIZE, p.queue(), e3, e4, e5);
+
+            assertFalse(e3.isEvicted());
+            assertFalse(e4.isEvicted());
+            assertFalse(e5.isEvicted());
+
+            p.onEntryAccessed(true, e4);
+
+            check(MockEntry.ENTRY_SIZE, p.queue(), e3, e5);
+
+            assertFalse(e3.isEvicted());
+            assertFalse(e5.isEvicted());
+
+            p.onEntryAccessed(true, e5);
+
+            check(MockEntry.ENTRY_SIZE, p.queue(), e3);
+
+            assertFalse(e3.isEvicted());
+
+            p.onEntryAccessed(true, e3);
+
+            check(MockEntry.ENTRY_SIZE, p.queue());
+
+            info(p);
+        }
+        finally {
+            stopGrid();
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override protected LruEvictionPolicy<String, String> createPolicy(int plcMax) {
+        LruEvictionPolicy<String, String> plc = new LruEvictionPolicy<>();
+
+        plc.setMaxSize(this.plcMax);
+        plc.setBatchSize(this.plcBatchSize);
+        plc.setMaxMemSize(this.plcMaxMemSize);
+
+        return plc;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected LruEvictionPolicy<String, String> createNearPolicy(int nearMax) {
+        LruEvictionPolicy<String, String> plc = new LruEvictionPolicy<>();
+
+        plc.setMaxSize(nearMax);
+        plc.setBatchSize(plcBatchSize);
+
+        return plc;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void checkNearPolicies(int endNearPlcSize) {
+        for (int i = 0; i < gridCnt; i++)
+            for (EvictableEntry<String, String> e : nearPolicy(i).queue())
+                assert !e.isCached() : "Invalid near policy size: " + nearPolicy(i).queue();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void checkPolicies() {
+        for (int i = 0; i < gridCnt; i++) {
+            if (plcMaxMemSize > 0) {
+                int size = 0;
+
+                for (EvictableEntry<String, String> entry : policy(i).queue())
+                    size += ((CacheEvictableEntryImpl)entry).size();
+
+                assertEquals(size, ((LruEvictionPolicy)policy(i)).getCurrentMemSize());
+            }
+            else
+                assertTrue(policy(i).queue().size() <= plcMax + plcBatchSize);
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e5d5d08d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/lru/LruNearEvictionPolicySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/lru/LruNearEvictionPolicySelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/lru/LruNearEvictionPolicySelfTest.java
new file mode 100644
index 0000000..218b817
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/lru/LruNearEvictionPolicySelfTest.java
@@ -0,0 +1,140 @@
+/*
+ * 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.eviction.lru;
+
+import org.apache.ignite.*;
+import org.apache.ignite.cache.*;
+import org.apache.ignite.cache.eviction.lru.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.spi.discovery.tcp.*;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.*;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*;
+import org.apache.ignite.testframework.junits.common.*;
+
+import java.util.*;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.*;
+import static org.apache.ignite.cache.CacheMode.*;
+import static org.apache.ignite.cache.CacheRebalanceMode.*;
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.*;
+
+/**
+ * LRU near eviction tests (GG-8884).
+ */
+public class LruNearEvictionPolicySelfTest extends GridCommonAbstractTest {
+    /** */
+    private static final TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true);
+
+    /** Maximum size for near eviction policy. */
+    private static final int EVICTION_MAX_SIZE = 10;
+
+    /** Grid count. */
+    private static final int GRID_COUNT = 2;
+
+    /** Cache atomicity mode specified by test. */
+    private CacheAtomicityMode atomicityMode;
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration c = super.getConfiguration(gridName);
+
+        CacheConfiguration cc = new CacheConfiguration();
+
+        cc.setAtomicityMode(atomicityMode);
+        cc.setCacheMode(PARTITIONED);
+        cc.setWriteSynchronizationMode(PRIMARY_SYNC);
+        cc.setRebalanceMode(SYNC);
+        cc.setStartSize(100);
+        cc.setBackups(0);
+
+        NearCacheConfiguration nearCfg = new NearCacheConfiguration();
+
+        LruEvictionPolicy plc = new LruEvictionPolicy();
+        plc.setMaxSize(EVICTION_MAX_SIZE);
+
+        nearCfg.setNearEvictionPolicy(plc);
+        cc.setNearConfiguration(nearCfg);
+
+        c.setCacheConfiguration(cc);
+
+        TcpDiscoverySpi disco = new TcpDiscoverySpi();
+
+        disco.setIpFinder(ipFinder);
+
+        c.setDiscoverySpi(disco);
+
+        return c;
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testAtomicNearEvictionMaxSize() throws Exception {
+        atomicityMode = ATOMIC;
+
+        checkNearEvictionMaxSize();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testTransactionalNearEvictionMaxSize() throws Exception {
+        atomicityMode = TRANSACTIONAL;
+
+        checkNearEvictionMaxSize();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    private void checkNearEvictionMaxSize() throws Exception {
+        startGridsMultiThreaded(GRID_COUNT);
+
+        try {
+            Random rand = new Random(0);
+
+            int cnt = 1000;
+
+            info("Inserting " + cnt + " keys to cache.");
+
+            try (IgniteDataStreamer<Integer, String> ldr = grid(0).dataStreamer(null)) {
+                for (int i = 0; i < cnt; i++)
+                    ldr.addData(i, Integer.toString(i));
+            }
+
+            for (int i = 0; i < GRID_COUNT; i++)
+                assertTrue("Near cache size " + near(i).nearSize() + ", but eviction maximum size " + EVICTION_MAX_SIZE,
+                    near(i).nearSize() <= EVICTION_MAX_SIZE);
+
+            info("Getting " + cnt + " keys from cache.");
+
+            for (int i = 0; i < cnt; i++) {
+                IgniteCache<Integer, String> cache = grid(rand.nextInt(GRID_COUNT)).cache(null);
+
+                assertTrue(cache.get(i).equals(Integer.toString(i)));
+            }
+
+            for (int i = 0; i < GRID_COUNT; i++)
+                assertTrue("Near cache size " + near(i).nearSize() + ", but eviction maximum size " + EVICTION_MAX_SIZE,
+                    near(i).nearSize() <= EVICTION_MAX_SIZE);
+        }
+        finally {
+            stopAllGrids();
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e5d5d08d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/lru/LruNearOnlyNearEvictionPolicySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/lru/LruNearOnlyNearEvictionPolicySelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/lru/LruNearOnlyNearEvictionPolicySelfTest.java
new file mode 100644
index 0000000..faca01d
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/lru/LruNearOnlyNearEvictionPolicySelfTest.java
@@ -0,0 +1,175 @@
+/*
+ * 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.eviction.lru;
+
+import org.apache.ignite.*;
+import org.apache.ignite.cache.*;
+import org.apache.ignite.cache.eviction.lru.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.spi.discovery.tcp.*;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.*;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*;
+import org.apache.ignite.testframework.junits.common.*;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.*;
+import static org.apache.ignite.cache.CacheMode.*;
+import static org.apache.ignite.cache.CacheRebalanceMode.*;
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.*;
+
+/**
+ * LRU near eviction tests for NEAR_ONLY distribution mode (GG-8884).
+ */
+public class LruNearOnlyNearEvictionPolicySelfTest extends GridCommonAbstractTest {
+    /** */
+    private static final TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true);
+
+    /** Grid count. */
+    private static final int GRID_COUNT = 2;
+
+    /** Maximum size for near eviction policy. */
+    private static final int EVICTION_MAX_SIZE = 10;
+
+    /** Node count. */
+    private int cnt;
+
+    /** Caching mode specified by test. */
+    private CacheMode cacheMode;
+
+    /** Cache atomicity mode specified by test. */
+    private CacheAtomicityMode atomicityMode;
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        super.beforeTest();
+
+        cnt = 0;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration c = super.getConfiguration(gridName);
+
+        if (cnt == 0)
+            c.setClientMode(true);
+
+        CacheConfiguration cc = new CacheConfiguration();
+
+        cc.setAtomicityMode(atomicityMode);
+        cc.setCacheMode(cacheMode);
+        cc.setWriteSynchronizationMode(PRIMARY_SYNC);
+        cc.setRebalanceMode(SYNC);
+        cc.setStartSize(100);
+        cc.setBackups(0);
+
+        c.setCacheConfiguration(cc);
+
+        TcpDiscoverySpi disco = new TcpDiscoverySpi();
+
+        disco.setIpFinder(ipFinder);
+
+        c.setDiscoverySpi(disco);
+
+        cnt++;
+
+        return c;
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPartitionedAtomicNearEvictionMaxSize() throws Exception {
+        atomicityMode = ATOMIC;
+        cacheMode = PARTITIONED;
+
+        checkNearEvictionMaxSize();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPartitionedTransactionalNearEvictionMaxSize() throws Exception {
+        atomicityMode = TRANSACTIONAL;
+        cacheMode = PARTITIONED;
+
+        checkNearEvictionMaxSize();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testReplicatedAtomicNearEvictionMaxSize() throws Exception {
+        atomicityMode = ATOMIC;
+        cacheMode = REPLICATED;
+
+        checkNearEvictionMaxSize();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testReplicatedTransactionalNearEvictionMaxSize() throws Exception {
+        atomicityMode = TRANSACTIONAL;
+        cacheMode = REPLICATED;
+
+        checkNearEvictionMaxSize();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    private void checkNearEvictionMaxSize() throws Exception {
+        startGrids(GRID_COUNT);
+
+        try {
+            NearCacheConfiguration nearCfg = new NearCacheConfiguration();
+
+            LruEvictionPolicy plc = new LruEvictionPolicy();
+            plc.setMaxSize(EVICTION_MAX_SIZE);
+
+            nearCfg.setNearEvictionPolicy(plc);
+
+            grid(0).createNearCache(null, nearCfg);
+
+            int cnt = 1000;
+
+            info("Inserting " + cnt + " keys to cache.");
+
+            try (IgniteDataStreamer<Integer, String> ldr = grid(1).dataStreamer(null)) {
+                for (int i = 0; i < cnt; i++)
+                    ldr.addData(i, Integer.toString(i));
+            }
+
+            assertTrue("Near cache size " + near(0).nearSize() + ", but eviction maximum size " + EVICTION_MAX_SIZE,
+                near(0).nearSize() <= EVICTION_MAX_SIZE);
+
+            info("Getting " + cnt + " keys from cache.");
+
+            for (int i = 0; i < cnt; i++) {
+                IgniteCache<Integer, String> cache = grid(0).cache(null);
+
+                assertTrue(cache.get(i).equals(Integer.toString(i)));
+            }
+
+            assertTrue("Near cache size " + near(0).nearSize() + ", but eviction maximum size " + EVICTION_MAX_SIZE,
+                near(0).nearSize() <= EVICTION_MAX_SIZE);
+        }
+        finally {
+            stopAllGrids();
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e5d5d08d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/random/GridCacheRandomEvictionPolicySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/random/GridCacheRandomEvictionPolicySelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/random/GridCacheRandomEvictionPolicySelfTest.java
deleted file mode 100644
index 7088714..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/random/GridCacheRandomEvictionPolicySelfTest.java
+++ /dev/null
@@ -1,258 +0,0 @@
-/*
- * 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.eviction.random;
-
-import org.apache.ignite.*;
-import org.apache.ignite.cache.eviction.random.*;
-import org.apache.ignite.internal.processors.cache.eviction.*;
-import org.jetbrains.annotations.*;
-
-import java.util.*;
-import java.util.concurrent.*;
-
-/**
- * Random eviction policy test.
- */
-public class GridCacheRandomEvictionPolicySelfTest extends
-    GridCacheEvictionAbstractTest<RandomEvictionPolicy<String, String>> {
-    /**
-     * @throws Exception If failed.
-     */
-    public void testMemory() throws Exception {
-        try {
-            Ignite g = startGrid(0);
-
-            int max = 10;
-
-            policy(0).setMaxSize(max);
-
-            int keys = 31;
-
-            for (int i = 0; i < keys; i++) {
-                String s = Integer.toString(i);
-
-                g.cache(null).put(s, s);
-            }
-
-            assert g.cache(null).size() <= max;
-        }
-        finally {
-            stopAllGrids();
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testRandom() throws Exception {
-        try {
-            Ignite g = startGrid(0);
-
-            int max = 10;
-
-            policy(0).setMaxSize(max);
-
-            Random rand = new Random();
-
-            int keys = 31;
-
-            String[] t = new String[keys];
-
-            for (int i = 0; i < t.length; i++)
-                t[i] = Integer.toString(i);
-
-            int runs = 10000;
-
-            for (int i = 0; i < runs; i++) {
-                boolean rmv = rand.nextBoolean();
-
-                int j = rand.nextInt(t.length);
-
-                if (rmv)
-                    g.cache(null).remove(t[j]);
-                else
-                    g.cache(null).put(t[j], t[j]);
-
-                if (i % 1000 == 0)
-                    info("Stats [cntr=" + i + ", total=" + runs + ']');
-            }
-
-            assert g.cache(null).size() <= max;
-
-            info(policy(0));
-        }
-        finally {
-            stopAllGrids();
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testAllowEmptyEntries() throws Exception {
-        try {
-            startGrid();
-
-            IgniteCache<String, String> c = jcache();
-
-            MockEntry e1 = new MockEntry("1", c);
-
-            MockEntry e2 = new MockEntry("2", c);
-
-            MockEntry e3 = new MockEntry("3", c);
-
-            MockEntry e4 = new MockEntry("4", c);
-
-            MockEntry e5 = new MockEntry("5", c);
-
-            RandomEvictionPolicy<String, String> p = policy();
-
-            p.setMaxSize(10);
-
-            p.onEntryAccessed(false, e1);
-
-            assertFalse(e1.isEvicted());
-
-            p.onEntryAccessed(false, e2);
-
-            assertFalse(e1.isEvicted());
-            assertFalse(e2.isEvicted());
-
-            p.onEntryAccessed(false, e3);
-
-            assertFalse(e1.isEvicted());
-            assertFalse(e3.isEvicted());
-
-            p.onEntryAccessed(false, e4);
-
-            assertFalse(e1.isEvicted());
-            assertFalse(e3.isEvicted());
-            assertFalse(e4.isEvicted());
-
-            p.onEntryAccessed(false, e5);
-
-            assertFalse(e1.isEvicted());
-            assertFalse(e3.isEvicted());
-            assertFalse(e5.isEvicted());
-        }
-        finally {
-            stopAllGrids();
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testRandomMultiThreaded() throws Exception {
-        try {
-            final Ignite g = startGrid(0);
-
-            int max = 10;
-
-            policy(0).setMaxSize(max);
-
-            final Random rand = new Random();
-
-            int keys = 31;
-
-            final String[] t = new String[keys];
-
-            for (int i = 0; i < t.length; i++)
-                t[i] = Integer.toString(i);
-
-            multithreaded(new Callable() {
-                @Nullable @Override public Object call() {
-                    int runs = 3000;
-
-                    for (int i = 0; i < runs; i++) {
-                        boolean rmv = rand.nextBoolean();
-
-                        int j = rand.nextInt(t.length);
-
-                        if (rmv)
-                            g.cache(null).remove(t[j]);
-                        else
-                            g.cache(null).put(t[j], t[j]);
-
-                        if (i != 0 && i % 1000 == 0)
-                            info("Stats [cntr=" + i + ", total=" + runs + ']');
-                    }
-
-                    return null;
-                }
-            }, 10);
-
-            assert g.cache(null).size() <= max;
-
-            info(policy(0));
-        }
-        finally {
-            stopAllGrids();
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public void testPartitionedNearDisabled() throws Exception {
-        // No-op.
-    }
-
-    /** {@inheritDoc} */
-    @Override public void testPartitionedNearEnabled() throws Exception {
-        // No-op.
-    }
-
-    /** {@inheritDoc} */
-    @Override public void testPartitionedNearDisabledMultiThreaded() throws Exception {
-        // No-op.
-    }
-
-    /** {@inheritDoc} */
-    @Override public void testPartitionedNearDisabledBackupSyncMultiThreaded() throws Exception {
-        // No-op.
-    }
-
-    /** {@inheritDoc} */
-    @Override public void testPartitionedNearEnabledMultiThreaded() throws Exception {
-        // No-op.
-    }
-
-    /** {@inheritDoc} */
-    @Override public void testPartitionedNearEnabledBackupSyncMultiThreaded() throws Exception {
-        // No-op.
-    }
-
-    /** {@inheritDoc} */
-    @Override protected RandomEvictionPolicy<String, String> createPolicy(int plcMax) {
-        return new RandomEvictionPolicy<>(plcMax);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected RandomEvictionPolicy<String, String> createNearPolicy(int nearMax) {
-        return new RandomEvictionPolicy<>(plcMax);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void checkNearPolicies(int nearMax) {
-        // No-op.
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void checkPolicies(int plcMax) {
-        // No-op.
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e5d5d08d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/random/RandomEvictionPolicySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/random/RandomEvictionPolicySelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/random/RandomEvictionPolicySelfTest.java
new file mode 100644
index 0000000..ef34a13
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/random/RandomEvictionPolicySelfTest.java
@@ -0,0 +1,357 @@
+/*
+ * 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.eviction.random;
+
+import org.apache.ignite.*;
+import org.apache.ignite.cache.eviction.random.*;
+import org.apache.ignite.internal.processors.cache.eviction.*;
+import org.jetbrains.annotations.*;
+
+import java.util.*;
+import java.util.concurrent.*;
+
+/**
+ * Random eviction policy test.
+ */
+public class RandomEvictionPolicySelfTest extends
+    EvictionAbstractTest<RandomEvictionPolicy<String, String>> {
+    /**
+     * @throws Exception If failed.
+     */
+    public void testMemory() throws Exception {
+        try {
+            Ignite g = startGrid(0);
+
+            int max = 10;
+
+            policy(0).setMaxSize(max);
+
+            int keys = 31;
+
+            for (int i = 0; i < keys; i++) {
+                String s = Integer.toString(i);
+
+                g.cache(null).put(s, s);
+            }
+
+            assert g.cache(null).size() <= max;
+        }
+        finally {
+            stopAllGrids();
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testRandom() throws Exception {
+        try {
+            Ignite g = startGrid(0);
+
+            int max = 10;
+
+            policy(0).setMaxSize(max);
+
+            Random rand = new Random();
+
+            int keys = 31;
+
+            String[] t = new String[keys];
+
+            for (int i = 0; i < t.length; i++)
+                t[i] = Integer.toString(i);
+
+            int runs = 10000;
+
+            for (int i = 0; i < runs; i++) {
+                boolean rmv = rand.nextBoolean();
+
+                int j = rand.nextInt(t.length);
+
+                if (rmv)
+                    g.cache(null).remove(t[j]);
+                else
+                    g.cache(null).put(t[j], t[j]);
+
+                if (i % 1000 == 0)
+                    info("Stats [cntr=" + i + ", total=" + runs + ']');
+            }
+
+            assert g.cache(null).size() <= max;
+
+            info(policy(0));
+        }
+        finally {
+            stopAllGrids();
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testAllowEmptyEntries() throws Exception {
+        try {
+            startGrid();
+
+            IgniteCache<String, String> c = jcache();
+
+            MockEntry e1 = new MockEntry("1", c);
+            MockEntry e2 = new MockEntry("2", c);
+            MockEntry e3 = new MockEntry("3", c);
+            MockEntry e4 = new MockEntry("4", c);
+            MockEntry e5 = new MockEntry("5", c);
+
+            RandomEvictionPolicy<String, String> p = policy();
+
+            p.setMaxSize(10);
+
+            p.onEntryAccessed(false, e1);
+
+            assertFalse(e1.isEvicted());
+
+            p.onEntryAccessed(false, e2);
+
+            assertFalse(e1.isEvicted());
+            assertFalse(e2.isEvicted());
+
+            p.onEntryAccessed(false, e3);
+
+            assertFalse(e1.isEvicted());
+            assertFalse(e3.isEvicted());
+
+            p.onEntryAccessed(false, e4);
+
+            assertFalse(e1.isEvicted());
+            assertFalse(e3.isEvicted());
+            assertFalse(e4.isEvicted());
+
+            p.onEntryAccessed(false, e5);
+
+            assertFalse(e1.isEvicted());
+            assertFalse(e3.isEvicted());
+            assertFalse(e5.isEvicted());
+        }
+        finally {
+            stopAllGrids();
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testRandomMultiThreaded() throws Exception {
+        try {
+            final Ignite g = startGrid(0);
+
+            int max = 10;
+
+            policy(0).setMaxSize(max);
+
+            final Random rand = new Random();
+
+            int keys = 31;
+
+            final String[] t = new String[keys];
+
+            for (int i = 0; i < t.length; i++)
+                t[i] = Integer.toString(i);
+
+            multithreaded(new Callable() {
+                @Nullable @Override public Object call() {
+                    int runs = 3000;
+
+                    for (int i = 0; i < runs; i++) {
+                        boolean rmv = rand.nextBoolean();
+
+                        int j = rand.nextInt(t.length);
+
+                        if (rmv)
+                            g.cache(null).remove(t[j]);
+                        else
+                            g.cache(null).put(t[j], t[j]);
+
+                        if (i != 0 && i % 1000 == 0)
+                            info("Stats [cntr=" + i + ", total=" + runs + ']');
+                    }
+
+                    return null;
+                }
+            }, 10);
+
+            assert g.cache(null).size() <= max;
+
+            info(policy(0));
+        }
+        finally {
+            stopAllGrids();
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void testMaxMemSizeAllowEmptyEntries() throws Exception {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public void testMaxMemSizeMemory() throws Exception {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public void testMaxMemSizePartitionedNearDisabled() throws Exception {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public void testMaxMemSizePolicy() throws Exception {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public void testMaxMemSizePolicyWithBatch() throws Exception {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public void testMaxMemSizePut() throws Exception {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public void testMaxMemSizeRandom() throws Exception {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public void testMaxSizeAllowEmptyEntries() throws Exception {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public void testMaxSizeAllowEmptyEntriesWithBatch() throws Exception {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public void testMaxSizeMemory() throws Exception {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public void testMaxSizeMemoryWithBatch() throws Exception {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void doTestPolicy() throws Exception {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public void testMaxSizePut() throws Exception {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public void testMaxSizePutWithBatch() throws Exception {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public void testMaxSizeRandom() throws Exception {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public void testMaxSizeRandomWithBatch() throws Exception {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public void testMaxSizePolicyWithBatch() throws Exception {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public void testMaxSizePartitionedNearDisabledWithBatch() throws Exception {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void doTestPolicyWithBatch() throws Exception {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public void testMaxSizePartitionedNearDisabled() throws Exception {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public void testPartitionedNearEnabled() throws Exception {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public void testPartitionedNearDisabledMultiThreaded() throws Exception {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public void testPartitionedNearDisabledBackupSyncMultiThreaded() throws Exception {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public void testPartitionedNearEnabledMultiThreaded() throws Exception {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public void testPartitionedNearEnabledBackupSyncMultiThreaded() throws Exception {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override protected RandomEvictionPolicy<String, String> createPolicy(int plcMax) {
+        RandomEvictionPolicy<String, String> plc = new RandomEvictionPolicy<>();
+
+        plc.setMaxSize(plcMax);
+
+        return plc;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected RandomEvictionPolicy<String, String> createNearPolicy(int nearMax) {
+        RandomEvictionPolicy<String, String> plc = new RandomEvictionPolicy<>();
+
+        plc.setMaxSize(plcMax);
+
+        return plc;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void checkNearPolicies(int nearMax) {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void checkPolicies() {
+        // No-op.
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e5d5d08d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/sorted/GridCacheSortedBatchEvictionPolicySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/sorted/GridCacheSortedBatchEvictionPolicySelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/sorted/GridCacheSortedBatchEvictionPolicySelfTest.java
deleted file mode 100644
index 3cec217..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/sorted/GridCacheSortedBatchEvictionPolicySelfTest.java
+++ /dev/null
@@ -1,385 +0,0 @@
-/*
- * 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.eviction.sorted;
-
-import org.apache.ignite.*;
-import org.apache.ignite.cache.eviction.*;
-import org.apache.ignite.cache.eviction.sorted.*;
-import org.apache.ignite.internal.processors.cache.eviction.*;
-
-import java.util.*;
-
-import static org.apache.ignite.cache.CacheMode.*;
-
-/**
- * Sorted batch eviction test.
- */
-public class GridCacheSortedBatchEvictionPolicySelfTest extends
-    GridCacheEvictionAbstractTest<SortedEvictionPolicy<String, String>>{
-    /**
-     * @throws Exception If failed.
-     */
-    public void testPolicy() throws Exception {
-        try {
-            startGrid();
-
-            GridCacheEvictionAbstractTest.MockEntry e1 = new GridCacheEvictionAbstractTest.MockEntry("1", "1");
-            GridCacheEvictionAbstractTest.MockEntry e2 = new GridCacheEvictionAbstractTest.MockEntry("2", "2");
-            GridCacheEvictionAbstractTest.MockEntry e3 = new GridCacheEvictionAbstractTest.MockEntry("3", "3");
-            GridCacheEvictionAbstractTest.MockEntry e4 = new GridCacheEvictionAbstractTest.MockEntry("4", "4");
-            GridCacheEvictionAbstractTest.MockEntry e5 = new GridCacheEvictionAbstractTest.MockEntry("5", "5");
-
-            SortedEvictionPolicy<String, String> p = policy();
-
-            p.setMaxSize(3);
-
-            p.setBatchSize(2);
-
-            p.onEntryAccessed(false, e1);
-
-            check(p.set(), e1);
-
-            p.onEntryAccessed(false, e2);
-
-            check(p.set(), e1, e2);
-
-            p.onEntryAccessed(false, e3);
-
-            check(p.set(), e1, e2, e3);
-
-            p.onEntryAccessed(false, e4);
-
-            check(p.set(), e1, e2, e3, e4);
-
-            assertFalse(e1.isEvicted());
-            assertFalse(e2.isEvicted());
-            assertFalse(e3.isEvicted());
-            assertFalse(e4.isEvicted());
-
-            assertEquals(4, p.getCurrentSize());
-
-            p.onEntryAccessed(false, e5);
-
-            // Batch evicted.
-            check(p.set(), e3, e4, e5);
-
-            assertEquals(3, p.getCurrentSize());
-
-            assertTrue(e1.isEvicted());
-            assertTrue(e2.isEvicted());
-            assertFalse(e3.isEvicted());
-            assertFalse(e4.isEvicted());
-            assertFalse(e5.isEvicted());
-
-            p.onEntryAccessed(false, e1 = new GridCacheEvictionAbstractTest.MockEntry("1", "1"));
-
-            check(p.set(), e1, e3, e4, e5);
-
-            assertEquals(4, p.getCurrentSize());
-
-            assertFalse(e1.isEvicted());
-            assertFalse(e3.isEvicted());
-            assertFalse(e4.isEvicted());
-            assertFalse(e5.isEvicted());
-
-            p.onEntryAccessed(false, e5);
-
-            check(p.set(), e1, e3, e4, e5);
-
-            assertFalse(e1.isEvicted());
-            assertFalse(e3.isEvicted());
-            assertFalse(e4.isEvicted());
-            assertFalse(e5.isEvicted());
-
-            p.onEntryAccessed(false, e1);
-
-            assertEquals(4, p.getCurrentSize());
-
-            check(p.set(), e1, e3, e4, e5);
-
-            assertFalse(e1.isEvicted());
-            assertFalse(e3.isEvicted());
-            assertFalse(e4.isEvicted());
-            assertFalse(e5.isEvicted());
-
-            p.onEntryAccessed(true, e1);
-
-            assertEquals(3, p.getCurrentSize());
-
-            assertFalse(e3.isEvicted());
-            assertFalse(e4.isEvicted());
-            assertFalse(e5.isEvicted());
-
-            p.onEntryAccessed(true, e4);
-
-            assertEquals(2, p.getCurrentSize());
-
-            assertFalse(e3.isEvicted());
-            assertFalse(e5.isEvicted());
-
-            p.onEntryAccessed(true, e5);
-
-            assertEquals(1, p.getCurrentSize());
-
-            assertFalse(e3.isEvicted());
-
-            p.onEntryAccessed(true, e3);
-
-            assertEquals(0, p.getCurrentSize());
-
-            assertFalse(e3.isEvicted());
-
-            info(p);
-        }
-        finally {
-            stopAllGrids();
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testMemory() throws Exception {
-        try {
-            startGrid();
-
-            SortedEvictionPolicy<String, String> p = policy();
-
-            int max = 10;
-
-            int batchSize = 2;
-
-            p.setMaxSize(max);
-            p.setBatchSize(batchSize);
-
-            int cnt = max + batchSize;
-
-            for (int i = 0; i < cnt; i++)
-                p.onEntryAccessed(false, new GridCacheEvictionAbstractTest.MockEntry(Integer.toString(i), Integer.toString(i)));
-
-            info(p);
-
-            assertEquals(cnt - batchSize, p.getCurrentSize());
-        }
-        finally {
-            stopAllGrids();
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testRandom() throws Exception {
-        try {
-            startGrid();
-
-            SortedEvictionPolicy<String, String> p = policy();
-
-            int max = 10;
-
-            int batchSize = 2;
-
-            p.setMaxSize(max);
-
-            p.setBatchSize(batchSize);
-
-            Random rand = new Random();
-
-            int keys = 31;
-
-            GridCacheEvictionAbstractTest.MockEntry[] fifos = new GridCacheEvictionAbstractTest.MockEntry[keys];
-
-            for (int i = 0; i < fifos.length; i++)
-                fifos[i] = new GridCacheEvictionAbstractTest.MockEntry(Integer.toString(i));
-
-            int runs = 5000000;
-
-            for (int i = 0; i < runs; i++) {
-                boolean rmv = rand.nextBoolean();
-
-                int j = rand.nextInt(fifos.length);
-
-                GridCacheEvictionAbstractTest.MockEntry e = entry(fifos, j);
-
-                if (rmv)
-                    fifos[j] = new GridCacheEvictionAbstractTest.MockEntry(Integer.toString(j));
-
-                p.onEntryAccessed(rmv, e);
-            }
-
-            info(p);
-
-            int curSize = p.getCurrentSize();
-
-            assert curSize < max + batchSize :
-                "curSize < max + batchSize [curSize=" + curSize + ", max=" + max + ", batchSize=" + batchSize + ']';
-        }
-        finally {
-            stopAllGrids();
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testAllowEmptyEntries() throws Exception {
-        try {
-            startGrid();
-
-            GridCacheEvictionAbstractTest.MockEntry e1 = new GridCacheEvictionAbstractTest.MockEntry("1");
-
-            GridCacheEvictionAbstractTest.MockEntry e2 = new GridCacheEvictionAbstractTest.MockEntry("2");
-
-            GridCacheEvictionAbstractTest.MockEntry e3 = new GridCacheEvictionAbstractTest.MockEntry("3");
-
-            GridCacheEvictionAbstractTest.MockEntry e4 = new GridCacheEvictionAbstractTest.MockEntry("4");
-
-            GridCacheEvictionAbstractTest.MockEntry e5 = new GridCacheEvictionAbstractTest.MockEntry("5");
-
-            SortedEvictionPolicy<String, String> p = policy();
-
-            p.setBatchSize(2);
-
-            p.onEntryAccessed(false, e1);
-
-            assertFalse(e1.isEvicted());
-
-            p.onEntryAccessed(false, e2);
-
-            assertFalse(e1.isEvicted());
-            assertFalse(e2.isEvicted());
-
-            p.onEntryAccessed(false, e3);
-
-            assertFalse(e1.isEvicted());
-            assertFalse(e3.isEvicted());
-
-            p.onEntryAccessed(false, e4);
-
-            assertFalse(e1.isEvicted());
-            assertFalse(e3.isEvicted());
-            assertFalse(e4.isEvicted());
-
-            p.onEntryAccessed(false, e5);
-
-            assertFalse(e1.isEvicted());
-            assertFalse(e3.isEvicted());
-            assertFalse(e5.isEvicted());
-        }
-        finally {
-            stopAllGrids();
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testPut() throws Exception {
-        mode = LOCAL;
-        syncCommit = true;
-        plcMax = 10;
-
-        Ignite ignite = startGrid();
-
-        try {
-            IgniteCache<Object, Object> cache = ignite.cache(null);
-
-            int cnt = 500;
-
-            int min = Integer.MAX_VALUE;
-
-            int minIdx = 0;
-
-            for (int i = 0; i < cnt; i++) {
-                cache.put(i, i);
-
-                int cacheSize = cache.size();
-
-                if (i > plcMax && cacheSize < min) {
-                    min = cacheSize;
-                    minIdx = i;
-                }
-            }
-
-            // Batch evicted.
-            assert min >= plcMax : "Min cache size is too small: " + min;
-
-            info("Min cache size [min=" + min + ", idx=" + minIdx + ']');
-            info("Current cache size " + cache.size());
-            info("Current cache key size " + cache.size());
-
-            min = Integer.MAX_VALUE;
-
-            minIdx = 0;
-
-            // Touch.
-            for (int i = cnt; --i > cnt - plcMax;) {
-                cache.get(i);
-
-                int cacheSize = cache.size();
-
-                if (cacheSize < min) {
-                    min = cacheSize;
-                    minIdx = i;
-                }
-            }
-
-            info("----");
-            info("Min cache size [min=" + min + ", idx=" + minIdx + ']');
-            info("Current cache size " + cache.size());
-            info("Current cache key size " + cache.size());
-
-            // Batch evicted.
-            assert min >= plcMax : "Min cache size is too small: " + min;
-        }
-        finally {
-            stopAllGrids();
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public void testPartitionedNearDisabled() throws Exception {
-        plcBatchSize = 2;
-
-        super.testPartitionedNearDisabled();
-    }
-
-    /** {@inheritDoc} */
-    @Override protected SortedEvictionPolicy<String, String> createPolicy(int plcMax) {
-        return new SortedEvictionPolicy<>(10, 2, null);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected SortedEvictionPolicy<String, String> createNearPolicy(int nearMax) {
-        return new SortedEvictionPolicy<>(nearMax, 2, null);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void checkNearPolicies(int endNearPlcSize) {
-        for (int i = 0; i < gridCnt; i++)
-            for (EvictableEntry<String, String> e : nearPolicy(i).set())
-                assert !e.isCached() : "Invalid near policy size: " + nearPolicy(i).set();
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void checkPolicies(int plcMax) {
-        for (int i = 0; i < gridCnt; i++)
-            assert policy(i).set().size() <= plcMax + policy(i).getBatchSize();
-    }
-
-}