Skip to content

Commit

Permalink
# IGNITE-56 Migration of tests to IgniteCache
Browse files Browse the repository at this point in the history
  • Loading branch information
sevdokimov-gg committed Feb 6, 2015
1 parent 0194aef commit e0b3193
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 83 deletions.
Expand Up @@ -225,13 +225,13 @@ public void testRehashMultithreaded1() throws Exception {
} }
}, 10); }, 10);


cache().get(rand.nextInt(cnt)); jcache().get(rand.nextInt(cnt));


System.gc(); System.gc();


Thread.sleep(1000); Thread.sleep(1000);


cache().get(rand.nextInt(cnt)); jcache().get(rand.nextInt(cnt));


assertEquals(0, local().map.iteratorMapSize()); assertEquals(0, local().map.iteratorMapSize());
} }
Expand Down Expand Up @@ -320,13 +320,13 @@ public void testRehashMultithreaded2() throws Exception {
} }
}, 10); }, 10);


cache().get(rand.nextInt(cnt)); jcache().get(rand.nextInt(cnt));


System.gc(); System.gc();


Thread.sleep(1000); Thread.sleep(1000);


cache().get(rand.nextInt(cnt)); jcache().get(rand.nextInt(cnt));


assertEquals(0, local().map.iteratorMapSize()); assertEquals(0, local().map.iteratorMapSize());
} }
Expand Down
Expand Up @@ -17,9 +17,11 @@


package org.apache.ignite.internal.processors.cache; package org.apache.ignite.internal.processors.cache;


