http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1652fd18/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(); - } - -}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1652fd18/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/sorted/GridCacheSortedEvictionPolicyPerformanceTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/sorted/GridCacheSortedEvictionPolicyPerformanceTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/sorted/GridCacheSortedEvictionPolicyPerformanceTest.java deleted file mode 100644 index 8d97a1e..0000000 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/sorted/GridCacheSortedEvictionPolicyPerformanceTest.java +++ /dev/null @@ -1,135 +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.*; -import org.apache.ignite.cache.eviction.fifo.*; -import org.apache.ignite.cache.eviction.sorted.*; -import org.apache.ignite.configuration.*; -import org.apache.ignite.internal.util.typedef.internal.*; -import org.apache.ignite.testframework.junits.common.*; - -import org.jsr166.*; - -import java.util.concurrent.*; -import java.util.concurrent.atomic.*; - -/** - * {@link SortedEvictionPolicy} performance test. - */ -public class GridCacheSortedEvictionPolicyPerformanceTest extends GridCommonAbstractTest { - /** Threads. */ - private static final int THREADS = 8; - - /** Keys. */ - private static final int KEYS = 100_000; - - /** Max size. */ - private static final int MAX_SIZE = 1000; - - /** Put probability. */ - private static final int P_PUT = 50; - - /** Get probability. */ - private static final int P_GET = 30; - - /** Measurement count. */ - private static final int MEASUREMENT_CNT = 100; - - /** Rnd. */ - private static final ThreadLocalRandom8 RND = ThreadLocalRandom8.current(); - - /** Ignite. */ - private static Ignite ignite; - - /** {@inheritDoc} */ - @Override protected void beforeTestsStarted() throws Exception { - ignite = startGrid(); - } - - /** {@inheritDoc} */ - @Override protected void afterTestsStopped() throws Exception { - stopAllGrids(); - } - - /** {@inheritDoc} */ - @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { - IgniteConfiguration cfg = super.getConfiguration(gridName); - - CacheConfiguration ccfg = defaultCacheConfiguration(); - - ccfg.setCacheMode(CacheMode.PARTITIONED); - ccfg.setAtomicityMode(CacheAtomicityMode.ATOMIC); - ccfg.setNearConfiguration(null); - ccfg.setEvictionPolicy(new SortedEvictionPolicy(MAX_SIZE)); -// ccfg.setEvictionPolicy(new FifoEvictionPolicy(MAX_SIZE)); - ccfg.setEvictSynchronized(false); - - cfg.setPeerClassLoadingEnabled(false); - - cfg.setCacheConfiguration(ccfg); - - return cfg; - } - - /** - * Tests throughput. - */ - public void testThroughput() throws Exception { - final LongAdder8 cnt = new LongAdder8(); - final AtomicBoolean finished = new AtomicBoolean(); - - final int pPut = P_PUT; - final int pGet = P_PUT + P_GET; - - final IgniteCache<Integer, Integer> cache = ignite.cache(null); - - multithreadedAsync(new Callable<Object>() { - @Override public Object call() throws Exception { - for (;;) { - U.sleep(1000); - - info("Ops/sec: " + cnt.sumThenReset()); - } - } - }, 1); - - multithreaded( - new Callable<Object>() { - @Override public Object call() throws Exception { - while (!finished.get()) { - int p = RND.nextInt(100); - - int key = RND.nextInt(KEYS); - - if (p >= 0 && p < pPut) - cache.put(key, 0); - else if (p >= pPut && p < pGet) - cache.get(key); - else - cache.remove(key); - - cnt.increment(); - } - - return null; - } - }, THREADS); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1652fd18/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/sorted/GridCacheSortedEvictionPolicySelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/sorted/GridCacheSortedEvictionPolicySelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/sorted/GridCacheSortedEvictionPolicySelfTest.java deleted file mode 100644 index 041234e..0000000 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/sorted/GridCacheSortedEvictionPolicySelfTest.java +++ /dev/null @@ -1,373 +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 eviction test. - */ -public class GridCacheSortedEvictionPolicySelfTest extends - GridCacheEvictionAbstractTest<SortedEvictionPolicy<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"); - - SortedEvictionPolicy<String, String> p = policy(); - - p.setMaxSize(3); - - 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); - - assertFalse(e1.isEvicted()); - assertFalse(e2.isEvicted()); - assertFalse(e3.isEvicted()); - - assertEquals(3, p.getCurrentSize()); - - p.onEntryAccessed(false, e4); - - check(p.set(), e2, e3, e4); - - assertEquals(3, p.getCurrentSize()); - - assertTrue(e1.isEvicted()); - assertFalse(e2.isEvicted()); - assertFalse(e3.isEvicted()); - assertFalse(e4.isEvicted()); - - p.onEntryAccessed(false, e5); - - check(p.set(), e3, e4, e5); - - assertEquals(3, p.getCurrentSize()); - - assertTrue(e2.isEvicted()); - assertFalse(e3.isEvicted()); - assertFalse(e4.isEvicted()); - assertFalse(e5.isEvicted()); - - p.onEntryAccessed(false, e1 = new MockEntry("1", "1")); - - check(p.set(), e3, e4, e5); - - assertEquals(3, p.getCurrentSize()); - - assertTrue(e1.isEvicted()); - assertFalse(e3.isEvicted()); - assertFalse(e4.isEvicted()); - assertFalse(e5.isEvicted()); - - p.onEntryAccessed(false, e5); - - check(p.set(), e3, e4, e5); - - assertFalse(e3.isEvicted()); - assertFalse(e4.isEvicted()); - assertFalse(e5.isEvicted()); - - p.onEntryAccessed(false, e1); - - assertEquals(3, p.getCurrentSize()); - - check(p.set(), e3, e4, e5); - - assertTrue(e1.isEvicted()); - assertFalse(e3.isEvicted()); - assertFalse(e4.isEvicted()); - assertFalse(e5.isEvicted()); - - p.onEntryAccessed(false, e5); - - assertEquals(3, p.getCurrentSize()); - - check(p.set(), e3, e4, e5); - - assertFalse(e3.isEvicted()); - assertFalse(e4.isEvicted()); - assertFalse(e5.isEvicted()); - - p.onEntryAccessed(true, e3); - - assertEquals(2, p.getCurrentSize()); - - assertFalse(e3.isEvicted()); - assertFalse(e4.isEvicted()); - assertFalse(e5.isEvicted()); - - p.onEntryAccessed(true, e4); - - assertEquals(1, p.getCurrentSize()); - - assertFalse(e4.isEvicted()); - assertFalse(e5.isEvicted()); - - p.onEntryAccessed(true, e5); - - assertEquals(0, p.getCurrentSize()); - - assertFalse(e5.isEvicted()); - - info(p); - } - finally { - stopAllGrids(); - } - } - - /** - * @throws Exception If failed. - */ - public void testMemory() throws Exception { - try { - startGrid(); - - SortedEvictionPolicy<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(); - - SortedEvictionPolicy<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(); - - assertTrue("curSize <= max [curSize=" + curSize + ", max=" + max + ']', curSize <= 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"); - - SortedEvictionPolicy<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; - } - } - - assertTrue("Min cache size is too small: " + min, min >= plcMax); - - 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()); - - assertTrue("Min cache size is too small: " + min, min >= plcMax); - } - finally { - stopAllGrids(); - } - } - - /** {@inheritDoc} */ - @Override protected SortedEvictionPolicy<String, String> createPolicy(int plcMax) { - return new SortedEvictionPolicy<>(plcMax); - } - - /** {@inheritDoc} */ - @Override protected SortedEvictionPolicy<String, String> createNearPolicy(int nearMax) { - return new SortedEvictionPolicy<>(nearMax); - } - - /** {@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; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1652fd18/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/sorted/SortedEvictionPolicyPerformanceTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/sorted/SortedEvictionPolicyPerformanceTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/sorted/SortedEvictionPolicyPerformanceTest.java new file mode 100644 index 0000000..a687da9 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/sorted/SortedEvictionPolicyPerformanceTest.java @@ -0,0 +1,134 @@ +/* + * 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.*; +import org.apache.ignite.cache.eviction.sorted.*; +import org.apache.ignite.configuration.*; +import org.apache.ignite.internal.util.typedef.internal.*; +import org.apache.ignite.testframework.junits.common.*; + +import org.jsr166.*; + +import java.util.concurrent.*; +import java.util.concurrent.atomic.*; + +/** + * {@link SortedEvictionPolicy} performance test. + */ +public class SortedEvictionPolicyPerformanceTest extends GridCommonAbstractTest { + /** Threads. */ + private static final int THREADS = 8; + + /** Keys. */ + private static final int KEYS = 100_000; + + /** Max size. */ + private static final int MAX_SIZE = 1000; + + /** Put probability. */ + private static final int P_PUT = 50; + + /** Get probability. */ + private static final int P_GET = 30; + + /** Rnd. */ + private static final ThreadLocalRandom8 RND = ThreadLocalRandom8.current(); + + /** Ignite. */ + private static Ignite ignite; + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + ignite = startGrid(); + } + + /** {@inheritDoc} */ + @Override protected void afterTestsStopped() throws Exception { + stopAllGrids(); + } + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + CacheConfiguration ccfg = defaultCacheConfiguration(); + + ccfg.setCacheMode(CacheMode.PARTITIONED); + ccfg.setAtomicityMode(CacheAtomicityMode.ATOMIC); + ccfg.setNearConfiguration(null); + + SortedEvictionPolicy plc = new SortedEvictionPolicy(); + plc.setMaxSize(MAX_SIZE); + + ccfg.setEvictionPolicy(plc); + ccfg.setEvictSynchronized(false); + + cfg.setPeerClassLoadingEnabled(false); + + cfg.setCacheConfiguration(ccfg); + + return cfg; + } + + /** + * Tests throughput. + */ + public void testThroughput() throws Exception { + final LongAdder8 cnt = new LongAdder8(); + final AtomicBoolean finished = new AtomicBoolean(); + + final int pPut = P_PUT; + final int pGet = P_PUT + P_GET; + + final IgniteCache<Integer, Integer> cache = ignite.cache(null); + + multithreadedAsync(new Callable<Object>() { + @Override public Object call() throws Exception { + for (;;) { + U.sleep(1000); + + info("Ops/sec: " + cnt.sumThenReset()); + } + } + }, 1); + + multithreaded( + new Callable<Object>() { + @Override public Object call() throws Exception { + while (!finished.get()) { + int p = RND.nextInt(100); + + int key = RND.nextInt(KEYS); + + if (p >= 0 && p < pPut) + cache.put(key, 0); + else if (p >= pPut && p < pGet) + cache.get(key); + else + cache.remove(key); + + cnt.increment(); + } + + return null; + } + }, THREADS); + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1652fd18/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/sorted/SortedEvictionPolicySelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/sorted/SortedEvictionPolicySelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/sorted/SortedEvictionPolicySelfTest.java new file mode 100644 index 0000000..a283352 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/sorted/SortedEvictionPolicySelfTest.java @@ -0,0 +1,266 @@ +/* + * 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.cache.eviction.sorted.*; +import org.apache.ignite.internal.processors.cache.eviction.*; + +/** + * Sorted eviction policy tests. + */ +public class SortedEvictionPolicySelfTest extends + EvictionAbstractTest<SortedEvictionPolicy<String, String>> { + /** {@inheritDoc} */ + @Override protected void doTestPolicy() 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"); + + SortedEvictionPolicy<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()); + + check(MockEntry.ENTRY_SIZE, p.queue(), e1, e2, e3); + + p.onEntryAccessed(false, 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(), e3, e4, e5); + + assertTrue(e1.isEvicted()); + assertFalse(e3.isEvicted()); + assertFalse(e4.isEvicted()); + assertFalse(e5.isEvicted()); + + p.onEntryAccessed(false, e5); + + check(MockEntry.ENTRY_SIZE, p.queue(), e3, e4, e5); + + assertFalse(e3.isEvicted()); + assertFalse(e4.isEvicted()); + assertFalse(e5.isEvicted()); + + p.onEntryAccessed(false, e1); + + check(MockEntry.ENTRY_SIZE, p.queue(), e3, e4, e5); + + assertTrue(e1.isEvicted()); + assertFalse(e3.isEvicted()); + assertFalse(e4.isEvicted()); + assertFalse(e5.isEvicted()); + + p.onEntryAccessed(false, e5); + + check(MockEntry.ENTRY_SIZE, p.queue(), e3, e4, e5); + + assertFalse(e3.isEvicted()); + assertFalse(e4.isEvicted()); + assertFalse(e5.isEvicted()); + + p.onEntryAccessed(true, e3); + + check(MockEntry.ENTRY_SIZE, p.queue(), e4, e5); + + assertFalse(e3.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 { + stopAllGrids(); + } + } + + /** {@inheritDoc} */ + @Override protected void doTestPolicyWithBatch() 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"); + + SortedEvictionPolicy<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); + + 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(), e1, e3, e4, e5); + + assertFalse(e1.isEvicted()); + assertFalse(e3.isEvicted()); + assertFalse(e4.isEvicted()); + assertFalse(e5.isEvicted()); + + p.onEntryAccessed(false, e5); + + check(MockEntry.ENTRY_SIZE, p.queue(), e1, e3, e4, e5); + + assertFalse(e1.isEvicted()); + assertFalse(e3.isEvicted()); + assertFalse(e4.isEvicted()); + assertFalse(e5.isEvicted()); + + p.onEntryAccessed(false, e1); + + check(MockEntry.ENTRY_SIZE, p.queue(), e1, e3, e4, e5); + + assertFalse(e1.isEvicted()); + assertFalse(e3.isEvicted()); + assertFalse(e4.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()); + + assertFalse(e3.isEvicted()); + + info(p); + } + finally { + stopAllGrids(); + } + } + + /** {@inheritDoc} */ + @Override protected SortedEvictionPolicy<String, String> createPolicy(int plcMax) { + SortedEvictionPolicy<String, String> plc = new SortedEvictionPolicy<>(); + + plc.setMaxSize(this.plcMax); + plc.setBatchSize(this.plcBatchSize); + plc.setMaxMemorySize(this.plcMaxMemSize); + + return plc; + } + + /** {@inheritDoc} */ + @Override protected SortedEvictionPolicy<String, String> createNearPolicy(int nearMax) { + SortedEvictionPolicy<String, String> plc = new SortedEvictionPolicy<>(); + + plc.setMaxSize(nearMax); + plc.setBatchSize(plcBatchSize); + + return plc; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1652fd18/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/expiry/IgniteCacheClientNearCacheExpiryTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/expiry/IgniteCacheClientNearCacheExpiryTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/expiry/IgniteCacheClientNearCacheExpiryTest.java new file mode 100644 index 0000000..602ac18 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/expiry/IgniteCacheClientNearCacheExpiryTest.java @@ -0,0 +1,103 @@ +/* + * 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.expiry; + +import org.apache.ignite.*; +import org.apache.ignite.cache.*; +import org.apache.ignite.configuration.*; +import org.apache.ignite.internal.processors.cache.*; +import org.apache.ignite.internal.util.typedef.internal.*; + +import javax.cache.expiry.*; + +import java.util.concurrent.*; + +import static org.apache.ignite.cache.CacheAtomicityMode.*; +import static org.apache.ignite.cache.CacheMode.*; + +/** + * + */ +public class IgniteCacheClientNearCacheExpiryTest extends IgniteCacheAbstractTest { + /** */ + private static final int NODES = 3; + + /** {@inheritDoc} */ + @Override protected int gridCount() { + return NODES; + } + + /** {@inheritDoc} */ + @Override protected CacheMode cacheMode() { + return PARTITIONED; + } + + /** {@inheritDoc} */ + @Override protected CacheAtomicityMode atomicityMode() { + return TRANSACTIONAL; + } + + /** {@inheritDoc} */ + @Override protected NearCacheConfiguration nearConfiguration() { + return new NearCacheConfiguration(); + } + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + if (gridName.equals(getTestGridName(NODES - 1))) + cfg.setClientMode(true); + + return cfg; + } + + /** + * @throws Exception If failed. + */ + public void testExpirationOnClient() throws Exception { + Ignite ignite = grid(NODES - 1); + + assertTrue(ignite.configuration().isClientMode()); + + IgniteCache<Object, Object> cache = ignite.cache(null); + + assertTrue(((IgniteCacheProxy)cache).context().isNear()); + + for (int i = 0 ; i < 100; i++) + cache.put(i, i); + + CreatedExpiryPolicy plc = new CreatedExpiryPolicy(new Duration(TimeUnit.MILLISECONDS, 500)); + + IgniteCache<Object, Object> cacheWithExpiry = cache.withExpiryPolicy(plc); + + for (int i = 100 ; i < 200; i++) { + cacheWithExpiry.put(i, i); + + assertEquals(i, cacheWithExpiry.localPeek(i)); + } + + U.sleep(1000); + + for (int i = 0 ; i < 100; i++) + assertEquals(i, cacheWithExpiry.localPeek(i)); + + for (int i = 100 ; i < 200; i++) + assertNull(cache.localPeek(i)); + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1652fd18/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/expiry/IgniteCacheExpiryPolicyTestSuite.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/expiry/IgniteCacheExpiryPolicyTestSuite.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/expiry/IgniteCacheExpiryPolicyTestSuite.java index c006f69..c78ec5c 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/expiry/IgniteCacheExpiryPolicyTestSuite.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/expiry/IgniteCacheExpiryPolicyTestSuite.java @@ -50,6 +50,8 @@ public class IgniteCacheExpiryPolicyTestSuite extends TestSuite { suite.addTestSuite(IgniteCacheTtlCleanupSelfTest.class); + suite.addTestSuite(IgniteCacheClientNearCacheExpiryTest.class); + return suite; } } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1652fd18/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/CacheLocalOffHeapAndSwapMetricsSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/CacheLocalOffHeapAndSwapMetricsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/CacheLocalOffHeapAndSwapMetricsSelfTest.java new file mode 100644 index 0000000..3d44600 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/CacheLocalOffHeapAndSwapMetricsSelfTest.java @@ -0,0 +1,412 @@ +/* + * 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.local; + +import org.apache.ignite.*; +import org.apache.ignite.cache.*; +import org.apache.ignite.cache.eviction.fifo.*; +import org.apache.ignite.configuration.*; +import org.apache.ignite.spi.swapspace.file.*; +import org.apache.ignite.testframework.junits.common.*; + +/** + * + */ +public class CacheLocalOffHeapAndSwapMetricsSelfTest extends GridCommonAbstractTest { + /** Grid count. */ + private static final int GRID_CNT = 1; + + /** Keys count. */ + private static final int KEYS_CNT = 1000; + + /** Max size. */ + private static final int MAX_SIZE = 100; + + /** Entry size. */ + private static final int ENTRY_SIZE = 86; // Calculated as allocated size divided on entries count. + + /** Offheap max count. */ + private static final int OFFHEAP_MAX_CNT = KEYS_CNT / 2; + + /** Offheap max size. */ + private static final int OFFHEAP_MAX_SIZE = ENTRY_SIZE * OFFHEAP_MAX_CNT; + + /** Cache. */ + private IgniteCache<Integer, Integer> cache; + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + cfg.setSwapSpaceSpi(new FileSwapSpaceSpi()); + + return cfg; + } + + /** + * @param offHeapSize Max off-heap size. + * @param swapEnabled Swap enabled. + */ + private void createCache(int offHeapSize, boolean swapEnabled) { + CacheConfiguration ccfg = defaultCacheConfiguration(); + + ccfg.setStatisticsEnabled(true); + + ccfg.setCacheMode(CacheMode.LOCAL); + ccfg.setAtomicityMode(CacheAtomicityMode.ATOMIC); + ccfg.setMemoryMode(CacheMemoryMode.ONHEAP_TIERED); + + ccfg.setOffHeapMaxMemory(offHeapSize); + ccfg.setSwapEnabled(swapEnabled); + + ccfg.setEvictionPolicy(new FifoEvictionPolicy(MAX_SIZE)); + + cache = grid(0).getOrCreateCache(ccfg); + } + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + super.beforeTestsStarted(); + + startGrids(GRID_CNT); + } + + /** {@inheritDoc} */ + @Override protected void afterTestsStopped() throws Exception { + super.afterTestsStopped(); + + stopAllGrids(); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + if (cache != null) + cache.close(); + } + + /** + * @throws Exception if failed. + */ + public void testOffHeapMetrics() throws Exception { + createCache(0, false); + + for (int i = 0; i < KEYS_CNT; i++) + cache.put(i, i); + + printStat(); + + assertEquals(cache.metrics().getCacheEvictions(), cache.metrics().getOffHeapPuts()); + assertEquals(KEYS_CNT, cache.metrics().getOffHeapGets()); + assertEquals(0, cache.metrics().getOffHeapHits()); + assertEquals(0f, cache.metrics().getOffHeapHitPercentage()); + assertEquals(KEYS_CNT, cache.metrics().getOffHeapMisses()); + assertEquals(100f, cache.metrics().getOffHeapMissPercentage()); + assertEquals(0, cache.metrics().getOffHeapRemovals()); + + assertEquals(0, cache.metrics().getOffHeapEvictions()); + assertEquals(cache.metrics().getCacheEvictions(), cache.metrics().getOffHeapEntriesCount()); + assertEquals(cache.metrics().getCacheEvictions(), cache.metrics().getOffHeapPrimaryEntriesCount()); + assertEquals(0, cache.metrics().getOffHeapBackupEntriesCount()); + + for (int i = 0; i < KEYS_CNT; i++) + cache.get(i); + + printStat(); + + assertEquals(cache.metrics().getCacheEvictions(), cache.metrics().getOffHeapPuts()); + assertEquals(KEYS_CNT * 2, cache.metrics().getOffHeapGets()); + assertEquals(KEYS_CNT, cache.metrics().getOffHeapHits()); + assertEquals(100 * KEYS_CNT / (KEYS_CNT * 2.0), cache.metrics().getOffHeapHitPercentage(), 0.1); + assertEquals(KEYS_CNT, cache.metrics().getOffHeapMisses()); + assertEquals(100 * KEYS_CNT / (KEYS_CNT * 2.0), cache.metrics().getOffHeapMissPercentage(), 0.1); + assertEquals(KEYS_CNT, cache.metrics().getOffHeapRemovals()); + + assertEquals(0, cache.metrics().getOffHeapEvictions()); + assertEquals(KEYS_CNT - MAX_SIZE, cache.metrics().getOffHeapEntriesCount()); + assertEquals(KEYS_CNT - MAX_SIZE, cache.metrics().getOffHeapPrimaryEntriesCount()); + assertEquals(0, cache.metrics().getOffHeapBackupEntriesCount()); + + for (int i = KEYS_CNT; i < KEYS_CNT * 2; i++) + cache.get(i); + + printStat(); + + assertEquals(cache.metrics().getCacheEvictions(), cache.metrics().getOffHeapPuts()); + assertEquals(KEYS_CNT * 3, cache.metrics().getOffHeapGets()); + assertEquals(KEYS_CNT, cache.metrics().getOffHeapHits()); + assertEquals(100 / 3.0, cache.metrics().getOffHeapHitPercentage(), 0.1); + assertEquals(KEYS_CNT * 2, cache.metrics().getOffHeapMisses()); + assertEquals(100 - (100 / 3.0), cache.metrics().getOffHeapMissPercentage(), 0.1); + assertEquals(KEYS_CNT, cache.metrics().getOffHeapRemovals()); + + assertEquals(0, cache.metrics().getOffHeapEvictions()); + assertEquals(KEYS_CNT - MAX_SIZE, cache.metrics().getOffHeapEntriesCount()); + assertEquals(KEYS_CNT - MAX_SIZE, cache.metrics().getOffHeapPrimaryEntriesCount()); + assertEquals(0, cache.metrics().getOffHeapBackupEntriesCount()); + + for (int i = 0; i < KEYS_CNT; i++) + cache.remove(i); + + printStat(); + + assertEquals(cache.metrics().getCacheEvictions(), cache.metrics().getOffHeapPuts()); + assertEquals(KEYS_CNT * 4 - MAX_SIZE, cache.metrics().getOffHeapGets()); + assertEquals(KEYS_CNT * 2 - MAX_SIZE, cache.metrics().getOffHeapHits()); + assertEquals(100 * (KEYS_CNT * 2.0 - MAX_SIZE) / (KEYS_CNT * 4.0 - MAX_SIZE), + cache.metrics().getOffHeapHitPercentage(), 0.1); + assertEquals(KEYS_CNT * 2, cache.metrics().getOffHeapMisses()); + assertEquals(100 * KEYS_CNT * 2.0 / (KEYS_CNT * 4.0 - MAX_SIZE), + cache.metrics().getOffHeapMissPercentage(), 0.1); + assertEquals(KEYS_CNT * 2 - MAX_SIZE, cache.metrics().getOffHeapRemovals()); + + assertEquals(0, cache.metrics().getOffHeapEvictions()); + assertEquals(0, cache.metrics().getOffHeapEntriesCount()); + assertEquals(0, cache.metrics().getOffHeapPrimaryEntriesCount()); + assertEquals(0, cache.metrics().getOffHeapBackupEntriesCount()); + } + + /** + * @throws Exception if failed. + */ + public void testSwapMetrics() throws Exception { + createCache(-1, true); + + for (int i = 0; i < KEYS_CNT; i++) + cache.put(i, i); + + printStat(); + + assertEquals(cache.metrics().getCacheEvictions(), cache.metrics().getSwapPuts()); + assertEquals(KEYS_CNT, cache.metrics().getSwapGets()); + assertEquals(0, cache.metrics().getSwapHits()); + assertEquals(0f, cache.metrics().getSwapHitPercentage()); + assertEquals(KEYS_CNT, cache.metrics().getSwapMisses()); + assertEquals(100f, cache.metrics().getSwapMissPercentage()); + assertEquals(0, cache.metrics().getSwapRemovals()); + + assertEquals(cache.metrics().getCacheEvictions(), cache.metrics().getSwapEntriesCount()); + + for (int i = 0; i < KEYS_CNT; i++) + cache.get(i); + + printStat(); + + assertEquals(cache.metrics().getCacheEvictions(), cache.metrics().getSwapPuts()); + assertEquals(KEYS_CNT * 2, cache.metrics().getSwapGets()); + assertEquals(KEYS_CNT, cache.metrics().getSwapHits()); + assertEquals(100 * KEYS_CNT / (KEYS_CNT * 2.0), cache.metrics().getSwapHitPercentage(), 0.1); + assertEquals(KEYS_CNT, cache.metrics().getSwapMisses()); + assertEquals(100 * KEYS_CNT / (KEYS_CNT * 2.0), cache.metrics().getSwapMissPercentage(), 0.1); + assertEquals(KEYS_CNT, cache.metrics().getSwapRemovals()); + + assertEquals(KEYS_CNT - MAX_SIZE, cache.metrics().getSwapEntriesCount()); + + for (int i = KEYS_CNT; i < KEYS_CNT * 2; i++) + cache.get(i); + + printStat(); + + assertEquals(cache.metrics().getCacheEvictions(), cache.metrics().getSwapPuts()); + assertEquals(KEYS_CNT * 3, cache.metrics().getSwapGets()); + assertEquals(KEYS_CNT, cache.metrics().getSwapHits()); + assertEquals(100 / 3.0, cache.metrics().getSwapHitPercentage(), 0.1); + assertEquals(KEYS_CNT * 2, cache.metrics().getSwapMisses()); + assertEquals(100 - (100 / 3.0), cache.metrics().getSwapMissPercentage(), 0.1); + assertEquals(KEYS_CNT, cache.metrics().getSwapRemovals()); + + assertEquals(KEYS_CNT - MAX_SIZE, cache.metrics().getSwapEntriesCount()); + + for (int i = 0; i < KEYS_CNT; i++) + cache.remove(i); + + printStat(); + + assertEquals(cache.metrics().getCacheEvictions(), cache.metrics().getSwapPuts()); + assertEquals(KEYS_CNT * 4 - MAX_SIZE, cache.metrics().getSwapGets()); + assertEquals(KEYS_CNT * 2 - MAX_SIZE, cache.metrics().getSwapHits()); + assertEquals(100 * (KEYS_CNT * 2.0 - MAX_SIZE) / (KEYS_CNT * 4.0 - MAX_SIZE), + cache.metrics().getSwapHitPercentage(), 0.1); + assertEquals(KEYS_CNT * 2, cache.metrics().getSwapMisses()); + assertEquals(100 * KEYS_CNT * 2.0 / (KEYS_CNT * 4.0 - MAX_SIZE), + cache.metrics().getSwapMissPercentage(), 0.1); + assertEquals(KEYS_CNT * 2 - MAX_SIZE, cache.metrics().getSwapRemovals()); + + assertEquals(0, cache.metrics().getSwapEntriesCount()); + } + + /** + * @throws Exception if failed. + */ + public void testOffHeapAndSwapMetrics() throws Exception { + createCache(OFFHEAP_MAX_SIZE, true); + + for (int i = 0; i < KEYS_CNT; i++) + cache.put(i, i); + + printStat(); + + assertEquals(cache.metrics().getCacheEvictions(), cache.metrics().getOffHeapPuts()); + assertEquals(KEYS_CNT, cache.metrics().getOffHeapGets()); + assertEquals(0, cache.metrics().getOffHeapHits()); + assertEquals(0f, cache.metrics().getOffHeapHitPercentage()); + assertEquals(KEYS_CNT, cache.metrics().getOffHeapMisses()); + assertEquals(100f, cache.metrics().getOffHeapMissPercentage()); + assertEquals(0, cache.metrics().getOffHeapRemovals()); + + assertEquals(KEYS_CNT - MAX_SIZE - OFFHEAP_MAX_CNT, cache.metrics().getOffHeapEvictions()); + assertEquals(OFFHEAP_MAX_CNT, cache.metrics().getOffHeapEntriesCount()); + assertEquals(OFFHEAP_MAX_CNT, cache.metrics().getOffHeapPrimaryEntriesCount()); + assertEquals(0, cache.metrics().getOffHeapBackupEntriesCount()); + + assertEquals(cache.metrics().getOffHeapEvictions(), cache.metrics().getSwapPuts()); + assertEquals(KEYS_CNT, cache.metrics().getSwapGets()); + assertEquals(0, cache.metrics().getSwapHits()); + assertEquals(0f, cache.metrics().getSwapHitPercentage()); + assertEquals(KEYS_CNT, cache.metrics().getSwapMisses()); + assertEquals(100f, cache.metrics().getSwapMissPercentage()); + assertEquals(0, cache.metrics().getSwapRemovals()); + + assertEquals(cache.metrics().getOffHeapEvictions(), cache.metrics().getSwapEntriesCount()); + + for (int i = 0; i < KEYS_CNT; i++) + cache.get(i); + + printStat(); + + assertEquals(cache.metrics().getCacheEvictions(), cache.metrics().getOffHeapPuts()); + assertEquals(KEYS_CNT * 2, cache.metrics().getOffHeapGets()); + assertEquals(0, cache.metrics().getOffHeapHits()); + assertEquals(0.0, cache.metrics().getOffHeapHitPercentage(), 0.1); + assertEquals(KEYS_CNT * 2, cache.metrics().getOffHeapMisses()); + assertEquals(100.0, cache.metrics().getOffHeapMissPercentage(), 0.1); + assertEquals(0, cache.metrics().getOffHeapRemovals()); + + assertEquals(cache.metrics().getCacheEvictions() - OFFHEAP_MAX_CNT, cache.metrics().getOffHeapEvictions()); + assertEquals(OFFHEAP_MAX_CNT, cache.metrics().getOffHeapEntriesCount()); + assertEquals(OFFHEAP_MAX_CNT, cache.metrics().getOffHeapPrimaryEntriesCount()); + assertEquals(0, cache.metrics().getOffHeapBackupEntriesCount()); + + assertEquals(cache.metrics().getOffHeapEvictions(), cache.metrics().getSwapPuts()); + assertEquals(KEYS_CNT * 2, cache.metrics().getSwapGets()); + assertEquals(KEYS_CNT, cache.metrics().getSwapHits()); + assertEquals(100 * KEYS_CNT / (KEYS_CNT * 2.0), cache.metrics().getSwapHitPercentage(), 0.1); + assertEquals(KEYS_CNT, cache.metrics().getSwapMisses()); + assertEquals(100 * KEYS_CNT / (KEYS_CNT * 2.0), cache.metrics().getSwapMissPercentage(), 0.1); + assertEquals(KEYS_CNT, cache.metrics().getSwapRemovals()); + + assertEquals(KEYS_CNT - MAX_SIZE - OFFHEAP_MAX_CNT, cache.metrics().getSwapEntriesCount()); + + for (int i = KEYS_CNT; i < KEYS_CNT * 2; i++) + cache.get(i); + + printStat(); + + assertEquals(cache.metrics().getCacheEvictions(), cache.metrics().getOffHeapPuts()); + assertEquals(KEYS_CNT * 3, cache.metrics().getOffHeapGets()); + assertEquals(0, cache.metrics().getOffHeapHits()); + assertEquals(0.0, cache.metrics().getOffHeapHitPercentage(), 0.1); + assertEquals(KEYS_CNT * 3, cache.metrics().getOffHeapMisses()); + assertEquals(100.0, cache.metrics().getOffHeapMissPercentage(), 0.1); + assertEquals(0, cache.metrics().getOffHeapRemovals()); + + assertEquals(cache.metrics().getCacheEvictions() - OFFHEAP_MAX_CNT, cache.metrics().getOffHeapEvictions()); + assertEquals(OFFHEAP_MAX_CNT, cache.metrics().getOffHeapEntriesCount()); + assertEquals(OFFHEAP_MAX_CNT, cache.metrics().getOffHeapPrimaryEntriesCount()); + assertEquals(0, cache.metrics().getOffHeapBackupEntriesCount()); + + assertEquals(cache.metrics().getOffHeapEvictions(), cache.metrics().getSwapPuts()); + assertEquals(KEYS_CNT * 3, cache.metrics().getSwapGets()); + assertEquals(KEYS_CNT, cache.metrics().getSwapHits()); + assertEquals(100 / 3.0, cache.metrics().getSwapHitPercentage(), 0.1); + assertEquals(KEYS_CNT * 2, cache.metrics().getSwapMisses()); + assertEquals(100 - (100 / 3.0), cache.metrics().getSwapMissPercentage(), 0.1); + assertEquals(KEYS_CNT, cache.metrics().getSwapRemovals()); + + assertEquals(KEYS_CNT - MAX_SIZE - OFFHEAP_MAX_CNT, cache.metrics().getSwapEntriesCount()); + + for (int i = 0; i < KEYS_CNT; i++) + cache.remove(i); + + printStat(); + + assertEquals(cache.metrics().getCacheEvictions(), cache.metrics().getOffHeapPuts()); + assertEquals(KEYS_CNT * 4 - MAX_SIZE, cache.metrics().getOffHeapGets()); + assertEquals(OFFHEAP_MAX_CNT, cache.metrics().getOffHeapHits()); + assertEquals(100 * OFFHEAP_MAX_CNT / (KEYS_CNT * 4.0 - MAX_SIZE), + cache.metrics().getOffHeapHitPercentage(), 0.1); + assertEquals(KEYS_CNT * 4 - OFFHEAP_MAX_CNT - MAX_SIZE, cache.metrics().getOffHeapMisses()); + assertEquals(100 * (KEYS_CNT * 4 - OFFHEAP_MAX_CNT - MAX_SIZE) / (KEYS_CNT * 4.0 - MAX_SIZE), + cache.metrics().getOffHeapMissPercentage(), 0.1); + assertEquals(OFFHEAP_MAX_CNT, cache.metrics().getOffHeapRemovals()); + + assertEquals(cache.metrics().getCacheEvictions() - OFFHEAP_MAX_CNT, cache.metrics().getOffHeapEvictions()); + assertEquals(0, cache.metrics().getOffHeapEntriesCount()); + assertEquals(0, cache.metrics().getOffHeapPrimaryEntriesCount()); + assertEquals(0, cache.metrics().getOffHeapBackupEntriesCount()); + + assertEquals(cache.metrics().getOffHeapEvictions(), cache.metrics().getSwapPuts()); + assertEquals(KEYS_CNT * 4 - MAX_SIZE - OFFHEAP_MAX_CNT, cache.metrics().getSwapGets()); + assertEquals(KEYS_CNT * 2 - MAX_SIZE - OFFHEAP_MAX_CNT, cache.metrics().getSwapHits()); + assertEquals(100 * (KEYS_CNT * 2.0 - MAX_SIZE - OFFHEAP_MAX_CNT) / (KEYS_CNT * 4.0 - MAX_SIZE - OFFHEAP_MAX_CNT), + cache.metrics().getSwapHitPercentage(), 0.1); + assertEquals(KEYS_CNT * 2, cache.metrics().getSwapMisses()); + assertEquals(100 * KEYS_CNT * 2.0 / (KEYS_CNT * 4.0 - MAX_SIZE - OFFHEAP_MAX_CNT), + cache.metrics().getSwapMissPercentage(), 0.1); + assertEquals(KEYS_CNT * 2 - MAX_SIZE - OFFHEAP_MAX_CNT, cache.metrics().getSwapRemovals()); + + assertEquals(0, cache.metrics().getSwapEntriesCount()); + } + + /** + * Prints stats. + */ + protected void printStat() { + System.out.println("!!! -------------------------------------------------------"); + System.out.println("!!! Puts: cache = " + cache.metrics().getCachePuts() + + ", offheap = " + cache.metrics().getOffHeapPuts() + + ", swap = " + cache.metrics().getSwapPuts()); + System.out.println("!!! Gets: cache = " + cache.metrics().getCacheGets() + + ", offheap = " + cache.metrics().getOffHeapGets() + + ", swap = " + cache.metrics().getSwapGets()); + System.out.println("!!! Removes: cache = " + cache.metrics().getCacheRemovals() + + ", offheap = " + cache.metrics().getOffHeapRemovals() + + ", swap = " + cache.metrics().getSwapRemovals()); + System.out.println("!!! Evictions: cache = " + cache.metrics().getCacheEvictions() + + ", offheap = " + cache.metrics().getOffHeapEvictions() + + ", swap = none" ); + System.out.println("!!! Hits: cache = " + cache.metrics().getCacheHits() + + ", offheap = " + cache.metrics().getOffHeapHits() + + ", swap = " + cache.metrics().getSwapHits()); + System.out.println("!!! Hit(%): cache = " + cache.metrics().getCacheHitPercentage() + + ", offheap = " + cache.metrics().getOffHeapHitPercentage() + + ", swap = " + cache.metrics().getSwapHitPercentage()); + System.out.println("!!! Misses: cache = " + cache.metrics().getCacheMisses() + + ", offheap = " + cache.metrics().getOffHeapMisses() + + ", swap = " + cache.metrics().getSwapMisses()); + System.out.println("!!! Miss(%): cache = " + cache.metrics().getCacheMissPercentage() + + ", offheap = " + cache.metrics().getOffHeapMissPercentage() + + ", swap = " + cache.metrics().getSwapMissPercentage()); + System.out.println("!!! Entries: cache = " + cache.metrics().getSize() + + ", offheap = " + cache.metrics().getOffHeapEntriesCount() + + ", swap = " + cache.metrics().getSwapEntriesCount()); + System.out.println("!!! Size: cache = none" + + ", offheap = " + cache.metrics().getOffHeapAllocatedSize() + + ", swap = " + cache.metrics().getSwapSize()); + System.out.println(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1652fd18/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/GridCacheExLocalFullApiSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/GridCacheExLocalFullApiSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/GridCacheExLocalFullApiSelfTest.java deleted file mode 100644 index 71c0495..0000000 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/GridCacheExLocalFullApiSelfTest.java +++ /dev/null @@ -1,30 +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.local; - -import org.apache.ignite.cache.*; -import org.apache.ignite.internal.processors.cache.*; - -/** - * Tests private cache interface on local cache. - */ -public class GridCacheExLocalFullApiSelfTest extends GridCacheExAbstractFullApiSelfTest { - @Override protected CacheMode cacheMode() { - return CacheMode.LOCAL; - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1652fd18/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/GridCacheContinuousQueryAbstractSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/GridCacheContinuousQueryAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/GridCacheContinuousQueryAbstractSelfTest.java index 5a78f9f..378d5a3 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/GridCacheContinuousQueryAbstractSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/GridCacheContinuousQueryAbstractSelfTest.java @@ -42,6 +42,7 @@ import javax.cache.*; import javax.cache.configuration.*; import javax.cache.event.*; import javax.cache.integration.*; +import java.io.*; import java.util.*; import java.util.concurrent.*; import java.util.concurrent.atomic.*; @@ -57,7 +58,7 @@ import static org.apache.ignite.internal.processors.cache.query.CacheQueryType.* /** * Continuous queries tests. */ -public abstract class GridCacheContinuousQueryAbstractSelfTest extends GridCommonAbstractTest { +public abstract class GridCacheContinuousQueryAbstractSelfTest extends GridCommonAbstractTest implements Serializable { /** IP finder. */ private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); @@ -177,10 +178,7 @@ public abstract class GridCacheContinuousQueryAbstractSelfTest extends GridCommo assertEquals(String.valueOf(i), 3, ((Map)U.field(proc, "locInfos")).size()); assertEquals(String.valueOf(i), 0, ((Map)U.field(proc, "rmtInfos")).size()); assertEquals(String.valueOf(i), 0, ((Map)U.field(proc, "startFuts")).size()); - assertEquals(String.valueOf(i), 0, ((Map)U.field(proc, "waitForStartAck")).size()); assertEquals(String.valueOf(i), 0, ((Map)U.field(proc, "stopFuts")).size()); - assertEquals(String.valueOf(i), 0, ((Map)U.field(proc, "waitForStopAck")).size()); - assertEquals(String.valueOf(i), 0, ((Map)U.field(proc, "pending")).size()); CacheContinuousQueryManager mgr = grid(i).context().cache().internalCache().context().continuousQueries(); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1652fd18/modules/core/src/test/java/org/apache/ignite/internal/processors/continuous/GridEventConsumeSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/continuous/GridEventConsumeSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/continuous/GridEventConsumeSelfTest.java index d219a60..9ffef4b 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/continuous/GridEventConsumeSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/continuous/GridEventConsumeSelfTest.java @@ -28,9 +28,11 @@ import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.lang.*; import org.apache.ignite.marshaller.optimized.*; import org.apache.ignite.resources.*; +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.io.*; import java.util.*; import java.util.concurrent.*; import java.util.concurrent.atomic.*; @@ -42,7 +44,7 @@ import static org.apache.ignite.internal.processors.continuous.GridContinuousPro /** * Event consume test. */ -public class GridEventConsumeSelfTest extends GridCommonAbstractTest implements Serializable { +public class GridEventConsumeSelfTest extends GridCommonAbstractTest { /** */ private static final String PRJ_PRED_CLS_NAME = "org.apache.ignite.tests.p2p.GridEventConsumeProjectionPredicate"; @@ -55,6 +57,9 @@ public class GridEventConsumeSelfTest extends GridCommonAbstractTest implements /** Number of created consumes per thread in multithreaded test. */ private static final int CONSUME_CNT = 500; + /** */ + private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); + /** Consume latch. */ private static volatile CountDownLatch consumeLatch; @@ -71,6 +76,12 @@ public class GridEventConsumeSelfTest extends GridCommonAbstractTest implements @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(gridName); + TcpDiscoverySpi disc = new TcpDiscoverySpi(); + + disc.setIpFinder(IP_FINDER); + + cfg.setDiscoverySpi(disc); + if (include) cfg.setUserAttributes(F.asMap("include", true)); @@ -80,7 +91,7 @@ public class GridEventConsumeSelfTest extends GridCommonAbstractTest implements } /** {@inheritDoc} */ - @Override protected void beforeTestsStarted() throws Exception { + @Override protected void beforeTest() throws Exception { assertTrue(GRID_CNT > 1); include = true; @@ -93,32 +104,33 @@ public class GridEventConsumeSelfTest extends GridCommonAbstractTest implements } /** {@inheritDoc} */ - @Override protected void afterTestsStopped() throws Exception { - stopAllGrids(); - } - - /** {@inheritDoc} */ @Override protected void afterTest() throws Exception { - assertEquals(GRID_CNT, grid(0).cluster().nodes().size()); + try { + assertEquals(GRID_CNT, grid(0).cluster().nodes().size()); - for (int i = 0; i < GRID_CNT; i++) { - IgniteKernal grid = (IgniteKernal)grid(i); + for (int i = 0; i < GRID_CNT; i++) { + IgniteEx grid = grid(i); - GridContinuousProcessor proc = grid.context().continuous(); + GridContinuousProcessor proc = grid.context().continuous(); - if (noAutoUnsubscribe) { - localRoutines(proc).clear(); + try { + if (!noAutoUnsubscribe) { + Map rmtInfos = U.field(proc, "rmtInfos"); - U.<Map>field(proc, "rmtInfos").clear(); - } + assertTrue("Unexpected remote infos: " + rmtInfos, rmtInfos.isEmpty()); + } + } + finally { + U.<Map>field(proc, "rmtInfos").clear(); + } - assertEquals(0, localRoutines(proc).size()); - assertEquals(0, U.<Map>field(proc, "rmtInfos").size()); - assertEquals(0, U.<Map>field(proc, "startFuts").size()); - assertEquals(0, U.<Map>field(proc, "waitForStartAck").size()); - assertEquals(0, U.<Map>field(proc, "stopFuts").size()); - assertEquals(0, U.<Map>field(proc, "waitForStopAck").size()); - assertEquals(0, U.<Map>field(proc, "pending").size()); + assertEquals(0, U.<Map>field(proc, "rmtInfos").size()); + assertEquals(0, U.<Map>field(proc, "startFuts").size()); + assertEquals(0, U.<Map>field(proc, "stopFuts").size()); + } + } + finally { + stopAllGrids(); } } @@ -511,28 +523,6 @@ public class GridEventConsumeSelfTest extends GridCommonAbstractTest implements /** * @throws Exception If failed. */ - public void testEmptyProjection() throws Exception { - try { - events(grid(0).cluster().forPredicate(F.<ClusterNode>alwaysFalse())).remoteListen( - new P2<UUID, Event>() { - @Override public boolean apply(UUID nodeId, Event evt) { - return true; - } - }, - null - ); - - assert false : "Exception was not thrown."; - } - catch (IgniteException e) { - assertTrue(e.getMessage().startsWith( - "Failed to register remote continuous listener (projection is empty).")); - } - } - - /** - * @throws Exception If failed. - */ public void testStopByCallback() throws Exception { final Collection<UUID> nodeIds = new HashSet<>(); final AtomicInteger cnt = new AtomicInteger(); @@ -665,7 +655,7 @@ public class GridEventConsumeSelfTest extends GridCommonAbstractTest implements final CountDownLatch latch = new CountDownLatch(GRID_CNT + 1); UUID consumeId = grid(0).events().remoteListen( - new P2<UUID, Event>() { + notSerializableProxy(new P2<UUID, Event>() { @Override public boolean apply(UUID nodeId, Event evt) { info("Event from " + nodeId + " [" + evt.shortDisplay() + ']'); @@ -677,12 +667,12 @@ public class GridEventConsumeSelfTest extends GridCommonAbstractTest implements return true; } - }, - new P1<Event>() { + }), + notSerializableProxy(new P1<Event>() { @Override public boolean apply(Event evt) { return evt.type() == EVT_JOB_STARTED; } - }, + }), EVT_JOB_STARTED, EVT_JOB_FINISHED ); @@ -873,14 +863,14 @@ public class GridEventConsumeSelfTest extends GridCommonAbstractTest implements final CountDownLatch latch = new CountDownLatch(GRID_CNT); for (int i = 0; i < GRID_CNT; i++) { - grid(0).events().localListen(new IgnitePredicate<Event>() { + grid(i).events().localListen(new IgnitePredicate<Event>() { @Override public boolean apply(Event evt) { if (nodeId.equals(((DiscoveryEvent) evt).eventNode().id())) latch.countDown(); return true; } - }, EVT_NODE_LEFT); + }, EVT_NODE_LEFT, EVT_NODE_FAILED); } g.events().remoteListen( @@ -895,7 +885,7 @@ public class GridEventConsumeSelfTest extends GridCommonAbstractTest implements stopGrid("anotherGrid"); - latch.await(); + assert latch.await(3000, MILLISECONDS); } /** @@ -941,7 +931,7 @@ public class GridEventConsumeSelfTest extends GridCommonAbstractTest implements stopGrid("anotherGrid"); - discoLatch.await(); + discoLatch.await(3000, MILLISECONDS); grid(0).compute().broadcast(F.noop()); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1652fd18/modules/core/src/test/java/org/apache/ignite/internal/processors/datastreamer/DataStreamProcessorSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/datastreamer/DataStreamProcessorSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/datastreamer/DataStreamProcessorSelfTest.java index 1f0319f..81751f2 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/datastreamer/DataStreamProcessorSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/datastreamer/DataStreamProcessorSelfTest.java @@ -84,6 +84,7 @@ public class DataStreamProcessorSelfTest extends GridCommonAbstractTest { TcpDiscoverySpi spi = new TcpDiscoverySpi(); + spi.setForceServerMode(true); spi.setIpFinder(ipFinder); cfg.setDiscoverySpi(spi); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1652fd18/modules/core/src/test/java/org/apache/ignite/internal/processors/datastreamer/DataStreamerMultiThreadedSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/datastreamer/DataStreamerMultiThreadedSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/datastreamer/DataStreamerMultiThreadedSelfTest.java index bea3809..e0092d4 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/datastreamer/DataStreamerMultiThreadedSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/datastreamer/DataStreamerMultiThreadedSelfTest.java @@ -41,6 +41,9 @@ public class DataStreamerMultiThreadedSelfTest extends GridCommonAbstractTest { /** IP finder. */ private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); + /** */ + private boolean dynamicCache; + /** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(gridName); @@ -50,13 +53,22 @@ public class DataStreamerMultiThreadedSelfTest extends GridCommonAbstractTest { cfg.setDiscoverySpi(discoSpi); + if (!dynamicCache) + cfg.setCacheConfiguration(cacheConfiguration()); + + return cfg; + } + + /** + * @return Cache configuration. + */ + private CacheConfiguration cacheConfiguration() { CacheConfiguration ccfg = defaultCacheConfiguration(); ccfg.setCacheMode(PARTITIONED); ccfg.setBackups(1); - cfg.setCacheConfiguration(ccfg); - return cfg; + return ccfg; } /** {@inheritDoc} */ @@ -68,8 +80,22 @@ public class DataStreamerMultiThreadedSelfTest extends GridCommonAbstractTest { * @throws Exception If failed. */ public void testStartStopIgnites() throws Exception { - fail("https://issues.apache.org/jira/browse/IGNITE-840"); + startStopIgnites(); + } + + /** + * @throws Exception If failed. + */ + public void testStartStopIgnitesDynamicCache() throws Exception { + dynamicCache = true; + + startStopIgnites(); + } + /** + * @throws Exception If failed. + */ + private void startStopIgnites() throws Exception { for (int attempt = 0; attempt < 3; ++attempt) { log.info("Iteration: " + attempt); @@ -77,28 +103,29 @@ public class DataStreamerMultiThreadedSelfTest extends GridCommonAbstractTest { Set<IgniteFuture> futs = new HashSet<>(); - IgniteInternalFuture<?> fut; + final AtomicInteger igniteId = new AtomicInteger(1); - try (final DataStreamerImpl dataLdr = (DataStreamerImpl)ignite.dataStreamer(null)) { - dataLdr.maxRemapCount(0); + IgniteInternalFuture<?> fut = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() { + @Override public Object call() throws Exception { + for (int i = 1; i < 5; ++i) + startGrid(igniteId.incrementAndGet()); - final AtomicInteger igniteId = new AtomicInteger(1); + return true; + } + }, 2, "start-node-thread"); - fut = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() { - @Override public Object call() throws Exception { - for (int i = 1; i < 5; ++i) - startGrid(igniteId.incrementAndGet()); + if (dynamicCache) + ignite.getOrCreateCache(cacheConfiguration()); - return true; - } - }, 2, "start-node-thread"); + try (final DataStreamerImpl dataLdr = (DataStreamerImpl)ignite.dataStreamer(null)) { + dataLdr.maxRemapCount(0); - Random random = new Random(); + Random rnd = new Random(); long endTime = U.currentTimeMillis() + 15_000; while (!fut.isDone() && U.currentTimeMillis() < endTime) - futs.add(dataLdr.addData(random.nextInt(100_000), random.nextInt(100_000))); + futs.add(dataLdr.addData(rnd.nextInt(100_000), String.valueOf(rnd.nextInt(100_000)))); } for (IgniteFuture f : futs)
