Skip to content

Commit

Permalink
IGNITE-96 Migrating tests on new API.
Browse files Browse the repository at this point in the history
  • Loading branch information
niktikhonov committed Feb 9, 2015
1 parent 2c2204d commit ae5198f
Show file tree
Hide file tree
Showing 24 changed files with 136 additions and 3,367 deletions.
Expand Up @@ -119,7 +119,7 @@ private void runConcurrentTest(Ignite g, final int keysCnt, final int batchSize)

final AtomicInteger evictedKeysCnt = new AtomicInteger();

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

cache.loadCache(null, 0);

Expand All @@ -135,7 +135,8 @@ private void runConcurrentTest(Ignite g, final int keysCnt, final int batchSize)
keys.add(i);

if (keys.size() == batchSize) {
cache.evictAll(keys);
for (Long key : keys)
cache.evict(key);

evictedKeysCnt.addAndGet(batchSize);

Expand Down Expand Up @@ -163,7 +164,8 @@ private void runConcurrentTest(Ignite g, final int keysCnt, final int batchSize)
keys.add(i);

if (keys.size() == batchSize) {
cache.promoteAll(keys);
for (Long key : keys)
cache.promote(key);

unswappedKeys.addAndGet(batchSize);

Expand All @@ -176,7 +178,7 @@ private void runConcurrentTest(Ignite g, final int keysCnt, final int batchSize)
}
}
}
catch (IgniteCheckedException e) {
catch (IgniteException e) {
e.printStackTrace();
}
}
Expand Down
Expand Up @@ -171,9 +171,9 @@ public void testPolicyConsistencyLruLocal() throws Exception {
*/
private void checkPolicyConsistency() throws Exception {
try {
Ignite ignite = startGrid(1);
final Ignite ignite = startGrid(1);

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

long start = System.currentTimeMillis();

Expand All @@ -187,10 +187,10 @@ public Object call() throws Exception {

int j = rnd.nextInt(keyCnt);

try (IgniteTx tx = cache.txStart()) {
try (IgniteTx tx = ignite.transactions().txStart()) {
// Put or remove?
if (rnd.nextBoolean())
cache.putx(j, j);
cache.put(j, j);
else
cache.remove(j);

Expand All @@ -215,7 +215,7 @@ public Object call() throws Exception {
", internalQueueSize" + queue.size() + ", duration=" + (System.currentTimeMillis() - start) + ']');

for (Cache.Entry<Integer, Integer> e : queue) {
Integer rmv = cache.remove(e.getKey());
Integer rmv = cache.getAndRemove(e.getKey());

if (rmv == null)
fail("Eviction policy contains key that is not present in cache: " + e);
Expand Down
Expand Up @@ -132,11 +132,11 @@ private void checkConcurrentPuts() throws Exception {
try {
Ignite ignite = startGrid(1);

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

// Warm up.
for (int i = 0; i < warmUpPutsCnt; i++) {
cache.putx(i, i);
cache.put(i, i);

if (i != 0 && i % 1000 == 0)
info("Warm up puts count: " + i);
Expand All @@ -158,7 +158,7 @@ private void checkConcurrentPuts() throws Exception {
for (int i = 0; i < iterCnt; i++) {
int j = idx.incrementAndGet();

cache.putx(j, j);
cache.put(j, j);

if (i != 0 && i % 10000 == 0)
// info("Puts count: " + i);
Expand Down
Expand Up @@ -165,10 +165,10 @@ public void testLocalSync() throws Throwable {

Ignite g = startGrid(0);

final GridCache<Integer, Integer> cache = g.cache(null);
final IgniteCache<Integer, Integer> cache = g.jcache(null);

for (int i = 1; i < 20; i++) {
cache.putx(i * gridCnt, i * gridCnt);
cache.put(i * gridCnt, i * gridCnt);

info("Put to cache: " + i * gridCnt);
}
Expand All @@ -181,18 +181,18 @@ private void checkEvictions() throws Throwable {

Ignite ignite = grid(0);

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

// Put 1 entry to primary node.
cache.putx(0, 0);
cache.put(0, 0);

Integer nearVal = this.<Integer, Integer>jcache(2).get(0);

assert nearVal == 0 : "Unexpected near value: " + nearVal;

// Put several vals to primary node.
for (int i = 1; i < 20; i++) {
cache.putx(i * gridCnt, i * gridCnt);
cache.put(i * gridCnt, i * gridCnt);

info("Put to cache: " + i * gridCnt);
}
Expand Down Expand Up @@ -228,10 +228,8 @@ private void checkEvictions() throws Throwable {
info("Near node near key set: " + new TreeSet<>(this.<Integer, Integer>near(2).keySet()));

try {
assert cache.size() == 10 : "Invalid cache size [size=" + cache.size() +
", keys=" + new TreeSet<>(cache.keySet()) + ']';
assert cache.size() == 10 : "Invalid key size [size=" + cache.size() +
", keys=" + new TreeSet<>(cache.keySet()) + ']';
assert cache.size() == 10 : "Invalid cache size [size=" + cache.size() + ']';
assert cache.size() == 10 : "Invalid key size [size=" + cache.size() + ']';

assert jcache(2).localSize() == 0;

Expand Down
Expand Up @@ -34,6 +34,8 @@

import javax.cache.configuration.*;

import java.util.*;

import static org.apache.ignite.cache.CacheAtomicityMode.*;

/**
Expand Down Expand Up @@ -170,13 +172,13 @@ private void checkPolicy0() throws Exception {

Ignite g = startGrids();

GridCache<String, String> cache = g.cache(null);
IgniteCache<String, String> cache = g.jcache(null);

try {
info(">>> Checking policy [txConcurrency=" + txConcurrency + ", txIsolation=" + txIsolation +
", plc=" + plc + ", nearPlc=" + nearPlc + ']');

checkExplicitTx(cache);
checkExplicitTx(g, cache);

checkImplicitTx(cache);
}
Expand All @@ -193,12 +195,20 @@ private void checkPolicy0() throws Exception {
* @param cache Cache to test.
* @throws Exception If failed.
*/
private void checkImplicitTx(GridCache<String, String> cache) throws Exception {
private void checkImplicitTx(IgniteCache<String, String> cache) throws Exception {
assertNull(cache.get("key1"));
assertNull(cache.getAsync("key2").get());

assertTrue(cache.getAll(F.asList("key3", "key4")).isEmpty());
assertTrue(cache.getAllAsync(F.asList("key5", "key6")).get().isEmpty());
IgniteCache<String, String> asyncCache = cache.withAsync();

asyncCache.get("key2");

assertNull(asyncCache.future().get());

assertTrue(cache.getAll(F.asSet("key3", "key4")).isEmpty());

asyncCache.getAll(F.asSet("key5", "key6"));

assertTrue(((Collection)asyncCache.future().get()).isEmpty());

cache.put("key7", "key7");
cache.remove("key7", "key7");
Expand All @@ -213,8 +223,10 @@ private void checkImplicitTx(GridCache<String, String> cache) throws Exception {
* @param cache Cache to test.
* @throws Exception If failed.
*/
private void checkExplicitTx(GridCache<String, String> cache) throws Exception {
IgniteTx tx = cache.txStart();
private void checkExplicitTx(Ignite ignite, IgniteCache<String, String> cache) throws Exception {
IgniteCache<String, String> asyncCache = cache.withAsync();

IgniteTx tx = ignite.transactions().txStart();

try {
assertNull(cache.get("key1"));
Expand All @@ -225,40 +237,44 @@ private void checkExplicitTx(GridCache<String, String> cache) throws Exception {
tx.close();
}

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

try {
assertNull(cache.getAsync("key2").get());
asyncCache.get("key2");

assertNull(asyncCache.future().get());

tx.commit();
}
finally {
tx.close();
}

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

try {
assertTrue(cache.getAll(F.asList("key3", "key4")).isEmpty());
assertTrue(cache.getAll(F.asSet("key3", "key4")).isEmpty());

tx.commit();
}
finally {
tx.close();
}

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

try {
assertTrue(cache.getAllAsync(F.asList("key5", "key6")).get().isEmpty());
asyncCache.getAll(F.asSet("key5", "key6"));

assertTrue(((Collection)asyncCache.future().get()).isEmpty());

tx.commit();
}
finally {
tx.close();
}

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

try {
cache.put("key7", "key7");
Expand All @@ -283,10 +299,10 @@ private void checkExplicitTx(GridCache<String, String> cache) throws Exception {
* @throws org.apache.ignite.internal.IgniteInterruptedCheckedException If interrupted while sleeping.
*/
@SuppressWarnings({"ErrorNotRethrown", "TypeMayBeWeakened"})
private void checkEmpty(GridCache<String, String> cache) throws IgniteInterruptedCheckedException {
private void checkEmpty(IgniteCache<String, String> cache) throws IgniteInterruptedCheckedException {
for (int i = 0; i < 3; i++) {
try {
assertTrue(cache.entrySet().toString(), cache.entrySet().isEmpty());
assertTrue(!cache.iterator().hasNext());

break;
}
Expand Down
Expand Up @@ -17,9 +17,11 @@

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

import org.apache.ignite.*;
import org.apache.ignite.cache.*;
import org.apache.ignite.cache.eviction.*;
import org.apache.ignite.configuration.*;
import org.apache.ignite.internal.*;
import org.apache.ignite.internal.util.typedef.*;
import org.apache.ignite.spi.discovery.tcp.*;
import org.apache.ignite.spi.discovery.tcp.ipfinder.*;
Expand Down Expand Up @@ -159,7 +161,7 @@ protected void check(Collection<Cache.Entry<String, String>> c1, MockEntry... c2
/** @return Policy. */
@SuppressWarnings({"unchecked"})
protected T policy() {
return (T)grid().cache(null).configuration().getEvictionPolicy();
return (T)internalCache().configuration().getEvictionPolicy();
}

/**
Expand All @@ -168,7 +170,7 @@ protected T policy() {
*/
@SuppressWarnings({"unchecked"})
protected T policy(int i) {
return (T)grid(i).cache(null).configuration().getEvictionPolicy();
return (T)internalCache(i).configuration().getEvictionPolicy();
}

/**
Expand All @@ -177,7 +179,7 @@ protected T policy(int i) {
*/
@SuppressWarnings({"unchecked"})
protected T nearPolicy(int i) {
return (T)grid(i).cache(null).configuration().getNearEvictionPolicy();
return (T)internalCache(i).configuration().getNearEvictionPolicy();
}

/**
Expand Down Expand Up @@ -296,7 +298,7 @@ private void checkPartitioned(int endSize, int endPlcSize, boolean near) throws
int cnt = 500;

for (int i = 0; i < cnt; i++) {
GridCache<Integer, String> cache = grid(rand.nextInt(2)).cache(null);
IgniteCache<Integer, String> cache = grid(rand.nextInt(2)).jcache(null);

int key = rand.nextInt(100);
String val = Integer.toString(key);
Expand Down Expand Up @@ -347,12 +349,14 @@ protected void checkPartitionedMultiThreaded(int gridCnt) throws Exception {
int cnt = 100;

for (int i = 0; i < cnt && !Thread.currentThread().isInterrupted(); i++) {
GridCache<Integer, String> cache = grid(rand.nextInt(2)).cache(null);
IgniteEx grid = grid(rand.nextInt(2));

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

int key = rand.nextInt(1000);
String val = Integer.toString(key);

try (IgniteTx tx = cache.txStart(PESSIMISTIC, REPEATABLE_READ)) {
try (IgniteTx tx = grid.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
String v = cache.get(key);

assert v == null || v.equals(Integer.toString(key)) : "Invalid value for key [key=" + key +
Expand Down
Expand Up @@ -132,12 +132,12 @@ private void checkEvictionFilter() throws Exception {
try {
Ignite g = grid(0);

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

int cnt = 1;

for (int i = 0; i < cnt; i++)
c.putx(i, i);
c.put(i, i);

Map<Object, AtomicInteger> cnts = filter.counts();

Expand Down Expand Up @@ -187,18 +187,18 @@ public void _testPartitionedMixed() throws Exception {

Ignite g = startGrid();

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

try {
int id = 1;

cache.putx(id++, 1);
cache.putx(id++, 2);
cache.put(id++, 1);
cache.put(id++, 2);

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

cache.putx(i, String.valueOf(i));
cache.put(i, String.valueOf(i));
}

info(">>>> " + cache.get(1));
Expand Down

0 comments on commit ae5198f

Please sign in to comment.