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 CacheSplitBrainTest method newCacheConfig.
private static CacheConfig newCacheConfig(String cacheName, Class<? extends CacheMergePolicy> mergePolicy) {
CacheConfig cacheConfig = new CacheConfig();
cacheConfig.setName(cacheName);
cacheConfig.setMergePolicy(mergePolicy.getName());
return cacheConfig;
}
use of com.hazelcast.config.CacheConfig in project hazelcast by hazelcast.
the class HazelcastServerCacheManager method createCacheConfig.
@Override
protected <K, V> CacheConfig<K, V> createCacheConfig(String cacheName, CacheConfig<K, V> config, boolean createAlsoOnOthers, boolean syncCreate) {
CacheConfig<K, V> currentCacheConfig = cacheService.getCacheConfig(cacheName);
OperationService operationService = nodeEngine.getOperationService();
// Create cache config on all nodes.
CacheCreateConfigOperation op = new CacheCreateConfigOperation(config, createAlsoOnOthers);
// Run "CacheCreateConfigOperation" on this node. Its itself handles interaction with other nodes.
// This operation doesn't block operation thread even "syncCreate" is specified.
// In that case, scheduled thread is used, not operation thread.
InternalCompletableFuture future = operationService.invokeOnTarget(CacheService.SERVICE_NAME, op, nodeEngine.getThisAddress());
if (syncCreate) {
return (CacheConfig<K, V>) future.join();
} else {
return currentCacheConfig;
}
}
use of com.hazelcast.config.CacheConfig in project hazelcast by hazelcast.
the class CacheCreateConfigMessageTask method extractCacheConfigFromMessage.
private CacheConfig extractCacheConfigFromMessage() {
int clientVersion = getClientVersion();
CacheConfig cacheConfig = null;
if (BuildInfo.UNKNOWN_HAZELCAST_VERSION == clientVersion) {
boolean compatibilityEnabled = nodeEngine.getProperties().getBoolean(GroupProperty.COMPATIBILITY_3_6_CLIENT_ENABLED);
if (compatibilityEnabled) {
LegacyCacheConfig legacyCacheConfig = nodeEngine.toObject(parameters.cacheConfig, LegacyCacheConfig.class);
if (null == legacyCacheConfig) {
return null;
}
return legacyCacheConfig.getConfigAndReset();
}
}
return (CacheConfig) nodeEngine.toObject(parameters.cacheConfig);
}
use of com.hazelcast.config.CacheConfig in project hazelcast by hazelcast.
the class ClientCacheRecordStateStressTest method all_records_are_readable_state_in_the_end.
@Test
public void all_records_are_readable_state_in_the_end() throws Exception {
HazelcastInstance member = factory.newHazelcastInstance();
CachingProvider provider = HazelcastServerCachingProvider.createCachingProvider(member);
final CacheManager serverCacheManager = provider.getCacheManager();
factory.newHazelcastInstance();
factory.newHazelcastInstance();
// populated from member.
CacheConfig cacheConfig = new CacheConfig();
cacheConfig.getEvictionConfig().setMaximumSizePolicy(ENTRY_COUNT).setSize(MAX_VALUE);
final Cache memberCache = serverCacheManager.createCache(cacheName, cacheConfig);
for (int i = 0; i < KEY_SPACE; i++) {
memberCache.put(i, i);
}
ClientConfig clientConfig = new ClientConfig();
NearCacheConfig nearCacheConfig = new NearCacheConfig();
nearCacheConfig.setInvalidateOnChange(true).setLocalUpdatePolicy(localUpdatePolicy).getEvictionConfig().setMaximumSizePolicy(ENTRY_COUNT).setSize(MAX_VALUE);
clientConfig.addNearCacheConfig(nearCacheConfig);
List<Thread> threads = new ArrayList<Thread>();
// member
for (int i = 0; i < PUT_THREAD_COUNT; i++) {
Put put = new Put(memberCache);
threads.add(put);
}
// client
HazelcastClientProxy client = (HazelcastClientProxy) factory.newHazelcastClient(clientConfig);
CachingProvider clientCachingProvider = HazelcastClientCachingProvider.createCachingProvider(client);
CacheManager cacheManager = clientCachingProvider.getCacheManager();
final Cache clientCache = cacheManager.createCache(cacheName, cacheConfig);
for (int i = 0; i < GET_ALL_THREAD_COUNT; i++) {
GetAll getAll = new GetAll(clientCache);
threads.add(getAll);
}
for (int i = 0; i < PUT_ALL_THREAD_COUNT; i++) {
PutAll putAll = new PutAll(clientCache);
threads.add(putAll);
}
for (int i = 0; i < PUT_IF_ABSENT_THREAD_COUNT; i++) {
PutIfAbsent putIfAbsent = new PutIfAbsent(clientCache);
threads.add(putIfAbsent);
}
for (int i = 0; i < GET_THREAD_COUNT; i++) {
Get get = new Get(clientCache);
threads.add(get);
}
for (int i = 0; i < REMOVE_THREAD_COUNT; i++) {
Remove remove = new Remove(clientCache);
threads.add(remove);
}
for (int i = 0; i < CLEAR_THREAD_COUNT; i++) {
Clear clear = new Clear(clientCache);
threads.add(clear);
}
// start threads
for (Thread thread : threads) {
thread.start();
}
// stress for a while
sleepSeconds(TEST_RUN_SECONDS);
// stop threads
stop.set(true);
for (Thread thread : threads) {
thread.join();
}
assertFinalRecordStateIsReadPermitted(clientCache, member);
}
Aggregations