Search in sources :

Example 81 with IgnitePredicate

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);
    }
}
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

IgnitePredicate (org.apache.ignite.lang.IgnitePredicate)81 Event (org.apache.ignite.events.Event)44 CountDownLatch (java.util.concurrent.CountDownLatch)35 Ignite (org.apache.ignite.Ignite)32 UUID (java.util.UUID)20 ClusterNode (org.apache.ignite.cluster.ClusterNode)18 ArrayList (java.util.ArrayList)15 Ignition (org.apache.ignite.Ignition)10 IgniteRunnable (org.apache.ignite.lang.IgniteRunnable)10 Collection (java.util.Collection)9 HashMap (java.util.HashMap)9 Map (java.util.Map)9 IgfsEvent (org.apache.ignite.events.IgfsEvent)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 ClusterGroup (org.apache.ignite.cluster.ClusterGroup)8 CacheQueryExecutedEvent (org.apache.ignite.events.CacheQueryExecutedEvent)8 CacheEvent (org.apache.ignite.events.CacheEvent)7 IgniteBiPredicate (org.apache.ignite.lang.IgniteBiPredicate)7 IgniteBiTuple (org.apache.ignite.lang.IgniteBiTuple)7 IgniteCallable (org.apache.ignite.lang.IgniteCallable)7