Search in sources :

Example 41 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 42 with CacheConfig

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

the class ClientNearCacheTestSupport method createCacheConfig.

protected CacheConfig createCacheConfig(InMemoryFormat inMemoryFormat) {
    CacheConfig cacheConfig = new CacheConfig().setName(DEFAULT_CACHE_NAME).setInMemoryFormat(inMemoryFormat);
    //noinspection unchecked
    cacheConfig.setCacheLoaderFactory(FactoryBuilder.factoryOf(ClientNearCacheTestSupport.TestCacheLoader.class));
    return cacheConfig;
}
Also used : CacheConfig(com.hazelcast.config.CacheConfig) NearCacheConfig(com.hazelcast.config.NearCacheConfig)

Example 43 with CacheConfig

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

the class ClientManagerTest method testMultiClusterMultipleClients.

@Test
public void testMultiClusterMultipleClients() throws MalformedURLException, URISyntaxException {
    final String cacheName = "test";
    final String key1 = "key1";
    final String valuecm1 = "Value-is-cm1";
    final String valuecm2 = "Value-is-cm2";
    final HazelcastClientCachingProvider cachingProvider = new HazelcastClientCachingProvider();
    final CacheManager cm1 = cachingProvider.getCacheManager(uri1, null);
    final CacheManager cm2 = cachingProvider.getCacheManager(uri2, null);
    final CacheConfig<String, String> cacheConfig = new CacheConfig<String, String>();
    final Cache<String, String> cache1 = cm1.createCache(cacheName, cacheConfig);
    final Cache<String, String> cache2 = cm2.createCache(cacheName, cacheConfig);
    cache1.put(key1, valuecm1);
    cache2.put(key1, valuecm2);
    assertEquals(valuecm1, cache1.get(key1));
    assertEquals(valuecm2, cache2.get(key1));
    cachingProvider.close(uri1, null);
    cachingProvider.close(uri2, null);
    //        cm1.close();
    //        cm2.close();
    final CacheManager cm11 = cachingProvider.getCacheManager(uri1, null);
    final Cache<String, String> cache11 = cm11.getCache(cacheName);
    assertEquals(valuecm1, cache11.get(key1));
    cm11.close();
}
Also used : HazelcastClientCachingProvider(com.hazelcast.client.cache.impl.HazelcastClientCachingProvider) CacheManager(javax.cache.CacheManager) CacheConfig(com.hazelcast.config.CacheConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 44 with CacheConfig

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

the class ClientCacheHelperTest method setUp.

@Before
public void setUp() {
    CacheSimpleConfig cacheSimpleConfig = new CacheSimpleConfig();
    cacheSimpleConfig.setName(SIMPLE_CACHE_NAME);
    Config config = new Config();
    config.addCacheConfig(cacheSimpleConfig);
    hazelcastFactory.newHazelcastInstance(config);
    client = getHazelcastClientInstanceImpl(hazelcastFactory.newHazelcastClient());
    exceptionThrowingClient = mock(HazelcastClientInstanceImpl.class, RETURNS_DEEP_STUBS);
    when(exceptionThrowingClient.getClientPartitionService()).thenThrow(new IllegalArgumentException("expected"));
    newCacheConfig = new CacheConfig<String, String>(CACHE_NAME);
    cacheConfig = new CacheConfig<String, String>(CACHE_NAME);
    configs = new ConcurrentHashMap<String, CacheConfig>(singletonMap(CACHE_NAME, cacheConfig));
}
Also used : CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) ClientCacheHelper.createCacheConfig(com.hazelcast.client.cache.impl.ClientCacheHelper.createCacheConfig) ClientCacheHelper.getCacheConfig(com.hazelcast.client.cache.impl.ClientCacheHelper.getCacheConfig) Config(com.hazelcast.config.Config) CacheConfig(com.hazelcast.config.CacheConfig) ClientTestUtil.getHazelcastClientInstanceImpl(com.hazelcast.client.impl.ClientTestUtil.getHazelcastClientInstanceImpl) HazelcastClientInstanceImpl(com.hazelcast.client.impl.HazelcastClientInstanceImpl) ClientCacheHelper.createCacheConfig(com.hazelcast.client.cache.impl.ClientCacheHelper.createCacheConfig) ClientCacheHelper.getCacheConfig(com.hazelcast.client.cache.impl.ClientCacheHelper.getCacheConfig) CacheConfig(com.hazelcast.config.CacheConfig) Before(org.junit.Before)

Example 45 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)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