use of com.hazelcast.config.CacheConfig 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 com.hazelcast.config.CacheConfig in project hazelcast by hazelcast.
the class CacheLoadAllTest method createCacheConfig.
@Override
protected <K, V> CacheConfig<K, V> createCacheConfig() {
CacheConfig cacheConfig = super.createCacheConfig();
cacheConfig.setBackupCount(INSTANCE_COUNT - 1);
cacheConfig.setReadThrough(true);
cacheConfig.setCacheLoaderFactory(FactoryBuilder.factoryOf(TestCacheLoader.class));
return cacheConfig;
}
use of com.hazelcast.config.CacheConfig 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 com.hazelcast.config.CacheConfig in project hazelcast by hazelcast.
the class CachePartitionLostListenerTest method test_partitionLostListenerInvoked_whenNodeCrashed.
@Test
public void test_partitionLostListenerInvoked_whenNodeCrashed() {
List<HazelcastInstance> instances = getCreatedInstancesShuffledAfterWarmedUp(2);
HazelcastInstance survivingInstance = instances.get(0);
HazelcastInstance terminatingInstance = instances.get(1);
HazelcastServerCachingProvider cachingProvider = createCachingProvider(survivingInstance);
CacheManager cacheManager = cachingProvider.getCacheManager();
CacheConfig<Integer, String> config = new CacheConfig<Integer, String>();
config.setBackupCount(0);
Cache<Integer, String> cache = cacheManager.createCache(getIthCacheName(0), config);
ICache iCache = cache.unwrap(ICache.class);
final EventCollectingCachePartitionLostListener listener = new EventCollectingCachePartitionLostListener(0);
iCache.addPartitionLostListener(listener);
final Set<Integer> survivingPartitionIds = new HashSet<Integer>();
Node survivingNode = getNode(survivingInstance);
Address survivingAddress = survivingNode.getThisAddress();
for (IPartition partition : survivingNode.getPartitionService().getPartitions()) {
if (survivingAddress.equals(partition.getReplicaAddress(0))) {
survivingPartitionIds.add(partition.getPartitionId());
}
}
terminatingInstance.getLifecycleService().terminate();
waitAllForSafeState(survivingInstance);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
final List<CachePartitionLostEvent> events = listener.getEvents();
assertFalse(events.isEmpty());
for (CachePartitionLostEvent event : events) {
assertFalse(survivingPartitionIds.contains(event.getPartitionId()));
}
}
});
cacheManager.destroyCache(getIthCacheName(0));
cacheManager.close();
cachingProvider.close();
}
use of com.hazelcast.config.CacheConfig in project hazelcast by hazelcast.
the class CachePartitionLostListenerTest method test_partitionLostListenerInvoked.
@Test
public void test_partitionLostListenerInvoked() {
List<HazelcastInstance> instances = getCreatedInstancesShuffledAfterWarmedUp(1);
final HazelcastInstance instance = instances.get(0);
HazelcastServerCachingProvider cachingProvider = createCachingProvider(instance);
CacheManager cacheManager = cachingProvider.getCacheManager();
CacheConfig<Integer, String> config = new CacheConfig<Integer, String>();
Cache<Integer, String> cache = cacheManager.createCache(getIthCacheName(0), config);
ICache iCache = cache.unwrap(ICache.class);
final EventCollectingCachePartitionLostListener listener = new EventCollectingCachePartitionLostListener(0);
iCache.addPartitionLostListener(listener);
final IPartitionLostEvent internalEvent = new IPartitionLostEvent(1, 1, null);
CacheService cacheService = getNode(instance).getNodeEngine().getService(CacheService.SERVICE_NAME);
cacheService.onPartitionLost(internalEvent);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
List<CachePartitionLostEvent> events = listener.getEvents();
assertEquals(1, events.size());
CachePartitionLostEvent event = events.get(0);
assertEquals(internalEvent.getPartitionId(), event.getPartitionId());
assertEquals(getIthCacheName(0), event.getSource());
assertEquals(getIthCacheName(0), event.getName());
assertEquals(instance.getCluster().getLocalMember(), event.getMember());
assertEquals(CacheEventType.PARTITION_LOST, event.getEventType());
}
});
cacheManager.destroyCache(getIthCacheName(0));
cacheManager.close();
cachingProvider.close();
}
Aggregations