use of javax.cache.CacheManager 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.CacheManager in project hazelcast by hazelcast.
the class CacheIteratorAbstractTest method getCache.
private Cache<Integer, Integer> getCache() {
String cacheName = randomString();
CacheManager cacheManager = cachingProvider.getCacheManager();
CacheConfig<Integer, Integer> config = new CacheConfig<Integer, Integer>();
return cacheManager.createCache(cacheName, config);
}
use of javax.cache.CacheManager in project hazelcast by hazelcast.
the class CacheListenerTest method testReplaceIfSameWithSyncListener_whenEntryNotExists.
@Test(timeout = 30000)
public void testReplaceIfSameWithSyncListener_whenEntryNotExists() {
CachingProvider cachingProvider = getCachingProvider();
CacheManager cacheManager = cachingProvider.getCacheManager();
CompleteConfiguration<String, String> config = new MutableConfiguration<String, String>().setTypes(String.class, String.class).addCacheEntryListenerConfiguration(new MutableCacheEntryListenerConfiguration<String, String>(FactoryBuilder.factoryOf(new TestListener(new AtomicInteger())), null, true, true));
Cache<String, String> cache = cacheManager.createCache(randomString(), config);
// there should not be any hanging due to sync listener
cache.replace(randomString(), randomString(), randomString());
}
use of javax.cache.CacheManager in project hazelcast by hazelcast.
the class CacheListenerTest method testRemoveWithSyncListener_whenEntryNotExists.
@Test(timeout = 30000)
public void testRemoveWithSyncListener_whenEntryNotExists() {
CachingProvider cachingProvider = getCachingProvider();
CacheManager cacheManager = cachingProvider.getCacheManager();
CompleteConfiguration<String, String> config = new MutableConfiguration<String, String>().setTypes(String.class, String.class).addCacheEntryListenerConfiguration(new MutableCacheEntryListenerConfiguration<String, String>(FactoryBuilder.factoryOf(new TestListener(new AtomicInteger())), null, true, true));
Cache<String, String> cache = cacheManager.createCache(randomString(), config);
// there should not be any hanging due to sync listener
cache.remove(randomString());
}
use of javax.cache.CacheManager in project hazelcast by hazelcast.
the class CacheListenerTest method testSyncListener_shouldNotHang_AfterAction.
private void testSyncListener_shouldNotHang_AfterAction(String cacheName, CachingProvider provider, Runnable action) {
CacheManager cacheManager = provider.getCacheManager();
CompleteConfiguration<String, String> config = new MutableConfiguration<String, String>().addCacheEntryListenerConfiguration(new MutableCacheEntryListenerConfiguration<String, String>(FactoryBuilder.factoryOf(new TestListener(new AtomicInteger())), null, true, true));
final Cache<String, String> cache = cacheManager.createCache(cacheName, config);
int threads = 4;
final CountDownLatch latch = new CountDownLatch(threads);
for (int i = 0; i < threads; i++) {
new Thread() {
public void run() {
Random rand = new Random();
while (true) {
try {
cache.put(String.valueOf(rand.nextInt(100)), "value");
} catch (Throwable e) {
break;
}
}
latch.countDown();
}
}.start();
}
// wait a little for putting threads to start
sleepSeconds(3);
action.run();
assertOpenEventually("Cache operations should not hang when sync listener is present!", latch);
}
Aggregations