Search in sources :

Example 6 with CacheEntryEventSerializableFilter

use of org.apache.ignite.cache.CacheEntryEventSerializableFilter in project ignite by apache.

the class CacheContinuousQueryRandomOperationsTest method testFilterAndFactoryProvided.

/**
 * @throws Exception If failed.
 */
public void testFilterAndFactoryProvided() throws Exception {
    final CacheConfiguration<Object, Object> ccfg = cacheConfiguration(PARTITIONED, 1, ATOMIC, false);
    grid(0).createCache(ccfg);
    try {
        final ContinuousQuery qry = new ContinuousQuery();
        qry.setRemoteFilterFactory(new Factory<CacheEntryEventFilter>() {

            @Override
            public CacheEntryEventFilter create() {
                return null;
            }
        });
        qry.setRemoteFilter(new CacheEntryEventSerializableFilter() {

            @Override
            public boolean evaluate(CacheEntryEvent event) throws CacheEntryListenerException {
                return false;
            }
        });
        qry.setLocalListener(new CacheEntryUpdatedListener() {

            @Override
            public void onUpdated(Iterable iterable) throws CacheEntryListenerException {
            // No-op.
            }
        });
        GridTestUtils.assertThrows(log, new Callable<Object>() {

            @Override
            public Object call() throws Exception {
                return grid(0).cache(ccfg.getName()).query(qry);
            }
        }, IgniteException.class, null);
    } finally {
        grid(0).destroyCache(ccfg.getName());
    }
}
Also used : CacheEntryEventSerializableFilter(org.apache.ignite.cache.CacheEntryEventSerializableFilter) CacheEntryEventFilter(javax.cache.event.CacheEntryEventFilter) CacheEntryListenerException(javax.cache.event.CacheEntryListenerException) CacheEntryEvent(javax.cache.event.CacheEntryEvent) IgniteException(org.apache.ignite.IgniteException) CacheWriterException(javax.cache.integration.CacheWriterException) CacheEntryListenerException(javax.cache.event.CacheEntryListenerException) CacheLoaderException(javax.cache.integration.CacheLoaderException) AbstractContinuousQuery(org.apache.ignite.cache.query.AbstractContinuousQuery) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) CacheEntryUpdatedListener(javax.cache.event.CacheEntryUpdatedListener)

Example 7 with CacheEntryEventSerializableFilter

use of org.apache.ignite.cache.CacheEntryEventSerializableFilter in project ignite by apache.

the class CacheContinuousWithTransformerFailoverTest method testTransformerException.

/**
 * @throws Exception If failed.
 */
public void testTransformerException() throws Exception {
    try {
        startGrids(1);
        Ignite ignite = ignite(0);
        IgniteCache<Integer, Integer> cache = ignite.cache(DEFAULT_CACHE_NAME);
        final CountDownLatch latch = new CountDownLatch(10);
        ContinuousQueryWithTransformer<Integer, Integer, Integer> qry = new ContinuousQueryWithTransformer<>();
        qry.setLocalListener(new EventListener<Integer>() {

            /**
             */
            @LoggerResource
            private IgniteLogger log;

            @Override
            public void onUpdated(Iterable<? extends Integer> evts) throws CacheEntryListenerException {
                for (Integer evt : evts) {
                    log.debug("" + evt);
                }
            }
        });
        qry.setRemoteTransformerFactory(FactoryBuilder.factoryOf(new IgniteClosure<CacheEntryEvent<? extends Integer, ? extends Integer>, Integer>() {

            @Override
            public Integer apply(CacheEntryEvent<? extends Integer, ? extends Integer> evt) {
                latch.countDown();
                throw new RuntimeException("Test error.");
            }
        }));
        qry.setRemoteFilterFactory(FactoryBuilder.factoryOf(new CacheEntryEventSerializableFilter<Integer, Integer>() {

            @Override
            public boolean evaluate(CacheEntryEvent<? extends Integer, ? extends Integer> evt) {
                return true;
            }
        }));
        try (QueryCursor<Cache.Entry<Integer, Integer>> ignored = cache.query(qry)) {
            for (int i = 0; i < 10; i++) cache.put(i, i);
            assertTrue(latch.await(10, SECONDS));
        }
    } finally {
        stopAllGrids();
    }
}
Also used : LoggerResource(org.apache.ignite.resources.LoggerResource) ContinuousQueryWithTransformer(org.apache.ignite.cache.query.ContinuousQueryWithTransformer) CacheEntryEventSerializableFilter(org.apache.ignite.cache.CacheEntryEventSerializableFilter) IgniteClosure(org.apache.ignite.lang.IgniteClosure) CountDownLatch(java.util.concurrent.CountDownLatch) CacheEntryListenerException(javax.cache.event.CacheEntryListenerException) CacheEntryEvent(javax.cache.event.CacheEntryEvent) Ignite(org.apache.ignite.Ignite) IgniteLogger(org.apache.ignite.IgniteLogger)

