Search in sources :

Example 51 with CacheConfig

use of com.hazelcast.config.CacheConfig in project hazelcast by hazelcast.

the class CacheBasicAbstractTest method expiryTimeShouldNotBeChangedOnUpdateWhenCreatedExpiryPolicyIsUsed.

// https://github.com/hazelcast/hazelcast/issues/7236
@Test
public void expiryTimeShouldNotBeChangedOnUpdateWhenCreatedExpiryPolicyIsUsed() {
    final int CREATED_EXPIRY_TIME_IN_MSEC = 100;
    Duration duration = new Duration(TimeUnit.MILLISECONDS, CREATED_EXPIRY_TIME_IN_MSEC);
    CacheConfig<Integer, String> cacheConfig = new CacheConfig<Integer, String>();
    cacheConfig.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(duration));
    Cache<Integer, String> cache = createCache(cacheConfig);
    cache.put(1, "value");
    cache.put(1, "value");
    sleepAtLeastMillis(CREATED_EXPIRY_TIME_IN_MSEC + 1);
    assertNull(cache.get(1));
}
Also used : Duration(javax.cache.expiry.Duration) CacheConfig(com.hazelcast.config.CacheConfig) Test(org.junit.Test)

Example 52 with CacheConfig

use of com.hazelcast.config.CacheConfig in project hazelcast by hazelcast.

the class CacheBasicAbstractTest method entryShouldNotBeExpiredWhenTimeUnitIsNullAndDurationIsZero.

@Test
public void entryShouldNotBeExpiredWhenTimeUnitIsNullAndDurationIsZero() {
    Duration duration = new Duration(null, 0);
    CacheConfig<Integer, String> cacheConfig = new CacheConfig<Integer, String>();
    cacheConfig.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(duration));
    Cache<Integer, String> cache = createCache(cacheConfig);
    cache.put(1, "value");
    sleepAtLeastMillis(1);
    assertNotNull(cache.get(1));
}
Also used : Duration(javax.cache.expiry.Duration) CacheConfig(com.hazelcast.config.CacheConfig) Test(org.junit.Test)

Example 53 with CacheConfig

use of com.hazelcast.config.CacheConfig in project hazelcast by hazelcast.

the class CacheClearTest method createCacheConfig.

@Override
protected <K, V> CacheConfig<K, V> createCacheConfig() {
    CacheConfig cacheConfig = super.createCacheConfig();
    cacheConfig.setBackupCount(INSTANCE_COUNT - 1);
    return cacheConfig;
}
Also used : CacheConfig(com.hazelcast.config.CacheConfig)

Example 54 with CacheConfig

use of com.hazelcast.config.CacheConfig in project hazelcast by hazelcast.

the class CacheDestroyTest method test_cacheDestroyOperation.

@Test
public void test_cacheDestroyOperation() throws ExecutionException, InterruptedException {
    final String CACHE_NAME = "MyCache";
    final String FULL_CACHE_NAME = HazelcastCacheManager.CACHE_MANAGER_PREFIX + CACHE_NAME;
    CachingProvider cachingProvider = HazelcastServerCachingProvider.createCachingProvider(getHazelcastInstance());
    CacheManager cacheManager = cachingProvider.getCacheManager();
    cacheManager.createCache(CACHE_NAME, new CacheConfig());
    NodeEngineImpl nodeEngine1 = getNode(getHazelcastInstance()).getNodeEngine();
    final ICacheService cacheService1 = nodeEngine1.getService(ICacheService.SERVICE_NAME);
    InternalOperationService operationService1 = nodeEngine1.getOperationService();
    NodeEngineImpl nodeEngine2 = getNode(hazelcastInstances[1]).getNodeEngine();
    final ICacheService cacheService2 = nodeEngine2.getService(ICacheService.SERVICE_NAME);
    assertNotNull(cacheService1.getCacheConfig(FULL_CACHE_NAME));
    assertNotNull(cacheService2.getCacheConfig(FULL_CACHE_NAME));
    // Invoke on single node and the operation is also forward to others nodes by the operation itself
    operationService1.invokeOnTarget(ICacheService.SERVICE_NAME, new CacheDestroyOperation(FULL_CACHE_NAME), nodeEngine1.getThisAddress());
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertNull(cacheService1.getCacheConfig(FULL_CACHE_NAME));
            assertNull(cacheService2.getCacheConfig(FULL_CACHE_NAME));
        }
    });
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) CacheDestroyOperation(com.hazelcast.cache.impl.operation.CacheDestroyOperation) ICacheService(com.hazelcast.cache.impl.ICacheService) CacheManager(javax.cache.CacheManager) AssertTask(com.hazelcast.test.AssertTask) InternalOperationService(com.hazelcast.spi.impl.operationservice.InternalOperationService) CacheConfig(com.hazelcast.config.CacheConfig) ExecutionException(java.util.concurrent.ExecutionException) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 55 with CacheConfig

use of com.hazelcast.config.CacheConfig in project hazelcast by hazelcast.

the class CacheDestroyTest method createCacheConfig.

@Override
protected <K, V> CacheConfig<K, V> createCacheConfig() {
    CacheConfig cacheConfig = super.createCacheConfig();
    cacheConfig.setBackupCount(INSTANCE_COUNT - 1);
    return cacheConfig;
}
Also used : CacheConfig(com.hazelcast.config.CacheConfig)

Aggregations

CacheConfig (com.hazelcast.config.CacheConfig)77 Test (org.junit.Test)30 CacheManager (javax.cache.CacheManager)28 QuickTest (com.hazelcast.test.annotation.QuickTest)27 ParallelTest (com.hazelcast.test.annotation.ParallelTest)25 CachingProvider (javax.cache.spi.CachingProvider)16 HazelcastServerCachingProvider (com.hazelcast.cache.impl.HazelcastServerCachingProvider)14 HazelcastInstance (com.hazelcast.core.HazelcastInstance)14 AssertTask (com.hazelcast.test.AssertTask)13 NearCacheConfig (com.hazelcast.config.NearCacheConfig)11 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 ICacheService (com.hazelcast.cache.impl.ICacheService)8 HazelcastClientCachingProvider (com.hazelcast.client.cache.impl.HazelcastClientCachingProvider)8 ICache (com.hazelcast.cache.ICache)5 ClientConfig (com.hazelcast.client.config.ClientConfig)5 Config (com.hazelcast.config.Config)5 Data (com.hazelcast.nio.serialization.Data)5 CacheService (com.hazelcast.cache.impl.CacheService)4 HazelcastServerCachingProvider.createCachingProvider (com.hazelcast.cache.impl.HazelcastServerCachingProvider.createCachingProvider)4 Map (java.util.Map)4