http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3d78aa15/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/random/RandomEvictionPolicySelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/random/RandomEvictionPolicySelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/random/RandomEvictionPolicySelfTest.java new file mode 100644 index 0000000..ef34a13 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/random/RandomEvictionPolicySelfTest.java @@ -0,0 +1,357 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.processors.cache.eviction.random; + +import org.apache.ignite.*; +import org.apache.ignite.cache.eviction.random.*; +import org.apache.ignite.internal.processors.cache.eviction.*; +import org.jetbrains.annotations.*; + +import java.util.*; +import java.util.concurrent.*; + +/** + * Random eviction policy test. + */ +public class RandomEvictionPolicySelfTest extends + EvictionAbstractTest<RandomEvictionPolicy<String, String>> { + /** + * @throws Exception If failed. + */ + public void testMemory() throws Exception { + try { + Ignite g = startGrid(0); + + int max = 10; + + policy(0).setMaxSize(max); + + int keys = 31; + + for (int i = 0; i < keys; i++) { + String s = Integer.toString(i); + + g.cache(null).put(s, s); + } + + assert g.cache(null).size() <= max; + } + finally { + stopAllGrids(); + } + } + + /** + * @throws Exception If failed. + */ + public void testRandom() throws Exception { + try { + Ignite g = startGrid(0); + + int max = 10; + + policy(0).setMaxSize(max); + + Random rand = new Random(); + + int keys = 31; + + String[] t = new String[keys]; + + for (int i = 0; i < t.length; i++) + t[i] = Integer.toString(i); + + int runs = 10000; + + for (int i = 0; i < runs; i++) { + boolean rmv = rand.nextBoolean(); + + int j = rand.nextInt(t.length); + + if (rmv) + g.cache(null).remove(t[j]); + else + g.cache(null).put(t[j], t[j]); + + if (i % 1000 == 0) + info("Stats [cntr=" + i + ", total=" + runs + ']'); + } + + assert g.cache(null).size() <= max; + + info(policy(0)); + } + finally { + stopAllGrids(); + } + } + + /** + * @throws Exception If failed. + */ + public void testAllowEmptyEntries() throws Exception { + try { + startGrid(); + + IgniteCache<String, String> c = jcache(); + + MockEntry e1 = new MockEntry("1", c); + MockEntry e2 = new MockEntry("2", c); + MockEntry e3 = new MockEntry("3", c); + MockEntry e4 = new MockEntry("4", c); + MockEntry e5 = new MockEntry("5", c); + + RandomEvictionPolicy<String, String> p = policy(); + + p.setMaxSize(10); + + p.onEntryAccessed(false, e1); + + assertFalse(e1.isEvicted()); + + p.onEntryAccessed(false, e2); + + assertFalse(e1.isEvicted()); + assertFalse(e2.isEvicted()); + + p.onEntryAccessed(false, e3); + + assertFalse(e1.isEvicted()); + assertFalse(e3.isEvicted()); + + p.onEntryAccessed(false, e4); + + assertFalse(e1.isEvicted()); + assertFalse(e3.isEvicted()); + assertFalse(e4.isEvicted()); + + p.onEntryAccessed(false, e5); + + assertFalse(e1.isEvicted()); + assertFalse(e3.isEvicted()); + assertFalse(e5.isEvicted()); + } + finally { + stopAllGrids(); + } + } + + /** + * @throws Exception If failed. + */ + public void testRandomMultiThreaded() throws Exception { + try { + final Ignite g = startGrid(0); + + int max = 10; + + policy(0).setMaxSize(max); + + final Random rand = new Random(); + + int keys = 31; + + final String[] t = new String[keys]; + + for (int i = 0; i < t.length; i++) + t[i] = Integer.toString(i); + + multithreaded(new Callable() { + @Nullable @Override public Object call() { + int runs = 3000; + + for (int i = 0; i < runs; i++) { + boolean rmv = rand.nextBoolean(); + + int j = rand.nextInt(t.length); + + if (rmv) + g.cache(null).remove(t[j]); + else + g.cache(null).put(t[j], t[j]); + + if (i != 0 && i % 1000 == 0) + info("Stats [cntr=" + i + ", total=" + runs + ']'); + } + + return null; + } + }, 10); + + assert g.cache(null).size() <= max; + + info(policy(0)); + } + finally { + stopAllGrids(); + } + } + + /** {@inheritDoc} */ + @Override public void testMaxMemSizeAllowEmptyEntries() throws Exception { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void testMaxMemSizeMemory() throws Exception { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void testMaxMemSizePartitionedNearDisabled() throws Exception { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void testMaxMemSizePolicy() throws Exception { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void testMaxMemSizePolicyWithBatch() throws Exception { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void testMaxMemSizePut() throws Exception { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void testMaxMemSizeRandom() throws Exception { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void testMaxSizeAllowEmptyEntries() throws Exception { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void testMaxSizeAllowEmptyEntriesWithBatch() throws Exception { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void testMaxSizeMemory() throws Exception { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void testMaxSizeMemoryWithBatch() throws Exception { + // No-op. + } + + /** {@inheritDoc} */ + @Override protected void doTestPolicy() throws Exception { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void testMaxSizePut() throws Exception { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void testMaxSizePutWithBatch() throws Exception { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void testMaxSizeRandom() throws Exception { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void testMaxSizeRandomWithBatch() throws Exception { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void testMaxSizePolicyWithBatch() throws Exception { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void testMaxSizePartitionedNearDisabledWithBatch() throws Exception { + // No-op. + } + + /** {@inheritDoc} */ + @Override protected void doTestPolicyWithBatch() throws Exception { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void testMaxSizePartitionedNearDisabled() throws Exception { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void testPartitionedNearEnabled() throws Exception { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void testPartitionedNearDisabledMultiThreaded() throws Exception { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void testPartitionedNearDisabledBackupSyncMultiThreaded() throws Exception { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void testPartitionedNearEnabledMultiThreaded() throws Exception { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void testPartitionedNearEnabledBackupSyncMultiThreaded() throws Exception { + // No-op. + } + + /** {@inheritDoc} */ + @Override protected RandomEvictionPolicy<String, String> createPolicy(int plcMax) { + RandomEvictionPolicy<String, String> plc = new RandomEvictionPolicy<>(); + + plc.setMaxSize(plcMax); + + return plc; + } + + /** {@inheritDoc} */ + @Override protected RandomEvictionPolicy<String, String> createNearPolicy(int nearMax) { + RandomEvictionPolicy<String, String> plc = new RandomEvictionPolicy<>(); + + plc.setMaxSize(plcMax); + + return plc; + } + + /** {@inheritDoc} */ + @Override protected void checkNearPolicies(int nearMax) { + // No-op. + } + + /** {@inheritDoc} */ + @Override protected void checkPolicies() { + // No-op. + } +}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3d78aa15/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/3d78aa15/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/3d78aa15/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/3d78aa15/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/3d78aa15/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/3d78aa15/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/3d78aa15/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/expiry/IgniteCacheExpiryPolicyAbstractTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/expiry/IgniteCacheExpiryPolicyAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/expiry/IgniteCacheExpiryPolicyAbstractTest.java index b74a373..f77a389 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/expiry/IgniteCacheExpiryPolicyAbstractTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/expiry/IgniteCacheExpiryPolicyAbstractTest.java @@ -759,10 +759,11 @@ public abstract class IgniteCacheExpiryPolicyAbstractTest extends IgniteCacheAbs } /** - * TODO IGNITE-518 * @throws Exception If failed. */ - public void _testNearCreateUpdate() throws Exception { + public void testNearCreateUpdate() throws Exception { + fail("https://issues.apache.org/jira/browse/IGNITE-518"); + if (cacheMode() != PARTITIONED) return; @@ -883,10 +884,11 @@ public abstract class IgniteCacheExpiryPolicyAbstractTest extends IgniteCacheAbs } /** - * TODO IGNITE-518 * @throws Exception If failed. */ - public void _testNearAccess() throws Exception { + public void testNearAccess() throws Exception { + fail("https://issues.apache.org/jira/browse/IGNITE-518"); + if (cacheMode() != PARTITIONED) return; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3d78aa15/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/3d78aa15/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/expiry/IgniteCacheExpiryPolicyWithStoreAbstractTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/expiry/IgniteCacheExpiryPolicyWithStoreAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/expiry/IgniteCacheExpiryPolicyWithStoreAbstractTest.java index 3dec1a0..2dcb0c2 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/expiry/IgniteCacheExpiryPolicyWithStoreAbstractTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/expiry/IgniteCacheExpiryPolicyWithStoreAbstractTest.java @@ -137,7 +137,9 @@ public abstract class IgniteCacheExpiryPolicyWithStoreAbstractTest extends Ignit /** * @throws Exception If failed. */ - public void _testReadThrough() throws Exception { + public void testReadThrough() throws Exception { + fail("https://issues.apache.org/jira/browse/IGNITE-821"); + IgniteCache<Integer, Integer> cache = jcache(0); final Integer key = primaryKeys(cache, 1, 100_000).get(0); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3d78aa15/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/3d78aa15/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/3d78aa15/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/GridCacheLocalFullApiMultithreadedSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/GridCacheLocalFullApiMultithreadedSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/GridCacheLocalFullApiMultithreadedSelfTest.java index 887192a..3c75b5f 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/GridCacheLocalFullApiMultithreadedSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/GridCacheLocalFullApiMultithreadedSelfTest.java @@ -27,6 +27,11 @@ import static org.apache.ignite.cache.CacheMode.*; */ public class GridCacheLocalFullApiMultithreadedSelfTest extends GridCacheAbstractFullApiMultithreadedSelfTest { /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + fail("https://issues.apache.org/jira/browse/IGNITE-805"); + } + + /** {@inheritDoc} */ @Override protected int gridCount() { return 1; } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3d78aa15/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/GridCacheLocalTxExceptionSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/GridCacheLocalTxExceptionSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/GridCacheLocalTxExceptionSelfTest.java index 4b3c4d1..b659167 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/GridCacheLocalTxExceptionSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/GridCacheLocalTxExceptionSelfTest.java @@ -27,6 +27,11 @@ import static org.apache.ignite.cache.CacheMode.*; */ public class GridCacheLocalTxExceptionSelfTest extends IgniteTxExceptionAbstractSelfTest { /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + fail("https://issues.apache.org/jira/browse/IGNITE-257"); + } + + /** {@inheritDoc} */ @Override protected int gridCount() { return 1; } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3d78aa15/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 2e402f7..4681071 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); @@ -175,10 +176,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();