use of javax.cache.event.CacheEntryListenerException in project ignite by apache.
the class IgniteCacheContinuousQueryReconnectTest method testReconnect.
/**
* @throws Exception If failed.
*/
private void testReconnect(boolean clientQuery) throws Exception {
Ignite srv1 = startGrid(0);
ContinuousQuery<Object, Object> qry = new ContinuousQuery<>();
qry.setLocalListener(new CacheEntryUpdatedListener<Object, Object>() {
@Override
public void onUpdated(Iterable iterable) throws CacheEntryListenerException {
// No-op.
}
});
qry.setAutoUnsubscribe(false);
qry.setRemoteFilter(new CacheEntryEventSerializableFilter<Object, Object>() {
@Override
public boolean evaluate(CacheEntryEvent<?, ?> event) throws CacheEntryListenerException {
cnt.incrementAndGet();
return true;
}
});
Ignite client = startClientGrid(1);
IgniteCache<Object, Object> cache1 = srv1.cache(DEFAULT_CACHE_NAME);
IgniteCache<Object, Object> clCache = client.cache(DEFAULT_CACHE_NAME);
// 0 remote listeners.
putAndCheck(clCache, 0);
(clientQuery ? clCache : cache1).query(qry);
// 1 remote listener.
putAndCheck(clCache, 1);
startGrid(2);
// 2 remote listeners.
putAndCheck(clCache, 2);
stopGrid(0);
while (true) {
try {
clCache.get(1);
break;
} catch (IgniteClientDisconnectedException e) {
// Wait for reconnect.
e.reconnectFuture().get();
} catch (CacheException e) {
if (e.getCause() instanceof IgniteClientDisconnectedException)
// Wait for reconnect.
((IgniteClientDisconnectedException) e.getCause()).reconnectFuture().get();
}
}
// 1 remote listener.
putAndCheck(clCache, 1);
startGrid(3);
// 2 remote listeners.
putAndCheck(clCache, 2);
// Client node.
stopGrid(1);
client = startClientGrid(4);
clCache = client.cache(DEFAULT_CACHE_NAME);
// 2 remote listeners.
putAndCheck(clCache, 2);
startGrid(5);
// 3 remote listeners.
putAndCheck(clCache, 3);
}
use of javax.cache.event.CacheEntryListenerException in project ignite by apache.
the class ContinuousQueryMarshallerTest method check.
/**
* @param node1Name Node 1 name.
* @param node2Name Node 2 name.
*/
private void check(String node1Name, String node2Name) throws Exception {
final Ignite node1 = startGrid(node1Name);
final IgniteCache<Integer, MarshallerCheckingEntry> cache = node1.getOrCreateCache(CACHE_NAME);
for (int i = 0; i < 10; i++) cache.put(i, new MarshallerCheckingEntry(String.valueOf(i)));
final Ignite node2 = "client".equals(node2Name) ? startClientGrid(node2Name) : startGrid(node2Name);
final ContinuousQuery<Integer, MarshallerCheckingEntry> qry = new ContinuousQuery<>();
ScanQuery<Integer, MarshallerCheckingEntry> scanQry = new ScanQuery<>(new IgniteBiPredicate<Integer, MarshallerCheckingEntry>() {
@Override
public boolean apply(Integer key, MarshallerCheckingEntry val) {
return key % 2 == 0;
}
});
qry.setInitialQuery(scanQry);
qry.setRemoteFilterFactory(new DummyEventFilterFactory<>());
final CountDownLatch latch = new CountDownLatch(15);
qry.setLocalListener(new CacheEntryUpdatedListener<Integer, MarshallerCheckingEntry>() {
@Override
public void onUpdated(final Iterable<CacheEntryEvent<? extends Integer, ? extends MarshallerCheckingEntry>> evts) throws CacheEntryListenerException {
System.out.println(">> Client 1 events " + evts);
for (CacheEntryEvent<? extends Integer, ? extends MarshallerCheckingEntry> evt : evts) latch.countDown();
}
});
final IgniteCache<Integer, MarshallerCheckingEntry> cache1 = node2.cache(CACHE_NAME);
for (Cache.Entry<Integer, MarshallerCheckingEntry> entry : cache1.query(qry)) {
latch.countDown();
System.out.println(">> Initial entry " + entry);
}
for (int i = 10; i < 20; i++) cache1.put(i, new MarshallerCheckingEntry(i));
assertTrue(Long.toString(latch.getCount()), latch.await(5, TimeUnit.SECONDS));
}
Aggregations