use of com.hazelcast.nio.serialization.Data in project hazelcast by hazelcast.
the class ClientNearCacheTestSupport method putToCacheAndRemoveFromOtherNodeThenCantGetUpdatedFromClientNearCache.
protected void putToCacheAndRemoveFromOtherNodeThenCantGetUpdatedFromClientNearCache(InMemoryFormat inMemoryFormat) {
NearCacheConfig nearCacheConfig = createNearCacheConfig(inMemoryFormat);
nearCacheConfig.setInvalidateOnChange(true);
NearCacheTestContext nearCacheTestContext1 = createNearCacheTest(DEFAULT_CACHE_NAME, nearCacheConfig);
final NearCacheTestContext nearCacheTestContext2 = createNearCacheTest(DEFAULT_CACHE_NAME, nearCacheConfig);
// 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));
}
});
}
// delete cache record from client-1
for (int i = 0; i < DEFAULT_RECORD_COUNT; i++) {
nearCacheTestContext1.cache.remove(i);
}
// can't get deleted 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 updated.
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
Data keyData = nearCacheTestContext2.serializationService.toData(key);
assertNull(nearCacheTestContext2.nearCache.get(keyData));
}
});
}
}
use of com.hazelcast.nio.serialization.Data in project hazelcast by hazelcast.
the class ClientNearCacheTestSupport method putAndGetFromCacheAndThenGetFromClientNearCache.
protected void putAndGetFromCacheAndThenGetFromClientNearCache(InMemoryFormat inMemoryFormat) {
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++) {
String expectedValue = generateValueFromKey(i);
Data keyData = nearCacheTestContext.serializationService.toData(i);
assertEquals(expectedValue, nearCacheTestContext.nearCache.get(keyData));
}
}
use of com.hazelcast.nio.serialization.Data in project hazelcast by hazelcast.
the class ClientNearCacheTestSupport method createNearCacheTest.
protected NearCacheTestContext createNearCacheTest(String cacheName, NearCacheConfig nearCacheConfig, CacheConfig cacheConfig) {
ClientConfig clientConfig = createClientConfig();
clientConfig.addNearCacheConfig(nearCacheConfig);
HazelcastClientProxy client = (HazelcastClientProxy) hazelcastFactory.newHazelcastClient(clientConfig);
NearCacheManager nearCacheManager = client.client.getNearCacheManager();
CachingProvider provider = HazelcastClientCachingProvider.createCachingProvider(client);
HazelcastClientCacheManager cacheManager = (HazelcastClientCacheManager) provider.getCacheManager();
//noinspection unchecked
ICache<Object, String> cache = cacheManager.createCache(cacheName, cacheConfig);
NearCache<Data, String> nearCache = nearCacheManager.getNearCache(cacheManager.getCacheNameWithPrefix(cacheName));
return new NearCacheTestContext(client, cacheManager, nearCacheManager, cache, nearCache);
}
use of com.hazelcast.nio.serialization.Data in project hazelcast by hazelcast.
the class ClientMapNearCacheBasicTest method createContext.
@Override
protected <K, V> NearCacheTestContext<K, V, Data, String> createContext() {
ClientConfig clientConfig = getClientConfig().addNearCacheConfig(nearCacheConfig);
HazelcastInstance member = hazelcastFactory.newHazelcastInstance(getConfig());
HazelcastClientProxy client = (HazelcastClientProxy) hazelcastFactory.newHazelcastClient(clientConfig);
IMap<K, V> memberMap = member.getMap(DEFAULT_NEAR_CACHE_NAME);
IMap<K, V> clientMap = client.getMap(DEFAULT_NEAR_CACHE_NAME);
NearCacheManager nearCacheManager = client.client.getNearCacheManager();
NearCache<Data, String> nearCache = nearCacheManager.getNearCache(DEFAULT_NEAR_CACHE_NAME);
return new NearCacheTestContext<K, V, Data, String>(client.getSerializationService(), client, member, new IMapDataStructureAdapter<K, V>(clientMap), new IMapDataStructureAdapter<K, V>(memberMap), false, nearCache, nearCacheManager);
}
use of com.hazelcast.nio.serialization.Data in project hazelcast by hazelcast.
the class ClientMapNearCachePreloaderTest method createContext.
@Override
protected <K, V> NearCacheTestContext<K, V, Data, String> createContext(boolean createClient) {
HazelcastInstance member = hazelcastFactory.newHazelcastInstance(getConfig());
IMap<K, V> memberMap = member.getMap(nearCacheConfig.getName());
if (!createClient) {
return new NearCacheTestContext<K, V, Data, String>(getSerializationService(member), member, new IMapDataStructureAdapter<K, V>(memberMap), false, null, null);
}
NearCacheTestContext<K, V, Data, String> clientContext = createClientContext();
return new NearCacheTestContext<K, V, Data, String>(clientContext.serializationService, clientContext.nearCacheInstance, member, clientContext.nearCacheAdapter, new IMapDataStructureAdapter<K, V>(memberMap), false, clientContext.nearCache, clientContext.nearCacheManager);
}
Aggregations