use of org.apache.ignite.cache.CacheEntryEventSerializableFilter 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 org.apache.ignite.cache.CacheEntryEventSerializableFilter in project ignite by apache.
the class CacheContinuousWithTransformerReplicatedSelfTest method testExpired.
/**
* @throws Exception If failed.
*/
@Test
public void testExpired() throws Exception {
Ignite ignite = gridToRunQuery();
IgniteCache<Integer, Employee> cache = ignite.cache(DEFAULT_CACHE_NAME);
cache = cache.withExpiryPolicy(new CreatedExpiryPolicy(new Duration(MILLISECONDS, 100)));
final Set<Integer> keys = new GridConcurrentHashSet<>();
final CountDownLatch latch = new CountDownLatch(2);
ContinuousQueryWithTransformer<Integer, Employee, Integer> qry = new ContinuousQueryWithTransformer<>();
qry.setIncludeExpired(true);
qry.setRemoteFilterFactory(FactoryBuilder.factoryOf(new CacheEntryEventSerializableFilter<Integer, Employee>() {
@Override
public boolean evaluate(CacheEntryEvent event) throws CacheEntryListenerException {
return event.getEventType() == EventType.EXPIRED;
}
}));
qry.setRemoteTransformerFactory(FactoryBuilder.factoryOf(new IgniteClosure<CacheEntryEvent<? extends Integer, ? extends Employee>, Integer>() {
@Override
public Integer apply(CacheEntryEvent<? extends Integer, ? extends Employee> evt) {
assertNotNull(evt.getValue());
assertNotNull(evt.getOldValue());
return evt.getKey();
}
}));
qry.setLocalListener(new EventListener<Integer>() {
@Override
public void onUpdated(Iterable<? extends Integer> evts) {
for (Integer key : evts) {
keys.add(key);
latch.countDown();
}
}
});
try (QueryCursor<Cache.Entry<Integer, Employee>> ignored = cache.query(qry)) {
cache.put(1, new Employee(SARAH_CONNOR, 42));
cache.put(2, new Employee(JOHN_CONNOR, 42));
// Wait for expiration.
latch.await(LATCH_TIMEOUT, MILLISECONDS);
assertEquals(2, keys.size());
assertTrue(keys.contains(1));
assertTrue(keys.contains(2));
}
}
use of org.apache.ignite.cache.CacheEntryEventSerializableFilter 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 org.apache.ignite.cache.CacheEntryEventSerializableFilter in project ignite by apache.
the class GridCacheReplicatedPreloadSelfTest method testExternalClassesAtConfiguration.
/**
* @throws Exception If test failed.
*/
@Test
public void testExternalClassesAtConfiguration() throws Exception {
try {
extClassloadingAtCfg = true;
useExtClassLoader = true;
Ignite g1 = startGrid(1);
// Checks deserialization at node join.
Ignite g2 = startGrid(2);
Ignite g3 = startClientGrid(3);
IgniteCache<Integer, Object> cache1 = g1.cache(DEFAULT_CACHE_NAME);
IgniteCache<Integer, Object> cache2 = g2.cache(DEFAULT_CACHE_NAME);
IgniteCache<Integer, Object> cache3 = g3.cache(DEFAULT_CACHE_NAME);
final Class<CacheEntryListener> cls1 = (Class<CacheEntryListener>) getExternalClassLoader().loadClass("org.apache.ignite.tests.p2p.CacheDeploymentCacheEntryListener");
final Class<CacheEntryEventSerializableFilter> cls2 = (Class<CacheEntryEventSerializableFilter>) getExternalClassLoader().loadClass("org.apache.ignite.tests.p2p.CacheDeploymentCacheEntryEventSerializableFilter");
CacheEntryListenerConfiguration<Integer, Object> lsnrCfg = new MutableCacheEntryListenerConfiguration<>(new Factory<CacheEntryListener<Integer, Object>>() {
@Override
public CacheEntryListener<Integer, Object> create() {
try {
return cls1.newInstance();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}, new ClassFilterFactory(cls2), true, true);
cache1.registerCacheEntryListener(lsnrCfg);
cache1.put(1, 1);
assertEquals(1, cache2.get(1));
assertEquals(1, cache3.get(1));
} finally {
extClassloadingAtCfg = false;
useExtClassLoader = false;
}
}
use of org.apache.ignite.cache.CacheEntryEventSerializableFilter in project ignite by apache.
the class CacheEntryListenersTest method testListenersUnsupportedParameters.
/**
*/
@Test
@SuppressWarnings({ "ThrowableNotThrown", "deprecation" })
public void testListenersUnsupportedParameters() throws Exception {
try (IgniteClient client = startClient(0, 1, 2)) {
ClientCache<Integer, Integer> cache = client.getOrCreateCache("testUnsupportedParams");
// Check null listener factory.
CacheEntryListenerConfiguration<Integer, Integer> lsnrCfg1 = new MutableCacheEntryListenerConfiguration<>(null, null, true, false);
assertThrowsWithCause(() -> cache.registerCacheEntryListener(lsnrCfg1), NullPointerException.class);
// Check synchronous flag.
CacheEntryListenerConfiguration<Integer, Integer> lsnrCfg2 = new MutableCacheEntryListenerConfiguration<>(JCacheEntryListener::new, null, true, true);
assertThrowsWithCause(() -> cache.registerCacheEntryListener(lsnrCfg2), IllegalArgumentException.class);
// Check local flag.
ContinuousQueryListener<Integer, Integer> cqLsnr = new ContinuousQueryListener<>();
ContinuousQuery<Integer, Integer> qry1 = new ContinuousQuery<Integer, Integer>().setLocalListener(cqLsnr).setLocal(true);
assertThrowsWithCause(() -> cache.query(qry1), IllegalArgumentException.class);
// Check null listener.
ContinuousQuery<Integer, Integer> qry2 = new ContinuousQuery<>();
assertThrowsWithCause(() -> cache.query(qry2), NullPointerException.class);
// Check auto unsubscribe flag.
ContinuousQuery<Integer, Integer> qry3 = new ContinuousQuery<Integer, Integer>().setLocalListener(cqLsnr).setAutoUnsubscribe(false);
assertThrowsWithCause(() -> cache.query(qry3), IllegalArgumentException.class);
// Check continuous query as initial query.
ContinuousQuery<Integer, Integer> qry4 = new ContinuousQuery<Integer, Integer>().setLocalListener(cqLsnr).setInitialQuery(new ContinuousQuery<>());
assertThrowsWithCause(() -> cache.query(qry4), IllegalArgumentException.class);
// Check filter factory and filter defined at the same time.
CacheEntryEventSerializableFilter<Integer, Integer> rmtFilter = r -> true;
ContinuousQuery<Integer, Integer> qry5 = new ContinuousQuery<Integer, Integer>().setLocalListener(cqLsnr).setRemoteFilter(rmtFilter);
qry5.setRemoteFilterFactory(FactoryBuilder.factoryOf(rmtFilter));
assertThrowsWithCause(() -> cache.query(qry5), IllegalArgumentException.class);
}
}
Aggregations