Search in sources :

Example 11 with CacheEntryListenerException

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

the class CacheContinuousQueryRandomOperationsTest method batchOperation.

/**
 * @param ccfg Cache configuration.
 * @throws Exception If failed.
 */
private void batchOperation(CacheConfiguration ccfg) throws Exception {
    IgniteCache<QueryTestKey, QueryTestValue> cache = grid(getClientIndex()).createCache(ccfg);
    try {
        AbstractContinuousQuery<QueryTestKey, QueryTestValue> qry = createQuery();
        final List<CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue>> evts = new CopyOnWriteArrayList<>();
        if (noOpFilterFactory() != null)
            qry.setRemoteFilterFactory(noOpFilterFactory());
        if (qry instanceof ContinuousQuery) {
            ((ContinuousQuery<QueryTestKey, QueryTestValue>) qry).setLocalListener(new CacheEntryUpdatedListener<QueryTestKey, QueryTestValue>() {

                @Override
                public void onUpdated(Iterable<CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue>> events) throws CacheEntryListenerException {
                    for (CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue> e : events) evts.add(e);
                }
            });
        } else if (qry instanceof ContinuousQueryWithTransformer)
            initQueryWithTransformer((ContinuousQueryWithTransformer<QueryTestKey, QueryTestValue, CacheEntryEvent>) qry, evts);
        else
            fail("Unknown query type");
        Map<QueryTestKey, QueryTestValue> map = new TreeMap<>();
        for (int i = 0; i < KEYS; i++) map.put(new QueryTestKey(i), new QueryTestValue(i));
        try (QueryCursor qryCur = cache.query(qry)) {
            for (int i = 0; i < ITERATION_CNT / 2; i++) {
                log.info("Start iteration: " + i);
                // Not events.
                cache.removeAll(map.keySet());
                cache.invokeAll(map.keySet(), (EntryProcessor<QueryTestKey, QueryTestValue, ? extends Object>) (Object) new EntrySetValueProcessor(null, false));
                cache.invokeAll(map.keySet(), (EntryProcessor<QueryTestKey, QueryTestValue, ? extends Object>) (Object) new EntrySetValueProcessor(true));
                // Get events.
                cache.putAll(map);
                assert GridTestUtils.waitForCondition(new PA() {

                    @Override
                    public boolean apply() {
                        return evts.size() == KEYS;
                    }
                }, 5_000);
                checkEvents(evts, CREATED);
                evts.clear();
                // Not events.
                cache.invokeAll(map.keySet(), (EntryProcessor<QueryTestKey, QueryTestValue, ? extends Object>) (Object) new EntrySetValueProcessor(true));
                U.sleep(100);
                assertEquals(0, evts.size());
                // Get events.
                cache.invokeAll(map.keySet(), (EntryProcessor<QueryTestKey, QueryTestValue, ? extends Object>) (Object) new EntrySetValueProcessor(null, false));
                // Not events.
                cache.removeAll(map.keySet());
                cache.removeAll(map.keySet());
                assert GridTestUtils.waitForCondition(new PA() {

                    @Override
                    public boolean apply() {
                        return evts.size() == KEYS;
                    }
                }, 5_000);
                checkEvents(evts, REMOVED);
                evts.clear();
                log.info("Finish iteration: " + i);
            }
        }
    } finally {
        grid(getClientIndex()).destroyCache(ccfg.getName());
    }
}
Also used : ContinuousQueryWithTransformer(org.apache.ignite.cache.query.ContinuousQueryWithTransformer) CacheEntryListenerException(javax.cache.event.CacheEntryListenerException) TreeMap(java.util.TreeMap) CacheEntryEvent(javax.cache.event.CacheEntryEvent) PA(org.apache.ignite.internal.util.typedef.PA) AbstractContinuousQuery(org.apache.ignite.cache.query.AbstractContinuousQuery) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) QueryCursor(org.apache.ignite.cache.query.QueryCursor) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 12 with CacheEntryListenerException

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

