use of org.apache.ignite.cache.query.SqlQuery in project ignite by apache.
the class IgniteCacheQueryMultiThreadedSelfTest method testMultiThreadedSwapUnswapObject.
/**
* @throws Exception If failed.
*/
@SuppressWarnings({ "TooBroadScope" })
public void testMultiThreadedSwapUnswapObject() throws Exception {
int threadCnt = 50;
final int keyCnt = 4000;
final int valCnt = 10000;
final Ignite g = grid(0);
// Put test values into cache.
final IgniteCache<Integer, TestValue> c = cache(Integer.class, TestValue.class);
assertEquals(0, g.cache(DEFAULT_CACHE_NAME).localSize());
assertEquals(0, c.query(new SqlQuery(TestValue.class, "1 = 1")).getAll().size());
Random rnd = new Random();
for (int i = 0; i < keyCnt; i += 1 + rnd.nextInt(3)) {
c.put(i, new TestValue(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, new TestValue(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(TestValue.class, "TestValue.val between ? and ?").setArgs(from, from + 250)).getAll();
}
}
}
}, threadCnt);
Thread.sleep(DURATION);
done.set(true);
fut.get();
}
Aggregations