use of org.apache.ignite.client.IgniteClient in project ignite by apache.
the class ComputeTaskTest method testExecuteTaskAsync2WithExceptionInTask.
/**
* Tests asynchronous task execution with an exception.
*/
@Test
public void testExecuteTaskAsync2WithExceptionInTask() throws Exception {
try (IgniteClient client = startClient(0)) {
IgniteClientFuture<Object> fut = client.compute().executeAsync2(TestExceptionalTask.class.getName(), null);
String errMessage = fut.handle((f, t) -> t.getMessage()).toCompletableFuture().get(2, TimeUnit.SECONDS);
assertTrue(errMessage.contains("cause=Foo"));
}
}
use of org.apache.ignite.client.IgniteClient in project ignite by apache.
the class CacheEntryListenersTest method testListenersClose.
/**
*/
@Test
public void testListenersClose() throws Exception {
try (IgniteClient client = startClient(0, 1, 2)) {
ClientCache<Integer, Integer> cache = client.getOrCreateCache("testListenersClose");
ContinuousQueryListener<Integer, Integer> lsnr1 = new ContinuousQueryListener<>();
QueryCursor<?> qry = cache.query(new ContinuousQuery<Integer, Integer>().setLocalListener(lsnr1));
JCacheEntryListener<Integer, Integer> lsnr2 = new JCacheEntryListener<>();
CacheEntryListenerConfiguration<Integer, Integer> lsnrCfg = new MutableCacheEntryListenerConfiguration<>(() -> lsnr2, null, true, false);
cache.registerCacheEntryListener(lsnrCfg);
cache.put(0, 0);
lsnr1.assertNextCacheEvent(EventType.CREATED, 0, 0);
lsnr2.assertNextCacheEvent(EventType.CREATED, 0, 0);
qry.close();
cache.deregisterCacheEntryListener(lsnrCfg);
for (int i = 0; i < 100; i++) cache.put(i, i);
assertTrue(lsnr1.isQueueEmpty());
assertTrue(lsnr2.isQueueEmpty());
}
}
use of org.apache.ignite.client.IgniteClient in project ignite by apache.
the class CacheEntryListenersTest method testContinuousQueriesWithTimeInterval.
/**
* Test continuous queries with time interval parameter.
*/
@Test
public void testContinuousQueriesWithTimeInterval() throws Exception {
try (IgniteClient client = startClient(1, 2)) {
ClientCache<Integer, Integer> cache = client.getOrCreateCache("testCQWithTimeInterval");
IgniteCache<Integer, Integer> nodeCache = grid(0).getOrCreateCache(cache.getName());
ContinuousQueryListener<Integer, Integer> lsnr = new ContinuousQueryListener<>();
ContinuousQuery<Integer, Integer> qry = new ContinuousQuery<Integer, Integer>().setLocalListener(lsnr).setPageSize(10).setTimeInterval(TIMEOUT);
long ts1 = U.currentTimeMillis();
cache.query(qry);
// Put data to the remote node.
int key = primaryKey(nodeCache);
cache.put(key, key);
assertNotNull(lsnr.poll(TIMEOUT * 2));
assertTrue(lsnr.isQueueEmpty());
long ts2 = U.currentTimeMillis();
// Ensure that item was received after timeout.
assertTrue("ts2 - ts1 = " + (ts2 - ts1), ts2 - ts1 >= TIMEOUT);
}
}
use of org.apache.ignite.client.IgniteClient in project ignite by apache.
the class CacheEntryListenersTest method testContinuousQueriesWithInitialQuery.
/**
* Test continuous queries with initial query.
*/
@Test
public void testContinuousQueriesWithInitialQuery() throws Exception {
try (IgniteClient client = startClient(0, 1, 2)) {
ClientCache<Integer, Integer> cache = client.getOrCreateCache("testCQWithInitQ");
for (int i = 0; i < 100; i++) cache.put(i, i);
ContinuousQueryListener<Integer, Integer> lsnr = new ContinuousQueryListener<>();
QueryCursor<Cache.Entry<Integer, Integer>> cur = cache.query(new ContinuousQuery<Integer, Integer>().setInitialQuery(new ScanQuery<>()).setLocalListener(lsnr));
assertTrue(lsnr.isQueueEmpty());
assertEquals(100, cur.getAll().size());
cache.put(100, 100);
lsnr.assertNextCacheEvent(EventType.CREATED, 100, 100);
cache.put(100, 101);
lsnr.assertNextCacheEvent(EventType.UPDATED, 100, 101);
cache.remove(100);
lsnr.assertNextCacheEvent(EventType.REMOVED, 100);
}
}
use of org.apache.ignite.client.IgniteClient in project ignite by apache.
the class CacheEntryListenersTest method testContinuousQueriesWithPageSize.
/**
* Test continuous queries with page size parameter.
*/
@Test
public void testContinuousQueriesWithPageSize() throws Exception {
try (IgniteClient client = startClient(1, 2)) {
ClientCache<Integer, Integer> cache = client.getOrCreateCache("testCQWithPageSize");
IgniteCache<Integer, Integer> nodeCache = grid(0).getOrCreateCache(cache.getName());
ContinuousQueryListener<Integer, Integer> lsnr = new ContinuousQueryListener<>();
ContinuousQuery<Integer, Integer> qry = new ContinuousQuery<Integer, Integer>().setLocalListener(lsnr).setPageSize(10);
cache.query(qry);
// Each node has its own buffer, put data to the exactly one remote node.
primaryKeys(nodeCache, 15).forEach(key -> cache.put(key, key));
// Check that only first page is received.
aggregateListenerEvents(lsnr, 10);
assertTrue(lsnr.isQueueEmpty());
primaryKeys(nodeCache, 6).forEach(key -> cache.put(key, key));
// Check that only second page is received.
aggregateListenerEvents(lsnr, 10);
assertTrue(lsnr.isQueueEmpty());
}
}
Aggregations