use of javax.cache.configuration.MutableCacheEntryListenerConfiguration in project hazelcast by hazelcast.
the class CacheBasicAbstractTest method testRemovingSameEntryTwiceShouldTriggerEntryListenerOnlyOnce.
@Test
public void testRemovingSameEntryTwiceShouldTriggerEntryListenerOnlyOnce() {
String cacheName = randomString();
CacheConfig<Integer, String> config = createCacheConfig();
final CacheFromDifferentNodesTest.SimpleEntryListener<Integer, String> listener = new CacheFromDifferentNodesTest.SimpleEntryListener<Integer, String>();
MutableCacheEntryListenerConfiguration<Integer, String> listenerConfiguration = new MutableCacheEntryListenerConfiguration<Integer, String>(FactoryBuilder.factoryOf(listener), null, true, true);
config.addCacheEntryListenerConfiguration(listenerConfiguration);
Cache<Integer, String> cache = cacheManager.createCache(cacheName, config);
assertNotNull(cache);
Integer key = 1;
String value = "value";
cache.put(key, value);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(1, listener.created.get());
}
});
cache.removeAll();
cache.removeAll();
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(1, listener.removed.get());
}
});
}
use of javax.cache.configuration.MutableCacheEntryListenerConfiguration in project hazelcast by hazelcast.
the class CacheBasicAbstractTest method testCompletionEvent.
@Test
public void testCompletionEvent() {
String cacheName = randomString();
CacheConfig<Integer, String> config = createCacheConfig();
final CacheFromDifferentNodesTest.SimpleEntryListener<Integer, String> listener = new CacheFromDifferentNodesTest.SimpleEntryListener<Integer, String>();
MutableCacheEntryListenerConfiguration<Integer, String> listenerConfiguration = new MutableCacheEntryListenerConfiguration<Integer, String>(FactoryBuilder.factoryOf(listener), null, true, true);
config.addCacheEntryListenerConfiguration(listenerConfiguration);
Cache<Integer, String> cache = cacheManager.createCache(cacheName, config);
assertNotNull(cache);
Integer key1 = 1;
String value1 = "value1";
cache.put(key1, value1);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(1, listener.created.get());
}
});
Integer key2 = 2;
String value2 = "value2";
cache.put(key2, value2);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(2, listener.created.get());
}
});
Set<Integer> keys = new HashSet<Integer>();
keys.add(key1);
keys.add(key2);
cache.removeAll(keys);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(2, listener.removed.get());
}
});
}
use of javax.cache.configuration.MutableCacheEntryListenerConfiguration in project hazelcast by hazelcast.
the class CacheFromDifferentNodesTest method testCompletionTestByPuttingAndRemovingFromDifferentNodes.
// Issue https://github.com/hazelcast/hazelcast/issues/5865
@Test
public void testCompletionTestByPuttingAndRemovingFromDifferentNodes() throws InterruptedException {
String cacheName = "simpleCache";
CacheManager cacheManager1 = cachingProvider1.getCacheManager();
CacheManager cacheManager2 = cachingProvider2.getCacheManager();
CacheConfig<Integer, String> config = new CacheConfig<Integer, String>();
final SimpleEntryListener<Integer, String> listener = new SimpleEntryListener<Integer, String>();
MutableCacheEntryListenerConfiguration<Integer, String> listenerConfiguration = new MutableCacheEntryListenerConfiguration<Integer, String>(FactoryBuilder.factoryOf(listener), null, true, true);
config.addCacheEntryListenerConfiguration(listenerConfiguration);
Cache<Integer, String> cache1 = cacheManager1.createCache(cacheName, config);
Cache<Integer, String> cache2 = cacheManager2.getCache(cacheName);
assertNotNull(cache1);
assertNotNull(cache2);
Integer key1 = 1;
String value1 = "value1";
cache1.put(key1, value1);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(1, listener.created.get());
}
});
Integer key2 = 2;
String value2 = "value2";
cache1.put(key2, value2);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(2, listener.created.get());
}
});
Set<Integer> keys = new HashSet<Integer>();
keys.add(key1);
keys.add(key2);
cache2.removeAll(keys);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(2, listener.removed.get());
}
});
}
use of javax.cache.configuration.MutableCacheEntryListenerConfiguration in project ignite by apache.
the class IgniteCacheEntryListenerExpiredEventsTest method checkExpiredEvents.
/**
* @param ccfg Cache configuration.
* @throws Exception If failed.
*/
private void checkExpiredEvents(CacheConfiguration<Object, Object> ccfg) throws Exception {
IgniteCache<Object, Object> cache = ignite(0).createCache(ccfg);
try {
evtCntr = new AtomicInteger();
CacheEntryListenerConfiguration<Object, Object> lsnrCfg = new MutableCacheEntryListenerConfiguration<>(new ExpiredListenerFactory(), null, true, false);
cache.registerCacheEntryListener(lsnrCfg);
IgniteCache<Object, Object> expiryCache = cache.withExpiryPolicy(new ModifiedExpiryPolicy(new Duration(MILLISECONDS, 500)));
expiryCache.put(1, 1);
for (int i = 0; i < 10; i++) cache.get(i);
boolean wait = GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return evtCntr.get() > 0;
}
}, 5000);
assertTrue(wait);
U.sleep(100);
assertEquals(1, evtCntr.get());
} finally {
ignite(0).destroyCache(cache.getName());
}
}
use of javax.cache.configuration.MutableCacheEntryListenerConfiguration in project ignite by apache.
the class GridCacheReplicatedPreloadSelfTest method testExternalClassesAtConfiguration.
/**
* @throws Exception If test failed.
*/
public void testExternalClassesAtConfiguration() throws Exception {
try {
extClassloadingAtCfg = true;
useExtClassLoader = true;
Ignite g1 = startGrid(1);
// Checks deserialization at node join.
Ignite g2 = startGrid(2);
isClient = true;
Ignite g3 = startGrid(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;
isClient = false;
useExtClassLoader = false;
}
}
Aggregations