# IGNITE-56 Use IgniteCache instead of GridCache in the tests.
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/89c1e292 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/89c1e292 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/89c1e292 Branch: refs/heads/ignite-181 Commit: 89c1e292ed02e94446d71386b4448632bd15b8ac Parents: 75ce20d Author: sevdokimov <sergey.evdoki...@jetbrains.com> Authored: Sun Feb 8 15:54:30 2015 +0300 Committer: sevdokimov <sergey.evdoki...@jetbrains.com> Committed: Sun Feb 8 15:54:30 2015 +0300 ---------------------------------------------------------------------- .../cache/GridCacheAbstractFlagsTest.java | 2 +- .../cache/GridCacheIteratorPerformanceTest.java | 80 ++++++-------------- .../distributed/GridCacheEventAbstractTest.java | 2 +- .../GridCacheDistributedEvictionsSelfTest.java | 8 +- .../GridCacheEvictionLockUnlockSelfTest.java | 2 +- ...cheSynchronousEvictionsFailoverSelfTest.java | 13 ++-- .../IgniteCacheExpiryPolicyAbstractTest.java | 6 +- .../IgniteCacheLoadAllAbstractTest.java | 2 +- 8 files changed, 41 insertions(+), 74 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/89c1e292/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFlagsTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFlagsTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFlagsTest.java index 3463f30..ee35555 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFlagsTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFlagsTest.java @@ -90,7 +90,7 @@ public abstract class GridCacheAbstractFlagsTest extends GridCacheAbstractSelfTe } }, gridCount() * 3); - cache(0).flagsOn(CacheFlag.SYNC_COMMIT).put(key, val); + ((IgniteCacheProxy)jcache(0)).flagOn(CacheFlag.SYNC_COMMIT).put(key, val); l.countDown(); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/89c1e292/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheIteratorPerformanceTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheIteratorPerformanceTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheIteratorPerformanceTest.java index 684c346..c74e36c 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheIteratorPerformanceTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheIteratorPerformanceTest.java @@ -17,7 +17,7 @@ package org.apache.ignite.internal.processors.cache; -import org.apache.ignite.cache.*; +import org.apache.ignite.*; import org.apache.ignite.configuration.*; import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.lang.*; @@ -26,6 +26,8 @@ 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 javax.cache.*; + import static org.apache.ignite.cache.CacheMode.*; /** @@ -81,19 +83,20 @@ public class GridCacheIteratorPerformanceTest extends GridCommonAbstractTest { /** * Iterates over cache. * - * @param prj Projection. + * @param cache Projection. * @param c Visitor closure. */ - private void iterate(CacheProjection<Integer, Integer> prj, IgniteInClosure<CacheEntry<Integer, Integer>> c) { - prj.forEach(c); + private void iterate(IgniteCache<Integer, Integer> cache, IgniteInClosure<Cache.Entry<Integer, Integer>> c) { + for (Cache.Entry<Integer, Integer> entry : cache.localEntries()) + c.apply(entry); } /** * @return Empty filter. */ - private IgniteInClosure<CacheEntry<Integer, Integer>> emptyFilter() { - return new CI1<CacheEntry<Integer, Integer>>() { - @Override public void apply(CacheEntry<Integer, Integer> e) { + private IgniteInClosure<Cache.Entry<Integer, Integer>> emptyFilter() { + return new CI1<Cache.Entry<Integer, Integer>>() { + @Override public void apply(Cache.Entry<Integer, Integer> e) { // No-op } }; @@ -103,14 +106,14 @@ public class GridCacheIteratorPerformanceTest extends GridCommonAbstractTest { * @throws Exception If failed. */ public void testSmall() throws Exception { - CacheProjection<Integer, Integer> cache = grid().cache(null); + IgniteCache<Integer, Integer> cache = grid().jcache(null); for (int i = 0; i < SMALL_ENTRY_CNT; i++) - assert cache.putx(i, i); + cache.put(i, i); assert cache.size() == SMALL_ENTRY_CNT; - IgniteInClosure<CacheEntry<Integer, Integer>> c = emptyFilter(); + IgniteInClosure<Cache.Entry<Integer, Integer>> c = emptyFilter(); // Warmup. for (int i = 0; i < 10; i ++) @@ -132,14 +135,14 @@ public class GridCacheIteratorPerformanceTest extends GridCommonAbstractTest { * @throws Exception If failed. */ public void testLarge() throws Exception { - CacheProjection<Integer, Integer> cache = grid().cache(null); + IgniteCache<Integer, Integer> cache = grid().jcache(null); for (int i = 0; i < LARGE_ENTRY_CNT; i++) - assert cache.putx(i, i); + cache.put(i, i); assert cache.size() == LARGE_ENTRY_CNT; - IgniteInClosure<CacheEntry<Integer, Integer>> c = emptyFilter(); + IgniteInClosure<Cache.Entry<Integer, Integer>> c = emptyFilter(); // Warmup. for (int i = 0; i < 3; i++) @@ -160,57 +163,19 @@ public class GridCacheIteratorPerformanceTest extends GridCommonAbstractTest { /** * @throws Exception If failed. */ - public void testProjectionFiltered() throws Exception { - GridCache<Integer, Integer> cache = grid().cache(null); - - for (int i = 0; i < LARGE_ENTRY_CNT; i++) - assert cache.putx(i, i); - - assert cache.size() == LARGE_ENTRY_CNT; - - IgniteInClosure<CacheEntry<Integer, Integer>> c = emptyFilter(); - - CacheProjection<Integer, Integer> prj = cache.projection(new P2<Integer, Integer>() { - @Override public boolean apply(Integer key, Integer val) { - return val < SMALL_ENTRY_CNT; - } - }); - - assert prj.size() == SMALL_ENTRY_CNT; - - // Warmup. - for (int i = 0; i < 3; i++) - iterate(prj, c); - - long start = System.currentTimeMillis(); - - iterate(prj, c); - - long time = System.currentTimeMillis() - start; - - X.println(">>>"); - X.println(">>> Iterated over " + prj.size() + " entries."); - X.println(">>> Iteration time: " + time + "ms."); - X.println(">>>"); - } - - - /** - * @throws Exception If failed. - */ public void testFiltered() throws Exception { - GridCache<Integer, Integer> cache = grid().cache(null); + IgniteCache<Integer, Integer> cache = grid().jcache(null); for (int i = 0; i < LARGE_ENTRY_CNT; i++) - assert cache.putx(i, i); + cache.put(i, i); assert cache.size() == LARGE_ENTRY_CNT; final BoxedInt cnt = new BoxedInt(); - IgniteInClosure<CacheEntry<Integer, Integer>> c = new CI1<CacheEntry<Integer, Integer>>() { - @Override public void apply(CacheEntry<Integer, Integer> t) { - if (t.peek() < SMALL_ENTRY_CNT) + IgniteInClosure<Cache.Entry<Integer, Integer>> c = new CI1<Cache.Entry<Integer, Integer>>() { + @Override public void apply(Cache.Entry<Integer, Integer> t) { + if (t.getValue() < SMALL_ENTRY_CNT) cnt.increment(); } }; @@ -249,6 +214,9 @@ public class GridCacheIteratorPerformanceTest extends GridCommonAbstractTest { this.i = i; } + /** + * Default constructor. + */ BoxedInt() { // No-op. } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/89c1e292/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheEventAbstractTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheEventAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheEventAbstractTest.java index a16ca16..7f40eb7 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheEventAbstractTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheEventAbstractTest.java @@ -223,7 +223,7 @@ public abstract class GridCacheEventAbstractTest extends GridCacheAbstractSelfTe */ public void testGetPutRemove() throws Exception { // TODO: GG-7578. - if (cache(0).configuration().getCacheMode() == CacheMode.REPLICATED) + if (jcache(0).getConfiguration(CacheConfiguration.class).getCacheMode() == CacheMode.REPLICATED) return; runTest( http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/89c1e292/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/GridCacheDistributedEvictionsSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/GridCacheDistributedEvictionsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/GridCacheDistributedEvictionsSelfTest.java index 7745a6a..ec2d50d 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/GridCacheDistributedEvictionsSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/GridCacheDistributedEvictionsSelfTest.java @@ -186,7 +186,7 @@ public class GridCacheDistributedEvictionsSelfTest extends GridCommonAbstractTes // Put 1 entry to primary node. cache.putx(0, 0); - Integer nearVal = this.<Integer, Integer>cache(2).get(0); + Integer nearVal = this.<Integer, Integer>jcache(2).get(0); assert nearVal == 0 : "Unexpected near value: " + nearVal; @@ -199,8 +199,8 @@ public class GridCacheDistributedEvictionsSelfTest extends GridCommonAbstractTes for (int i = 0; i < 3; i++) { try { - assert cache(2).get(0) == null : "Entry has not been evicted from near node for key: " + 0; - assert cache(1).get(0) == null : "Entry has not been evicted from backup node for key: " + 0; + assert jcache(2).get(0) == null : "Entry has not been evicted from near node for key: " + 0; + assert jcache(1).get(0) == null : "Entry has not been evicted from backup node for key: " + 0; assert cache.get(0) == null : "Entry has not been evicted from primary node for key: " + 0; } catch (Throwable e) { @@ -233,7 +233,7 @@ public class GridCacheDistributedEvictionsSelfTest extends GridCommonAbstractTes assert cache.size() == 10 : "Invalid key size [size=" + cache.size() + ", keys=" + new TreeSet<>(cache.keySet()) + ']'; - assert cache(2).isEmpty(); + assert jcache(2).localSize() == 0; break; } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/89c1e292/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/GridCacheEvictionLockUnlockSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/GridCacheEvictionLockUnlockSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/GridCacheEvictionLockUnlockSelfTest.java index 0208375..83dd738 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/GridCacheEvictionLockUnlockSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/GridCacheEvictionLockUnlockSelfTest.java @@ -136,7 +136,7 @@ public class GridCacheEvictionLockUnlockSelfTest extends GridCommonAbstractTest assertEquals(gridCnt, touchCnt.get()); for (int j = 0; j < gridCnt; j++) - assertFalse(cache(j).containsKey("key")); + assertFalse(jcache(j).containsKey("key")); } } finally { http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/89c1e292/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/GridCacheSynchronousEvictionsFailoverSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/GridCacheSynchronousEvictionsFailoverSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/GridCacheSynchronousEvictionsFailoverSelfTest.java index edc4576..f348d7c 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/GridCacheSynchronousEvictionsFailoverSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/GridCacheSynchronousEvictionsFailoverSelfTest.java @@ -78,7 +78,7 @@ public class GridCacheSynchronousEvictionsFailoverSelfTest extends GridCacheAbst * @throws Exception If failed. */ public void testSynchronousEvictions() throws Exception { - GridCache<String, Integer> cache = cache(0); + IgniteCache<String, Integer> cache = jcache(0); final AtomicBoolean stop = new AtomicBoolean(); @@ -87,9 +87,9 @@ public class GridCacheSynchronousEvictionsFailoverSelfTest extends GridCacheAbst try { Map<String, Integer> data = new HashMap<>(); - addKeysForNode(cache.affinity(), grid(0).localNode(), data); - addKeysForNode(cache.affinity(), grid(1).localNode(), data); - addKeysForNode(cache.affinity(), grid(2).localNode(), data); + addKeysForNode(affinity(cache), grid(0).localNode(), data); + addKeysForNode(affinity(cache), grid(1).localNode(), data); + addKeysForNode(affinity(cache), grid(2).localNode(), data); fut = GridTestUtils.runAsync(new Callable<Void>() { @Override public Void call() throws Exception { @@ -119,12 +119,11 @@ public class GridCacheSynchronousEvictionsFailoverSelfTest extends GridCacheAbst try { cache.putAll(data); } - catch (IgniteCheckedException ignore) { + catch (IgniteException ignore) { continue; } - for (String key : data.keySet()) - cache.evict(key); + cache.localEvict(data.keySet()); } } finally { http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/89c1e292/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 580f356..0990929 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 @@ -810,7 +810,7 @@ public abstract class IgniteCacheExpiryPolicyAbstractTest extends IgniteCacheAbs } }, 3000); - GridCache<Integer, Object> cache = cache(0); + IgniteCache<Integer, Object> cache = jcache(0); for (int i = 0; i < gridCount(); i++) { ClusterNode node = grid(i).cluster().localNode(); @@ -820,8 +820,8 @@ public abstract class IgniteCacheExpiryPolicyAbstractTest extends IgniteCacheAbs if (val != null) { log.info("Unexpected value [grid=" + i + - ", primary=" + cache.affinity().isPrimary(node, key) + - ", backup=" + cache.affinity().isBackup(node, key) + ']'); + ", primary=" + affinity(cache).isPrimary(node, key) + + ", backup=" + affinity(cache).isBackup(node, key) + ']'); } assertNull("Unexpected non-null value for grid " + i, val); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/89c1e292/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/integration/IgniteCacheLoadAllAbstractTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/integration/IgniteCacheLoadAllAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/integration/IgniteCacheLoadAllAbstractTest.java index 819a482..8fe8d0d 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/integration/IgniteCacheLoadAllAbstractTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/integration/IgniteCacheLoadAllAbstractTest.java @@ -204,7 +204,7 @@ public abstract class IgniteCacheLoadAllAbstractTest extends IgniteCacheAbstract * @param expVals Expected values. */ private void checkValues(int keys, Map<Integer, String> expVals) { - CacheAffinity<Object> aff = cache(0).affinity(); + CacheAffinity<Object> aff = grid(0).affinity(null); for (int i = 0; i < gridCount(); i++) { ClusterNode node = ignite(i).cluster().localNode();