use of javax.cache.configuration.MutableConfiguration in project hazelcast by hazelcast.
the class CacheListenerTest method testPutIfAbsentWithSyncListener_whenEntryExists.
@Test(timeout = 30000)
public void testPutIfAbsentWithSyncListener_whenEntryExists() {
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.putIfAbsent(key, randomString());
}
use of javax.cache.configuration.MutableConfiguration in project ignite by apache.
the class CacheStopAndDestroySelfTest method testTckStyleCreateDestroyClose.
/**
* Tests start -> destroy -> start -> close using CacheManager.
*/
public void testTckStyleCreateDestroyClose() throws Exception {
startGridsMultiThreaded(gridCount());
CacheManager mgr = Caching.getCachingProvider().getCacheManager();
String cacheName = "cache";
mgr.createCache(cacheName, new MutableConfiguration<Integer, String>().setTypes(Integer.class, String.class));
mgr.destroyCache(cacheName);
Cache<Integer, String> cache = mgr.createCache(cacheName, new MutableConfiguration<Integer, String>().setTypes(Integer.class, String.class));
cache.close();
cache.close();
try {
cache.get(1);
fail();
} catch (IllegalStateException ignored) {
// No-op;
}
}
use of javax.cache.configuration.MutableConfiguration in project hazelcast by hazelcast.
the class CacheSerializationTest method test_CacheReplicationOperation_serialization.
@Test
public void test_CacheReplicationOperation_serialization() throws Exception {
TestHazelcastInstanceFactory factory = new TestHazelcastInstanceFactory(1);
HazelcastInstance hazelcastInstance = factory.newHazelcastInstance();
try {
CachingProvider provider = HazelcastServerCachingProvider.createCachingProvider(hazelcastInstance);
CacheManager manager = provider.getCacheManager();
CompleteConfiguration configuration = new MutableConfiguration();
Cache cache1 = manager.createCache("cache1", configuration);
Cache cache2 = manager.createCache("cache2", configuration);
Cache cache3 = manager.createCache("cache3", configuration);
for (int i = 0; i < 1000; i++) {
cache1.put("key" + i, i);
cache2.put("key" + i, i);
cache3.put("key" + i, i);
}
HazelcastInstanceProxy proxy = (HazelcastInstanceProxy) hazelcastInstance;
Field original = HazelcastInstanceProxy.class.getDeclaredField("original");
original.setAccessible(true);
HazelcastInstanceImpl impl = (HazelcastInstanceImpl) original.get(proxy);
NodeEngineImpl nodeEngine = impl.node.nodeEngine;
CacheService cacheService = nodeEngine.getService(CacheService.SERVICE_NAME);
int partitionCount = nodeEngine.getPartitionService().getPartitionCount();
for (int partitionId = 0; partitionId < partitionCount; partitionId++) {
CachePartitionSegment segment = cacheService.getSegment(partitionId);
CacheReplicationOperation operation = new CacheReplicationOperation(segment, 1);
Data serialized = service.toData(operation);
try {
service.toObject(serialized);
} catch (Exception e) {
throw new Exception("Partition: " + partitionId, e);
}
}
} finally {
factory.shutdownAll();
}
}
use of javax.cache.configuration.MutableConfiguration 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.configuration.MutableConfiguration 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());
}
Aggregations