use of com.hazelcast.config.NearCacheConfig in project hazelcast by hazelcast.
the class ClientReplicatedMapProxy method initNearCache.
private void initNearCache() {
ClientContext context = getContext();
NearCacheConfig nearCacheConfig = context.getClientConfig().getNearCacheConfig(name);
if (nearCacheConfig == null) {
return;
}
nearCache = context.getNearCacheManager().getOrCreateNearCache(name, nearCacheConfig);
if (nearCache.isInvalidatedOnChange()) {
addNearCacheInvalidateListener();
}
}
use of com.hazelcast.config.NearCacheConfig in project hazelcast by hazelcast.
the class NearCachedClientMapProxy method onInitialize.
@Override
protected void onInitialize() {
super.onInitialize();
ClientContext context = getContext();
logger = context.getLoggingService().getLogger(getClass());
NearCacheConfig nearCacheConfig = context.getClientConfig().getNearCacheConfig(name);
NearCacheManager nearCacheManager = context.getNearCacheManager();
IMapDataStructureAdapter<K, V> adapter = new IMapDataStructureAdapter<K, V>(this);
nearCache = nearCacheManager.getOrCreateNearCache(name, nearCacheConfig, adapter);
invalidateOnChange = nearCache.isInvalidatedOnChange();
if (invalidateOnChange) {
addNearCacheInvalidationListener(new ConnectedServerVersionAwareNearCacheEventHandler());
}
}
use of com.hazelcast.config.NearCacheConfig 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);
}
use of com.hazelcast.config.NearCacheConfig in project hazelcast by hazelcast.
the class ClientNearCacheTestSupport method testNearCacheExpiration_withTTL.
protected void testNearCacheExpiration_withTTL(InMemoryFormat inMemoryFormat) {
NearCacheConfig nearCacheConfig = createNearCacheConfig(inMemoryFormat);
nearCacheConfig.setTimeToLiveSeconds(MAX_TTL_SECONDS);
testNearCacheExpiration(nearCacheConfig, MAX_TTL_SECONDS);
}
use of com.hazelcast.config.NearCacheConfig in project hazelcast by hazelcast.
the class ClientNearCacheTestSupport method doTestGetAllReturnsFromNearCache.
protected void doTestGetAllReturnsFromNearCache(InMemoryFormat inMemoryFormat) {
if (inMemoryFormat != InMemoryFormat.OBJECT) {
return;
}
NearCacheConfig nearCacheConfig = createNearCacheConfig(inMemoryFormat);
NearCacheTestContext nearCacheTestContext = createNearCacheTestAndFillWithData(DEFAULT_CACHE_NAME, nearCacheConfig);
for (int i = 0; i < DEFAULT_RECORD_COUNT; i++) {
assertNull(nearCacheTestContext.nearCache.get(nearCacheTestContext.serializationService.toData(i)));
}
for (int i = 0; i < DEFAULT_RECORD_COUNT; i++) {
// get records so they will be stored in Near Cache
nearCacheTestContext.cache.get(i);
}
for (int i = 0; i < DEFAULT_RECORD_COUNT; i++) {
Data keyData = nearCacheTestContext.serializationService.toData(i);
// check if same reference to verify data coming from Near Cache
assertSame(nearCacheTestContext.cache.get(i), nearCacheTestContext.nearCache.get(keyData));
}
}
Aggregations