use of org.apache.ignite.Ignite 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.Ignite 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.Ignite in project ignite by apache.
the class IgniteClientReconnectCacheQueriesFailoverTest method testReconnectCacheQueries.
/**
* @throws Exception If failed.
*/
public void testReconnectCacheQueries() throws Exception {
final Ignite client = grid(serverCount());
final IgniteCache<Integer, Person> cache = client.cache(DEFAULT_CACHE_NAME);
assertNotNull(cache);
reconnectFailover(new Callable<Void>() {
@Override
public Void call() throws Exception {
SqlQuery<Integer, Person> sqlQry = new SqlQuery<>(Person.class, "where id > 1");
try {
assertEquals(9999, cache.query(sqlQry).getAll().size());
} catch (CacheException e) {
if (e.getCause() instanceof IgniteClientDisconnectedException)
throw e;
else
log.info("Ignore error: " + e);
}
try {
SqlFieldsQuery fieldsQry = new SqlFieldsQuery("select avg(p.id) from Person p");
List<List<?>> res = cache.query(fieldsQry).getAll();
assertEquals(1, res.size());
Integer avg = (Integer) res.get(0).get(0);
assertEquals(5_000, avg.intValue());
} catch (CacheException e) {
if (e.getCause() instanceof IgniteClientDisconnectedException)
throw e;
else
log.info("Ignore error: " + e);
}
return null;
}
});
}
use of org.apache.ignite.Ignite in project ignite by apache.
the class IgniteClientReconnectCacheQueriesFailoverTest method testReconnectScanQuery.
/**
* @throws Exception If failed.
*/
public void testReconnectScanQuery() throws Exception {
final Ignite client = grid(serverCount());
final IgniteCache<Integer, Person> cache = client.cache(DEFAULT_CACHE_NAME);
assertNotNull(cache);
final Affinity<Integer> aff = client.affinity(DEFAULT_CACHE_NAME);
final Map<Integer, Integer> partMap = new HashMap<>();
for (int i = 0; i < aff.partitions(); i++) partMap.put(i, 0);
for (int i = 0; i <= 10_000; i++) {
Integer part = aff.partition(i);
Integer size = partMap.get(part);
partMap.put(part, size + 1);
}
reconnectFailover(new Callable<Void>() {
@Override
public Void call() throws Exception {
ScanQuery<Integer, Person> qry = new ScanQuery<>(new IgniteBiPredicate<Integer, Person>() {
@Override
public boolean apply(Integer key, Person val) {
return val.getId() % 2 == 1;
}
});
assertEquals(5000, cache.query(qry).getAll().size());
ThreadLocalRandom rnd = ThreadLocalRandom.current();
Integer part = rnd.nextInt(0, aff.partitions());
qry = new ScanQuery<>(part);
assertEquals((int) partMap.get(part), cache.query(qry).getAll().size());
return null;
}
});
}
use of org.apache.ignite.Ignite in project ignite by apache.
the class IgniteClientReconnectQueriesTest method testReconnectQueryInProgress.
/**
* @throws Exception If failed.
*/
public void testReconnectQueryInProgress() throws Exception {
Ignite cln = grid(serverCount());
assertTrue(cln.cluster().localNode().isClient());
final Ignite srv = clientRouter(cln);
final IgniteCache<Integer, Person> clnCache = cln.getOrCreateCache(QUERY_CACHE);
clnCache.put(1, new Person(1, "name1", "surname1"));
clnCache.put(2, new Person(2, "name2", "surname2"));
clnCache.put(3, new Person(3, "name3", "surname3"));
blockMessage(GridQueryNextPageResponse.class);
final SqlQuery<Integer, Person> qry = new SqlQuery<>(Person.class, "_key <> 0");
qry.setPageSize(1);
final QueryCursor<Cache.Entry<Integer, Person>> cur1 = clnCache.query(qry);
final IgniteInternalFuture<Object> fut = GridTestUtils.runAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
try {
cur1.getAll();
} catch (CacheException e) {
checkAndWait(e);
return true;
}
return false;
}
});
// Check that client waiting operation.
GridTestUtils.assertThrows(log, new Callable<Object>() {
@Override
public Object call() throws Exception {
return fut.get(200);
}
}, IgniteFutureTimeoutCheckedException.class, null);
assertNotDone(fut);
unblockMessage();
reconnectClientNode(cln, srv, null);
assertTrue((Boolean) fut.get(2, SECONDS));
QueryCursor<Cache.Entry<Integer, Person>> cur2 = clnCache.query(qry);
assertEquals(3, cur2.getAll().size());
}
Aggregations