Search in sources :

Example 21 with CacheEntryListenerException

use of javax.cache.event.CacheEntryListenerException in project ignite by apache.

the class IgniteCacheContinuousQueryReconnectTest method testReconnect.

/**
 * @throws Exception If failed.
 */
private void testReconnect(boolean clientQuery) throws Exception {
    Ignite srv1 = startGrid(0);
    ContinuousQuery<Object, Object> qry = new ContinuousQuery<>();
    qry.setLocalListener(new CacheEntryUpdatedListener<Object, Object>() {

        @Override
        public void onUpdated(Iterable iterable) throws CacheEntryListenerException {
        // No-op.
        }
    });
    qry.setAutoUnsubscribe(false);
    qry.setRemoteFilter(new CacheEntryEventSerializableFilter<Object, Object>() {

        @Override
        public boolean evaluate(CacheEntryEvent<?, ?> event) throws CacheEntryListenerException {
            cnt.incrementAndGet();
            return true;
        }
    });
    Ignite client = startClientGrid(1);
    IgniteCache<Object, Object> cache1 = srv1.cache(DEFAULT_CACHE_NAME);
    IgniteCache<Object, Object> clCache = client.cache(DEFAULT_CACHE_NAME);
    // 0 remote listeners.
    putAndCheck(clCache, 0);
    (clientQuery ? clCache : cache1).query(qry);
    // 1 remote listener.
    putAndCheck(clCache, 1);
    startGrid(2);
    // 2 remote listeners.
    putAndCheck(clCache, 2);
    stopGrid(0);
    while (true) {
        try {
            clCache.get(1);
            break;
        } catch (IgniteClientDisconnectedException e) {
            // Wait for reconnect.
            e.reconnectFuture().get();
        } catch (CacheException e) {
            if (e.getCause() instanceof IgniteClientDisconnectedException)
                // Wait for reconnect.
                ((IgniteClientDisconnectedException) e.getCause()).reconnectFuture().get();
        }
    }
    // 1 remote listener.
    putAndCheck(clCache, 1);
    startGrid(3);
    // 2 remote listeners.
    putAndCheck(clCache, 2);
    // Client node.
    stopGrid(1);
    client = startClientGrid(4);
    clCache = client.cache(DEFAULT_CACHE_NAME);
    // 2 remote listeners.
    putAndCheck(clCache, 2);
    startGrid(5);
    // 3 remote listeners.
    putAndCheck(clCache, 3);
}
Also used : CacheException(javax.cache.CacheException) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) CacheEntryListenerException(javax.cache.event.CacheEntryListenerException) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) Ignite(org.apache.ignite.Ignite)

Example 22 with CacheEntryListenerException

use of javax.cache.event.CacheEntryListenerException in project ignite by apache.

the class ContinuousQueryMarshallerTest method check.

/**
 * @param node1Name Node 1 name.
 * @param node2Name Node 2 name.
 */
private void check(String node1Name, String node2Name) throws Exception {
    final Ignite node1 = startGrid(node1Name);
    final IgniteCache<Integer, MarshallerCheckingEntry> cache = node1.getOrCreateCache(CACHE_NAME);
    for (int i = 0; i < 10; i++) cache.put(i, new MarshallerCheckingEntry(String.valueOf(i)));
    final Ignite node2 = "client".equals(node2Name) ? startClientGrid(node2Name) : startGrid(node2Name);
    final ContinuousQuery<Integer, MarshallerCheckingEntry> qry = new ContinuousQuery<>();
    ScanQuery<Integer, MarshallerCheckingEntry> scanQry = new ScanQuery<>(new IgniteBiPredicate<Integer, MarshallerCheckingEntry>() {

        @Override
        public boolean apply(Integer key, MarshallerCheckingEntry val) {
            return key % 2 == 0;
        }
    });
    qry.setInitialQuery(scanQry);
    qry.setRemoteFilterFactory(new DummyEventFilterFactory<>());
    final CountDownLatch latch = new CountDownLatch(15);
    qry.setLocalListener(new CacheEntryUpdatedListener<Integer, MarshallerCheckingEntry>() {

        @Override
        public void onUpdated(final Iterable<CacheEntryEvent<? extends Integer, ? extends MarshallerCheckingEntry>> evts) throws CacheEntryListenerException {
            System.out.println(">> Client 1 events " + evts);
            for (CacheEntryEvent<? extends Integer, ? extends MarshallerCheckingEntry> evt : evts) latch.countDown();
        }
    });
    final IgniteCache<Integer, MarshallerCheckingEntry> cache1 = node2.cache(CACHE_NAME);
    for (Cache.Entry<Integer, MarshallerCheckingEntry> entry : cache1.query(qry)) {
        latch.countDown();
        System.out.println(">> Initial entry " + entry);
    }
    for (int i = 10; i < 20; i++) cache1.put(i, new MarshallerCheckingEntry(i));
    assertTrue(Long.toString(latch.getCount()), latch.await(5, TimeUnit.SECONDS));
}
Also used : ScanQuery(org.apache.ignite.cache.query.ScanQuery) CountDownLatch(java.util.concurrent.CountDownLatch) CacheEntryListenerException(javax.cache.event.CacheEntryListenerException) CacheEntryEvent(javax.cache.event.CacheEntryEvent) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) Ignite(org.apache.ignite.Ignite) IgniteCache(org.apache.ignite.IgniteCache) Cache(javax.cache.Cache)

Aggregations

CacheEntryListenerException (javax.cache.event.CacheEntryListenerException)22 CacheEntryEvent (javax.cache.event.CacheEntryEvent)15 ContinuousQuery (org.apache.ignite.cache.query.ContinuousQuery)15 Ignite (org.apache.ignite.Ignite)7 CountDownLatch (java.util.concurrent.CountDownLatch)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 CacheEntryEventSerializableFilter (org.apache.ignite.cache.CacheEntryEventSerializableFilter)5 QueryCursor (org.apache.ignite.cache.query.QueryCursor)5 Test (org.junit.Test)5 CacheException (javax.cache.CacheException)4 IgniteException (org.apache.ignite.IgniteException)4 ContinuousQueryWithTransformer (org.apache.ignite.cache.query.ContinuousQueryWithTransformer)4 CacheEntryUpdatedListener (javax.cache.event.CacheEntryUpdatedListener)3 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)3 AbstractContinuousQuery (org.apache.ignite.cache.query.AbstractContinuousQuery)3 PlatformMemory (org.apache.ignite.internal.processors.platform.memory.PlatformMemory)3 PlatformOutputStream (org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream)3 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)3 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 Cache (javax.cache.Cache)2