use of javax.cache.event.CacheEntryListenerException in project ignite by apache.
the class CacheContinuousWithTransformerFailoverTest method testTransformerException.
/**
* @throws Exception If failed.
*/
@Test
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) {
if (log.isDebugEnabled())
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();
}
}
use of javax.cache.event.CacheEntryListenerException in project ignite by apache.
the class CacheContinuousWithTransformerReplicatedSelfTest method testTransformerReturnNull.
/**
* @throws Exception If failed.
*/
@Test
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);
}
}
use of javax.cache.event.CacheEntryListenerException in project ignite by apache.
the class PlatformUtils method evaluateContinuousQueryEvent.
/**
* Evaluate the filter.
*
* @param ctx Context.
* @param filterPtr Native filter pointer.
* @param evt Event.
* @return Result.
* @throws CacheEntryListenerException In case of failure.
*/
public static boolean evaluateContinuousQueryEvent(PlatformContext ctx, long filterPtr, CacheEntryEvent evt) throws CacheEntryListenerException {
assert filterPtr != 0;
try (PlatformMemory mem = ctx.memory().allocate()) {
PlatformOutputStream out = mem.output();
out.writeLong(filterPtr);
writeCacheEntryEvent(ctx.writer(out), evt);
out.synchronize();
return ctx.gateway().continuousQueryFilterApply(mem.pointer()) == 1;
} catch (Exception e) {
throw toCacheEntryListenerException(e);
}
}
use of javax.cache.event.CacheEntryListenerException in project ignite by apache.
the class PlatformUtils method applyContinuousQueryEvents.
/**
* Apply continuous query events to listener.
*
* @param ctx Context.
* @param lsnrPtr Listener pointer.
* @param evts Events.
* @throws javax.cache.event.CacheEntryListenerException In case of failure.
*/
public static void applyContinuousQueryEvents(PlatformContext ctx, long lsnrPtr, Iterable<CacheEntryEvent> evts) throws CacheEntryListenerException {
assert lsnrPtr != 0;
assert evts != null;
try (PlatformMemory mem = ctx.memory().allocate()) {
PlatformOutputStream out = mem.output();
BinaryRawWriterEx writer = ctx.writer(out);
writer.writeLong(lsnrPtr);
int cntPos = writer.reserveInt();
int cnt = 0;
for (CacheEntryEvent evt : evts) {
writeCacheEntryEvent(writer, evt);
cnt++;
}
writer.writeInt(cntPos, cnt);
out.synchronize();
ctx.gateway().continuousQueryListenerApply(mem.pointer());
} catch (Exception e) {
throw toCacheEntryListenerException(e);
}
}
use of javax.cache.event.CacheEntryListenerException in project ignite by apache.
the class GridCacheContinuousQueryReplicatedTxOneNodeTest method doTest.
/**
* @throws Exception If failed.
*/
private void doTest(boolean loc) throws Exception {
try {
IgniteCache<String, Integer> cache = startGrid(0).cache(DEFAULT_CACHE_NAME);
ContinuousQuery<String, Integer> qry = new ContinuousQuery<>();
final AtomicInteger cnt = new AtomicInteger();
final CountDownLatch latch = new CountDownLatch(10);
qry.setLocalListener(new CacheEntryUpdatedListener<String, Integer>() {
@Override
public void onUpdated(Iterable<CacheEntryEvent<? extends String, ? extends Integer>> evts) throws CacheEntryListenerException {
for (CacheEntryEvent<? extends String, ? extends Integer> evt : evts) {
cnt.incrementAndGet();
latch.countDown();
}
}
});
cache.query(qry.setLocal(loc));
startGrid(1);
awaitPartitionMapExchange();
for (int i = 0; i < 10; i++) cache.put("key" + i, i);
assert latch.await(5000, TimeUnit.MILLISECONDS);
assertEquals(10, cnt.get());
} finally {
stopAllGrids();
}
}
Aggregations