use of org.apache.ignite.cache.query.SqlQuery in project ignite by apache.
the class IgniteCacheQueryMultiThreadedSelfTest method testMultiThreadedSwapUnswapLong.
/**
* JUnit.
*
* @throws Exception If failed.
*/
@SuppressWarnings({ "TooBroadScope" })
public void testMultiThreadedSwapUnswapLong() throws Exception {
int threadCnt = 50;
final int keyCnt = 2000;
final int valCnt = 10000;
final Ignite g = grid(0);
// Put test values into cache.
final IgniteCache<Integer, Long> c = cache(Integer.class, Long.class);
assertEquals(0, g.cache(DEFAULT_CACHE_NAME).localSize());
assertEquals(0, c.query(new SqlQuery(Long.class, "1 = 1")).getAll().size());
Random rnd = new Random();
for (int i = 0; i < keyCnt; i += 1 + rnd.nextInt(3)) {
c.put(i, (long) rnd.nextInt(valCnt));
if (evictsEnabled() && rnd.nextBoolean())
c.localEvict(Arrays.asList(i));
}
final AtomicBoolean done = new AtomicBoolean();
IgniteInternalFuture<?> fut = multithreadedAsync(new CAX() {
@Override
public void applyx() throws IgniteCheckedException {
Random rnd = new Random();
while (!done.get()) {
int key = rnd.nextInt(keyCnt);
switch(rnd.nextInt(5)) {
case 0:
c.put(key, (long) rnd.nextInt(valCnt));
break;
case 1:
if (evictsEnabled())
c.localEvict(Arrays.asList(key));
break;
case 2:
c.remove(key);
break;
case 3:
c.get(key);
break;
case 4:
int from = rnd.nextInt(valCnt);
c.query(new SqlQuery(Long.class, "_val between ? and ?").setArgs(from, from + 250)).getAll();
}
}
}
}, threadCnt);
Thread.sleep(DURATION);
done.set(true);
fut.get();
}
use of org.apache.ignite.cache.query.SqlQuery in project ignite by apache.
the class IgniteCacheQueryMultiThreadedSelfTest method testMultiThreadedSwapUnswapString.
/**
* JUnit.
*
* @throws Exception If failed.
*/
@SuppressWarnings({ "TooBroadScope" })
public void testMultiThreadedSwapUnswapString() throws Exception {
int threadCnt = 50;
final int keyCnt = 2000;
final int valCnt = 10000;
final Ignite g = grid(0);
// Put test values into cache.
final IgniteCache<Integer, String> c = cache(Integer.class, String.class);
assertEquals(0, g.cache(DEFAULT_CACHE_NAME).localSize());
assertEquals(0, c.query(new SqlQuery(String.class, "1 = 1")).getAll().size());
Random rnd = new Random();
for (int i = 0; i < keyCnt; i += 1 + rnd.nextInt(3)) {
c.put(i, String.valueOf(rnd.nextInt(valCnt)));
if (evictsEnabled() && rnd.nextBoolean())
c.localEvict(Arrays.asList(i));
}
final AtomicBoolean done = new AtomicBoolean();
IgniteInternalFuture<?> fut = multithreadedAsync(new CAX() {
@Override
public void applyx() throws IgniteCheckedException {
Random rnd = new Random();
while (!done.get()) {
switch(rnd.nextInt(5)) {
case 0:
c.put(rnd.nextInt(keyCnt), String.valueOf(rnd.nextInt(valCnt)));
break;
case 1:
if (evictsEnabled())
c.localEvict(Arrays.asList(rnd.nextInt(keyCnt)));
break;
case 2:
c.remove(rnd.nextInt(keyCnt));
break;
case 3:
c.get(rnd.nextInt(keyCnt));
break;
case 4:
int from = rnd.nextInt(valCnt);
c.query(new SqlQuery(String.class, "_val between ? and ?").setArgs(String.valueOf(from), String.valueOf(from + 250))).getAll();
}
}
}
}, threadCnt);
Thread.sleep(DURATION);
done.set(true);
fut.get();
}
use of org.apache.ignite.cache.query.SqlQuery in project ignite by apache.
the class IgniteCacheQueryMultiThreadedSelfTest method testMultiThreadedSameQuery.
/**
* JUnit.
*
* @throws Exception If failed.
*/
@SuppressWarnings({ "TooBroadScope" })
public void testMultiThreadedSameQuery() throws Exception {
int threadCnt = 50;
final int keyCnt = 10;
final int logMod = 5000;
final Ignite g = grid(0);
// Put test values into cache.
final IgniteCache<Integer, Integer> c = cache(Integer.class, Integer.class);
for (int i = 0; i < keyCnt; i++) {
c.put(i, i);
c.localEvict(Arrays.asList(i));
}
final AtomicInteger cnt = new AtomicInteger();
final AtomicBoolean done = new AtomicBoolean();
IgniteInternalFuture<?> fut = multithreadedAsync(new CAX() {
@Override
public void applyx() throws IgniteCheckedException {
int iter = 0;
while (!done.get() && !Thread.currentThread().isInterrupted()) {
iter++;
Collection<Cache.Entry<Integer, Integer>> entries = c.query(new SqlQuery(Integer.class, "_val >= 0")).getAll();
assert entries != null;
assertEquals("Query results [entries=" + entries + ", aff=" + affinityNodes(entries, g) + ", iteration=" + iter + ']', keyCnt, entries.size());
if (cnt.incrementAndGet() % logMod == 0) {
GridCacheQueryManager<Object, Object> qryMgr = ((IgniteKernal) g).internalCache(c.getName()).context().queries();
assert qryMgr != null;
qryMgr.printMemoryStats();
}
}
}
}, threadCnt);
Thread.sleep(DURATION);
info("Finishing test...");
done.set(true);
fut.get();
}
use of org.apache.ignite.cache.query.SqlQuery in project ignite by apache.
the class IgniteCacheQueryMultiThreadedSelfTest method testMultiThreadedNewQueries.
/**
* JUnit.
*
* @throws Exception If failed.
*/
@SuppressWarnings({ "TooBroadScope" })
public void testMultiThreadedNewQueries() throws Exception {
int threadCnt = 50;
final int keyCnt = 10;
final int logMod = 5000;
final Ignite g = grid(0);
// Put test values into cache.
final IgniteCache<Integer, Integer> c = cache(Integer.class, Integer.class);
for (int i = 0; i < keyCnt; i++) {
c.put(i, i);
c.localEvict(Arrays.asList(i));
}
final AtomicInteger cnt = new AtomicInteger();
final AtomicBoolean done = new AtomicBoolean();
IgniteInternalFuture<?> fut = multithreadedAsync(new CAX() {
@Override
public void applyx() throws IgniteCheckedException {
int iter = 0;
while (!done.get() && !Thread.currentThread().isInterrupted()) {
iter++;
Collection<Cache.Entry<Integer, Integer>> entries = c.query(new SqlQuery(Integer.class, "_val >= 0")).getAll();
assert entries != null;
assertEquals("Entries count is not as expected on iteration: " + iter, keyCnt, entries.size());
if (cnt.incrementAndGet() % logMod == 0) {
GridCacheQueryManager<Object, Object> qryMgr = ((IgniteKernal) g).internalCache(c.getName()).context().queries();
assert qryMgr != null;
qryMgr.printMemoryStats();
}
}
}
}, threadCnt);
Thread.sleep(DURATION);
done.set(true);
fut.get();
}
use of org.apache.ignite.cache.query.SqlQuery in project ignite by apache.
the class IgniteCacheQueryMultiThreadedSelfTest method _testMultiThreadedSwapUnswapLongString.
/**
* JUnit.
*
* @throws Exception If failed.
*/
@SuppressWarnings({ "TooBroadScope" })
public void _testMultiThreadedSwapUnswapLongString() throws Exception {
fail("http://atlassian.gridgain.com/jira/browse/GG-11216");
int threadCnt = 50;
final int keyCnt = 2000;
final int valCnt = 10000;
final Ignite g = grid(0);
// Put test values into cache.
final IgniteCache<Integer, Object> c = cache(Integer.class, Object.class);
assertEquals(0, g.cache(DEFAULT_CACHE_NAME).size());
assertEquals(0, c.query(new SqlQuery(Object.class, "1 = 1")).getAll().size());
Random rnd = new Random();
for (int i = 0; i < keyCnt; i += 1 + rnd.nextInt(3)) {
c.put(i, rnd.nextBoolean() ? (long) rnd.nextInt(valCnt) : String.valueOf(rnd.nextInt(valCnt)));
if (evictsEnabled() && rnd.nextBoolean())
c.localEvict(Arrays.asList(i));
}
final AtomicBoolean done = new AtomicBoolean();
IgniteInternalFuture<?> fut = multithreadedAsync(new CAX() {
@Override
public void applyx() throws IgniteCheckedException {
Random rnd = new Random();
while (!done.get()) {
int key = rnd.nextInt(keyCnt);
switch(rnd.nextInt(5)) {
case 0:
c.put(key, rnd.nextBoolean() ? (long) rnd.nextInt(valCnt) : String.valueOf(rnd.nextInt(valCnt)));
break;
case 1:
if (evictsEnabled())
c.localEvict(Arrays.asList(key));
break;
case 2:
c.remove(key);
break;
case 3:
c.get(key);
break;
case 4:
int from = rnd.nextInt(valCnt);
c.query(new SqlQuery(Object.class, "_val between ? and ?").setArgs(from, from + 250)).getAll();
}
}
}
}, threadCnt);
Thread.sleep(DURATION);
done.set(true);
fut.get();
}
Aggregations