timoninmaxim commented on code in PR #11342:
URL: https://github.com/apache/ignite/pull/11342#discussion_r1593770609
##########
modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAbstractQuerySelfTest.java:
##########
@@ -1883,6 +1888,114 @@ public void testFieldsQueryEvents() throws Exception {
}
}
+ /**
+ * @throws Exception If failed.
+ */
+ @Test
+ public void testIndexQueryEvents() throws Exception {
+ final Map<Integer, Type2> qryResults = new ConcurrentHashMap<>();
+ final IgniteCache<Integer, Type2> cache = jcache(Integer.class,
Type2.class);
+ final boolean evtsDisabled =
cache.getConfiguration(CacheConfiguration.class).isEventsDisabled();
+
+ final CountDownLatch readLatch = new CountDownLatch(evtsDisabled ? 0 :
2);
+ final CountDownLatch execLatch = new CountDownLatch(evtsDisabled ? 0 :
+ cacheMode() == REPLICATED ? 1 : gridCount());
+
+ IgnitePredicate[] objReadLsnrs = new IgnitePredicate[gridCount()];
+ IgnitePredicate[] qryExecLsnrs = new IgnitePredicate[gridCount()];
+
+ for (int i = 0; i < gridCount(); i++) {
+ IgnitePredicate<Event> objReadPred = new IgnitePredicate<Event>() {
+ @Override public boolean apply(Event evt) {
+ assert evt instanceof CacheQueryReadEvent;
+
+ if (evtsDisabled)
+ fail("Cache events are disabled");
+
+ CacheQueryReadEvent<Integer, Type2> qe =
(CacheQueryReadEvent<Integer, Type2>)evt;
+
+ assertEquals(INDEX.name(), qe.queryType());
+ assertEquals(cache.getName(), qe.cacheName());
+ assertEquals("Type2", QueryUtils.typeName(qe.className()));
+ assertNotNull(qe.scanQueryFilter());
+ assertNull(qe.clause());
+ assertNull(qe.continuousQueryFilter());
+ assertNull(qe.arguments());
+
+ qryResults.put(qe.key(), qe.value());
+
+ readLatch.countDown();
+
+ return true;
+ }
+ };
+
+ grid(i).events().localListen(objReadPred,
EVT_CACHE_QUERY_OBJECT_READ);
+ objReadLsnrs[i] = objReadPred;
+
+ IgnitePredicate<Event> qryExecPred = 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(INDEX.name(), qe.queryType());
+ assertEquals(cache.getName(), qe.cacheName());
+ assertEquals("Type2", QueryUtils.typeName(qe.className()));
+ assertNotNull(qe.scanQueryFilter());
+ assertNull(qe.clause());
+ assertNull(qe.continuousQueryFilter());
+ assertNull(qe.arguments());
+
+ execLatch.countDown();
+
+ return true;
+ }
+ };
+
+ grid(i).events().localListen(qryExecPred,
EVT_CACHE_QUERY_EXECUTED);
+ qryExecLsnrs[i] = qryExecPred;
+ }
+
+ try {
+ cache.put(1, new Type2(1, "John"));
+ cache.put(2, new Type2(2, "Bill"));
+ cache.put(3, new Type2(3, "Sam"));
+ cache.put(4, new Type2(4, "Bill"));
+ cache.put(5, new Type2(5, "Bob"));
+
+ IndexQuery<Integer, Type2> qry = new IndexQuery<Integer,
Type2>(Type2.class)
+ .setCriteria(gt("id", 1), lt("id", 5))
+ .setFilter((k, v) -> v.name().contains("Bill"));
+
+ if (cacheMode() == REPLICATED)
+ qry.setLocal(true);
+
+ QueryCursor<Cache.Entry<Integer, Type2>> cursor = cache.query(qry);
+
+ cursor.getAll();
+
+ assert readLatch.await(1000, MILLISECONDS);
+ assert execLatch.await(1000, MILLISECONDS);
+
+ if (!evtsDisabled) {
Review Comment:
Let's check that qryResults are empty case when `evtsDisabled = true`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]