use of javax.cache.spi.CachingProvider in project hazelcast by hazelcast.
the class CacheResourceTest method testCloseableCacheLoader.
@Test
public void testCloseableCacheLoader() throws InterruptedException {
CachingProvider provider = HazelcastServerCachingProvider.createCachingProvider(factory.newHazelcastInstance());
CacheManager cacheManager = provider.getCacheManager();
CloseableCacheLoader loader = new CloseableCacheLoader();
Factory<CloseableCacheLoader> loaderFactory = FactoryBuilder.factoryOf(loader);
CompleteConfiguration<Object, Object> configuration = new CacheConfig().setCacheLoaderFactory(loaderFactory).setReadThrough(true);
Cache<Object, Object> cache = cacheManager.createCache("test", configuration);
// trigger partition assignment
cache.get("key");
factory.newHazelcastInstance();
for (int i = 0; i < 1000; i++) {
cache.get(i);
LockSupport.parkNanos(1000);
}
assertFalse("CacheLoader should not be closed!", loader.closed);
}
use of javax.cache.spi.CachingProvider in project hazelcast by hazelcast.
the class CacheResourceTest method testCloseableCacheListener.
@Test
public void testCloseableCacheListener() {
CachingProvider provider = HazelcastServerCachingProvider.createCachingProvider(factory.newHazelcastInstance());
CacheManager cacheManager = provider.getCacheManager();
CloseableListener listener = new CloseableListener();
Factory<CloseableListener> listenerFactory = FactoryBuilder.factoryOf(listener);
CompleteConfiguration<Object, Object> configuration = new CacheConfig().addCacheEntryListenerConfiguration(new MutableCacheEntryListenerConfiguration(listenerFactory, null, true, false));
Cache<Object, Object> cache = cacheManager.createCache("test", configuration);
cache.close();
assertTrue("CloseableListener.close() should be called when cache is closed!", listener.closed);
}
use of javax.cache.spi.CachingProvider in project hazelcast by hazelcast.
the class CacheListenerTest method testGetAndReplaceWithSyncListener_whenEntryNotExists.
@Test(timeout = 30000)
public void testGetAndReplaceWithSyncListener_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.getAndReplace(randomString(), randomString());
}
use of javax.cache.spi.CachingProvider in project hazelcast by hazelcast.
the class CacheListenerTest method testRemoveIfSameWithSyncListener_whenValueIsNotSame.
@Test(timeout = 30000)
public void testRemoveIfSameWithSyncListener_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.remove(key, randomString());
}
use of javax.cache.spi.CachingProvider in project hazelcast by hazelcast.
the class CacheListenerTest method testSyncListener_shouldNotHang_whenCacheClosed.
@Test
public void testSyncListener_shouldNotHang_whenCacheClosed() {
final CachingProvider provider = getCachingProvider();
final String cacheName = randomMapName();
testSyncListener_shouldNotHang_AfterAction(cacheName, provider, new Runnable() {
@Override
public void run() {
Cache cache = provider.getCacheManager().getCache(cacheName);
cache.close();
}
});
}
Aggregations