Search in sources :

Example 6 with CacheQueryExecutedEvent

use of org.apache.ignite.events.CacheQueryExecutedEvent in project ignite by apache.

the class IgniteSqlSkipReducerOnUpdateDmlSelfTest method testEvents.

/**
 * @throws Exception if failed.
 */
public void testEvents() throws Exception {
    final CountDownLatch latch = new CountDownLatch(NODE_COUNT);
    final IgnitePredicate<Event> pred = new IgnitePredicate<Event>() {

        @Override
        public boolean apply(Event evt) {
            assert evt instanceof CacheQueryExecutedEvent;
            CacheQueryExecutedEvent qe = (CacheQueryExecutedEvent) evt;
            assertNotNull(qe.clause());
            latch.countDown();
            return true;
        }
    };
    for (int idx = 0; idx < NODE_COUNT; idx++) grid(idx).events().localListen(pred, EVT_CACHE_QUERY_EXECUTED);
    IgniteCache<Integer, Organization> cache = grid(NODE_CLIENT).cache(CACHE_ORG);
    for (int i = 0; i < 1024; i++) cache.put(i, new Organization("Acme Inc #" + i, 0));
    cache.query(new SqlFieldsQueryEx("UPDATE \"org\".Organization o SET name = UPPER(name)", false).setSkipReducerOnUpdate(true)).getAll();
    assertTrue(latch.await(5000, MILLISECONDS));
    for (int idx = 0; idx < NODE_COUNT; idx++) grid(idx).events().stopLocalListen(pred);
}
Also used : IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) SqlFieldsQueryEx(org.apache.ignite.internal.processors.cache.query.SqlFieldsQueryEx) CacheQueryExecutedEvent(org.apache.ignite.events.CacheQueryExecutedEvent) Event(org.apache.ignite.events.Event) CountDownLatch(java.util.concurrent.CountDownLatch) CacheQueryExecutedEvent(org.apache.ignite.events.CacheQueryExecutedEvent)

Example 7 with CacheQueryExecutedEvent

use of org.apache.ignite.events.CacheQueryExecutedEvent in project ignite by apache.

the class IgniteCacheAbstractQuerySelfTest method testFieldsQueryEvents.

/**
 * @throws Exception If failed.
 */
public void testFieldsQueryEvents() throws Exception {
    final IgniteCache<UUID, Person> cache = jcache(UUID.class, Person.class);
    final boolean evtsDisabled = cache.getConfiguration(CacheConfiguration.class).isEventsDisabled();
    final CountDownLatch execLatch = new CountDownLatch(evtsDisabled ? 0 : cacheMode() == REPLICATED ? 1 : gridCount());
    IgnitePredicate[] qryExecLsnrs = 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);
        qryExecLsnrs[i] = pred;
    }
    try {
        for (int i = 1; i <= 20; i++) cache.put(UUID.randomUUID(), new Person("Person " + i, i));
        QueryCursor<List<?>> q = cache.query(new SqlFieldsQuery("select _key, name from Person where salary > ?").setArgs(10));
        q.getAll();
        assert execLatch.await(1000, MILLISECONDS);
    } finally {
        for (int i = 0; i < gridCount(); i++) grid(i).events().stopLocalListen(qryExecLsnrs[i]);
    }
}
Also used : IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) CountDownLatch(java.util.concurrent.CountDownLatch) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) CacheQueryExecutedEvent(org.apache.ignite.events.CacheQueryExecutedEvent) CacheQueryExecutedEvent(org.apache.ignite.events.CacheQueryExecutedEvent) Event(org.apache.ignite.events.Event) CacheQueryReadEvent(org.apache.ignite.events.CacheQueryReadEvent) List(java.util.List) ArrayList(java.util.ArrayList) UUID(java.util.UUID) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 8 with CacheQueryExecutedEvent

use of org.apache.ignite.events.CacheQueryExecutedEvent in project ignite by apache.

the class IgniteCacheAbstractQuerySelfTest method testScanQueryEvents.

/**
 * @throws Exception If failed.
 */
