use of javax.cache.event.CacheEntryUpdatedListener in project ignite by apache.
the class TcpDiscoveryMultiThreadedTest method _testCustomEventOnJoinCoordinatorStop.
/**
* @throws Exception If failed.
*/
public void _testCustomEventOnJoinCoordinatorStop() throws Exception {
for (int k = 0; k < 10; k++) {
log.info("Iteration: " + k);
clientFlagGlobal = false;
final int START_NODES = 5;
final int JOIN_NODES = 5;
startGrids(START_NODES);
final AtomicInteger startIdx = new AtomicInteger(START_NODES);
final AtomicBoolean stop = new AtomicBoolean();
IgniteInternalFuture<?> fut1 = GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
Ignite ignite = ignite(START_NODES - 1);
while (!stop.get()) {
ignite.createCache(ccfg);
ignite.destroyCache(ccfg.getName());
}
return null;
}
});
try {
final CyclicBarrier barrier = new CyclicBarrier(JOIN_NODES + 1);
IgniteInternalFuture<?> fut2 = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
int idx = startIdx.getAndIncrement();
Thread.currentThread().setName("start-thread-" + idx);
barrier.await();
Ignite ignite = startGrid(idx);
assertFalse(ignite.configuration().isClientMode());
log.info("Started node: " + ignite.name());
IgniteCache<Object, Object> cache = ignite.getOrCreateCache(DEFAULT_CACHE_NAME);
ContinuousQuery<Object, Object> qry = new ContinuousQuery<>();
qry.setLocalListener(new CacheEntryUpdatedListener<Object, Object>() {
@Override
public void onUpdated(Iterable<CacheEntryEvent<?, ?>> evts) {
// No-op.
}
});
QueryCursor<Cache.Entry<Object, Object>> cur = cache.query(qry);
cur.close();
return null;
}
}, JOIN_NODES, "start-thread");
barrier.await();
U.sleep(ThreadLocalRandom.current().nextInt(10, 100));
for (int i = 0; i < START_NODES - 1; i++) {
GridTestUtils.invoke(ignite(i).configuration().getDiscoverySpi(), "simulateNodeFailure");
stopGrid(i);
}
stop.set(true);
fut1.get();
fut2.get();
} finally {
stop.set(true);
fut1.get();
}
stopAllGrids();
}
}
Aggregations