use of javax.cache.configuration.MutableConfiguration in project hazelcast by hazelcast.
the class CacheContextTest method cacheEntryListenerCountIncreasedAndDecreasedCorrectly.
protected void cacheEntryListenerCountIncreasedAndDecreasedCorrectly(DecreaseType decreaseType) {
CacheManager cacheManager = provider.getCacheManager();
CacheEntryListenerConfiguration<String, String> cacheEntryListenerConfig = new MutableCacheEntryListenerConfiguration<String, String>(FactoryBuilder.factoryOf(new TestListener()), null, true, true);
CompleteConfiguration<String, String> cacheConfig = new MutableConfiguration<String, String>();
Cache<String, String> cache = cacheManager.createCache(CACHE_NAME, cacheConfig);
cache.registerCacheEntryListener(cacheEntryListenerConfig);
final CacheService cacheService1 = getCacheService(hazelcastInstance1);
final CacheService cacheService2 = getCacheService(hazelcastInstance2);
assertTrueEventually(new AssertTask() {
@Override
public void run() {
assertNotNull(cacheService1.getCacheContext(CACHE_NAME_WITH_PREFIX));
}
});
assertTrueEventually(new AssertTask() {
@Override
public void run() {
assertNotNull(cacheService2.getCacheContext(CACHE_NAME_WITH_PREFIX));
}
});
final CacheContext cacheContext1 = cacheService1.getCacheContext(CACHE_NAME_WITH_PREFIX);
final CacheContext cacheContext2 = cacheService2.getCacheContext(CACHE_NAME_WITH_PREFIX);
assertTrueEventually(new AssertTask() {
@Override
public void run() {
assertEquals(1, cacheContext1.getCacheEntryListenerCount());
}
});
assertTrueEventually(new AssertTask() {
@Override
public void run() {
assertEquals(1, cacheContext2.getCacheEntryListenerCount());
}
});
switch(decreaseType) {
case DEREGISTER:
cache.deregisterCacheEntryListener(cacheEntryListenerConfig);
break;
case SHUTDOWN:
driverInstance.getLifecycleService().shutdown();
break;
case TERMINATE:
driverInstance.getLifecycleService().terminate();
break;
default:
throw new IllegalArgumentException("Unsupported decrease type: " + decreaseType);
}
assertTrueEventually(new AssertTask() {
@Override
public void run() {
assertEquals(0, cacheContext1.getCacheEntryListenerCount());
}
});
assertTrueEventually(new AssertTask() {
@Override
public void run() {
assertEquals(0, cacheContext2.getCacheEntryListenerCount());
}
});
}
use of javax.cache.configuration.MutableConfiguration in project hazelcast by hazelcast.
the class CacheFromDifferentNodesTest method testCachesDestroy.
@Test
public void testCachesDestroy() {
CacheManager cacheManager = cachingProvider1.getCacheManager();
CacheManager cacheManager2 = cachingProvider2.getCacheManager();
MutableConfiguration configuration = new MutableConfiguration();
final Cache c1 = cacheManager.createCache("c1", configuration);
final Cache c2 = cacheManager2.getCache("c1");
c1.put("key", "value");
cacheManager.destroyCache("c1");
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
try {
c2.get("key");
throw new AssertionError("get should throw IllegalStateException");
} catch (IllegalStateException e) {
// ignored as expected
}
}
});
}
use of javax.cache.configuration.MutableConfiguration in project hazelcast by hazelcast.
the class CacheFromDifferentNodesTest method testCachesDestroyFromOtherManagers.
@Test
public void testCachesDestroyFromOtherManagers() {
CacheManager cacheManager = cachingProvider1.getCacheManager();
CacheManager cacheManager2 = cachingProvider2.getCacheManager();
MutableConfiguration configuration = new MutableConfiguration();
final Cache c1 = cacheManager.createCache("c1", configuration);
final Cache c2 = cacheManager2.createCache("c2", configuration);
c1.put("key", "value");
c2.put("key", "value");
cacheManager.close();
assertTrueAllTheTime(new AssertTask() {
@Override
public void run() throws Exception {
c2.get("key");
}
}, 10);
}
use of javax.cache.configuration.MutableConfiguration in project hazelcast by hazelcast.
the class CacheListenerTest method testReplaceIfSameWithSyncListener_whenValueIsNotSame.
@Test(timeout = 30000)
public void testReplaceIfSameWithSyncListener_whenValueIsNotSame() {
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);
String key = randomString();
cache.put(key, randomString());
// there should not be any hanging due to sync listener
cache.replace(key, randomString(), randomString());
}
use of javax.cache.configuration.MutableConfiguration in project hazelcast by hazelcast.
the class CacheListenerTest method testReplaceWithSyncListener_whenEntryNotExists.
@Test(timeout = 30000)
public void testReplaceWithSyncListener_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());
}
Aggregations