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 80f7901 commit 1d7267a
Show file tree
Hide file tree
Showing 21 changed files with 123 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,15 @@ protected GridCacheAbstractLoadTest() {
* @param writeClos Write closure.
* @param readClos ReadClosure.
*/
protected void loadTest(final CIX1<CacheProjection<Integer, Integer>> writeClos,
final CIX1<CacheProjection<Integer, Integer>> readClos) {
protected void loadTest(final CIX1<IgniteCache<Integer, Integer>> writeClos,
final CIX1<IgniteCache<Integer, Integer>> readClos) {
info("Read threads: " + readThreads());
info("Write threads: " + writeThreads());
info("Test duration (ms): " + testDuration);

Ignite ignite = G.ignite();
final Ignite ignite = G.ignite();

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

assert cache != null;

Expand All @@ -142,7 +142,7 @@ protected void loadTest(final CIX1<CacheProjection<Integer, Integer>> writeClos,

while (!done.get()) {
if (tx) {
try (IgniteTx tx = cache.txStart()) {
try (IgniteTx tx = ignite.transactions().txStart()) {
writeClos.apply(cache);

tx.commit();
Expand All @@ -164,7 +164,7 @@ protected void loadTest(final CIX1<CacheProjection<Integer, Integer>> writeClos,

while(!done.get()) {
if (tx) {
try (IgniteTx tx = cache.txStart()) {
try (IgniteTx tx = ignite.transactions().txStart()) {
readClos.apply(cache);

tx.commit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,22 @@ public static void main(String[] args) throws Exception {
startNodes();

for (int i = 0; i < KEY_CNT; i++) {
GridCache<Object, Integer> c = cache(i);
IgniteCache<Object, Integer> c = cache(i);

c.putx((long)i, 0);
c.putx(new UserKey(i, 0), 0);
c.putx(new UserKey(i, 1), 0);
c.putx(new UserKey(i, 2), 0);
c.put((long) i, 0);
c.put(new UserKey(i, 0), 0);
c.put(new UserKey(i, 1), 0);
c.put(new UserKey(i, 2), 0);
}

assert cache(5).get(5L) != null;

long key = 5;

GridCache<Object, Integer> c = cache(key);
IgniteCache<Object, Integer> c = cache(key);
Ignite ignite = ignite(key);

try (IgniteTx tx = c.txStartAffinity(key, PESSIMISTIC, REPEATABLE_READ, 0, 0)) {
try (IgniteTx tx = ignite.transactions().txStartAffinity(c.getName(), key, PESSIMISTIC, REPEATABLE_READ, 0, 0)) {
Integer val = c.get(key);
Integer userVal1 = c.get(new UserKey(key, 0));
Integer userVal2 = c.get(new UserKey(key, 1));
Expand All @@ -90,10 +91,10 @@ public static void main(String[] args) throws Exception {

int newVal = val + 1;

c.putx(key, newVal);
c.putx(new UserKey(key, 0), newVal);
c.putx(new UserKey(key, 1), newVal);
c.putx(new UserKey(key, 2), newVal);
c.put(key, newVal);
c.put(new UserKey(key, 0), newVal);
c.put(new UserKey(key, 1), newVal);
c.put(new UserKey(key, 2), newVal);

tx.commit();
}
Expand Down Expand Up @@ -153,10 +154,21 @@ public static void main(String[] args) throws Exception {
* @param key Key.
* @return Cache.
*/
private static GridCache<Object, Integer> cache(long key) {
UUID id = Ignition.ignite("grid-0").cache(null).affinity().mapKeyToNode(key).id();
private static IgniteCache<Object, Integer> cache(long key) {
UUID id = Ignition.ignite("grid-0").affinity(null).mapKeyToNode(key).id();

return Ignition.ignite(id).cache(null);
return Ignition.ignite(id).jcache(null);
}


/**
* @param key Key.
* @return Cache.
*/
private static Ignite ignite(long key) {
UUID id = Ignition.ignite("grid-0").affinity(null).mapKeyToNode(key).id();

return Ignition.ignite(id);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static void main(String[] args) throws Exception {
X.println("threadCnt=" + THREADS);
X.println("testWrite=" + testWrite);

final GridCache<Long, Long> cache = g.cache(CACHE);
final IgniteCache<Long, Long> cache = g.jcache(CACHE);

assert cache != null;

Expand All @@ -86,7 +86,7 @@ public static void main(String[] args) throws Exception {
@Nullable @Override public Object call() throws Exception {
long keyVal = cntr.incrementAndGet();

cache.putx(keyVal % 100000, keyVal);
cache.put(keyVal % 100000, keyVal);

long ops = opCnt.incrementAndGet();

Expand Down Expand Up @@ -136,7 +136,7 @@ public static void main(String[] args) throws Exception {
if (keyVal >= PUT_CNT)
break;

cache.putx(keyVal % 100000, keyVal);
cache.put(keyVal % 100000, keyVal);

long ops = opCnt.incrementAndGet();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ protected void loadTestIgnite(final CIX1<Ignite> writeClos, final CIX1<Ignite> r

final Ignite ignite = G.ignite();

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

assert cache != null;

Expand All @@ -390,7 +390,7 @@ protected void loadTestIgnite(final CIX1<Ignite> writeClos, final CIX1<Ignite> r

while (!done.get()) {
if (tx) {
try (IgniteTx tx = cache.txStart()) {
try (IgniteTx tx = ignite.transactions().txStart()) {
writeClos.apply(ignite);

tx.commit();
Expand All @@ -412,7 +412,7 @@ protected void loadTestIgnite(final CIX1<Ignite> writeClos, final CIX1<Ignite> r

while(!done.get()) {
if (tx) {
try (IgniteTx tx = cache.txStart()) {
try (IgniteTx tx = ignite.transactions().txStart()) {
readClos.apply(ignite);

tx.commit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private static void ignitePutAll(Ignite ignite, final long max, int threads) thr
X.println(">>> Testing putAll");
X.println(">>>");

final GridCache<CacheAffinityKey<Long>, Long> cache = ignite.cache(CACHE);
final IgniteCache<CacheAffinityKey<Long>, Long> cache = ignite.jcache(CACHE);

assert cache != null;

Expand Down Expand Up @@ -133,12 +133,12 @@ private static void ignitePutAll(Ignite ignite, final long max, int threads) thr
* @param threads Threads.
* @throws Exception If failed.
*/
private static void igniteGroupLock(Ignite ignite, final long max, int threads) throws Exception {
private static void igniteGroupLock(final Ignite ignite, final long max, int threads) throws Exception {
X.println(">>>");
X.println(">>> Testing group lock");
X.println(">>>");

final GridCache<CacheAffinityKey<Long>, Long> cache = ignite.cache(CACHE);
final IgniteCache<CacheAffinityKey<Long>, Long> cache = ignite.jcache(CACHE);

assert cache != null;

Expand Down Expand Up @@ -172,7 +172,8 @@ private static void igniteGroupLock(Ignite ignite, final long max, int threads)

// Threads should not lock the same key.

try (IgniteTx tx = cache.txStartAffinity(affKey, PESSIMISTIC, REPEATABLE_READ, 0, BATCH_SIZE)) {
try (IgniteTx tx = ignite.transactions().txStartAffinity(cache.getName(), affKey, PESSIMISTIC,
REPEATABLE_READ, 0, BATCH_SIZE)) {
for (long i = 0; i < BATCH_SIZE; i++) {
cache.put(new CacheAffinityKey<>((key % rangeCnt) + base, affKey), i);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ private GridCacheLoadTest() {
}

/** Write closure. */
private final CIX1<CacheProjection<Integer, Integer>> writeClos =
new CIX1<CacheProjection<Integer, Integer>>() {
@Override public void applyx(CacheProjection<Integer, Integer> cache)
private final CIX1<IgniteCache<Integer, Integer>> writeClos =
new CIX1<IgniteCache<Integer, Integer>>() {
@Override public void applyx(IgniteCache<Integer, Integer> cache)
throws IgniteCheckedException {
for (int i = 0; i < operationsPerTx; i++) {
int kv = RAND.nextInt(KEY_RANGE);

assert cache.putx(kv, kv);
cache.put(kv, kv);

long cnt = writes.incrementAndGet();

Expand All @@ -63,9 +63,9 @@ private GridCacheLoadTest() {
};

/** Read closure. */
private final CIX1<CacheProjection<Integer, Integer>> readClos =
new CIX1<CacheProjection<Integer, Integer>>() {
@Override public void applyx(CacheProjection<Integer, Integer> cache)
private final CIX1<IgniteCache<Integer, Integer>> readClos =
new CIX1<IgniteCache<Integer, Integer>>() {
@Override public void applyx(IgniteCache<Integer, Integer> cache)
throws IgniteCheckedException {
for (int i = 0; i < operationsPerTx; i++) {
int k = RAND.nextInt(KEY_RANGE);
Expand Down Expand Up @@ -102,7 +102,7 @@ private byte[] newArray() {
private void memoryTest() {
Ignite ignite = G.ignite();

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

assert cache != null;

Expand All @@ -114,16 +114,18 @@ private void memoryTest() {
while (true) {
int idx;

cache.putx(idx = cnt.getAndIncrement(), newArray());
cache.put(idx = cnt.getAndIncrement(), newArray());

if (idx % 1000 == 0)
info("Stored '" + idx + "' objects in cache [cache-size=" + cache.keySet().size() + ']');
info("Stored '" + idx + "' objects in cache [cache-size=" + cache.size(CachePeekMode.ALL)
+ ']');
}
}
}, threads, "memory-test-worker");
}
catch (OutOfMemoryError ignore) {
info("Populated '" + cnt.get() + "' 1K objects into cache [cache-size=" + cache.keySet().size() + ']');
info("Populated '" + cnt.get() + "' 1K objects into cache [cache-size=" + cache.size(CachePeekMode.ALL)
+ ']');
}
catch (Exception e) {
e.printStackTrace();
Expand All @@ -150,7 +152,7 @@ public static void main(String[] args) throws Exception {
if (LOAD)
test.loadTest(test.writeClos, test.readClos);

G.ignite().cache(null).clear();
G.ignite().jcache(null).clear();

System.gc();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class GridCachePutRemoveLoadTest {
private final Arguments args;

/** */
private GridCache<Object, Object> cache;
private IgniteCache<Object, Object> cache;

/**
* @param args Arguments.
Expand Down Expand Up @@ -134,7 +134,7 @@ protected void startNodes() throws Exception {

assert g != null;

cache = g.cache("cache");
cache = g.jcache("cache");

assert cache != null;
}
Expand Down Expand Up @@ -188,7 +188,7 @@ private void runTest() throws Exception {
for (long i = 0; i < Long.MAX_VALUE; i++) {
Long key = queue.take();

cache.removex(key);
cache.remove(key);

rmvNum.set(key);
}
Expand All @@ -203,7 +203,7 @@ private void runTest() throws Exception {
}

for (long i = 0; i < Long.MAX_VALUE; i++) {
cache.putx(i, i);
cache.put(i, i);

putNum.set(i);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package org.apache.ignite.loadtests.cache;

import org.apache.ignite.cache.*;
import org.apache.ignite.*;
import org.apache.ignite.cache.eviction.lru.*;
import org.apache.ignite.configuration.*;
import org.apache.ignite.internal.util.typedef.*;
Expand Down Expand Up @@ -77,14 +77,14 @@ private static void runTest(final int putCnt, int userThreads) throws Exception

GridTestUtils.runMultiThreaded(new Callable<Object>() {
@Nullable @Override public Object call() throws Exception {
GridCache<Integer, Student> cache = G.ignite().cache(null);
IgniteCache<Integer, Student> cache = G.ignite().jcache(null);

assert cache != null;

long startTime = System.currentTimeMillis();

for (int i = 0; i < putCnt; i++) {
cache.putx(keyGen.incrementAndGet(), new Student());
cache.put(keyGen.incrementAndGet(), new Student());

int cnt = txCntr.incrementAndGet();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ private static IgniteInternalFuture<?> doPut(final Ignite g) {

return GridTestUtils.runMultiThreadedAsync(new CAX() {
@Override public void applyx() throws IgniteCheckedException {
GridCache<Integer, Integer> cache = g.cache(null);
IgniteCache<Integer, Integer> cache = g.jcache(null);

assert cache != null;

Expand All @@ -216,7 +216,7 @@ private static IgniteInternalFuture<?> doPut(final Ignite g) {
if (i > keyCnt)
break;

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

X.println(">>> Thread '" + Thread.currentThread().getName() + "' stopped.");
Expand All @@ -235,7 +235,7 @@ private static Collection<IgniteInternalFuture<Long>> doGetRemove(final Ignite g
@Nullable @Override public Object call() throws Exception {
getRemoveStartedLatch.await();

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

assert cache != null;

Expand Down Expand Up @@ -269,14 +269,14 @@ private static Collection<IgniteInternalFuture<Long>> doGetRemove(final Ignite g
@Nullable @Override public Object call() throws Exception {
getRemoveStartedLatch.await();

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

assert cache != null;

while (true) {
Integer i = swappedKeys.take();

Integer val = cache.remove(i);
Integer val = cache.getAndRemove(i);

assert val != null && val.equals(i);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static void main(String[] args) throws Exception {
IgniteConfiguration cfg = (IgniteConfiguration)ctx.getBean("grid.cfg");

try (Ignite g = G.start(cfg)) {
GridCache<Integer, Integer> c = g.cache(null);
IgniteCache<Integer, Integer> c = g.jcache(null);

long init = mem.getHeapMemoryUsage().getUsed();

Expand Down

0 comments on commit 1d7267a

Please sign in to comment.