the class CacheContinuousQueryRandomOperationsTest method singleOperation.

/**
 * @param ccfg Cache configuration.
 * @throws Exception If failed.
 */
private void singleOperation(CacheConfiguration ccfg) throws Exception {
    IgniteCache<QueryTestKey, QueryTestValue> cache = grid(getClientIndex()).createCache(ccfg);
    try {
        AbstractContinuousQuery<QueryTestKey, QueryTestValue> qry = createQuery();
        final List<CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue>> evts = new CopyOnWriteArrayList<>();
        if (noOpFilterFactory() != null)
            qry.setRemoteFilterFactory(noOpFilterFactory());
        if (qry instanceof ContinuousQuery) {
            ((ContinuousQuery<QueryTestKey, QueryTestValue>) qry).setLocalListener(new CacheEntryUpdatedListener<QueryTestKey, QueryTestValue>() {

                @Override
                public void onUpdated(Iterable<CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue>> events) throws CacheEntryListenerException {
                    for (CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue> e : events) evts.add(e);
                }
            });
        } else if (qry instanceof ContinuousQueryWithTransformer)
            initQueryWithTransformer((ContinuousQueryWithTransformer<QueryTestKey, QueryTestValue, CacheEntryEvent>) qry, evts);
        else
            fail("Unknown query type");
        QueryTestKey key = new QueryTestKey(1);
        try (QueryCursor qryCur = cache.query(qry)) {
            for (int i = 0; i < ITERATION_CNT; i++) {
                log.info("Start iteration: " + i);
                // Not events.
                cache.invoke(key, (EntryProcessor<QueryTestKey, QueryTestValue, ? extends Object>) (Object) new EntrySetValueProcessor(true));
                // Get events.
                cache.put(key, new QueryTestValue(1));
                cache.remove(key);
                // Not events.
                cache.invoke(key, (EntryProcessor<QueryTestKey, QueryTestValue, ? extends Object>) (Object) new EntrySetValueProcessor(null, false));
                cache.invoke(key, (EntryProcessor<QueryTestKey, QueryTestValue, ? extends Object>) (Object) new EntrySetValueProcessor(null, false));
                cache.invoke(key, (EntryProcessor<QueryTestKey, QueryTestValue, ? extends Object>) (Object) new EntrySetValueProcessor(true));
                cache.remove(key);
                // Get events.
                cache.put(key, new QueryTestValue(2));
                // Not events.
                cache.invoke(key, (EntryProcessor<QueryTestKey, QueryTestValue, ? extends Object>) (Object) new EntrySetValueProcessor(true));
                // Get events.
                cache.invoke(key, (EntryProcessor<QueryTestKey, QueryTestValue, ? extends Object>) (Object) new EntrySetValueProcessor(null, false));
                // Not events.
                cache.remove(key);
                // Get events.
                cache.put(key, new QueryTestValue(3));
                cache.put(key, new QueryTestValue(4));
                // Not events.
                cache.invoke(key, (EntryProcessor<QueryTestKey, QueryTestValue, ? extends Object>) (Object) new EntrySetValueProcessor(true));
                cache.putIfAbsent(key, new QueryTestValue(5));
                cache.putIfAbsent(key, new QueryTestValue(5));
                cache.putIfAbsent(key, new QueryTestValue(5));
                cache.invoke(key, (EntryProcessor<QueryTestKey, QueryTestValue, ? extends Object>) (Object) new EntrySetValueProcessor(true));
                cache.remove(key, new QueryTestValue(5));
                // Get events.
                cache.remove(key, new QueryTestValue(4));
                cache.putIfAbsent(key, new QueryTestValue(5));
                // Not events.
                cache.replace(key, new QueryTestValue(3), new QueryTestValue(2));
                cache.replace(key, new QueryTestValue(3), new QueryTestValue(2));
                cache.replace(key, new QueryTestValue(3), new QueryTestValue(2));
                // Get events.
                cache.replace(key, new QueryTestValue(5), new QueryTestValue(6));
                assert GridTestUtils.waitForCondition(new PA() {

                    @Override
                    public boolean apply() {
                        return evts.size() == 9;
                    }
                }, 5_000);
                checkSingleEvent(evts.get(0), CREATED, new QueryTestValue(1), null);
                checkSingleEvent(evts.get(1), REMOVED, new QueryTestValue(1), new QueryTestValue(1));
                checkSingleEvent(evts.get(2), CREATED, new QueryTestValue(2), null);
                checkSingleEvent(evts.get(3), REMOVED, new QueryTestValue(2), new QueryTestValue(2));
                checkSingleEvent(evts.get(4), CREATED, new QueryTestValue(3), null);
                checkSingleEvent(evts.get(5), EventType.UPDATED, new QueryTestValue(4), new QueryTestValue(3));
                checkSingleEvent(evts.get(6), REMOVED, new QueryTestValue(4), new QueryTestValue(4));
                checkSingleEvent(evts.get(7), CREATED, new QueryTestValue(5), null);
                checkSingleEvent(evts.get(8), EventType.UPDATED, new QueryTestValue(6), new QueryTestValue(5));
                evts.clear();
                cache.remove(key);
                cache.remove(key);
                assert GridTestUtils.waitForCondition(new PA() {

                    @Override
                    public boolean apply() {
                        return evts.size() == 1;
                    }
                }, 5_000);
                evts.clear();
                log.info("Finish iteration: " + i);
            }
        }
    } finally {
        grid(getClientIndex()).destroyCache(ccfg.getName());
    }
}
Also used : ContinuousQueryWithTransformer(org.apache.ignite.cache.query.ContinuousQueryWithTransformer) CacheEntryListenerException(javax.cache.event.CacheEntryListenerException) CacheEntryEvent(javax.cache.event.CacheEntryEvent) PA(org.apache.ignite.internal.util.typedef.PA) AbstractContinuousQuery(org.apache.ignite.cache.query.AbstractContinuousQuery) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) QueryCursor(org.apache.ignite.cache.query.QueryCursor) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 13 with CacheEntryListenerException

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

