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));
}
});
}
}
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;
}
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();
}
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));
}
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);
}
Aggregations