use of javax.cache.event.CacheEntryEvent in project ignite by apache.
the class GridCacheContinuousQueryNodesFilteringTest method startNodeWithCache.
/**
* Start first, attribute-bearing, node, create new cache and launch continuous query on it.
*
* @return Node.
* @throws Exception if failed.
*/
private Ignite startNodeWithCache() throws Exception {
Ignite node1 = startGrid("node1", getConfiguration("node1", true, null));
CacheConfiguration<Integer, Integer> ccfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME);
ccfg.setName("attrsTestCache");
ccfg.setNodeFilter(new IgnitePredicate<ClusterNode>() {
/**
* {@inheritDoc}
*/
@Override
public boolean apply(ClusterNode node) {
return "data".equals(node.attribute("node-type"));
}
});
IgniteCache<Integer, Integer> cache = node1.createCache(ccfg);
ContinuousQuery<Integer, Integer> qry = new ContinuousQuery<>();
qry.setRemoteFilterFactory(new RemoteFilterFactory());
qry.setLocalListener(new CacheEntryUpdatedListener<Integer, Integer>() {
/**
* {@inheritDoc}
*/
@Override
public void onUpdated(Iterable<CacheEntryEvent<? extends Integer, ? extends Integer>> evts) {
// No-op.
}
});
RemoteFilterFactory.clsLdr = getExternalClassLoader();
cache.query(qry);
// Switch class loader before starting the second node.
RemoteFilterFactory.clsLdr = getClass().getClassLoader();
return node1;
}
use of javax.cache.event.CacheEntryEvent in project ignite by apache.
the class GridCacheContinuousQueryReplicatedSelfTest method testCrossCallback.
/**
* Ensure that every node see every update.
*
* @throws Exception If failed.
*/
public void testCrossCallback() throws Exception {
// Prepare.
IgniteCache<Integer, Integer> cache1 = grid(0).cache(DEFAULT_CACHE_NAME);
IgniteCache<Integer, Integer> cache2 = grid(1).cache(DEFAULT_CACHE_NAME);
final int key1 = primaryKey(cache1);
final int key2 = primaryKey(cache2);
final CountDownLatch latch1 = new CountDownLatch(2);
final CountDownLatch latch2 = new CountDownLatch(2);
ContinuousQuery<Integer, Integer> qry1 = new ContinuousQuery<>();
qry1.setLocalListener(new CacheEntryUpdatedListener<Integer, Integer>() {
@Override
public void onUpdated(Iterable<CacheEntryEvent<? extends Integer, ? extends Integer>> evts) {
for (CacheEntryEvent<? extends Integer, ? extends Integer> evt : evts) {
log.info("Update in cache 1: " + evt);
if (evt.getKey() == key1 || evt.getKey() == key2)
latch1.countDown();
}
}
});
ContinuousQuery<Integer, Integer> qry2 = new ContinuousQuery<>();
qry2.setLocalListener(new CacheEntryUpdatedListener<Integer, Integer>() {
@Override
public void onUpdated(Iterable<CacheEntryEvent<? extends Integer, ? extends Integer>> evts) {
for (CacheEntryEvent<? extends Integer, ? extends Integer> evt : evts) {
log.info("Update in cache 2: " + evt);
if (evt.getKey() == key1 || evt.getKey() == key2)
latch2.countDown();
}
}
});
try (QueryCursor<Cache.Entry<Integer, Integer>> ignored = cache2.query(qry1);
QueryCursor<Cache.Entry<Integer, Integer>> ignore = cache2.query(qry2)) {
cache1.put(key1, key1);
cache1.put(key2, key2);
assert latch1.await(LATCH_TIMEOUT, MILLISECONDS);
assert latch2.await(LATCH_TIMEOUT, MILLISECONDS);
}
}
use of javax.cache.event.CacheEntryEvent in project ignite by apache.
the class GridCacheContinuousQueryReplicatedSelfTest method testRemoteNodeCallback.
/**
* @throws Exception If failed.
*/
public void testRemoteNodeCallback() throws Exception {
IgniteCache<Integer, Integer> cache1 = grid(0).cache(DEFAULT_CACHE_NAME);
IgniteCache<Integer, Integer> cache2 = grid(1).cache(DEFAULT_CACHE_NAME);
ContinuousQuery<Integer, Integer> qry = new ContinuousQuery<>();
final AtomicReference<Integer> val = new AtomicReference<>();
final CountDownLatch latch = new CountDownLatch(1);
qry.setLocalListener(new CacheEntryUpdatedListener<Integer, Integer>() {
@Override
public void onUpdated(Iterable<CacheEntryEvent<? extends Integer, ? extends Integer>> evts) {
Iterator<CacheEntryEvent<? extends Integer, ? extends Integer>> it = evts.iterator();
CacheEntryEvent<? extends Integer, ? extends Integer> e = it.next();
assert !it.hasNext();
log.info("Event: " + e);
val.set(e.getValue());
latch.countDown();
}
});
try (QueryCursor<Cache.Entry<Integer, Integer>> ignored = cache2.query(qry)) {
cache1.put(1, 10);
latch.await(LATCH_TIMEOUT, MILLISECONDS);
assertEquals(10, val.get().intValue());
}
}
use of javax.cache.event.CacheEntryEvent in project ignite by apache.
the class GridCacheContinuousQueryReplicatedTxOneNodeTest method doTest.
/**
* @throws Exception If failed.
*/
private void doTest(boolean loc) throws Exception {
try {
IgniteCache<String, Integer> cache = startGrid(0).cache(DEFAULT_CACHE_NAME);
ContinuousQuery<String, Integer> qry = new ContinuousQuery<>();
final AtomicInteger cnt = new AtomicInteger();
final CountDownLatch latch = new CountDownLatch(10);
qry.setLocalListener(new CacheEntryUpdatedListener<String, Integer>() {
@Override
public void onUpdated(Iterable<CacheEntryEvent<? extends String, ? extends Integer>> evts) throws CacheEntryListenerException {
for (CacheEntryEvent<? extends String, ? extends Integer> evt : evts) {
cnt.incrementAndGet();
latch.countDown();
}
}
});
cache.query(qry.setLocal(loc));
startGrid(1);
awaitPartitionMapExchange();
for (int i = 0; i < 10; i++) cache.put("key" + i, i);
assert latch.await(5000, TimeUnit.MILLISECONDS);
assertEquals(10, cnt.get());
} finally {
stopAllGrids();
}
}
use of javax.cache.event.CacheEntryEvent in project ignite by apache.
the class CacheContinuousQueryExecuteInPrimaryTest method doTestWithoutEventsEntries.
/**
* @throws Exception If failed.
*/
private void doTestWithoutEventsEntries(CacheConfiguration<Integer, String> ccfg) throws Exception {
try (IgniteCache<Integer, String> cache = grid(0).createCache(ccfg)) {
int ITERATION_CNT = 100;
final AtomicBoolean noOneListen = new AtomicBoolean(true);
for (int i = 0; i < ITERATION_CNT; i++) {
ContinuousQuery<Integer, String> qry = new ContinuousQuery<>();
qry.setLocalListener(new CacheEntryUpdatedListener<Integer, String>() {
@Override
public void onUpdated(Iterable<CacheEntryEvent<? extends Integer, ? extends String>> iterable) throws CacheEntryListenerException {
noOneListen.set(false);
}
});
qry.setRemoteFilterFactory(FactoryBuilder.factoryOf(new CacheEntryEventSerializableFilter<Integer, String>() {
@Override
public boolean evaluate(CacheEntryEvent<? extends Integer, ? extends String> cacheEntryEvent) throws CacheEntryListenerException {
return false;
}
}));
executeQuery(cache, qry, ccfg.getAtomicityMode() == TRANSACTIONAL);
}
assertTrue(noOneListen.get());
} finally {
ignite(0).destroyCache(ccfg.getName());
}
}
Aggregations