import org.apache.ignite.*;
import org.apache.ignite.cache.*; import org.apache.ignite.cache.*;
import org.apache.ignite.configuration.*; import org.apache.ignite.configuration.*;
import org.apache.ignite.internal.*; import org.apache.ignite.internal.*;
import org.apache.ignite.lang.*;
import org.apache.ignite.spi.discovery.tcp.*; import org.apache.ignite.spi.discovery.tcp.*;
import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*; import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*;
import org.apache.ignite.testframework.*; import org.apache.ignite.testframework.*;
Expand Down Expand Up @@ -83,7 +85,7 @@ public GridCacheMissingCommitVersionSelfTest() {
* @throws Exception If failed. * @throws Exception If failed.
*/ */
public void testMissingCommitVersion() throws Exception { public void testMissingCommitVersion() throws Exception {
final GridCache<Integer, Integer> cache = cache(); final IgniteCache<Integer, Integer> cache = jcache();


final int KEYS_PER_THREAD = 10_000; final int KEYS_PER_THREAD = 10_000;


Expand Down Expand Up @@ -115,12 +117,16 @@ public void testMissingCommitVersion() throws Exception {


log.info("Trying to update " + failedKey); 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 { try {
fut.get(5000); fut.get(5000);
} }
catch (IgniteFutureTimeoutCheckedException ignore) { catch (IgniteFutureTimeoutException ignore) {
fail("Put failed to finish in 5s."); fail("Put failed to finish in 5s.");
} }
} }
Expand Down
Expand Up @@ -17,6 +17,7 @@


package org.apache.ignite.internal.processors.cache; package org.apache.ignite.internal.processors.cache;


import org.apache.ignite.*;
import org.apache.ignite.cache.*; import org.apache.ignite.cache.*;
import org.apache.ignite.cache.store.*; import org.apache.ignite.cache.store.*;
import org.apache.ignite.configuration.*; import org.apache.ignite.configuration.*;
Expand Down Expand Up @@ -101,16 +102,16 @@ public void testWrite() throws Exception {


startGrid(); startGrid();


GridCache<Integer, String> cache = cache(); IgniteCache<Integer, String> cache = jcache();


try { try {
cache.get(1); cache.get(1);


IgniteTx tx = cache.txStart(); IgniteTx tx = grid().transactions().txStart();


try { try {
for (int i = 1; i <= 10; i++) for (int i = 1; i <= 10; i++)
cache.putx(i, Integer.toString(i)); cache.put(i, Integer.toString(i));


tx.commit(); tx.commit();
} }
Expand All @@ -122,11 +123,11 @@ public void testWrite() throws Exception {


assert putCnt.get() == 10; assert putCnt.get() == 10;


tx = cache.txStart(); tx = grid().transactions().txStart();


try { try {
for (int i = 1; i <= 10; i++) { for (int i = 1; i <= 10; i++) {
String val = cache.remove(i); String val = cache.getAndRemove(i);


assert val != null; assert val != null;
assert val.equals(Integer.toString(i)); assert val.equals(Integer.toString(i));
Expand Down
Expand Up @@ -17,6 +17,7 @@


package org.apache.ignite.internal.processors.cache; package org.apache.ignite.internal.processors.cache;


import org.apache.ignite.*;
import org.apache.ignite.cache.*; import org.apache.ignite.cache.*;
import org.apache.ignite.cache.store.*; import org.apache.ignite.cache.store.*;
import org.apache.ignite.configuration.*; import org.apache.ignite.configuration.*;
Expand Down Expand Up @@ -88,22 +89,22 @@ public class GridCacheStorePutxSelfTest extends GridCommonAbstractTest {
/** /**
* @throws Exception If failed. * @throws Exception If failed.
*/ */
public void testPutxShouldNotTriggerLoad() throws Exception { public void testPutShouldNotTriggerLoad() throws Exception {
assertTrue(cache().putx(1, 1)); jcache().put(1, 1);
assertTrue(cache().putx(2, 2, (IgnitePredicate)null)); jcache().put(2, 2);


assertEquals(0, loads.get()); assertEquals(0, loads.get());
} }


/** /**
* @throws Exception If failed. * @throws Exception If failed.
*/ */
public void testPutxShouldNotTriggerLoadWithTx() throws Exception { public void testPutShouldNotTriggerLoadWithTx() throws Exception {
GridCache<Integer, Integer> cache = cache(); IgniteCache<Integer, Integer> cache = jcache();


try (IgniteTx tx = cache.txStart()) { try (IgniteTx tx = grid().transactions().txStart()) {
assertTrue(cache.putx(1, 1)); cache.put(1, 1);
assertTrue(cache.putx(2, 2, (IgnitePredicate)null)); cache.put(2, 2);


tx.commit(); tx.commit();
} }
Expand Down
Expand Up @@ -17,6 +17,8 @@


package org.apache.ignite.internal.processors.cache; 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.*;
import org.apache.ignite.cache.store.*; import org.apache.ignite.cache.store.*;
import org.apache.ignite.configuration.*; import org.apache.ignite.configuration.*;
Expand Down Expand Up @@ -126,19 +128,23 @@ public void testReload() throws Exception {


assert swap() != null; assert swap() != null;


assert cache().putx("key", "val"); IgniteCache<String, String> cache = jcache();

cache.put("key", "val");


assert swap().size(spaceName()) == 0; assert swap().size(spaceName()) == 0;


assert cache().evict("key"); cache.localEvict(Collections.singleton("key"));


assert swapLatch.await(1, SECONDS); assert swapLatch.await(1, SECONDS);
Thread.sleep(100); Thread.sleep(100);


assert swap().count(spaceName()) == 1; assert swap().count(spaceName()) == 1;
assert swap().size(spaceName()) > 0; 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); assert unswapLatch.await(1, SECONDS);


Expand Down Expand Up @@ -175,21 +181,23 @@ public void testReloadAll() throws Exception {


assert swap() != null; assert swap() != null;


assert cache().putx("key1", "val1"); IgniteCache<String, String> cache = jcache();
assert cache().putx("key2", "val2");
cache.put("key1", "val1");
cache.put("key2", "val2");


assert swap().size(spaceName()) == 0; assert swap().size(spaceName()) == 0;


assert cache().evict("key1"); cache.localEvict(Collections.singleton("key1"));
assert cache().evict("key2"); cache.localEvict(Collections.singleton("key2"));


assert swapLatch.await(1, SECONDS); assert swapLatch.await(1, SECONDS);
Thread.sleep(100); Thread.sleep(100);


assert swap().count(spaceName()) == 2; assert swap().count(spaceName()) == 2;
assert swap().size(spaceName()) > 0 : swap().size(spaceName()); 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); assert unswapLatch.await(1, SECONDS);


Expand Down
Expand Up @@ -109,33 +109,33 @@ protected CacheAtomicWriteOrderMode writeOrderMode() {
public void testPutRemove() throws Exception { public void testPutRemove() throws Exception {
awaitPartitionMapExchange(); awaitPartitionMapExchange();


GridCache<String, Integer> cache = cache(); IgniteCache<String, Integer> cache = jcache();


int keyCnt = 10; int keyCnt = 10;


for (int i = 0; i < keyCnt; i++) for (int i = 0; i < keyCnt; i++)
cache.put("key" + i, i); cache.put("key" + i, i);


for (int g = 0; g < gridCount(); g++) { for (int g = 0; g < gridCount(); g++) {
GridCache<String, Integer> cache0 = cache(g); IgniteCache<String, Integer> cache0 = jcache(g);
ClusterNode locNode = grid(g).localNode(); ClusterNode locNode = grid(g).localNode();


for (int i = 0; i < keyCnt; i++) { for (int i = 0; i < keyCnt; i++) {
String key = "key" + 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() + ']'); 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 { else {
info("Node is reported as NOT affinity node for key [key=" + key + info("Node is reported as NOT affinity node for key [key=" + key +
", nodeId=" + locNode.id() + ']'); ", nodeId=" + locNode.id() + ']');


if (distributionMode() == NEAR_PARTITIONED && cache == cache0) if (distributionMode() == NEAR_PARTITIONED && cache == cache0)
assertEquals((Integer)i, cache0.peek(key)); assertEquals((Integer)i, cache0.localPeek(key, CachePeekMode.ONHEAP));
else else
assertNull(cache0.peek(key)); assertNull(cache0.localPeek(key, CachePeekMode.ONHEAP));
} }


assertEquals((Integer)i, cache0.get(key)); assertEquals((Integer)i, cache0.get(key));
Expand All @@ -145,15 +145,15 @@ public void testPutRemove() throws Exception {
info("Removing values from cache."); info("Removing values from cache.");


for (int i = 0; i < keyCnt; i++) 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++) { 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++) { for (int i = 0; i < keyCnt; i++) {
String key = "key" + i; String key = "key" + i;


assertNull(cache0.peek(key)); assertNull(cache0.localPeek(key, CachePeekMode.ONHEAP));


assertNull(cache0.get(key)); assertNull(cache0.get(key));
} }
Expand All @@ -166,7 +166,7 @@ public void testPutRemove() throws Exception {
public void testPutRemoveAll() throws Exception { public void testPutRemoveAll() throws Exception {
awaitPartitionMapExchange(); awaitPartitionMapExchange();


GridCache<String, Integer> cache = cache(); IgniteCache<String, Integer> cache = jcache();


int keyCnt = 10; int keyCnt = 10;


Expand All @@ -177,25 +177,25 @@ public void testPutRemoveAll() throws Exception {
} }


for (int g = 0; g < gridCount(); g++) { for (int g = 0; g < gridCount(); g++) {
GridCache<String, Integer> cache0 = cache(g); IgniteCache<String, Integer> cache0 = jcache(g);
ClusterNode locNode = grid(g).localNode(); ClusterNode locNode = grid(g).localNode();


for (int i = 0; i < keyCnt; i++) { for (int i = 0; i < keyCnt; i++) {
String key = "key" + 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() + ']'); 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 { else {
info("Node is reported as NOT affinity node for key [key=" + key + info("Node is reported as NOT affinity node for key [key=" + key +
", nodeId=" + locNode.id() + ']'); ", nodeId=" + locNode.id() + ']');


if (distributionMode() == NEAR_PARTITIONED && cache == cache0) if (distributionMode() == NEAR_PARTITIONED && cache == cache0)
assertEquals((Integer)i, cache0.peek(key)); assertEquals((Integer)i, cache0.localPeek(key, CachePeekMode.ONHEAP));
else else
assertNull(cache0.peek(key)); assertNull(cache0.localPeek(key, CachePeekMode.ONHEAP));
} }


assertEquals((Integer)i, cache0.get(key)); assertEquals((Integer)i, cache0.get(key));
Expand All @@ -211,12 +211,12 @@ public void testPutRemoveAll() throws Exception {
info(">>>> Starting values check"); info(">>>> Starting values check");


for (int g = 0; g < gridCount(); g++) { 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++) { for (int i = 0; i < keyCnt; i++) {
String key = "key" + i; String key = "key" + i;


assertNull(cache0.peek(key)); assertNull(cache0.localPeek(key, CachePeekMode.ONHEAP));
assertNull(cache0.get(key)); assertNull(cache0.get(key));
} }
} }
Expand Down

0 comments on commit e0b3193

Please sign in to comment.