Search in sources :

Example 1 with DummyEventFilterFactory

use of org.apache.ignite.custom.DummyEventFilterFactory in project ignite by apache.

the class ContinuousQueryPeerClassLoadingTest method check.

/**
 * @param node1Name Node 1 name.
 * @param node2Name Node 2 name.
 * @param node3Name Node 3 name.
 */
private void check(String node1Name, String node2Name, String node3Name) throws Exception {
    final Ignite node1 = startGrid(node1Name);
    final IgniteCache<Integer, String> cache = node1.getOrCreateCache(CACHE_NAME);
    for (int i = 0; i < 10; i++) cache.put(i, String.valueOf(i));
    final Ignite node2 = startGrid(node2Name);
    final ContinuousQuery<Integer, String> qry1 = new ContinuousQuery<>();
    final ContinuousQuery<Integer, String> qry2 = new ContinuousQuery<>();
    qry1.setRemoteFilterFactory(new DummyEventFilterFactory());
    qry2.setRemoteFilterFactory(new DummyEventFilterFactory());
    final AtomicInteger client1Evts = new AtomicInteger(0);
    final AtomicInteger client2Evts = new AtomicInteger(0);
    final CountDownLatch latch1 = new CountDownLatch(20);
    final CountDownLatch latch2 = new CountDownLatch(10);
    qry1.setLocalListener(new CacheEntryUpdatedListener<Integer, String>() {

        @Override
        public void onUpdated(final Iterable<CacheEntryEvent<? extends Integer, ? extends String>> evts) throws CacheEntryListenerException {
            System.out.println(">> Client 1 events " + evts);
            for (CacheEntryEvent<? extends Integer, ? extends String> evt : evts) latch1.countDown();
        }
    });
    qry2.setLocalListener(new CacheEntryUpdatedListener<Integer, String>() {

        @Override
        public void onUpdated(final Iterable<CacheEntryEvent<? extends Integer, ? extends String>> evts) throws CacheEntryListenerException {
            System.out.println(">> Client 2 events " + evts);
            for (CacheEntryEvent<? extends Integer, ? extends String> evt : evts) latch2.countDown();
        }
    });
    final IgniteCache<Integer, String> cache1 = node2.cache(CACHE_NAME);
    cache1.query(qry1);
    for (int i = 10; i < 20; i++) cache.put(i, String.valueOf(i));
    // Fail on start second client.
    final Ignite node3 = startGrid(node3Name);
    final IgniteCache<Integer, String> cache2 = node3.cache(CACHE_NAME);
    cache2.query(qry2);
    for (int i = 20; i < 30; i++) cache.put(i, String.valueOf(i));
    assert latch1.await(5, TimeUnit.SECONDS) : latch1.getCount();
    assert latch2.await(5, TimeUnit.SECONDS) : latch2.getCount();
}
Also used : DummyEventFilterFactory(org.apache.ignite.custom.DummyEventFilterFactory) CountDownLatch(java.util.concurrent.CountDownLatch) CacheEntryListenerException(javax.cache.event.CacheEntryListenerException) CacheEntryEvent(javax.cache.event.CacheEntryEvent) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Ignite(org.apache.ignite.Ignite)

Aggregations

CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 CacheEntryEvent (javax.cache.event.CacheEntryEvent)1 CacheEntryListenerException (javax.cache.event.CacheEntryListenerException)1 Ignite (org.apache.ignite.Ignite)1 ContinuousQuery (org.apache.ignite.cache.query.ContinuousQuery)1 DummyEventFilterFactory (org.apache.ignite.custom.DummyEventFilterFactory)1