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());
}
}
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());
}
}
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());
}
}
}
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;
}
}
};
}
};
}
Aggregations