Search in sources :

Example 1 with CacheQueryEntryEvent

use of org.apache.ignite.cache.query.CacheQueryEntryEvent in project ignite by apache.

the class CacheContinuousQueryFactoryFilterRandomOperationTest method waitAndCheckEvent.

/**
     * @param evtsQueues Event queue.
     * @param partCntrs Partition counters.
     * @param aff Affinity function.
     * @param key Key.
     * @param val Value.
     * @param oldVal Old value.
     * @throws Exception If failed.
     */
private void waitAndCheckEvent(List<BlockingQueue<CacheEntryEvent<?, ?>>> evtsQueues, Map<Integer, Long> partCntrs, Affinity<Object> aff, Object key, Object val, Object oldVal) throws Exception {
    if ((val == null && oldVal == null || (val != null && !isAccepted((QueryTestValue) val)))) {
        checkNoEvent(evtsQueues);
        return;
    }
    for (BlockingQueue<CacheEntryEvent<?, ?>> evtsQueue : evtsQueues) {
        CacheEntryEvent<?, ?> evt = evtsQueue.poll(5, SECONDS);
        assertNotNull("Failed to wait for event [key=" + key + ", val=" + val + ", oldVal=" + oldVal + ']', evt);
        assertEquals(key, evt.getKey());
        assertEquals(val, evt.getValue());
        assertEquals(oldVal, evt.getOldValue());
        long cntr = partCntrs.get(aff.partition(key));
        CacheQueryEntryEvent qryEntryEvt = evt.unwrap(CacheQueryEntryEvent.class);
        assertNotNull(cntr);
        assertNotNull(qryEntryEvt);
        assertEquals(cntr, qryEntryEvt.getPartitionUpdateCounter());
    }
}
Also used : CacheQueryEntryEvent(org.apache.ignite.cache.query.CacheQueryEntryEvent) CacheEntryEvent(javax.cache.event.CacheEntryEvent)

Example 2 with CacheQueryEntryEvent

use of org.apache.ignite.cache.query.CacheQueryEntryEvent in project ignite by apache.

the class CacheContinuousQueryRandomOperationsTest method waitAndCheckEvent.

/**
     * @param evtsQueues Event queue.
     * @param partCntrs Partition counters.
     * @param aff Affinity function.
     * @param key Key.
     * @param val Value.
     * @param oldVal Old value.
     * @throws Exception If failed.
     */
private void waitAndCheckEvent(List<BlockingQueue<CacheEntryEvent<?, ?>>> evtsQueues, Map<Integer, Long> partCntrs, Map<Object, Long> evtCntrs, Affinity<Object> aff, Object key, Object val, Object oldVal) throws Exception {
    if (val == null && oldVal == null) {
        checkNoEvent(evtsQueues);
        return;
    }
    for (BlockingQueue<CacheEntryEvent<?, ?>> evtsQueue : evtsQueues) {
        CacheEntryEvent<?, ?> evt = evtsQueue.poll(5, SECONDS);
        assertNotNull("Failed to wait for event [key=" + key + ", val=" + val + ", oldVal=" + oldVal + ']', evt);
        assertEquals(key, evt.getKey());
        assertEquals(val, evt.getValue());
        assertEquals(oldVal, evt.getOldValue());
        Long curPartCntr = partCntrs.get(aff.partition(key));
        Long cntr = evtCntrs.get(key);
        CacheQueryEntryEvent qryEntryEvt = evt.unwrap(CacheQueryEntryEvent.class);
        assertNotNull(cntr);
        assertNotNull(curPartCntr);
        assertNotNull(qryEntryEvt);
        assertTrue(cntr <= curPartCntr);
        assertEquals((long) cntr, qryEntryEvt.getPartitionUpdateCounter());
    }
}
Also used : CacheQueryEntryEvent(org.apache.ignite.cache.query.CacheQueryEntryEvent) CacheEntryEvent(javax.cache.event.CacheEntryEvent)

Example 3 with CacheQueryEntryEvent

use of org.apache.ignite.cache.query.CacheQueryEntryEvent in project ignite by apache.

the class CacheContinuousQueryRandomOperationsTest method waitAndCheckEvent.

/**
     *  @param evtsQueues Queue.
     * @param partCntrs Counters.
     * @param aff Affinity.
     * @param vals Values.
     * @param expData Expected data.
     */
