Skip to content

Commit

Permalink
# IGNITE-56 Migration tests to IgniteCache
Browse files Browse the repository at this point in the history
  • Loading branch information
sevdokimov-gg committed Feb 9, 2015
1 parent 05163ca commit 2c2204d
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 42 deletions.
Expand Up @@ -97,7 +97,7 @@ public abstract class GridCacheClientModesAbstractSelfTest extends GridCacheAbst
* @throws Exception If failed. * @throws Exception If failed.
*/ */
public void testPutFromClientNode() throws Exception { public void testPutFromClientNode() throws Exception {
GridCache<Object, Object> nearOnly = nearOnlyCache(); IgniteCache<Object, Object> nearOnly = nearOnlyCache();


for (int i = 0; i < 5; i++) for (int i = 0; i < 5; i++)
nearOnly.put(i, i); nearOnly.put(i, i);
Expand All @@ -113,20 +113,20 @@ public void testPutFromClientNode() throws Exception {
if (nearEnabled()) if (nearEnabled())
assertEquals(key, nearOnly.peek(key)); assertEquals(key, nearOnly.peek(key));


assertNull(nearOnly.peek(key, F.asList(GridCachePeekMode.PARTITIONED_ONLY))); assertNull(nearOnly.localPeek(key, CachePeekMode.PRIMARY, CachePeekMode.BACKUP));
} }
} }


