use of javax.cache.event.CacheEntryListenerException in project ignite by apache.
the class IgniteCacheConfigVariationsFullApiTest method testContinuousQuery.
/**
* @throws Exception If failed.
*/
@Test
public void testContinuousQuery() throws Exception {
runInAllDataModes(new TestRunnable() {
@Override
public void run() throws Exception {
final AtomicInteger updCnt = new AtomicInteger();
ContinuousQuery<Object, Object> qry = new ContinuousQuery<>();
qry.setInitialQuery(new ScanQuery<>(new IgniteBiPredicate<Object, Object>() {
@Override
public boolean apply(Object key, Object val) {
return valueOf(key) >= 3;
}
}));
qry.setLocalListener(new CacheEntryUpdatedListener<Object, Object>() {
@Override
public void onUpdated(Iterable<CacheEntryEvent<? extends Object, ? extends Object>> evts) throws CacheEntryListenerException {
for (CacheEntryEvent<? extends Object, ? extends Object> evt : evts) {
int v = valueOf(evt.getKey());
// Check filter.
assertTrue("v=" + v, v >= 10 && v < 15);
updCnt.incrementAndGet();
}
}
});
qry.setRemoteFilter(new TestCacheEntryEventSerializableFilter());
IgniteCache<Object, Object> cache = jcache();
for (int i = 0; i < 10; i++) cache.put(key(i), value(i));
try (QueryCursor<Cache.Entry<Object, Object>> cur = cache.query(qry)) {
int cnt = 0;
for (Cache.Entry<Object, Object> e : cur) {
cnt++;
int val = valueOf(e.getKey());
assertTrue("v=" + val, val >= 3);
}
assertEquals(7, cnt);
for (int i = 10; i < 20; i++) cache.put(key(i), value(i));
GridTestUtils.waitForCondition(new GridAbsPredicateX() {
@Override
public boolean applyx() throws IgniteCheckedException {
return updCnt.get() == 5;
}
}, 30_000);
}
}
});
}
use of javax.cache.event.CacheEntryListenerException in project ignite by apache.
the class ContinuousQueryPeerClassLoadingTest method check.
/**
* @param node1Name Node 1 name.
* @param node2Name Node 2 name.
* @param node3Name Node 3 name.
*/
private void check(String node1Name, String node2Name, String node3Name) throws Exception {
final Ignite node1 = startGrid(node1Name);
final IgniteCache<Integer, String> cache = node1.getOrCreateCache(CACHE_NAME);
for (int i = 0; i < 10; i++) cache.put(i, String.valueOf(i));
final Ignite node2 = node2Name.contains("client") ? startClientGrid(node2Name) : startGrid(node2Name);
final ContinuousQuery<Integer, String> qry1 = new ContinuousQuery<>();
final ContinuousQuery<Integer, String> qry2 = new ContinuousQuery<>();
qry1.setRemoteFilterFactory(new DummyEventFilterFactory<>());
qry2.setRemoteFilterFactory(new DummyEventFilterFactory<>());
final CountDownLatch latch1 = new CountDownLatch(20);
final CountDownLatch latch2 = new CountDownLatch(10);
qry1.setLocalListener(new CacheEntryUpdatedListener<Integer, String>() {
@Override
public void onUpdated(final Iterable<CacheEntryEvent<? extends Integer, ? extends String>> evts) throws CacheEntryListenerException {
System.out.println(">> Client 1 events " + evts);
for (CacheEntryEvent<? extends Integer, ? extends String> evt : evts) latch1.countDown();
}
});
qry2.setLocalListener(new CacheEntryUpdatedListener<Integer, String>() {
@Override
public void onUpdated(final Iterable<CacheEntryEvent<? extends Integer, ? extends String>> evts) throws CacheEntryListenerException {
System.out.println(">> Client 2 events " + evts);
for (CacheEntryEvent<? extends Integer, ? extends String> evt : evts) latch2.countDown();
}
});
final IgniteCache<Integer, String> cache1 = node2.cache(CACHE_NAME);
cache1.query(qry1);
for (int i = 10; i < 20; i++) cache.put(i, String.valueOf(i));
// Fail on start second client.
final Ignite node3 = node3Name.contains("client") ? startClientGrid(node3Name) : startGrid(node3Name);
final IgniteCache<Integer, String> cache2 = node3.cache(CACHE_NAME);
cache2.query(qry2);
for (int i = 20; i < 30; i++) cache.put(i, String.valueOf(i));
assert latch1.await(5, TimeUnit.SECONDS) : latch1.getCount();
assert latch2.await(5, TimeUnit.SECONDS) : latch2.getCount();
}
use of javax.cache.event.CacheEntryListenerException in project ignite by apache.
the class GridCacheContinuousQueryReplicatedTxOneNodeTest method doTestOneNode.
/**
* @throws Exception If failed.
*/
private void doTestOneNode(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);
for (int i = 0; i < 10; i++) cache.put("key" + i, i);
if (atomicMode() != CacheAtomicityMode.TRANSACTIONAL_SNAPSHOT)
cache.clear();
else {
// TODO IGNITE-7952. Remove "else" clause - do cache.clear() instead of iteration.
for (Iterator it = cache.iterator(); it.hasNext(); ) {
it.next();
it.remove();
}
}
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));
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.CacheEntryListenerException in project ignite by apache.
the class GridServiceContinuousQueryRedeployTest method testServiceRedeploymentAfterCancel.
/**
* @throws Exception If failed.
*/
@Test
public void testServiceRedeploymentAfterCancel() throws Exception {
final Ignite ignite = startGrid(0);
final IgniteCache<Object, Object> managementCache = ignite.getOrCreateCache(CACHE_NAME);
final ContinuousQuery<Object, Object> qry = new ContinuousQuery<>();
final List<Object> evts = Collections.synchronizedList(new ArrayList<>());
qry.setLocalListener(new CacheEntryUpdatedListener<Object, Object>() {
@Override
public void onUpdated(Iterable<CacheEntryEvent<?, ?>> iterable) throws CacheEntryListenerException {
for (CacheEntryEvent<?, ?> event : iterable) evts.add(event);
}
});
int iterations = 100;
while (iterations-- > 0) {
QueryCursor quorumCursor = managementCache.query(qry);
IgniteInternalFuture<?> fut1 = GridTestUtils.runAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
System.out.println("Deploy " + SERVICE_NAME);
deployService(ignite);
return null;
}
});
IgniteInternalFuture<?> fut2 = GridTestUtils.runAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
System.out.println("Undeploy " + SERVICE_NAME);
ignite.services().cancel(SERVICE_NAME);
return null;
}
});
fut1.get();
fut2.get();
U.sleep(100);
assert evts.size() <= 1 : evts.size();
ignite.services().cancel("service1");
evts.clear();
quorumCursor.close();
}
}
use of javax.cache.event.CacheEntryListenerException in project ignite by apache.
the class CacheContinuousQueryExecuteInPrimaryTest method doTestWithEventsEntries.
/**
* @throws Exception If failed.
*/
public void doTestWithEventsEntries(CacheConfiguration<Integer, String> ccfg) throws Exception {
try (IgniteCache<Integer, String> cache = grid(0).createCache(ccfg)) {
ContinuousQuery<Integer, String> qry = new ContinuousQuery<>();
final CountDownLatch latch = new CountDownLatch(16);
final AtomicInteger cnt = new AtomicInteger(0);
qry.setLocalListener(new CacheEntryUpdatedListener<Integer, String>() {
@Override
public void onUpdated(Iterable<CacheEntryEvent<? extends Integer, ? extends String>> iterable) throws CacheEntryListenerException {
for (CacheEntryEvent<? extends Integer, ? extends String> e : iterable) {
cnt.incrementAndGet();
latch.countDown();
}
}
});
qry.setRemoteFilterFactory(FactoryBuilder.factoryOf(new CacheEntryEventSerializableFilter<Integer, String>() {
@Override
public boolean evaluate(CacheEntryEvent<? extends Integer, ? extends String> e) throws CacheEntryListenerException {
return e.getKey() % 2 == 0;
}
}));
// Execute query.
executeQuery(cache, qry, ccfg.getAtomicityMode() != ATOMIC);
assertTrue(latch.await(LATCH_TIMEOUT, MILLISECONDS));
assertEquals(16, cnt.get());
} finally {
ignite(0).destroyCache(ccfg.getName());
}
}
Aggregations