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 7e9b0c1 commit 03d0282
Show file tree
Hide file tree
Showing 19 changed files with 150 additions and 144 deletions.
Expand Up @@ -431,12 +431,13 @@ public void testPutIfAbsentAsyncAvgTime() throws Exception {
* @throws Exception If failed. * @throws Exception If failed.
*/ */
public void testGetAndPutIfAbsentAsyncAvgTime() throws Exception { public void testGetAndPutIfAbsentAsyncAvgTime() throws Exception {
GridCache<Object, Object> cache = grid(0).cache(null); IgniteCache<Object, Object> cache = grid(0).jcache(null);
IgniteCache<Object, Object> cacheAsync = cache.withAsync();


Integer key = null; Integer key = null;


for (int i = 0; i < 1000; i++) { for (int i = 0; i < 1000; i++) {
if (cache.affinity().isPrimary(grid(0).localNode(), i)) { if (affinity(cache).isPrimary(grid(0).localNode(), i)) {
key = i; key = i;


break; break;
Expand All @@ -445,7 +446,9 @@ public void testGetAndPutIfAbsentAsyncAvgTime() throws Exception {


assertEquals(0.0f, cache.metrics().getAveragePutTime()); assertEquals(0.0f, cache.metrics().getAveragePutTime());


IgniteInternalFuture<?> fut = cache.putIfAbsentAsync(key, key); cacheAsync.getAndPutIfAbsent(key, key);

IgniteFuture<?> fut = cache.future();


fut.get(); fut.get();


Expand Down
Expand Up @@ -114,10 +114,9 @@ public abstract class GridCacheAbstractSelfTest extends GridCommonAbstractTest {
// Preloading may happen as nodes leave, so we need to wait. // Preloading may happen as nodes leave, so we need to wait.
new GridAbsPredicateX() { new GridAbsPredicateX() {
@Override public boolean applyx() throws IgniteCheckedException { @Override public boolean applyx() throws IgniteCheckedException {
//<Object, Object> to support remove(key) jcache(fi).removeAll();
GridCache<Object, Object> cache = grid(fi).cache(null);


cache.removeAll(); GridCache<Object, Object> cache = internalCache(fi);


// Fix for tests where mapping was removed at primary node // Fix for tests where mapping was removed at primary node
// but was not removed at others. // but was not removed at others.
Expand Down
Expand Up @@ -23,6 +23,7 @@
import org.apache.ignite.cluster.*; import org.apache.ignite.cluster.*;
import org.apache.ignite.compute.*; import org.apache.ignite.compute.*;
import org.apache.ignite.configuration.*; import org.apache.ignite.configuration.*;
import org.apache.ignite.internal.*;
import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.*;
import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.internal.util.typedef.internal.*;
import org.apache.ignite.lang.*; import org.apache.ignite.lang.*;
Expand Down Expand Up @@ -269,7 +270,7 @@ public void checkPutAllFailoverGroupLock(boolean near, int workerCnt, int shutdo
for (Ignite g : runningWorkers) { for (Ignite g : runningWorkers) {
info(">>>>> " + g.jcache(CACHE_NAME).localSize()); info(">>>>> " + g.jcache(CACHE_NAME).localSize());


primaryCacheSize += g.cache(CACHE_NAME).primarySize(); primaryCacheSize += ((IgniteKernal)g).internalCache(CACHE_NAME).primarySize();
} }


assertTrue(TEST_MAP_SIZE <= primaryCacheSize); assertTrue(TEST_MAP_SIZE <= primaryCacheSize);
Expand Down
Expand Up @@ -21,6 +21,7 @@
import org.apache.ignite.cache.*; import org.apache.ignite.cache.*;
import org.apache.ignite.cache.eviction.fifo.*; import org.apache.ignite.cache.eviction.fifo.*;
import org.apache.ignite.configuration.*; import org.apache.ignite.configuration.*;
import org.apache.ignite.internal.*;
import org.apache.ignite.spi.discovery.tcp.*; import org.apache.ignite.spi.discovery.tcp.*;
import org.apache.ignite.spi.discovery.tcp.ipfinder.*; import org.apache.ignite.spi.discovery.tcp.ipfinder.*;
import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*; import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*;
Expand Down Expand Up @@ -180,7 +181,7 @@ private void performanceTest() throws Exception {
Ignite g = startGrid(); Ignite g = startGrid();


try { try {
GridCache<Integer, Integer> cache = g.cache(null); GridCache<Integer, Integer> cache = ((IgniteKernal)g).internalCache(null);


// int max = 17 * 1024 * 1024; // int max = 17 * 1024 * 1024;
int max = Integer.MAX_VALUE; int max = Integer.MAX_VALUE;
Expand Down Expand Up @@ -210,7 +211,7 @@ private void performanceMultithreadedTest() throws Exception {
Ignite g = startGrid(); Ignite g = startGrid();


try { try {
final GridCache<Integer, Integer> c = g.cache(null); final GridCache<Integer, Integer> c = ((IgniteKernal)g).internalCache(null);


final long start = System.currentTimeMillis(); final long start = System.currentTimeMillis();


Expand Down
Expand Up @@ -122,7 +122,7 @@ private void checkSwap() throws Exception {


startGrid(1); startGrid(1);


int size = grid(1).cache(null).size(); int size = grid(1).jcache(null).localSize();


info("New node cache size: " + size); info("New node cache size: " + size);


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.transactions.*; import org.apache.ignite.transactions.*;


Expand Down Expand Up @@ -206,10 +207,10 @@ public void testPessimisticSerializableRollbacksNoData() throws Exception {
*/ */
private void testCommits(IgniteTxConcurrency concurrency, IgniteTxIsolation isolation, boolean put) private void testCommits(IgniteTxConcurrency concurrency, IgniteTxIsolation isolation, boolean put)
throws Exception { throws Exception {
GridCache<Integer, Integer> cache = grid(0).cache(null); IgniteCache<Integer, Integer> cache = grid(0).jcache(null);


for (int i = 0; i < TX_CNT; i++) { for (int i = 0; i < TX_CNT; i++) {
IgniteTx tx = cache.txStart(concurrency, isolation); IgniteTx tx = grid(0).transactions().txStart(concurrency, isolation);


if (put) if (put)
for (int j = 0; j < keyCount(); j++) for (int j = 0; j < keyCount(); j++)
Expand All @@ -220,7 +221,7 @@ private void testCommits(IgniteTxConcurrency concurrency, IgniteTxIsolation isol


for (int i = 0; i < gridCount(); i++) { for (int i = 0; i < gridCount(); i++) {
IgniteTxMetrics metrics = grid(i).transactions().metrics(); IgniteTxMetrics metrics = grid(i).transactions().metrics();
CacheMetrics cacheMetrics = grid(i).cache(null).metrics(); CacheMetrics cacheMetrics = grid(i).jcache(null).metrics();


if (i == 0) { if (i == 0) {
assertEquals(TX_CNT, metrics.txCommits()); assertEquals(TX_CNT, metrics.txCommits());
Expand Down Expand Up @@ -248,10 +249,10 @@ private void testCommits(IgniteTxConcurrency concurrency, IgniteTxIsolation isol
*/ */
private void testRollbacks(IgniteTxConcurrency concurrency, IgniteTxIsolation isolation, private void testRollbacks(IgniteTxConcurrency concurrency, IgniteTxIsolation isolation,
boolean put) throws Exception { boolean put) throws Exception {
GridCache<Integer, Integer> cache = grid(0).cache(null); IgniteCache<Integer, Integer> cache = grid(0).jcache(null);


for (int i = 0; i < TX_CNT; i++) { for (int i = 0; i < TX_CNT; i++) {
IgniteTx tx = cache.txStart(concurrency, isolation); IgniteTx tx = grid(0).transactions().txStart(concurrency, isolation);


if (put) if (put)
for (int j = 0; j < keyCount(); j++) for (int j = 0; j < keyCount(); j++)
Expand All @@ -262,7 +263,7 @@ private void testRollbacks(IgniteTxConcurrency concurrency, IgniteTxIsolation is


for (int i = 0; i < gridCount(); i++) { for (int i = 0; i < gridCount(); i++) {
IgniteTxMetrics metrics = grid(i).transactions().metrics(); IgniteTxMetrics metrics = grid(i).transactions().metrics();
CacheMetrics cacheMetrics = grid(i).cache(null).metrics(); CacheMetrics cacheMetrics = grid(i).jcache(null).metrics();


assertEquals(0, metrics.txCommits()); assertEquals(0, metrics.txCommits());
assertEquals(0, cacheMetrics.getCacheTxCommits()); assertEquals(0, cacheMetrics.getCacheTxCommits());
Expand Down
Expand Up @@ -122,26 +122,26 @@ public void checkByteArrays() throws Exception {
byte[] val = new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}; byte[] val = new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 0};


for (int i = 0; i < keyCnt; i++) for (int i = 0; i < keyCnt; i++)
grid(0).cache(null).put(String.valueOf(i), val); grid(0).jcache(null).put(String.valueOf(i), val);


for (int i = 0; i < keyCnt; i++) for (int i = 0; i < keyCnt; i++)
grid(0).cache(null).get(String.valueOf(i)); grid(0).jcache(null).get(String.valueOf(i));


startGrid(1); startGrid(1);


if (memMode == ONHEAP_TIERED) { if (memMode == ONHEAP_TIERED) {
for (int i = 0; i < keyCnt; i++) for (int i = 0; i < keyCnt; i++)
grid(0).cache(null).evict(String.valueOf(i)); grid(0).jcache(null).evict(String.valueOf(i));


for (int i = 0; i < keyCnt; i++) for (int i = 0; i < keyCnt; i++)
grid(0).cache(null).promote(String.valueOf(i)); grid(0).jcache(null).promote(String.valueOf(i));
} }


startGrid(2); startGrid(2);


for (int g = 0; g < 3; g++) { for (int g = 0; g < 3; g++) {
for (int i = 0; i < keyCnt; i++) { for (int i = 0; i < keyCnt; i++) {
byte[] o = (byte[])grid(g).cache(null).get(String.valueOf(i)); byte[] o = (byte[])grid(g).jcache(null).get(String.valueOf(i));


assertTrue("Got invalid value [val=" + Arrays.toString(val) + ", actual=" + Arrays.toString(o) + ']', assertTrue("Got invalid value [val=" + Arrays.toString(val) + ", actual=" + Arrays.toString(o) + ']',
Arrays.equals(val, o)); Arrays.equals(val, o));
Expand Down
Expand Up @@ -21,6 +21,7 @@
import org.apache.ignite.cache.*; import org.apache.ignite.cache.*;
import org.apache.ignite.cluster.*; import org.apache.ignite.cluster.*;
import org.apache.ignite.configuration.*; import org.apache.ignite.configuration.*;
import org.apache.ignite.internal.*;


import java.util.*; import java.util.*;
import java.util.concurrent.*; import java.util.concurrent.*;
Expand Down Expand Up @@ -247,7 +248,7 @@ public void testPutRemoveConsistencyMultithreaded() throws Exception {


Ignite ignite = grid(g); Ignite ignite = grid(g);


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


int k = rnd.nextInt(range); int k = rnd.nextInt(range);


Expand All @@ -273,7 +274,7 @@ public void testPutRemoveConsistencyMultithreaded() throws Exception {
Long firstVal = null; Long firstVal = null;


for (int g = 0; g < gridCount(); g++) { for (int g = 0; g < gridCount(); g++) {
Long val = (Long)grid(g).cache(null).peek(i); Long val = (Long)grid(g).jcache(null).peek(i);


if (firstVal == null && val != null) if (firstVal == null && val != null)
firstVal = val; firstVal = val;
Expand All @@ -300,7 +301,7 @@ public void testPutRemoveConsistencyMultithreaded() throws Exception {
* @param g Grid to check. * @param g Grid to check.
*/ */
private void checkKeySet(Ignite g) { private void checkKeySet(Ignite g) {
GridCache<Object, Object> cache = g.cache(null); GridCache<Object, Object> cache = ((IgniteKernal)g).internalCache(null);


Set<Object> keys = cache.keySet(); Set<Object> keys = cache.keySet();


Expand Down
Expand Up @@ -122,14 +122,14 @@ public void testNodeStop() throws Exception {
private int cnt; private int cnt;


@SuppressWarnings({"BusyWait"}) @SuppressWarnings({"BusyWait"})
@Override public void applyx() throws IgniteCheckedException { @Override public void applyx() {
while (cnt++ < txCnt && !done.get()) { while (cnt++ < txCnt && !done.get()) {
GridCache<Object, Object> cache = grid(0).cache(null); IgniteCache<Object, Object> cache = grid(0).jcache(null);


if (cnt % logMod == 0) if (cnt % logMod == 0)
info("Starting transaction: " + cnt); info("Starting transaction: " + cnt);


try (IgniteTx tx = cache.txStart()) { try (IgniteTx tx = grid(0).transactions().txStart()) {
int kv = RAND.nextInt(keyRange); int kv = RAND.nextInt(keyRange);


cache.put(kv, kv); cache.put(kv, kv);
Expand All @@ -138,7 +138,7 @@ public void testNodeStop() throws Exception {


tx.commit(); tx.commit();
} }
catch (IgniteTxOptimisticCheckedException e) { catch (IgniteTxOptimisticException e) {
info("Caught cache optimistic exception: " + e); info("Caught cache optimistic exception: " + e);
} }


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 @@ -138,7 +139,7 @@ public void testTxWritesOnDhtNode() throws Exception {
private void checkSingleWrites() throws Exception { private void checkSingleWrites() throws Exception {
prepare(); prepare();


GridCache<Integer, String> cache = grid(0).cache(null); IgniteCache<Integer, String> cache = grid(0).jcache(null);


for (int i = 0; i < 100; i++) for (int i = 0; i < 100; i++)
cache.put(i, String.valueOf(i)); cache.put(i, String.valueOf(i));
Expand All @@ -157,7 +158,7 @@ private void checkBatchWrites() throws Exception {
for (int i = 0; i < 100; i++) for (int i = 0; i < 100; i++)
map.put(i, String.valueOf(i)); map.put(i, String.valueOf(i));


grid(0).cache(null).putAll(map); grid(0).jcache(null).putAll(map);


checkWrites(); checkWrites();
} }
Expand All @@ -168,9 +169,9 @@ private void checkBatchWrites() throws Exception {
private void checkTxWrites() throws Exception { private void checkTxWrites() throws Exception {
prepare(); prepare();


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


try (IgniteTx tx = cache.txStart(PESSIMISTIC, REPEATABLE_READ)) { try (IgniteTx tx = grid(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
for (int i = 0; i < 100; i++) for (int i = 0; i < 100; i++)
cache.put(i, String.valueOf(i)); cache.put(i, String.valueOf(i));


Expand Down
Expand Up @@ -95,7 +95,7 @@ public void testPutGet() throws Exception {


final Ignite ignite = grid(); final Ignite ignite = grid();


ignite.cache(null).put(key, "val"); ignite.jcache(null).put(key, "val");


GridCacheEntryEx<String,Integer> dhtEntry = dht(ignite).peekEx(key); GridCacheEntryEx<String,Integer> dhtEntry = dht(ignite).peekEx(key);


Expand All @@ -122,14 +122,14 @@ public void testPutGet() throws Exception {
* @throws Exception If failed. * @throws Exception If failed.
*/ */
private String txGet(Ignite ignite, String key) throws Exception { private String txGet(Ignite ignite, String key) throws Exception {
try (IgniteTx tx = ignite.cache(null).txStart(PESSIMISTIC, REPEATABLE_READ)) { try (IgniteTx tx = ignite.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
GridCacheEntryEx<String, Integer> dhtEntry = dht(ignite).peekEx(key); GridCacheEntryEx<String, Integer> dhtEntry = dht(ignite).peekEx(key);


if (DEBUG) if (DEBUG)
info("DHT entry [hash=" + System.identityHashCode(dhtEntry) + ", xid=" + tx.xid() + info("DHT entry [hash=" + System.identityHashCode(dhtEntry) + ", xid=" + tx.xid() +
", entry=" + dhtEntry + ']'); ", entry=" + dhtEntry + ']');


String val = ignite.<String, String>cache(null).get(key); String val = ignite.<String, String>jcache(null).get(key);


assertNotNull(val); assertNotNull(val);
assertEquals("val", val); assertEquals("val", val);
Expand Down

0 comments on commit 03d0282

Please sign in to comment.