private void waitAndCheckEvent(List<BlockingQueue<CacheEntryEvent<?, ?>>> evtsQueues, Map<Integer, Long> partCntrs, Map<Object, Long> evtCntrs, Affinity<Object> aff, SortedMap<Object, Object> vals, Map<Object, Object> expData) throws Exception {
    for (BlockingQueue<CacheEntryEvent<?, ?>> evtsQueue : evtsQueues) {
        Map<Object, CacheEntryEvent> rcvEvts = new HashMap<>();
        for (int i = 0; i < vals.size(); i++) {
            CacheEntryEvent<?, ?> evt = evtsQueue.poll(5, SECONDS);
            rcvEvts.put(evt.getKey(), evt);
        }
        assertEquals(vals.size(), rcvEvts.size());
        for (Map.Entry<Object, Object> e : vals.entrySet()) {
            Object key = e.getKey();
            Object val = e.getValue();
            Object oldVal = expData.get(key);
            if (val == null && oldVal == null) {
                checkNoEvent(evtsQueues);
                continue;
            }
            CacheEntryEvent evt = rcvEvts.get(key);
            assertNotNull("Failed to wait for event [key=" + key + ", val=" + val + ", oldVal=" + oldVal + ']', evt);
            assertEquals(key, evt.getKey());
            assertEquals(val, evt.getValue());
            assertEquals(oldVal, evt.getOldValue());
            Long curPartCntr = partCntrs.get(aff.partition(key));
            Long cntr = evtCntrs.get(key);
            CacheQueryEntryEvent qryEntryEvt = (CacheQueryEntryEvent) evt.unwrap(CacheQueryEntryEvent.class);
            assertNotNull(cntr);
            assertNotNull(curPartCntr);
            assertNotNull(qryEntryEvt);
            assertTrue(cntr <= curPartCntr);
            assertEquals((long) cntr, qryEntryEvt.getPartitionUpdateCounter());
        }
    }
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) CacheQueryEntryEvent(org.apache.ignite.cache.query.CacheQueryEntryEvent) CacheEntryEvent(javax.cache.event.CacheEntryEvent) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SortedMap(java.util.SortedMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) TreeMap(java.util.TreeMap)

Example 4 with CacheQueryEntryEvent

use of org.apache.ignite.cache.query.CacheQueryEntryEvent in project ignite by apache.

the class CacheContinuousQueryManager method existingEntries.

/**
     * @param keepBinary Keep binary flag.
     * @param filter Filter.
     * @return Iterable for events created for existing cache entries.
     * @throws IgniteCheckedException If failed.
     */
public Iterable<CacheEntryEvent<?, ?>> existingEntries(final boolean keepBinary, final CacheEntryEventFilter filter) throws IgniteCheckedException {
    final Iterator<Cache.Entry<?, ?>> it = cctx.cache().igniteIterator(keepBinary);
    final Cache cache = cctx.kernalContext().cache().jcache(cctx.name());
    return new Iterable<CacheEntryEvent<?, ?>>() {

        @Override
        public Iterator<CacheEntryEvent<?, ?>> iterator() {
            return new Iterator<CacheEntryEvent<?, ?>>() {

                private CacheQueryEntryEvent<?, ?> next;

                {
                    advance();
                }

                @Override
                public boolean hasNext() {
                    return next != null;
                }

                @Override
                public CacheEntryEvent<?, ?> next() {
                    if (!hasNext())
                        throw new NoSuchElementException();
                    CacheEntryEvent next0 = next;
                    advance();
                    return next0;
                }

                @Override
                public void remove() {
                    throw new UnsupportedOperationException();
                }

                private void advance() {
                    next = null;
                    while (next == null) {
                        if (!it.hasNext())
                            break;
                        Cache.Entry e = it.next();
                        next = new CacheEntryEventImpl(cache, CREATED, e.getKey(), e.getValue());
                        if (filter != null && !filter.evaluate(next))
                            next = null;
                    }
                }
            };
        }
    };
}
Also used : Iterator(java.util.Iterator) CacheQueryEntryEvent(org.apache.ignite.cache.query.CacheQueryEntryEvent) CacheEntryEvent(javax.cache.event.CacheEntryEvent) NoSuchElementException(java.util.NoSuchElementException) Cache(javax.cache.Cache)

Aggregations

CacheEntryEvent (javax.cache.event.CacheEntryEvent)4 CacheQueryEntryEvent (org.apache.ignite.cache.query.CacheQueryEntryEvent)4 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 NoSuchElementException (java.util.NoSuchElementException)1 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 Cache (javax.cache.Cache)1