Example 8 with CacheEntryEventSerializableFilter

use of org.apache.ignite.cache.CacheEntryEventSerializableFilter in project ignite by apache.

the class CacheContinuousWithTransformerReplicatedSelfTest method testTransformerReturnNull.

/**
 * @throws Exception If failed.
 */
public void testTransformerReturnNull() throws Exception {
    Ignite ignite = gridToRunQuery();
    IgniteCache<Integer, Employee> cache = ignite.cache(DEFAULT_CACHE_NAME);
    ContinuousQueryWithTransformer<Integer, Employee, String> qry = new ContinuousQueryWithTransformer<>();
    final AtomicInteger cnt = new AtomicInteger(0);
    qry.setLocalListener(new EventListener() {

        @Override
        public void onUpdated(Iterable events) throws CacheEntryListenerException {
            for (Object e : events) {
                assertNull(e);
                cnt.incrementAndGet();
            }
        }
    });
    qry.setRemoteTransformerFactory(FactoryBuilder.factoryOf(new IgniteClosure<CacheEntryEvent<? extends Integer, ? extends Employee>, String>() {

        @Override
        public String apply(CacheEntryEvent<? extends Integer, ? extends Employee> evt) {
            return null;
        }
    }));
    qry.setRemoteFilterFactory(FactoryBuilder.factoryOf(new CacheEntryEventSerializableFilter<Integer, Employee>() {

        @Override
        public boolean evaluate(CacheEntryEvent<? extends Integer, ? extends Employee> evt) {
            return true;
        }
    }));
    try (QueryCursor<Cache.Entry<Integer, Employee>> ignored = cache.query(qry)) {
        for (int i = 0; i < 10; i++) cache.put(i, new Employee(JOHN_CONNOR, i));
        boolean evtsReceived = GridTestUtils.waitForCondition(new GridAbsPredicate() {

            @Override
            public boolean apply() {
                return cnt.get() == 10;
            }
        }, 20_000);
        assertTrue(evtsReceived);
    }
}
Also used : ContinuousQueryWithTransformer(org.apache.ignite.cache.query.ContinuousQueryWithTransformer) CacheEntryEventSerializableFilter(org.apache.ignite.cache.CacheEntryEventSerializableFilter) IgniteClosure(org.apache.ignite.lang.IgniteClosure) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) CacheEntryListenerException(javax.cache.event.CacheEntryListenerException) CacheEntryEvent(javax.cache.event.CacheEntryEvent) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Ignite(org.apache.ignite.Ignite) BinaryObject(org.apache.ignite.binary.BinaryObject) EventListener(org.apache.ignite.cache.query.ContinuousQueryWithTransformer.EventListener)

Example 9 with CacheEntryEventSerializableFilter

use of org.apache.ignite.cache.CacheEntryEventSerializableFilter in project ignite by apache.

the class CacheContinuousWithTransformerReplicatedSelfTest method testExpired.

/**
 * @throws Exception If failed.
 */