the class CacheContinuousBatchAckTest method checkBackupAcknowledgeMessage.

/**
 * @param ccfg Cache configuration.
 * @throws Exception If failed.
 */
private void checkBackupAcknowledgeMessage(CacheConfiguration<Object, Object> ccfg) throws Exception {
    QueryCursor qry = null;
    IgniteCache<Object, Object> cache = null;
    try {
        ContinuousQuery q = new ContinuousQuery();
        q.setLocalListener(new CacheEntryUpdatedListener() {

            @Override
            public void onUpdated(Iterable iterable) throws CacheEntryListenerException {
            // No-op.
            }
        });
        cache = grid(SERVER).getOrCreateCache(ccfg);
        qry = cache.query(q);
        for (int i = 0; i < GridTestUtils.SF.applyLB(10000, 1000); i++) cache.put(i, i);
        assertFalse(GridTestUtils.waitForCondition(fail::get, 1300L));
    } finally {
        if (qry != null)
            qry.close();
        if (cache != null)
            grid(SERVER).destroyCache(cache.getName());
    }
}
Also used : ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) CacheEntryUpdatedListener(javax.cache.event.CacheEntryUpdatedListener) CacheEntryListenerException(javax.cache.event.CacheEntryListenerException) QueryCursor(org.apache.ignite.cache.query.QueryCursor)

Example 14 with CacheEntryListenerException

use of javax.cache.event.CacheEntryListenerException 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() != ATOMIC);
        }
        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)

Example 15 with CacheEntryListenerException

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

the class CacheContinuousQueryRandomOperationsTest method testFilterAndFactoryProvided.

/**
 * @throws Exception If failed.
 */
@Test
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) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

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