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