public void testExpired() throws Exception {
    Ignite ignite = gridToRunQuery();
    IgniteCache<Integer, Employee> cache = ignite.cache(DEFAULT_CACHE_NAME);
    cache = cache.withExpiryPolicy(new CreatedExpiryPolicy(new Duration(MILLISECONDS, 100)));
    final Set<Integer> keys = new GridConcurrentHashSet<>();
    final CountDownLatch latch = new CountDownLatch(2);
    ContinuousQueryWithTransformer<Integer, Employee, Integer> qry = new ContinuousQueryWithTransformer<>();
    qry.setIncludeExpired(true);
    qry.setRemoteFilterFactory(FactoryBuilder.factoryOf(new CacheEntryEventSerializableFilter<Integer, Employee>() {

        @Override
        public boolean evaluate(CacheEntryEvent event) throws CacheEntryListenerException {
            return event.getEventType() == EventType.EXPIRED;
        }
    }));
    qry.setRemoteTransformerFactory(FactoryBuilder.factoryOf(new IgniteClosure<CacheEntryEvent<? extends Integer, ? extends Employee>, Integer>() {

        @Override
        public Integer apply(CacheEntryEvent<? extends Integer, ? extends Employee> evt) {
            assertNull(evt.getValue());
            assertNotNull(evt.getOldValue());
            return evt.getKey();
        }
    }));
    qry.setLocalListener(new EventListener<Integer>() {

        @Override
        public void onUpdated(Iterable<? extends Integer> evts) {
            for (Integer key : evts) {
                keys.add(key);
                latch.countDown();
            }
        }
    });
    try (QueryCursor<Cache.Entry<Integer, Employee>> ignored = cache.query(qry)) {
        cache.put(1, new Employee(SARAH_CONNOR, 42));
        cache.put(2, new Employee(JOHN_CONNOR, 42));
        // Wait for expiration.
        latch.await(LATCH_TIMEOUT, MILLISECONDS);
        assertEquals(2, keys.size());
        assertTrue(keys.contains(1));
        assertTrue(keys.contains(2));
    }
}
Also used : ContinuousQueryWithTransformer(org.apache.ignite.cache.query.ContinuousQueryWithTransformer) CacheEntryEventSerializableFilter(org.apache.ignite.cache.CacheEntryEventSerializableFilter) IgniteClosure(org.apache.ignite.lang.IgniteClosure) Duration(javax.cache.expiry.Duration) CreatedExpiryPolicy(javax.cache.expiry.CreatedExpiryPolicy) CountDownLatch(java.util.concurrent.CountDownLatch) CacheEntryEvent(javax.cache.event.CacheEntryEvent) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GridConcurrentHashSet(org.apache.ignite.internal.util.GridConcurrentHashSet) Ignite(org.apache.ignite.Ignite)

Example 10 with CacheEntryEventSerializableFilter

use of org.apache.ignite.cache.CacheEntryEventSerializableFilter in project ignite by apache.

the class CacheContinuousQueryExecuteInPrimaryTest method doTestWithoutEventsEntries.

/**
 * @throws Exception If failed.
 */
private void doTestWithoutEventsEntries(CacheConfiguration<Integer, String> ccfg) throws Exception {
    try (IgniteCache<Integer, String> cache = grid(0).createCache(ccfg)) {
        int ITERATION_CNT = 100;
        final AtomicBoolean noOneListen = new AtomicBoolean(true);
        for (int i = 0; i < ITERATION_CNT; i++) {
            ContinuousQuery<Integer, String> qry = new ContinuousQuery<>();
            qry.setLocalListener(new CacheEntryUpdatedListener<Integer, String>() {

                @Override
                public void onUpdated(Iterable<CacheEntryEvent<? extends Integer, ? extends String>> iterable) throws CacheEntryListenerException {
                    noOneListen.set(false);
                }
            });
            qry.setRemoteFilterFactory(FactoryBuilder.factoryOf(new CacheEntryEventSerializableFilter<Integer, String>() {

                @Override
                public boolean evaluate(CacheEntryEvent<? extends Integer, ? extends String> cacheEntryEvent) throws CacheEntryListenerException {
                    return false;
                }
            }));
            executeQuery(cache, qry, ccfg.getAtomicityMode() == TRANSACTIONAL);
        }
        assertTrue(noOneListen.get());
    } finally {
        ignite(0).destroyCache(ccfg.getName());
    }
}
Also used : CacheEntryEventSerializableFilter(org.apache.ignite.cache.CacheEntryEventSerializableFilter) CacheEntryListenerException(javax.cache.event.CacheEntryListenerException) CacheEntryEvent(javax.cache.event.CacheEntryEvent) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery)

Aggregations

CacheEntryEventSerializableFilter (org.apache.ignite.cache.CacheEntryEventSerializableFilter)10 CacheEntryEvent (javax.cache.event.CacheEntryEvent)8 CacheEntryListenerException (javax.cache.event.CacheEntryListenerException)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 Ignite (org.apache.ignite.Ignite)4 ContinuousQuery (org.apache.ignite.cache.query.ContinuousQuery)4 ContinuousQueryWithTransformer (org.apache.ignite.cache.query.ContinuousQueryWithTransformer)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 IgniteClosure (org.apache.ignite.lang.IgniteClosure)3 CacheEntryEventFilter (javax.cache.event.CacheEntryEventFilter)2 CacheEntryUpdatedListener (javax.cache.event.CacheEntryUpdatedListener)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 IgniteException (org.apache.ignite.IgniteException)2 BinaryObject (org.apache.ignite.binary.BinaryObject)2 AbstractContinuousQuery (org.apache.ignite.cache.query.AbstractContinuousQuery)2 EventListener (org.apache.ignite.cache.query.ContinuousQueryWithTransformer.EventListener)2 ClusterNode (org.apache.ignite.cluster.ClusterNode)2 Map (java.util.Map)1 UUID (java.util.UUID)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1