Search in sources :

Example 16 with CacheEntryUpdatedListener

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

the class TcpDiscoveryMultiThreadedTest method _testCustomEventOnJoinCoordinatorStop.

/**
 * @throws Exception If failed.
 */
public void _testCustomEventOnJoinCoordinatorStop() throws Exception {
    for (int k = 0; k < 10; k++) {
        log.info("Iteration: " + k);
        clientFlagGlobal = false;
        final int START_NODES = 5;
        final int JOIN_NODES = 5;
        startGrids(START_NODES);
        final AtomicInteger startIdx = new AtomicInteger(START_NODES);
        final AtomicBoolean stop = new AtomicBoolean();
        IgniteInternalFuture<?> fut1 = GridTestUtils.runAsync(new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
                Ignite ignite = ignite(START_NODES - 1);
                while (!stop.get()) {
                    ignite.createCache(ccfg);
                    ignite.destroyCache(ccfg.getName());
                }
                return null;
            }
        });
        try {
            final CyclicBarrier barrier = new CyclicBarrier(JOIN_NODES + 1);
            IgniteInternalFuture<?> fut2 = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {

                @Override
                public Object call() throws Exception {
                    int idx = startIdx.getAndIncrement();
                    Thread.currentThread().setName("start-thread-" + idx);
                    barrier.await();
                    Ignite ignite = startGrid(idx);
                    assertFalse(ignite.configuration().isClientMode());
                    log.info("Started node: " + ignite.name());
                    IgniteCache<Object, Object> cache = ignite.getOrCreateCache(DEFAULT_CACHE_NAME);
                    ContinuousQuery<Object, Object> qry = new ContinuousQuery<>();
                    qry.setLocalListener(new CacheEntryUpdatedListener<Object, Object>() {

                        @Override
                        public void onUpdated(Iterable<CacheEntryEvent<?, ?>> evts) {
                        // No-op.
                        }
                    });
                    QueryCursor<Cache.Entry<Object, Object>> cur = cache.query(qry);
                    cur.close();
                    return null;
                }
            }, JOIN_NODES, "start-thread");
            barrier.await();
            U.sleep(ThreadLocalRandom.current().nextInt(10, 100));
            for (int i = 0; i < START_NODES - 1; i++) {
                GridTestUtils.invoke(ignite(i).configuration().getDiscoverySpi(), "simulateNodeFailure");
                stopGrid(i);
            }
            stop.set(true);
            fut1.get();
            fut2.get();
        } finally {
            stop.set(true);
            fut1.get();
        }
        stopAllGrids();
    }
}
Also used : IgniteCache(org.apache.ignite.IgniteCache) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) CyclicBarrier(java.util.concurrent.CyclicBarrier) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CacheEntryUpdatedListener(javax.cache.event.CacheEntryUpdatedListener) Ignite(org.apache.ignite.Ignite) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) QueryCursor(org.apache.ignite.cache.query.QueryCursor) Cache(javax.cache.Cache) IgniteCache(org.apache.ignite.IgniteCache)

Aggregations

CacheEntryUpdatedListener (javax.cache.event.CacheEntryUpdatedListener)16 ContinuousQuery (org.apache.ignite.cache.query.ContinuousQuery)13 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 QueryCursor (org.apache.ignite.cache.query.QueryCursor)8 Ignite (org.apache.ignite.Ignite)7 IgniteCache (org.apache.ignite.IgniteCache)6 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)6 IgniteException (org.apache.ignite.IgniteException)6 Cache (javax.cache.Cache)4 ArrayList (java.util.ArrayList)3 CacheEntryListenerException (javax.cache.event.CacheEntryListenerException)3 IgniteClientDisconnectedException (org.apache.ignite.IgniteClientDisconnectedException)3 CacheEntryEventSerializableFilter (org.apache.ignite.cache.CacheEntryEventSerializableFilter)3 AbstractContinuousQuery (org.apache.ignite.cache.query.AbstractContinuousQuery)3 ClusterNode (org.apache.ignite.cluster.ClusterNode)3 IgniteClientDisconnectedCheckedException (org.apache.ignite.internal.IgniteClientDisconnectedCheckedException)3 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)3 PA (org.apache.ignite.internal.util.typedef.PA)3 UUID (java.util.UUID)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2