Search in sources :

Example 1 with CacheConfig

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);
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) HazelcastInstance(com.hazelcast.core.HazelcastInstance) CacheManager(javax.cache.CacheManager) CacheConfig(com.hazelcast.config.CacheConfig) CachingProvider(javax.cache.spi.CachingProvider) Cache(javax.cache.Cache)

Example 2 with CacheConfig

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;
}
Also used : CacheConfig(com.hazelcast.config.CacheConfig)

Example 3 with 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;
    }
}
Also used : CacheCreateConfigOperation(com.hazelcast.cache.impl.operation.CacheCreateConfigOperation) InternalCompletableFuture(com.hazelcast.spi.InternalCompletableFuture) OperationService(com.hazelcast.spi.OperationService) CacheConfig(com.hazelcast.config.CacheConfig)

Example 4 with CacheConfig

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);
}
Also used : LegacyCacheConfig(com.hazelcast.config.LegacyCacheConfig) LegacyCacheConfig(com.hazelcast.config.LegacyCacheConfig) CacheConfig(com.hazelcast.config.CacheConfig)

Example 5 with 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);
}
Also used : ArrayList(java.util.ArrayList) NearCacheConfig(com.hazelcast.config.NearCacheConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) CacheManager(javax.cache.CacheManager) ClientConfig(com.hazelcast.client.config.ClientConfig) HazelcastClientProxy(com.hazelcast.client.impl.HazelcastClientProxy) CacheConfig(com.hazelcast.config.CacheConfig) NearCacheConfig(com.hazelcast.config.NearCacheConfig) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) HazelcastClientCachingProvider(com.hazelcast.client.cache.impl.HazelcastClientCachingProvider) DefaultNearCache(com.hazelcast.internal.nearcache.impl.DefaultNearCache) Cache(javax.cache.Cache) NearCache(com.hazelcast.internal.nearcache.NearCache) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Aggregations

CacheConfig (com.hazelcast.config.CacheConfig)147 Test (org.junit.Test)65 QuickTest (com.hazelcast.test.annotation.QuickTest)55 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)48 CacheManager (javax.cache.CacheManager)45 HazelcastInstance (com.hazelcast.core.HazelcastInstance)34 CachingProvider (javax.cache.spi.CachingProvider)28 Config (com.hazelcast.config.Config)23 NearCacheConfig (com.hazelcast.config.NearCacheConfig)23 CacheTestSupport.createServerCachingProvider (com.hazelcast.cache.CacheTestSupport.createServerCachingProvider)20 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)17 AssertTask (com.hazelcast.test.AssertTask)16 ClientConfig (com.hazelcast.client.config.ClientConfig)15 CacheTestSupport.createClientCachingProvider (com.hazelcast.cache.CacheTestSupport.createClientCachingProvider)14 HazelcastServerCachingProvider (com.hazelcast.cache.impl.HazelcastServerCachingProvider)11 ConfigValidator.checkCacheConfig (com.hazelcast.internal.config.ConfigValidator.checkCacheConfig)11 ICacheService (com.hazelcast.cache.impl.ICacheService)10 Cache (javax.cache.Cache)10 PreJoinCacheConfig.asCacheConfig (com.hazelcast.cache.impl.PreJoinCacheConfig.asCacheConfig)9 CacheConfigTest (com.hazelcast.config.CacheConfigTest)9