use of javax.cache.spi.CachingProvider in project hazelcast by hazelcast.
the class CacheEntryProcessorTest method executeEntryProcessor.
private void executeEntryProcessor(Integer key, EntryProcessor<Integer, String, Void> entryProcessor, String cacheName) {
CachingProvider cachingProvider = HazelcastServerCachingProvider.createCachingProvider(node1);
CacheManager cacheManager = cachingProvider.getCacheManager();
CompleteConfiguration<Integer, String> config = new MutableConfiguration<Integer, String>().setTypes(Integer.class, String.class);
Cache<Integer, String> cache = cacheManager.createCache(cacheName, config);
cache.invoke(key, entryProcessor);
}
use of javax.cache.spi.CachingProvider in project hazelcast by hazelcast.
the class BaseCacheEvictionPolicyComparatorTest method do_test_evictionPolicyComparator.
void do_test_evictionPolicyComparator(EvictionConfig evictionConfig, int iterationCount) {
HazelcastInstance instance = createInstance(createConfig());
CachingProvider cachingProvider = createCachingProvider(instance);
CacheManager cacheManager = cachingProvider.getCacheManager();
CacheConfig cacheConfig = createCacheConfig(CACHE_NAME);
cacheConfig.setEvictionConfig(evictionConfig);
Cache cache = cacheManager.createCache(CACHE_NAME, cacheConfig);
for (int i = 0; i < iterationCount; i++) {
cache.put(i, "Value-" + i);
}
AtomicLong callCounter = (AtomicLong) getUserContext(instance).get("callCounter");
assertTrue(callCounter.get() > 0);
}
use of javax.cache.spi.CachingProvider in project hazelcast by hazelcast.
the class CacheManagementTest method doCacheManagement.
private void doCacheManagement(boolean enable, boolean stats) {
String cacheName = randomName();
CacheConfig cacheConfig = super.createCacheConfig();
cacheConfig.setManagementEnabled(false);
cacheConfig.setStatisticsEnabled(false);
CachingProvider cachingProvider = getCachingProvider();
CacheManager cacheManager = cachingProvider.getCacheManager();
cacheManager.createCache(cacheName, cacheConfig);
if (enable) {
if (stats) {
cacheManager.enableStatistics(cacheName, true);
} else {
cacheManager.enableManagement(cacheName, true);
}
}
if (enable) {
assertTrue(MXBeanUtil.isRegistered("hazelcast", cacheName, stats));
} else {
assertFalse(MXBeanUtil.isRegistered("hazelcast", cacheName, stats));
}
}
use of javax.cache.spi.CachingProvider in project hazelcast by hazelcast.
the class CacheBackupTest method entrySuccessfullyRetrievedFromBackup.
private void entrySuccessfullyRetrievedFromBackup(int backupCount, boolean sync) {
final String KEY = "key";
final String VALUE = "value";
final int nodeCount = backupCount + 1;
final TestHazelcastInstanceFactory instanceFactory = createHazelcastInstanceFactory(nodeCount);
final HazelcastInstance[] instances = new HazelcastInstance[nodeCount];
for (int i = 0; i < instances.length; i++) {
instances[i] = instanceFactory.newHazelcastInstance();
}
final HazelcastInstance hz = instances[0];
final CachingProvider cachingProvider = HazelcastServerCachingProvider.createCachingProvider(hz);
final CacheManager cacheManager = cachingProvider.getCacheManager();
final String cacheName = randomName();
final CacheConfig cacheConfig = new CacheConfig().setName(cacheName);
if (sync) {
cacheConfig.setBackupCount(backupCount);
} else {
cacheConfig.setAsyncBackupCount(backupCount);
}
final Cache cache = cacheManager.createCache(cacheName, cacheConfig);
warmUpPartitions(instances);
waitAllForSafeState(instances);
cache.put(KEY, VALUE);
final Node node = getNode(hz);
final InternalPartitionService partitionService = node.getPartitionService();
final int keyPartitionId = partitionService.getPartitionId(KEY);
for (int i = 1; i <= backupCount; i++) {
final Node backupNode = getNode(instances[i]);
final SerializationService serializationService = backupNode.getSerializationService();
final ICacheService cacheService = backupNode.getNodeEngine().getService(ICacheService.SERVICE_NAME);
if (sync) {
checkSavedRecordOnBackup(KEY, VALUE, cacheName, keyPartitionId, serializationService, cacheService);
} else {
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
checkSavedRecordOnBackup(KEY, VALUE, cacheName, keyPartitionId, serializationService, cacheService);
}
});
}
}
}
use of javax.cache.spi.CachingProvider in project hazelcast by hazelcast.
the class CacheContextTest method cacheEntryListenerCountIncreasedAndDecreasedCorrectly.
protected void cacheEntryListenerCountIncreasedAndDecreasedCorrectly(DecreaseType decreaseType) {
final String CACHE_NAME = "MyCache";
final String CACHE_NAME_WITH_PREFIX = "/hz/" + CACHE_NAME;
CachingProvider provider = initAndGetCachingProvider();
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() throws Exception {
assertNotNull(cacheService1.getCacheContext(CACHE_NAME_WITH_PREFIX));
}
});
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
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() throws Exception {
assertEquals(1, cacheContext1.getCacheEntryListenerCount());
}
});
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
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() throws Exception {
assertEquals(0, cacheContext1.getCacheEntryListenerCount());
}
});
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(0, cacheContext2.getCacheEntryListenerCount());
}
});
}
Aggregations