public void testScanQueryEvents() throws Exception {
    final Map<Integer, Integer> map = new ConcurrentHashMap<>();
    final IgniteCache<Integer, Integer> cache = jcache(Integer.class, Integer.class);
    final boolean evtsDisabled = cache.getConfiguration(CacheConfiguration.class).isEventsDisabled();
    final CountDownLatch latch = new CountDownLatch(evtsDisabled ? 0 : 10);
    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> pred = new IgnitePredicate<Event>() {

            @Override
            public boolean apply(Event evt) {
                assert evt instanceof CacheQueryReadEvent;
                if (evtsDisabled)
                    fail("Cache events are disabled");
                CacheQueryReadEvent<Integer, Integer> qe = (CacheQueryReadEvent<Integer, Integer>) evt;
                assertEquals(SCAN.name(), qe.queryType());
                assertEquals(cache.getName(), qe.cacheName());
                assertNull(qe.className());
                assertNull(null, qe.clause());
                assertNotNull(qe.scanQueryFilter());
                assertNull(qe.continuousQueryFilter());
                assertNull(qe.arguments());
                map.put(qe.key(), qe.value());
                latch.countDown();
                return true;
            }
        };
        grid(i).events().localListen(pred, EVT_CACHE_QUERY_OBJECT_READ);
        objReadLsnrs[i] = pred;
        IgnitePredicate<Event> execPred = 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(SCAN.name(), qe.queryType());
                assertEquals(cache.getName(), qe.cacheName());
                assertNull(qe.className());
                assertNull(null, qe.clause());
                assertNotNull(qe.scanQueryFilter());
                assertNull(qe.continuousQueryFilter());
                assertNull(qe.arguments());
                execLatch.countDown();
                return true;
            }
        };
        grid(i).events().localListen(execPred, EVT_CACHE_QUERY_EXECUTED);
        qryExecLsnrs[i] = execPred;
    }
    try {
        for (int i = 0; i < 20; i++) cache.put(i, i);
        IgniteBiPredicate<Integer, Integer> filter = new IgniteBiPredicate<Integer, Integer>() {

            @Override
            public boolean apply(Integer k, Integer v) {
                return k >= 10;
            }
        };
        QueryCursor<Cache.Entry<Integer, Integer>> q = cache.query(new ScanQuery<>(filter));
        q.getAll();
        assert latch.await(1000, MILLISECONDS);
        assert execLatch.await(1000, MILLISECONDS);
        if (!evtsDisabled) {
            assertEquals(10, map.size());
            for (int i = 10; i < 20; i++) assertEquals(i, map.get(i).intValue());
        }
    } finally {
        for (int i = 0; i < gridCount(); i++) {
            grid(i).events().stopLocalListen(objReadLsnrs[i]);
            grid(i).events().stopLocalListen(qryExecLsnrs[i]);
        }
    }
}
Also used : CacheQueryReadEvent(org.apache.ignite.events.CacheQueryReadEvent) IgniteBiPredicate(org.apache.ignite.lang.IgniteBiPredicate) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) CountDownLatch(java.util.concurrent.CountDownLatch) CacheQueryExecutedEvent(org.apache.ignite.events.CacheQueryExecutedEvent) CacheQueryExecutedEvent(org.apache.ignite.events.CacheQueryExecutedEvent) Event(org.apache.ignite.events.Event) CacheQueryReadEvent(org.apache.ignite.events.CacheQueryReadEvent) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 9 with CacheQueryExecutedEvent

use of org.apache.ignite.events.CacheQueryExecutedEvent 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);
    }
}
Also used : SqlQuery(org.apache.ignite.cache.query.SqlQuery) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) CountDownLatch(java.util.concurrent.CountDownLatch) CacheQueryExecutedEvent(org.apache.ignite.events.CacheQueryExecutedEvent) CacheQueryExecutedEvent(org.apache.ignite.events.CacheQueryExecutedEvent) Event(org.apache.ignite.events.Event) CacheQueryReadEvent(org.apache.ignite.events.CacheQueryReadEvent) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Aggregations

CacheQueryExecutedEvent (org.apache.ignite.events.CacheQueryExecutedEvent)9 CountDownLatch (java.util.concurrent.CountDownLatch)8 Event (org.apache.ignite.events.Event)8 IgnitePredicate (org.apache.ignite.lang.IgnitePredicate)8 CacheQueryReadEvent (org.apache.ignite.events.CacheQueryReadEvent)7 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)4 NearCacheConfiguration (org.apache.ignite.configuration.NearCacheConfiguration)4 ArrayList (java.util.ArrayList)2 List (java.util.List)2 UUID (java.util.UUID)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 HashSet (java.util.HashSet)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 CacheEntryEvent (javax.cache.event.CacheEntryEvent)1 IgniteException (org.apache.ignite.IgniteException)1 ContinuousQuery (org.apache.ignite.cache.query.ContinuousQuery)1 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)1 SqlQuery (org.apache.ignite.cache.query.SqlQuery)1 ClusterNode (org.apache.ignite.cluster.ClusterNode)1 CacheEvent (org.apache.ignite.events.CacheEvent)1