use of org.apache.ignite.client.IgniteClient in project ignite by apache.
the class CacheEntryListenersTest method testJCacheListeners.
/**
* Test JCache entry listeners.
*/
@Test
public void testJCacheListeners() throws Exception {
try (IgniteClient client = startClient(0, 1, 2)) {
ClientCache<Integer, Integer> cache = client.getOrCreateCache("testJCacheListeners");
JCacheEntryListener<Integer, Integer> lsnr = new JCacheEntryListener<>();
cache.registerCacheEntryListener(new MutableCacheEntryListenerConfiguration<>(() -> lsnr, null, true, false));
for (int i = 0; i < 10; i++) cache.put(i, i);
assertEquals(F.asMap(EventType.CREATED, IntStream.range(0, 10).boxed().collect(Collectors.toMap(i -> i, i -> i))), aggregateListenerEvents(lsnr, 10));
for (int i = 0; i < 10; i++) cache.put(i, -i);
assertEquals(F.asMap(EventType.UPDATED, IntStream.range(0, 10).boxed().collect(Collectors.toMap(i -> i, i -> -i))), aggregateListenerEvents(lsnr, 10));
for (int i = 0; i < 10; i++) cache.remove(i);
assertEquals(F.asMap(EventType.REMOVED, IntStream.range(0, 10).boxed().collect(Collectors.toMap(i -> i, i -> -i))), aggregateListenerEvents(lsnr, 10));
assertTrue(lsnr.isQueueEmpty());
}
}
use of org.apache.ignite.client.IgniteClient in project ignite by apache.
the class CacheEntryListenersTest method testDisconnectListeners.
/**
* Test disconnect event for cache entry listeners.
*/
@Test
public void testDisconnectListeners() throws Exception {
try (IgniteClient client = startClient(0, 1, 2)) {
ClientCache<Object, Object> cache = client.getOrCreateCache("testDisconnect");
ContinuousQueryListener<Object, Object> lsnr1 = new ContinuousQueryListener<>();
cache.query(new ContinuousQuery<>().setLocalListener(lsnr1), lsnr1);
JCacheEntryListener<Object, Object> lsnr2 = new JCacheEntryListener<>();
CacheEntryListenerConfiguration<Object, Object> lsnrCfg = new MutableCacheEntryListenerConfiguration<>(() -> lsnr2, null, true, false);
cache.registerCacheEntryListener(lsnrCfg, lsnr2);
cache.put(0, 0);
lsnr1.assertNextCacheEvent(EventType.CREATED, 0, 0);
lsnr2.assertNextCacheEvent(EventType.CREATED, 0, 0);
dropAllThinClientConnections();
// Can't detect channel failure until we send something to server.
cache.put(1, 1);
assertTrue(lsnr1.isQueueEmpty());
assertTrue(lsnr2.isQueueEmpty());
assertTrue(waitForCondition(lsnr1::isDisconnected, TIMEOUT));
assertTrue(waitForCondition(lsnr2::isDisconnected, TIMEOUT));
// Should be able to register the same listener on the same cache again.
cache.registerCacheEntryListener(lsnrCfg);
}
}
use of org.apache.ignite.client.IgniteClient in project ignite by apache.
the class CacheEntryListenersTest method testContinuousQueries.
/**
* Test continuous queries.
*/
@Test
public void testContinuousQueries() throws Exception {
try (IgniteClient client = startClient(0, 1, 2)) {
ClientCache<Integer, Integer> cache = client.getOrCreateCache("testCQ");
ContinuousQueryListener<Integer, Integer> lsnr = new ContinuousQueryListener<>();
cache.query(new ContinuousQuery<Integer, Integer>().setLocalListener(lsnr));
for (int i = 0; i < 10; i++) cache.put(i, i);
assertEquals(F.asMap(EventType.CREATED, IntStream.range(0, 10).boxed().collect(Collectors.toMap(i -> i, i -> i))), aggregateListenerEvents(lsnr, 10));
for (int i = 0; i < 10; i++) cache.put(i, -i);
assertEquals(F.asMap(EventType.UPDATED, IntStream.range(0, 10).boxed().collect(Collectors.toMap(i -> i, i -> -i))), aggregateListenerEvents(lsnr, 10));
for (int i = 0; i < 10; i++) cache.remove(i);
assertEquals(F.asMap(EventType.REMOVED, IntStream.range(0, 10).boxed().collect(Collectors.toMap(i -> i, i -> -i))), aggregateListenerEvents(lsnr, 10));
assertTrue(lsnr.isQueueEmpty());
}
}
use of org.apache.ignite.client.IgniteClient in project ignite by apache.
the class CacheEntryListenersTest method testListenersUnsupportedParameters.
/**
*/
@Test
@SuppressWarnings({ "ThrowableNotThrown", "deprecation" })
public void testListenersUnsupportedParameters() throws Exception {
try (IgniteClient client = startClient(0, 1, 2)) {
ClientCache<Integer, Integer> cache = client.getOrCreateCache("testUnsupportedParams");
// Check null listener factory.
CacheEntryListenerConfiguration<Integer, Integer> lsnrCfg1 = new MutableCacheEntryListenerConfiguration<>(null, null, true, false);
assertThrowsWithCause(() -> cache.registerCacheEntryListener(lsnrCfg1), NullPointerException.class);
// Check synchronous flag.
CacheEntryListenerConfiguration<Integer, Integer> lsnrCfg2 = new MutableCacheEntryListenerConfiguration<>(JCacheEntryListener::new, null, true, true);
assertThrowsWithCause(() -> cache.registerCacheEntryListener(lsnrCfg2), IllegalArgumentException.class);
// Check local flag.
ContinuousQueryListener<Integer, Integer> cqLsnr = new ContinuousQueryListener<>();
ContinuousQuery<Integer, Integer> qry1 = new ContinuousQuery<Integer, Integer>().setLocalListener(cqLsnr).setLocal(true);
assertThrowsWithCause(() -> cache.query(qry1), IllegalArgumentException.class);
// Check null listener.
ContinuousQuery<Integer, Integer> qry2 = new ContinuousQuery<>();
assertThrowsWithCause(() -> cache.query(qry2), NullPointerException.class);
// Check auto unsubscribe flag.
ContinuousQuery<Integer, Integer> qry3 = new ContinuousQuery<Integer, Integer>().setLocalListener(cqLsnr).setAutoUnsubscribe(false);
assertThrowsWithCause(() -> cache.query(qry3), IllegalArgumentException.class);
// Check continuous query as initial query.
ContinuousQuery<Integer, Integer> qry4 = new ContinuousQuery<Integer, Integer>().setLocalListener(cqLsnr).setInitialQuery(new ContinuousQuery<>());
assertThrowsWithCause(() -> cache.query(qry4), IllegalArgumentException.class);
// Check filter factory and filter defined at the same time.
CacheEntryEventSerializableFilter<Integer, Integer> rmtFilter = r -> true;
ContinuousQuery<Integer, Integer> qry5 = new ContinuousQuery<Integer, Integer>().setLocalListener(cqLsnr).setRemoteFilter(rmtFilter);
qry5.setRemoteFilterFactory(FactoryBuilder.factoryOf(rmtFilter));
assertThrowsWithCause(() -> cache.query(qry5), IllegalArgumentException.class);
}
}
use of org.apache.ignite.client.IgniteClient in project ignite by apache.
the class ServicesTest method testServiceTimeout.
/**
* Test services timeout.
*/
@Test
public void testServiceTimeout() throws Exception {
long timeout = 100L;
try (IgniteClient client = startClient(0)) {
TestServiceInterface svc = client.services().serviceProxy(CLUSTER_SINGLTON_SERVICE_NAME, TestServiceInterface.class, timeout);
TestService.latch = new CountDownLatch(1);
GridTestUtils.assertThrowsAnyCause(log, svc::waitLatch, ClientException.class, "timed out");
} finally {
if (TestService.latch != null) {
TestService.latch.countDown();
TestService.latch = null;
}
}
}
Aggregations