Search in sources :

Example 81 with CacheConfig

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

the class CacheExpirationPromotionTest method getCacheConfig.

protected CacheConfig getCacheConfig() {
    CacheConfig cacheConfig = new CacheConfig();
    cacheConfig.setName(cacheName);
    cacheConfig.setBackupCount(1);
    return cacheConfig;
}
Also used : CacheConfig(com.hazelcast.config.CacheConfig)

Example 82 with CacheConfig

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

the class ClientCacheStatsTest method testNearCacheStats_whenNearCacheEnabled.

private void testNearCacheStats_whenNearCacheEnabled() {
    String cacheName = randomName();
    CacheConfig cacheConfig = createCacheConfig();
    cacheConfig.setName(cacheName);
    ClientConfig clientConfig = ((HazelcastClientProxy) client).getClientConfig();
    clientConfig.addNearCacheConfig(new NearCacheConfig().setName(cacheName));
    ICache<Integer, String> cache = createCache(cacheName, cacheConfig);
    CacheStatistics stats = cache.getLocalCacheStatistics();
    assertNotNull(stats.getNearCacheStatistics());
}
Also used : CacheStatistics(com.hazelcast.cache.CacheStatistics) NearCacheConfig(com.hazelcast.config.NearCacheConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) HazelcastClientProxy(com.hazelcast.client.impl.clientside.HazelcastClientProxy) CacheConfig(com.hazelcast.config.CacheConfig) NearCacheConfig(com.hazelcast.config.NearCacheConfig)

Example 83 with CacheConfig

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

the class ClientCacheNearCacheRecordStateStressTest method setUp.

@Before
public void setUp() {
    String cacheName = randomMapName();
    Config config = getBaseConfig();
    ClientConfig clientConfig = new ClientConfig().addNearCacheConfig(newNearCacheConfig(cacheName));
    EvictionConfig evictionConfig = new EvictionConfig().setMaxSizePolicy(ENTRY_COUNT).setSize(MAX_VALUE);
    CacheConfig<Integer, Integer> cacheConfig = new CacheConfig<Integer, Integer>().setEvictionConfig(evictionConfig);
    HazelcastInstance member = factory.newHazelcastInstance(config);
    factory.newHazelcastInstance(config);
    factory.newHazelcastInstance(config);
    HazelcastInstance client = factory.newHazelcastClient(clientConfig);
    CachingProvider provider = createServerCachingProvider(member);
    CacheManager serverCacheManager = provider.getCacheManager();
    memberCache = serverCacheManager.createCache(cacheName, cacheConfig);
    CachingProvider clientCachingProvider = createClientCachingProvider(client);
    CacheManager cacheManager = clientCachingProvider.getCacheManager();
    clientCache = cacheManager.createCache(cacheName, cacheConfig);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) EvictionConfig(com.hazelcast.config.EvictionConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) Config(com.hazelcast.config.Config) CacheConfig(com.hazelcast.config.CacheConfig) NearCacheConfig(com.hazelcast.config.NearCacheConfig) NearCacheTestUtils.getBaseConfig(com.hazelcast.internal.nearcache.impl.NearCacheTestUtils.getBaseConfig) EvictionConfig(com.hazelcast.config.EvictionConfig) CacheManager(javax.cache.CacheManager) ClientConfig(com.hazelcast.client.config.ClientConfig) CacheTestSupport.createClientCachingProvider(com.hazelcast.cache.CacheTestSupport.createClientCachingProvider) CacheTestSupport.createServerCachingProvider(com.hazelcast.cache.CacheTestSupport.createServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) Before(org.junit.Before)

Example 84 with CacheConfig

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

the class ClientNearCacheTestSupport method putToCacheAndDontInvalidateFromClientNearCacheWhenPerEntryInvalidationIsDisabled.

