use of org.apache.ignite.cache.query.ContinuousQuery in project ignite by apache.
the class CacheEntryListenersTest method testListenersWithKeepBinary.
/**
* Test continuous queries and JCache entry listeners with keep binary flag.
*/
@Test
public void testListenersWithKeepBinary() throws Exception {
try (IgniteClient client = startClient(0, 1, 2)) {
ClientCache<Object, Object> cache1 = client.getOrCreateCache("testListenersWithKB");
ClientCache<Object, Object> cache2 = cache1.withKeepBinary();
ContinuousQueryListener<Object, Object> lsnr1 = new ContinuousQueryListener<>();
ContinuousQueryListener<Object, Object> lsnr2 = new ContinuousQueryListener<>();
cache1.query(new ContinuousQuery<>().setLocalListener(lsnr1));
cache2.query(new ContinuousQuery<>().setLocalListener(lsnr2));
JCacheEntryListener<Object, Object> lsnr3 = new JCacheEntryListener<>();
JCacheEntryListener<Object, Object> lsnr4 = new JCacheEntryListener<>();
cache1.registerCacheEntryListener(new MutableCacheEntryListenerConfiguration<>(() -> lsnr3, null, true, false));
cache2.registerCacheEntryListener(new MutableCacheEntryListenerConfiguration<>(() -> lsnr4, null, true, false));
Person person1 = new Person(0, "name");
Person person2 = new Person(1, "another name");
cache1.put(0, person1);
lsnr1.assertNextCacheEvent(EventType.CREATED, 0, person1);
lsnr2.assertNextCacheEvent(EventType.CREATED, 0, client.binary().toBinary(person1));
lsnr3.assertNextCacheEvent(EventType.CREATED, 0, person1);
lsnr4.assertNextCacheEvent(EventType.CREATED, 0, client.binary().toBinary(person1));
cache1.put(0, person2);
lsnr1.assertNextCacheEvent(EventType.UPDATED, 0, person2);
lsnr2.assertNextCacheEvent(EventType.UPDATED, 0, client.binary().toBinary(person2));
lsnr3.assertNextCacheEvent(EventType.UPDATED, 0, person2);
lsnr4.assertNextCacheEvent(EventType.UPDATED, 0, client.binary().toBinary(person2));
}
}
use of org.apache.ignite.cache.query.ContinuousQuery in project ignite by apache.
the class CacheEntryListenersTest method testContinuousQueriesWithConcurrentCompute.
/**
*/
@Test
public void testContinuousQueriesWithConcurrentCompute() throws Exception {
try (IgniteClient client = startClient(0, 1, 2)) {
int threadsCnt = 20;
int iterations = 50;
Set<UUID> allNodesIds = new HashSet<>(F.nodeIds(grid(0).cluster().nodes()));
AtomicInteger threadIdxs = new AtomicInteger();
GridTestUtils.runMultiThreaded(() -> {
int threadIdx = threadIdxs.incrementAndGet();
ClientCache<Integer, Integer> cache = client.getOrCreateCache("testCQwithCompute" + threadIdx);
try {
for (int i = 0; i < iterations; i++) {
ContinuousQueryListener<Integer, Integer> lsnr = new ContinuousQueryListener<>();
QueryCursor<?> cur = cache.query(new ContinuousQuery<Integer, Integer>().setLocalListener(lsnr));
cache.put(i, i);
Future<T2<UUID, Set<UUID>>> fut = client.compute().executeAsync2(TestTask.class.getName(), null);
assertEquals(allNodesIds, fut.get().get2());
lsnr.assertNextCacheEvent(EventType.CREATED, i, i);
assertTrue(lsnr.isQueueEmpty());
cur.close();
}
} catch (Exception e) {
log.error("Failure: ", e);
fail();
}
}, threadsCnt, "run-task-async");
}
}
use of org.apache.ignite.cache.query.ContinuousQuery in project ignite by apache.
the class JmxExporterSpiTest method testContinuousQuery.
/**
*/
@Test
public void testContinuousQuery() throws Exception {
try (IgniteEx remoteNode = startGrid(1)) {
IgniteCache<Integer, Integer> cache = ignite.createCache("cache-1");
assertEquals(0, systemView(CQ_SYS_VIEW).size());
assertEquals(0, systemView(remoteNode, CQ_SYS_VIEW).size());
try (QueryCursor qry = cache.query(new ContinuousQuery<>().setInitialQuery(new ScanQuery<>()).setPageSize(100).setTimeInterval(1000).setLocalListener(evts -> {
// No-op.
}).setRemoteFilterFactory(() -> evt -> true))) {
for (int i = 0; i < 100; i++) cache.put(i, i);
checkContinuousQueryView(ignite, ignite);
checkContinuousQueryView(ignite, remoteNode);
}
assertEquals(0, systemView(CQ_SYS_VIEW).size());
assertTrue(waitForCondition(() -> systemView(remoteNode, CQ_SYS_VIEW).isEmpty(), getTestTimeout()));
}
}
use of org.apache.ignite.cache.query.ContinuousQuery in project ignite by apache.
the class SystemViewSelfTest method testContinuousQuery.
/**
*/
@Test
public void testContinuousQuery() throws Exception {
try (IgniteEx originNode = startGrid(0);
IgniteEx remoteNode = startGrid(1)) {
IgniteCache<Integer, Integer> cache = originNode.createCache("cache-1");
SystemView<ContinuousQueryView> origQrys = originNode.context().systemView().view(CQ_SYS_VIEW);
SystemView<ContinuousQueryView> remoteQrys = remoteNode.context().systemView().view(CQ_SYS_VIEW);
assertEquals(0, origQrys.size());
assertEquals(0, remoteQrys.size());
try (QueryCursor qry = cache.query(new ContinuousQuery<>().setInitialQuery(new ScanQuery<>()).setPageSize(100).setTimeInterval(1000).setLocalListener(evts -> {
// No-op.
}).setRemoteFilterFactory(() -> evt -> true))) {
for (int i = 0; i < 100; i++) cache.put(i, i);
checkContinuousQueryView(originNode, origQrys, true);
checkContinuousQueryView(originNode, remoteQrys, false);
}
assertEquals(0, origQrys.size());
assertTrue(waitForCondition(() -> remoteQrys.size() == 0, getTestTimeout()));
}
}
use of org.apache.ignite.cache.query.ContinuousQuery 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);
}
}
});
}
Aggregations