/** /**
* @throws Exception If failed. * @throws Exception If failed.
*/ */
public void testGetFromClientNode() throws Exception { public void testGetFromClientNode() throws Exception {
GridCache<Object, Object> dht = dhtCache(); IgniteCache<Object, Object> dht = dhtCache();


for (int i = 0; i < 10; i++) for (int i = 0; i < 10; i++)
dht.put(i, i); dht.put(i, i);


GridCache<Object, Object> nearOnly = nearOnlyCache(); IgniteCache<Object, Object> nearOnly = nearOnlyCache();


assert dht != nearOnly; assert dht != nearOnly;


Expand Down Expand Up @@ -189,19 +189,19 @@ public void testNearOnlyAffinity() throws Exception {
/** /**
* @return Near only cache for this test. * @return Near only cache for this test.
*/ */
protected GridCache<Object, Object> nearOnlyCache() { protected IgniteCache<Object, Object> nearOnlyCache() {
assert nearOnlyGridName != null; assert nearOnlyGridName != null;


return G.ignite(nearOnlyGridName).cache(null); return G.ignite(nearOnlyGridName).jcache(null);
} }


/** /**
* @return DHT cache for this test. * @return DHT cache for this test.
*/ */
protected GridCache<Object, Object> dhtCache() { protected IgniteCache<Object, Object> dhtCache() {
for (int i = 0; i < gridCount(); i++) { for (int i = 0; i < gridCount(); i++) {
if (!nearOnlyGridName.equals(grid(i).name())) if (!nearOnlyGridName.equals(grid(i).name()))
return grid(i).cache(null); return grid(i).jcache(null);
} }


assert false : "Cannot find DHT cache for this test."; assert false : "Cannot find DHT cache for this test.";
Expand Down
Expand Up @@ -17,6 +17,7 @@


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


import org.apache.ignite.*;
import org.apache.ignite.cache.*; import org.apache.ignite.cache.*;
import org.apache.ignite.internal.processors.cache.*; import org.apache.ignite.internal.processors.cache.*;
import org.apache.ignite.testframework.*; import org.apache.ignite.testframework.*;
Expand Down Expand Up @@ -72,7 +73,7 @@ public void testEntrySet() throws Exception {


log.info("Use cache " + idx); log.info("Use cache " + idx);


GridCache<Object, Object> cache = grid(idx).cache(null); IgniteCache<Object, Object> cache = grid(idx).jcache(null);


for (int i = 0; i < 100; i++) for (int i = 0; i < 100; i++)
putAndCheckEntrySet(cache); putAndCheckEntrySet(cache);
Expand All @@ -90,27 +91,25 @@ public void testEntrySet() throws Exception {
* @param cache Cache. * @param cache Cache.
* @throws Exception If failed. * @throws Exception If failed.
*/ */
private void putAndCheckEntrySet(GridCache<Object, Object> cache) throws Exception { private void putAndCheckEntrySet(IgniteCache<Object, Object> cache) throws Exception {
try (IgniteTx tx = cache.txStart(PESSIMISTIC, REPEATABLE_READ)) { try (IgniteTx tx = cache.unwrap(Ignite.class).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
Integer total = (Integer) cache.get(TX_KEY); Integer total = (Integer) cache.get(TX_KEY);


if (total == null) if (total == null)
total = 0; total = 0;


int cntr = 0; int cntr = 0;


Set<Cache.Entry<Object, Object>> entries = cache.entrySet(); for (Cache.Entry e : cache) {

for (Cache.Entry e : entries) {
if (e.getKey() instanceof Integer) if (e.getKey() instanceof Integer)
cntr++; cntr++;
} }


assertEquals(total, (Integer)cntr); assertEquals(total, (Integer)cntr);


cache.putx(cntr + 1, cntr + 1); cache.put(cntr + 1, cntr + 1);


cache.putx(TX_KEY, cntr + 1); cache.put(TX_KEY, cntr + 1);


tx.commit(); tx.commit();
} }
Expand Down
Expand Up @@ -197,28 +197,6 @@ private Map<String, Integer> pairs(int size) {
return pairs; return pairs;
} }


/**
* @throws Exception If test failed.
*/
public void testFilteredPut() throws Exception {
GridCache<String, Integer> cache = grid(0).cache(null);

String key = "1";
int val = 1;

assert !cache.putx(key, val, F.<String, Integer>cacheHasPeekValue());

assert !cache.containsKey(key);

assertEquals(0, TestEventListener.eventCount(EVT_CACHE_OBJECT_PUT));

assert cache.putx(key, val);

assert cache.containsKey(key);

waitForEvents(0, F.t(EVT_CACHE_OBJECT_PUT, gridCnt));
}

/** /**
* @throws Exception If test failed. * @throws Exception If test failed.
*/ */
Expand Down
Expand Up @@ -17,6 +17,7 @@


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


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.util.typedef.*; import org.apache.ignite.internal.util.typedef.*;
Expand Down Expand Up @@ -64,7 +65,7 @@ private CacheConfiguration cacheConfiguration(String gridName) {
* @throws Exception If failed. * @throws Exception If failed.
*/ */
public void testBasicOps() throws Exception { public void testBasicOps() throws Exception {
GridCache<Object, Object> cache = grid(0).cache(null); IgniteCache<Object, Object> cache = grid(0).jcache(null);


for (int i = 0; i < 1000; i++) for (int i = 0; i < 1000; i++)
cache.put(i, i); cache.put(i, i);
Expand All @@ -73,7 +74,7 @@ public void testBasicOps() throws Exception {
assertEquals(i, cache.get(i)); assertEquals(i, cache.get(i));


for (int i = 0; i < 1000; i++) for (int i = 0; i < 1000; i++)
assertEquals(i, cache.remove(i)); assertEquals(i, cache.getAndRemove(i));


for (int i = 0; i < 1000; i++) for (int i = 0; i < 1000; i++)
assertNull(cache.get(i)); assertNull(cache.get(i));
Expand Down
Expand Up @@ -17,6 +17,7 @@


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


import org.apache.ignite.*;
import org.apache.ignite.cache.*; import org.apache.ignite.cache.*;
import org.apache.ignite.internal.processors.cache.distributed.*; import org.apache.ignite.internal.processors.cache.distributed.*;


Expand All @@ -40,14 +41,14 @@ public class GridCacheNearOnlySelfTest extends GridCacheClientModesAbstractSelfT
* @throws Exception If failed. * @throws Exception If failed.
*/ */
public void testUpdateNearOnlyReader() throws Exception { public void testUpdateNearOnlyReader() throws Exception {
GridCache<Object, Object> dhtCache = dhtCache(); IgniteCache<Object, Object> dhtCache = dhtCache();


final int keyCnt = 100; final int keyCnt = 100;


for (int i = 0; i < keyCnt; i++) for (int i = 0; i < keyCnt; i++)
dhtCache.put(i, i); dhtCache.put(i, i);


GridCache<Object, Object> nearOnlyCache = nearOnlyCache(); IgniteCache<Object, Object> nearOnlyCache = nearOnlyCache();


for (int i = 0; i < keyCnt; i++) { for (int i = 0; i < keyCnt; i++) {
assertNull(nearOnlyCache.peek(i)); assertNull(nearOnlyCache.peek(i));
Expand Down

0 comments on commit 2c2204d

Please sign in to comment.