protected void putToCacheAndDontInvalidateFromClientNearCacheWhenPerEntryInvalidationIsDisabled(InMemoryFormat inMemoryFormat) {
    CacheConfig cacheConfig = createCacheConfig(inMemoryFormat);
    cacheConfig.setDisablePerEntryInvalidationEvents(true);
    NearCacheConfig nearCacheConfig = createNearCacheConfig(inMemoryFormat);
    nearCacheConfig.setInvalidateOnChange(true);
    NearCacheTestContext nearCacheTestContext1 = createNearCacheTest(DEFAULT_CACHE_NAME, nearCacheConfig, cacheConfig);
    final NearCacheTestContext nearCacheTestContext2 = createNearCacheTest(DEFAULT_CACHE_NAME, nearCacheConfig, cacheConfig);
    // put cache record from client-1
    for (int i = 0; i < DEFAULT_RECORD_COUNT; i++) {
        nearCacheTestContext1.cache.put(i, generateValueFromKey(i));
    }
    // get records from client-2
    for (int i = 0; i < DEFAULT_RECORD_COUNT; i++) {
        final Integer key = i;
        final String value = nearCacheTestContext2.cache.get(key);
        // records are stored in the cache as async not sync, so these records will be there in cache eventually
        assertTrueEventually(new AssertTask() {

            @Override
            public void run() throws Exception {
                Data keyData = nearCacheTestContext2.serializationService.toData(key);
                assertEquals(value, nearCacheTestContext2.nearCache.get(keyData));
            }
        });
    }
    // update cache record from client-1
    for (int i = 0; i < DEFAULT_RECORD_COUNT; i++) {
        // update the cache records with new values
        nearCacheTestContext1.cache.put(i, generateValueFromKey(i + DEFAULT_RECORD_COUNT));
    }
    int invalidationEventFlushFreq = Integer.parseInt(CACHE_INVALIDATION_MESSAGE_BATCH_FREQUENCY_SECONDS.getDefaultValue());
    // wait some time and if there are invalidation events to be sent in batch
    // (we assume that they should be flushed, received and processed in this time window already)
    sleepSeconds(2 * invalidationEventFlushFreq);
    // get records from client-2
    for (int i = 0; i < DEFAULT_RECORD_COUNT; i++) {
        String actualValue = nearCacheTestContext2.cache.get(i);
        String expectedValue = generateValueFromKey(i);
        // verify that still we have old records in the Near Cache, because, per entry invalidation events are disabled
        assertEquals(expectedValue, actualValue);
    }
    nearCacheTestContext1.cache.clear();
    // can't get expired records from client-2
    for (int i = 0; i < DEFAULT_RECORD_COUNT; i++) {
        final int key = i;
        // records are stored in the Near Cache will be invalidated eventually, since cache records are cleared
        // because we just disable per entry invalidation events, not full-flush events
        assertTrueEventually(new AssertTask() {

            @Override
            public void run() throws Exception {
                Data keyData = nearCacheTestContext2.serializationService.toData(key);
                assertNull(nearCacheTestContext2.nearCache.get(keyData));
            }
        });
    }
}
Also used : NearCacheConfig(com.hazelcast.config.NearCacheConfig) AssertTask(com.hazelcast.test.AssertTask) Data(com.hazelcast.nio.serialization.Data) CacheConfig(com.hazelcast.config.CacheConfig) NearCacheConfig(com.hazelcast.config.NearCacheConfig) CacheLoaderException(javax.cache.integration.CacheLoaderException)

Example 85 with CacheConfig

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

the class ClientCacheProxyTest method isCacheOnUpdate_prints_warning_message_for_deprecated_policy_CACHE.

@Test
public void isCacheOnUpdate_prints_warning_message_for_deprecated_policy_CACHE() throws Exception {
    NearCacheConfig nearCacheConfig = new NearCacheConfig().setLocalUpdatePolicy(CACHE);
    TestLogger logger = new TestLogger();
    new ClientCacheProxy(new CacheConfig()).isCacheOnUpdate(nearCacheConfig, "cacheName", logger);
    assertNotNull(logger.message);
}
Also used : NearCacheConfig(com.hazelcast.config.NearCacheConfig) CacheConfig(com.hazelcast.config.CacheConfig) NearCacheConfig(com.hazelcast.config.NearCacheConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

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