use of org.apache.ignite.internal.util.typedef.CAX in project ignite by apache.
the class IgniteCacheQueryMultiThreadedSelfTest method testMultiThreadedSqlFieldsQuery.
/**
* SqlFieldsQuery paging mechanics stress test
*
* @throws Exception If failed.
*/
@SuppressWarnings({ "TooBroadScope" })
@Test
public void testMultiThreadedSqlFieldsQuery() throws Throwable {
int threadCnt = 16;
// set resultSet size bigger than page size
final int keyCnt = 1100;
final int logMod = 5000;
final Ignite g = grid(0);
// Put test values into cache.
final IgniteCache<Integer, TestValue> c = cache(Integer.class, TestValue.class);
for (int i = 0; i < keyCnt; i++) c.put(i, new TestValue(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++;
List<List<?>> entries = c.query(new SqlFieldsQuery("SELECT * from TestValue").setPageSize(100)).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(DEFAULT_CACHE_NAME).context().queries();
assert qryMgr != null;
qryMgr.printMemoryStats();
}
}
}
}, threadCnt);
Thread.sleep(DURATION);
done.set(true);
fut.get();
}
use of org.apache.ignite.internal.util.typedef.CAX in project ignite by apache.
the class IgniteCacheQueryMultiThreadedSelfTest method testMultiThreadedSwapUnswapLongString.
/**
* JUnit.
*
* @throws Exception If failed.
*/
@SuppressWarnings({ "TooBroadScope" })
@Test
public void testMultiThreadedSwapUnswapLongString() 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, 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();
}
use of org.apache.ignite.internal.util.typedef.CAX in project ignite by apache.
the class IgniteCacheQueryMultiThreadedSelfTest method testMultiThreadedSwapUnswapObject.
/**
* @throws Exception If failed.
*/
@SuppressWarnings({ "TooBroadScope" })
@Test
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();
}
use of org.apache.ignite.internal.util.typedef.CAX in project ignite by apache.
the class IgniteCacheClientQueryReplicatedNodeRestartSelfTest method testRestarts.
/**
* @throws Exception If failed.
*/
@Test
public void testRestarts() throws Exception {
int duration = 90 * 1000;
int qryThreadNum = 5;
// 2 of 4 data nodes
int restartThreadsNum = 2;
final int nodeLifeTime = 2 * 1000;
final int logFreq = 10;
startGridsMultiThreaded(GRID_CNT);
// The last is client only.
final AtomicIntegerArray locks = new AtomicIntegerArray(GRID_CNT - 1);
fillCaches();
final List<List<?>> pRes = grid(0).cache("pu").query(new SqlFieldsQuery(QRY)).getAll();
Thread.sleep(3000);
assertEquals(pRes, grid(0).cache("pu").query(new SqlFieldsQuery(QRY)).getAll());
assertFalse(pRes.isEmpty());
final AtomicInteger qryCnt = new AtomicInteger();
final AtomicBoolean qrysDone = new AtomicBoolean();
final List<Integer> cacheSize = new ArrayList<>(4);
for (int i = 0; i < GRID_CNT - 1; i++) {
int j = 0;
for (String cacheName : F.asList("co", "pr", "pe", "pu")) {
IgniteCache<?, ?> cache = grid(i).cache(cacheName);
assertClient(cache, false);
if (i == 0)
cacheSize.add(cache.size());
else
assertEquals(cacheSize.get(j++).intValue(), cache.size());
}
}
int j = 0;
for (String cacheName : F.asList("co", "pr", "pe", "pu")) {
IgniteCache<?, ?> cache = grid(GRID_CNT - 1).cache(cacheName);
assertClient(cache, true);
assertEquals(cacheSize.get(j++).intValue(), cache.size());
}
final IgniteCache<?, ?> clientCache = grid(GRID_CNT - 1).cache("pu");
IgniteInternalFuture<?> fut1 = multithreadedAsync(new CAX() {
@Override
public void applyx() throws IgniteCheckedException {
GridRandom rnd = new GridRandom();
while (!qrysDone.get()) {
SqlFieldsQuery qry = new SqlFieldsQuery(QRY);
boolean smallPageSize = rnd.nextBoolean();
if (smallPageSize)
qry.setPageSize(3);
List<List<?>> res;
try {
res = clientCache.query(qry).getAll();
} catch (CacheException e) {
assertTrue("On large page size must retry.", smallPageSize);
boolean failedOnRemoteFetch = false;
for (Throwable th = e; th != null; th = th.getCause()) {
if (!(th instanceof CacheException))
continue;
if (th.getMessage() != null && th.getMessage().startsWith("Failed to fetch data from node:")) {
failedOnRemoteFetch = true;
break;
}
}
if (!failedOnRemoteFetch) {
e.printStackTrace();
fail("Must fail inside of GridResultPage.fetchNextPage or subclass.");
}
res = FAKE;
}
if (res != FAKE && !res.equals(pRes)) {
int j = 0;
// Check for data loss.
for (String cacheName : F.asList("co", "pr", "pe", "pu")) {
assertEquals(cacheName, cacheSize.get(j++).intValue(), grid(GRID_CNT - 1).cache(cacheName).size());
}
// Fail with nice message.
assertEquals(pRes, res);
}
int c = qryCnt.incrementAndGet();
if (c % logFreq == 0)
info("Executed queries: " + c);
}
}
}, qryThreadNum, "query-thread");
final AtomicInteger restartCnt = new AtomicInteger();
final AtomicBoolean restartsDone = new AtomicBoolean();
IgniteInternalFuture<?> fut2 = multithreadedAsync(new Callable<Object>() {
@SuppressWarnings({ "BusyWait" })
@Override
public Object call() throws Exception {
GridRandom rnd = new GridRandom();
while (!restartsDone.get()) {
int g;
do {
g = rnd.nextInt(locks.length());
} while (!locks.compareAndSet(g, 0, -1));
log.info("Stop node: " + g);
stopGrid(g);
Thread.sleep(rnd.nextInt(nodeLifeTime));
log.info("Start node: " + g);
startGrid(g);
Thread.sleep(rnd.nextInt(nodeLifeTime));
locks.set(g, 0);
int c = restartCnt.incrementAndGet();
if (c % logFreq == 0)
info("Node restarts: " + c);
}
return true;
}
}, restartThreadsNum, "restart-thread");
Thread.sleep(duration);
info("Stopping..");
restartsDone.set(true);
fut2.get();
info("Restarts stopped.");
qrysDone.set(true);
fut1.get();
info("Queries stopped.");
}
Aggregations