http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a916db69/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/eviction/fifo/GridCacheFifoEvictionPolicySelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/eviction/fifo/GridCacheFifoEvictionPolicySelfTest.java b/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/eviction/fifo/GridCacheFifoEvictionPolicySelfTest.java deleted file mode 100644 index 0095262..0000000 --- a/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/eviction/fifo/GridCacheFifoEvictionPolicySelfTest.java +++ /dev/null @@ -1,380 +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.gridgain.grid.kernal.processors.cache.eviction.fifo; - -import org.apache.ignite.*; -import org.apache.ignite.cache.*; -import org.apache.ignite.cache.eviction.fifo.*; -import org.gridgain.grid.kernal.processors.cache.eviction.*; - -import java.util.*; - -import static org.apache.ignite.cache.GridCacheMode.*; - -/** - * FIFO Eviction test. - */ -@SuppressWarnings({"TypeMayBeWeakened"}) -public class GridCacheFifoEvictionPolicySelfTest extends - GridCacheEvictionAbstractTest<GridCacheFifoEvictionPolicy<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"); - - GridCacheFifoEvictionPolicy<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(); - - GridCacheFifoEvictionPolicy<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(); - - GridCacheFifoEvictionPolicy<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"); - - e1.setValue("val"); - - MockEntry e2 = new MockEntry("2"); - - MockEntry e3 = new MockEntry("3"); - - e3.setValue("val"); - - MockEntry e4 = new MockEntry("4"); - - MockEntry e5 = new MockEntry("5"); - - e5.setValue("val"); - - GridCacheFifoEvictionPolicy<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 { - GridCache<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()); - info("Current cache key size " + cache.size()); - info("Current cache entry set size " + cache.entrySet().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()); - info("Current cache entry set size " + cache.entrySet().size()); - - assert min >= plcMax : "Min cache size is too small: " + min; - } - finally { - stopAllGrids(); - } - } - - /** {@inheritDoc} */ - @Override protected GridCacheFifoEvictionPolicy<String, String> createPolicy(int plcMax) { - return new GridCacheFifoEvictionPolicy<>(plcMax); - } - - /** {@inheritDoc} */ - @Override protected GridCacheFifoEvictionPolicy<String, String> createNearPolicy(int nearMax) { - return new GridCacheFifoEvictionPolicy<>(nearMax); - } - - /** {@inheritDoc} */ - @Override protected void checkNearPolicies(int endNearPlcSize) { - for (int i = 0; i < gridCnt; i++) - for (GridCacheEntry<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/a916db69/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/eviction/lru/GridCacheLruEvictionPolicySelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/eviction/lru/GridCacheLruEvictionPolicySelfTest.java b/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/eviction/lru/GridCacheLruEvictionPolicySelfTest.java deleted file mode 100644 index dbc33d2..0000000 --- a/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/eviction/lru/GridCacheLruEvictionPolicySelfTest.java +++ /dev/null @@ -1,426 +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.gridgain.grid.kernal.processors.cache.eviction.lru; - -import org.apache.ignite.*; -import org.apache.ignite.cache.*; -import org.apache.ignite.cache.eviction.lru.*; -import org.gridgain.grid.kernal.processors.cache.eviction.*; - -import java.util.*; - -/** - * LRU Eviction test. - */ -@SuppressWarnings( {"TypeMayBeWeakened"}) -public class GridCacheLruEvictionPolicySelfTest extends - GridCacheEvictionAbstractTest<GridCacheLruEvictionPolicy<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"); - - GridCacheLruEvictionPolicy<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 { - GridCacheLruEvictionPolicy<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 { - GridCacheLruEvictionPolicy<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 { - GridCacheLruEvictionPolicy<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"); - - e1.setValue("val"); - - MockEntry e2 = new MockEntry("2"); - - MockEntry e3 = new MockEntry("3"); - - e3.setValue("val"); - - MockEntry e4 = new MockEntry("4"); - - MockEntry e5 = new MockEntry("5"); - - e5.setValue("val"); - - GridCacheLruEvictionPolicy<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 = GridCacheMode.LOCAL; - syncCommit = true; - plcMax = 100; - - Ignite ignite = startGrid(); - - try { - GridCache<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()); - info("Current cache key size " + cache.size()); - info("Current cache entry set size " + cache.entrySet().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()); - info("Current cache entry set size " + cache.entrySet().size()); - - assert min >= plcMax : "Min cache size is too small: " + min; - } - finally { - stopAllGrids(); - } - } - - /** {@inheritDoc} */ - @Override protected GridCacheLruEvictionPolicy<String, String> createPolicy(int plcMax) { - return new GridCacheLruEvictionPolicy<>(plcMax); - } - - @Override protected GridCacheLruEvictionPolicy<String, String> createNearPolicy(int nearMax) { - return new GridCacheLruEvictionPolicy<>(nearMax); - } - - /** {@inheritDoc} */ - @Override protected void checkNearPolicies(int endNearPlcSize) { - for (int i = 0; i < gridCnt; i++) - for (GridCacheEntry<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/a916db69/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/eviction/lru/GridCacheLruNearEvictionPolicySelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/eviction/lru/GridCacheLruNearEvictionPolicySelfTest.java b/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/eviction/lru/GridCacheLruNearEvictionPolicySelfTest.java deleted file mode 100644 index e8f3084..0000000 --- a/modules/core/src/test/java/org/gridgain/grid/kernal/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.gridgain.grid.kernal.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.GridCacheAtomicityMode.*; -import static org.apache.ignite.cache.GridCacheDistributionMode.*; -import static org.apache.ignite.cache.GridCacheMode.*; -import static org.apache.ignite.cache.GridCachePreloadMode.*; -import static org.apache.ignite.cache.GridCacheWriteSynchronizationMode.*; - -/** - * 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 GridCacheAtomicityMode 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.setDistributionMode(NEAR_PARTITIONED); - cc.setPreloadMode(SYNC); - cc.setNearEvictionPolicy(new GridCacheLruEvictionPolicy(EVICTION_MAX_SIZE)); - cc.setStartSize(100); - cc.setQueryIndexEnabled(true); - cc.setBackups(0); - - 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 (IgniteDataLoader<Integer, String> ldr = grid(0).dataLoader(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++) { - GridCache<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/a916db69/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/eviction/lru/GridCacheNearOnlyLruNearEvictionPolicySelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/eviction/lru/GridCacheNearOnlyLruNearEvictionPolicySelfTest.java b/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/eviction/lru/GridCacheNearOnlyLruNearEvictionPolicySelfTest.java deleted file mode 100644 index c4b37b9..0000000 --- a/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/eviction/lru/GridCacheNearOnlyLruNearEvictionPolicySelfTest.java +++ /dev/null @@ -1,167 +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.gridgain.grid.kernal.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.GridCacheAtomicityMode.*; -import static org.apache.ignite.cache.GridCacheDistributionMode.*; -import static org.apache.ignite.cache.GridCacheMode.*; -import static org.apache.ignite.cache.GridCachePreloadMode.*; -import static org.apache.ignite.cache.GridCacheWriteSynchronizationMode.*; - -/** - * 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 GridCacheMode cacheMode; - - /** Cache atomicity mode specified by test. */ - private GridCacheAtomicityMode 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); - - CacheConfiguration cc = new CacheConfiguration(); - - cc.setAtomicityMode(atomicityMode); - cc.setCacheMode(cacheMode); - cc.setWriteSynchronizationMode(PRIMARY_SYNC); - cc.setDistributionMode(cnt == 0 ? NEAR_ONLY : PARTITIONED_ONLY); - cc.setPreloadMode(SYNC); - cc.setNearEvictionPolicy(new GridCacheLruEvictionPolicy(EVICTION_MAX_SIZE)); - cc.setStartSize(100); - cc.setQueryIndexEnabled(true); - 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 { - int cnt = 1000; - - info("Inserting " + cnt + " keys to cache."); - - try (IgniteDataLoader<Integer, String> ldr = grid(1).dataLoader(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++) { - GridCache<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/a916db69/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/eviction/random/GridCacheRandomEvictionPolicySelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/eviction/random/GridCacheRandomEvictionPolicySelfTest.java b/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/eviction/random/GridCacheRandomEvictionPolicySelfTest.java deleted file mode 100644 index 0e63aad..0000000 --- a/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/eviction/random/GridCacheRandomEvictionPolicySelfTest.java +++ /dev/null @@ -1,265 +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.gridgain.grid.kernal.processors.cache.eviction.random; - -import org.apache.ignite.*; -import org.apache.ignite.cache.*; -import org.apache.ignite.cache.eviction.random.*; -import org.gridgain.grid.kernal.processors.cache.eviction.*; -import org.jetbrains.annotations.*; - -import java.util.*; -import java.util.concurrent.*; - -/** - * Random eviction policy test. - */ -public class GridCacheRandomEvictionPolicySelfTest extends - GridCacheEvictionAbstractTest<GridCacheRandomEvictionPolicy<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(); - - GridCache<String, String> c = cache(); - - MockEntry e1 = new MockEntry("1", c); - - e1.setValue("val"); - - MockEntry e2 = new MockEntry("2", c); - - MockEntry e3 = new MockEntry("3", c); - - e3.setValue("val"); - - MockEntry e4 = new MockEntry("4", c); - - MockEntry e5 = new MockEntry("5", c); - - e5.setValue("val"); - - GridCacheRandomEvictionPolicy<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() throws IgniteCheckedException { - 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 GridCacheRandomEvictionPolicy<String, String> createPolicy(int plcMax) { - return new GridCacheRandomEvictionPolicy<>(plcMax); - } - - /** {@inheritDoc} */ - @Override protected GridCacheRandomEvictionPolicy<String, String> createNearPolicy(int nearMax) { - return new GridCacheRandomEvictionPolicy<>(plcMax); - } - - /** {@inheritDoc} */ - @Override protected void checkNearPolicies(int nearMax) { - // No-op. - } - - /** {@inheritDoc} */ - @Override protected void checkPolicies(int plcMax) { - // No-op. - } -}