Repository: incubator-ignite Updated Branches: refs/heads/ignite-sql-tests 97a9adc85 -> 403da6db3
# IGNITE-56 Migration of tests to IgniteCache Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/e0b3193b Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/e0b3193b Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/e0b3193b Branch: refs/heads/ignite-sql-tests Commit: e0b3193bed4f46cc53a1148bbe796f44aa088821 Parents: 0194aef Author: sevdokimov <sevdoki...@gridgain.com> Authored: Fri Feb 6 17:34:52 2015 +0300 Committer: sevdokimov <sevdoki...@gridgain.com> Committed: Fri Feb 6 17:34:52 2015 +0300 ---------------------------------------------------------------------- .../cache/GridCacheConcurrentMapSelfTest.java | 8 +-- .../GridCacheMissingCommitVersionSelfTest.java | 12 +++- .../cache/GridCachePartitionedWritesTest.java | 11 ++-- .../cache/GridCacheStorePutxSelfTest.java | 17 ++--- .../cache/GridCacheSwapReloadSelfTest.java | 24 ++++--- ...idCacheValueConsistencyAbstractSelfTest.java | 34 +++++----- .../GridCacheWriteBehindStoreAbstractTest.java | 69 +++++++++----------- 7 files changed, 92 insertions(+), 83 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e0b3193b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentMapSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentMapSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentMapSelfTest.java index a5518cd..f702854 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentMapSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentMapSelfTest.java @@ -225,13 +225,13 @@ public class GridCacheConcurrentMapSelfTest extends GridCommonAbstractTest { } }, 10); - cache().get(rand.nextInt(cnt)); + jcache().get(rand.nextInt(cnt)); System.gc(); Thread.sleep(1000); - cache().get(rand.nextInt(cnt)); + jcache().get(rand.nextInt(cnt)); assertEquals(0, local().map.iteratorMapSize()); } @@ -320,13 +320,13 @@ public class GridCacheConcurrentMapSelfTest extends GridCommonAbstractTest { } }, 10); - cache().get(rand.nextInt(cnt)); + jcache().get(rand.nextInt(cnt)); System.gc(); Thread.sleep(1000); - cache().get(rand.nextInt(cnt)); + jcache().get(rand.nextInt(cnt)); assertEquals(0, local().map.iteratorMapSize()); } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e0b3193b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheMissingCommitVersionSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheMissingCommitVersionSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheMissingCommitVersionSelfTest.java index b47df6d..c3d955e 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheMissingCommitVersionSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheMissingCommitVersionSelfTest.java @@ -17,9 +17,11 @@ package org.apache.ignite.internal.processors.cache; +import org.apache.ignite.*; import org.apache.ignite.cache.*; import org.apache.ignite.configuration.*; import org.apache.ignite.internal.*; +import org.apache.ignite.lang.*; import org.apache.ignite.spi.discovery.tcp.*; import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*; import org.apache.ignite.testframework.*; @@ -83,7 +85,7 @@ public class GridCacheMissingCommitVersionSelfTest extends GridCommonAbstractTes * @throws Exception If failed. */ public void testMissingCommitVersion() throws Exception { - final GridCache<Integer, Integer> cache = cache(); + final IgniteCache<Integer, Integer> cache = jcache(); final int KEYS_PER_THREAD = 10_000; @@ -115,12 +117,16 @@ public class GridCacheMissingCommitVersionSelfTest extends GridCommonAbstractTes log.info("Trying to update " + failedKey); - IgniteInternalFuture<?> fut = cache.putAsync(failedKey, 2); + IgniteCache<Integer, Integer> asyncCache = cache.withAsync(); + + asyncCache.put(failedKey, 2); + + IgniteFuture<?> fut = asyncCache.future(); try { fut.get(5000); } - catch (IgniteFutureTimeoutCheckedException ignore) { + catch (IgniteFutureTimeoutException ignore) { fail("Put failed to finish in 5s."); } } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e0b3193b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCachePartitionedWritesTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCachePartitionedWritesTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCachePartitionedWritesTest.java index 99e7110..ea2e97a 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCachePartitionedWritesTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCachePartitionedWritesTest.java @@ -17,6 +17,7 @@ package org.apache.ignite.internal.processors.cache; +import org.apache.ignite.*; import org.apache.ignite.cache.*; import org.apache.ignite.cache.store.*; import org.apache.ignite.configuration.*; @@ -101,16 +102,16 @@ public class GridCachePartitionedWritesTest extends GridCommonAbstractTest { startGrid(); - GridCache<Integer, String> cache = cache(); + IgniteCache<Integer, String> cache = jcache(); try { cache.get(1); - IgniteTx tx = cache.txStart(); + IgniteTx tx = grid().transactions().txStart(); try { for (int i = 1; i <= 10; i++) - cache.putx(i, Integer.toString(i)); + cache.put(i, Integer.toString(i)); tx.commit(); } @@ -122,11 +123,11 @@ public class GridCachePartitionedWritesTest extends GridCommonAbstractTest { assert putCnt.get() == 10; - tx = cache.txStart(); + tx = grid().transactions().txStart(); try { for (int i = 1; i <= 10; i++) { - String val = cache.remove(i); + String val = cache.getAndRemove(i); assert val != null; assert val.equals(Integer.toString(i)); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e0b3193b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheStorePutxSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheStorePutxSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheStorePutxSelfTest.java index 862ed65..abe1a96 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheStorePutxSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheStorePutxSelfTest.java @@ -17,6 +17,7 @@ package org.apache.ignite.internal.processors.cache; +import org.apache.ignite.*; import org.apache.ignite.cache.*; import org.apache.ignite.cache.store.*; import org.apache.ignite.configuration.*; @@ -88,9 +89,9 @@ public class GridCacheStorePutxSelfTest extends GridCommonAbstractTest { /** * @throws Exception If failed. */ - public void testPutxShouldNotTriggerLoad() throws Exception { - assertTrue(cache().putx(1, 1)); - assertTrue(cache().putx(2, 2, (IgnitePredicate)null)); + public void testPutShouldNotTriggerLoad() throws Exception { + jcache().put(1, 1); + jcache().put(2, 2); assertEquals(0, loads.get()); } @@ -98,12 +99,12 @@ public class GridCacheStorePutxSelfTest extends GridCommonAbstractTest { /** * @throws Exception If failed. */ - public void testPutxShouldNotTriggerLoadWithTx() throws Exception { - GridCache<Integer, Integer> cache = cache(); + public void testPutShouldNotTriggerLoadWithTx() throws Exception { + IgniteCache<Integer, Integer> cache = jcache(); - try (IgniteTx tx = cache.txStart()) { - assertTrue(cache.putx(1, 1)); - assertTrue(cache.putx(2, 2, (IgnitePredicate)null)); + try (IgniteTx tx = grid().transactions().txStart()) { + cache.put(1, 1); + cache.put(2, 2); tx.commit(); } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e0b3193b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheSwapReloadSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheSwapReloadSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheSwapReloadSelfTest.java index c80a872d..fdc4649 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheSwapReloadSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheSwapReloadSelfTest.java @@ -17,6 +17,8 @@ package org.apache.ignite.internal.processors.cache; +import com.google.common.collect.*; +import org.apache.ignite.*; import org.apache.ignite.cache.*; import org.apache.ignite.cache.store.*; import org.apache.ignite.configuration.*; @@ -126,11 +128,13 @@ public class GridCacheSwapReloadSelfTest extends GridCommonAbstractTest { assert swap() != null; - assert cache().putx("key", "val"); + IgniteCache<String, String> cache = jcache(); + + cache.put("key", "val"); assert swap().size(spaceName()) == 0; - assert cache().evict("key"); + cache.localEvict(Collections.singleton("key")); assert swapLatch.await(1, SECONDS); Thread.sleep(100); @@ -138,7 +142,9 @@ public class GridCacheSwapReloadSelfTest extends GridCommonAbstractTest { assert swap().count(spaceName()) == 1; assert swap().size(spaceName()) > 0; - assert "val".equals(cache().reload("key")); + load(cache, "key", true); + + assert "val".equals(cache.localPeek("key", CachePeekMode.ONHEAP)); assert unswapLatch.await(1, SECONDS); @@ -175,13 +181,15 @@ public class GridCacheSwapReloadSelfTest extends GridCommonAbstractTest { assert swap() != null; - assert cache().putx("key1", "val1"); - assert cache().putx("key2", "val2"); + IgniteCache<String, String> cache = jcache(); + + cache.put("key1", "val1"); + cache.put("key2", "val2"); assert swap().size(spaceName()) == 0; - assert cache().evict("key1"); - assert cache().evict("key2"); + cache.localEvict(Collections.singleton("key1")); + cache.localEvict(Collections.singleton("key2")); assert swapLatch.await(1, SECONDS); Thread.sleep(100); @@ -189,7 +197,7 @@ public class GridCacheSwapReloadSelfTest extends GridCommonAbstractTest { assert swap().count(spaceName()) == 2; assert swap().size(spaceName()) > 0 : swap().size(spaceName()); - cache().reloadAll(F.asList("key1", "key2")); + loadAll(cache, ImmutableSet.of("key1", "key2"), true); assert unswapLatch.await(1, SECONDS); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e0b3193b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheValueConsistencyAbstractSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheValueConsistencyAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheValueConsistencyAbstractSelfTest.java index 6ad3f32..1fd138b 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheValueConsistencyAbstractSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheValueConsistencyAbstractSelfTest.java @@ -109,7 +109,7 @@ public abstract class GridCacheValueConsistencyAbstractSelfTest extends GridCach public void testPutRemove() throws Exception { awaitPartitionMapExchange(); - GridCache<String, Integer> cache = cache(); + IgniteCache<String, Integer> cache = jcache(); int keyCnt = 10; @@ -117,25 +117,25 @@ public abstract class GridCacheValueConsistencyAbstractSelfTest extends GridCach cache.put("key" + i, i); for (int g = 0; g < gridCount(); g++) { - GridCache<String, Integer> cache0 = cache(g); + IgniteCache<String, Integer> cache0 = jcache(g); ClusterNode locNode = grid(g).localNode(); for (int i = 0; i < keyCnt; i++) { String key = "key" + i; - if (cache.affinity().mapKeyToPrimaryAndBackups(key).contains(locNode)) { + if (ignite(0).affinity(null).mapKeyToPrimaryAndBackups(key).contains(locNode)) { info("Node is reported as affinity node for key [key=" + key + ", nodeId=" + locNode.id() + ']'); - assertEquals((Integer)i, cache0.peek(key)); + assertEquals((Integer)i, cache0.localPeek(key, CachePeekMode.ONHEAP)); } else { info("Node is reported as NOT affinity node for key [key=" + key + ", nodeId=" + locNode.id() + ']'); if (distributionMode() == NEAR_PARTITIONED && cache == cache0) - assertEquals((Integer)i, cache0.peek(key)); + assertEquals((Integer)i, cache0.localPeek(key, CachePeekMode.ONHEAP)); else - assertNull(cache0.peek(key)); + assertNull(cache0.localPeek(key, CachePeekMode.ONHEAP)); } assertEquals((Integer)i, cache0.get(key)); @@ -145,15 +145,15 @@ public abstract class GridCacheValueConsistencyAbstractSelfTest extends GridCach info("Removing values from cache."); for (int i = 0; i < keyCnt; i++) - assertEquals((Integer)i, cache.remove("key" + i)); + assertEquals((Integer)i, cache.getAndRemove("key" + i)); for (int g = 0; g < gridCount(); g++) { - GridCache<String, Integer> cache0 = cache(g); + IgniteCache<String, Integer> cache0 = jcache(g); for (int i = 0; i < keyCnt; i++) { String key = "key" + i; - assertNull(cache0.peek(key)); + assertNull(cache0.localPeek(key, CachePeekMode.ONHEAP)); assertNull(cache0.get(key)); } @@ -166,7 +166,7 @@ public abstract class GridCacheValueConsistencyAbstractSelfTest extends GridCach public void testPutRemoveAll() throws Exception { awaitPartitionMapExchange(); - GridCache<String, Integer> cache = cache(); + IgniteCache<String, Integer> cache = jcache(); int keyCnt = 10; @@ -177,25 +177,25 @@ public abstract class GridCacheValueConsistencyAbstractSelfTest extends GridCach } for (int g = 0; g < gridCount(); g++) { - GridCache<String, Integer> cache0 = cache(g); + IgniteCache<String, Integer> cache0 = jcache(g); ClusterNode locNode = grid(g).localNode(); for (int i = 0; i < keyCnt; i++) { String key = "key" + i; - if (cache.affinity().mapKeyToPrimaryAndBackups(key).contains(grid(g).localNode())) { + if (ignite(0).affinity(null).mapKeyToPrimaryAndBackups(key).contains(grid(g).localNode())) { info("Node is reported as affinity node for key [key=" + key + ", nodeId=" + locNode.id() + ']'); - assertEquals((Integer)i, cache0.peek(key)); + assertEquals((Integer)i, cache0.localPeek(key, CachePeekMode.ONHEAP)); } else { info("Node is reported as NOT affinity node for key [key=" + key + ", nodeId=" + locNode.id() + ']'); if (distributionMode() == NEAR_PARTITIONED && cache == cache0) - assertEquals((Integer)i, cache0.peek(key)); + assertEquals((Integer)i, cache0.localPeek(key, CachePeekMode.ONHEAP)); else - assertNull(cache0.peek(key)); + assertNull(cache0.localPeek(key, CachePeekMode.ONHEAP)); } assertEquals((Integer)i, cache0.get(key)); @@ -211,12 +211,12 @@ public abstract class GridCacheValueConsistencyAbstractSelfTest extends GridCach info(">>>> Starting values check"); for (int g = 0; g < gridCount(); g++) { - GridCache<String, Integer> cache0 = cache(g); + IgniteCache<String, Integer> cache0 = jcache(g); for (int i = 0; i < keyCnt; i++) { String key = "key" + i; - assertNull(cache0.peek(key)); + assertNull(cache0.localPeek(key, CachePeekMode.ONHEAP)); assertNull(cache0.get(key)); } } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e0b3193b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheWriteBehindStoreAbstractTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheWriteBehindStoreAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheWriteBehindStoreAbstractTest.java index ecabdd5..01dd961 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheWriteBehindStoreAbstractTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheWriteBehindStoreAbstractTest.java @@ -62,7 +62,7 @@ public abstract class GridCacheWriteBehindStoreAbstractTest extends GridCommonAb /** {@inheritDoc} */ @Override protected void afterTest() throws Exception { - GridCache<?, ?> cache = cache(); + IgniteCache<?, ?> cache = jcache(); if (cache != null) cache.clear(); @@ -107,17 +107,17 @@ public abstract class GridCacheWriteBehindStoreAbstractTest extends GridCommonAb /** @throws Exception If test fails. */ public void testWriteThrough() throws Exception { - GridCache<Integer, String> cache = cache(); + IgniteCache<Integer, String> cache = jcache(); Map<Integer, String> map = store.getMap(); assert map.isEmpty(); - IgniteTx tx = cache.txStart(OPTIMISTIC, REPEATABLE_READ); + IgniteTx tx = grid().transactions().txStart(OPTIMISTIC, REPEATABLE_READ); try { for (int i = 1; i <= 10; i++) { - cache.putx(i, Integer.toString(i)); + cache.put(i, Integer.toString(i)); checkLastMethod(null); } @@ -144,11 +144,11 @@ public abstract class GridCacheWriteBehindStoreAbstractTest extends GridCommonAb store.resetLastMethod(); - tx = cache.txStart(); + tx = grid().transactions().txStart(); try { for (int i = 1; i <= 10; i++) { - String val = cache.remove(i); + String val = cache.getAndRemove(i); checkLastMethod(null); @@ -172,15 +172,15 @@ public abstract class GridCacheWriteBehindStoreAbstractTest extends GridCommonAb /** @throws Exception If test failed. */ public void testReadThrough() throws Exception { - GridCache<Integer, String> cache = cache(); + IgniteCache<Integer, String> cache = jcache(); Map<Integer, String> map = store.getMap(); assert map.isEmpty(); - try (IgniteTx tx = cache.txStart(OPTIMISTIC, REPEATABLE_READ)) { + try (IgniteTx tx = grid().transactions().txStart(OPTIMISTIC, REPEATABLE_READ)) { for (int i = 1; i <= 10; i++) - cache.putx(i, Integer.toString(i)); + cache.put(i, Integer.toString(i)); checkLastMethod(null); @@ -201,8 +201,8 @@ public abstract class GridCacheWriteBehindStoreAbstractTest extends GridCommonAb cache.clear(); - assert cache.isEmpty(); - assert cache.isEmpty(); + assert cache.localSize() == 0; + assert cache.localSize() == 0; // Need to wait WFB flush timeout. U.sleep(WRITE_FROM_BEHIND_FLUSH_FREQUENCY + 100); @@ -223,12 +223,12 @@ public abstract class GridCacheWriteBehindStoreAbstractTest extends GridCommonAb cache.clear(); - assert cache.isEmpty(); - assert cache.isEmpty(); + assert cache.localSize() == 0; + assert cache.localSize() == 0; assert map.size() == 10; - Collection<Integer> keys = new ArrayList<>(); + Set<Integer> keys = new HashSet<>(); for (int i = 1; i <= 10; i++) keys.add(i); @@ -256,8 +256,8 @@ public abstract class GridCacheWriteBehindStoreAbstractTest extends GridCommonAb checkLastMethod("removeAll"); - assert cache.isEmpty(); - assert cache.isEmpty(); + assert cache.localSize() == 0; + assert cache.localSize() == 0; assert map.isEmpty(); } @@ -268,7 +268,7 @@ public abstract class GridCacheWriteBehindStoreAbstractTest extends GridCommonAb final AtomicBoolean running = new AtomicBoolean(true); - final GridCache<Integer, String> cache = cache(); + final IgniteCache<Integer, String> cache = jcache(); IgniteInternalFuture<?> fut = multithreadedAsync(new Runnable() { @SuppressWarnings({"NullableProblems"}) @@ -283,34 +283,27 @@ public abstract class GridCacheWriteBehindStoreAbstractTest extends GridCommonAb Random rnd = new Random(); - try { - int keyCnt = 20000; + int keyCnt = 20000; - while (running.get()) { - int op = rnd.nextInt(2); - int key = rnd.nextInt(keyCnt); + while (running.get()) { + int op = rnd.nextInt(2); + int key = rnd.nextInt(keyCnt); - switch (op) { - case 0: - cache.put(key, "val" + key); - set.add(key); + switch (op) { + case 0: + cache.put(key, "val" + key); + set.add(key); - break; + break; - case 1: - default: - cache.remove(key); - set.remove(key); + case 1: + default: + cache.remove(key); + set.remove(key); - break; - } + break; } } - catch (IgniteCheckedException e) { - error("Unexpected exception in put thread", e); - - assert false; - } } }, 10, "put");