use of org.apache.ignite.lang.IgnitePredicate in project ignite by apache.
the class IgniteCacheAbstractQuerySelfTest method checkSqlQueryEvents.
/**
* @throws Exception If failed.
*/
private void checkSqlQueryEvents() throws Exception {
final IgniteCache<Integer, Integer> cache = jcache(Integer.class, Integer.class);
final boolean evtsDisabled = cache.getConfiguration(CacheConfiguration.class).isEventsDisabled();
final CountDownLatch execLatch = new CountDownLatch(evtsDisabled ? 0 : cacheMode() == REPLICATED ? 1 : gridCount());
IgnitePredicate[] lsnrs = new IgnitePredicate[gridCount()];
for (int i = 0; i < gridCount(); i++) {
IgnitePredicate<Event> pred = new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
assert evt instanceof CacheQueryExecutedEvent;
if (evtsDisabled)
fail("Cache events are disabled");
CacheQueryExecutedEvent qe = (CacheQueryExecutedEvent) evt;
assertEquals(cache.getName(), qe.cacheName());
assertNotNull(qe.clause());
assertNull(qe.scanQueryFilter());
assertNull(qe.continuousQueryFilter());
assertArrayEquals(new Integer[] { 10 }, qe.arguments());
execLatch.countDown();
return true;
}
};
grid(i).events().localListen(pred, EVT_CACHE_QUERY_EXECUTED);
lsnrs[i] = pred;
}
try {
for (int i = 0; i < 20; i++) cache.put(i, i);
QueryCursor<Cache.Entry<Integer, Integer>> q = cache.query(new SqlQuery<Integer, Integer>(Integer.class, "_key >= ?").setArgs(10));
q.getAll();
assert execLatch.await(1000, MILLISECONDS);
} finally {
for (int i = 0; i < gridCount(); i++) grid(i).events().stopLocalListen(lsnrs[i], EVT_CACHE_QUERY_EXECUTED);
}
}
Aggregations