use of com.hazelcast.map.impl.proxy.NearCachedMapProxyImpl in project hazelcast by hazelcast.
the class MapRemoteService method createDistributedObject.
@Override
public DistributedObject createDistributedObject(String name) {
MapConfig mapConfig = nodeEngine.getConfig().findMapConfig(name);
checkMapConfig(mapConfig);
if (mapConfig.isNearCacheEnabled()) {
checkNearCacheConfig(name, mapConfig.getNearCacheConfig(), false);
return new NearCachedMapProxyImpl(name, mapServiceContext.getService(), nodeEngine, mapConfig);
} else {
return new MapProxyImpl(name, mapServiceContext.getService(), nodeEngine, mapConfig);
}
}
use of com.hazelcast.map.impl.proxy.NearCachedMapProxyImpl in project hazelcast by hazelcast.
the class NearCacheLiteMemberTest method testPutAll.
public static void testPutAll(HazelcastInstance instance, HazelcastInstance lite, String mapName) {
IMap<Object, Object> map = instance.getMap(mapName);
IMap<Object, Object> liteMap = lite.getMap(mapName);
NearCachedMapProxyImpl proxy = (NearCachedMapProxyImpl) liteMap;
NearCache liteNearCache = proxy.getNearCache();
SerializationService serializationService = ((SerializationServiceSupport) instance).getSerializationService();
int count = 100;
// fill the near cache with the same data as below so we can detect when it is emptied
for (int i = 0; i < count; i++) {
liteNearCache.put(serializationService.toData(i), i);
}
final NearCacheStats stats = liteNearCache.getNearCacheStats();
assertEquals(100, stats.getOwnedEntryCount());
Map<Object, Object> localMap = new HashMap<Object, Object>();
for (int i = 0; i < count; i++) {
localMap.put(i, i);
}
map.putAll(localMap);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(0, stats.getOwnedEntryCount());
}
});
for (int i = 0; i < count; i++) {
liteMap.get(i);
}
assertLiteMemberNearCacheNonEmpty(lite, mapName);
}
use of com.hazelcast.map.impl.proxy.NearCachedMapProxyImpl in project hazelcast by hazelcast.
the class GetAllTest method ensure_supplied_number_of_keys_are_in_near_cache.
@Test
public void ensure_supplied_number_of_keys_are_in_near_cache() throws Exception {
final int entryCount = 100000;
final String mapName = "test";
NearCacheConfig nearCacheConfig = new NearCacheConfig();
nearCacheConfig.setCacheLocalEntries(true);
nearCacheConfig.setInvalidateOnChange(true);
Config config = new Config();
config.getMapConfig(mapName).setNearCacheConfig(nearCacheConfig);
HazelcastInstance node = createHazelcastInstance(config);
IMap map = node.getMap(mapName);
for (int i = 0; i < entryCount; i++) {
map.put(i, i);
}
HashSet keys = new HashSet();
for (int i = 0; i < entryCount; i++) {
keys.add(i);
}
map.getAll(keys);
assertEquals(entryCount, ((NearCachedMapProxyImpl) map).getNearCache().size());
}
use of com.hazelcast.map.impl.proxy.NearCachedMapProxyImpl in project hazelcast by hazelcast.
the class NearCacheBatchInvalidationTest method testHigherBatchSize_shouldNotCauseAnyInvalidation_onRemoteNode.
@Test
public void testHigherBatchSize_shouldNotCauseAnyInvalidation_onRemoteNode() throws Exception {
String mapName = randomMapName();
Config config = newConfig(mapName);
configureBatching(config, true, Integer.MAX_VALUE, Integer.MAX_VALUE);
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory();
HazelcastInstance node1 = factory.newHazelcastInstance(config);
HazelcastInstance node2 = factory.newHazelcastInstance(config);
IMap<String, Integer> map1 = node1.getMap(mapName);
IMap<String, Integer> map2 = node2.getMap(mapName);
int size = 1000;
List<String> keys = new ArrayList<String>();
for (int i = 0; i < size; i++) {
keys.add(generateKeyOwnedBy(node1));
}
// fill map-1
for (int i = 0; i < size; i++) {
map1.put(keys.get(i), i);
}
// fill Near Cache on node-1
for (int i = 0; i < size; i++) {
map1.get(keys.get(i));
}
// fill Near Cache on node-2
for (int i = 0; i < size; i++) {
map2.get(keys.get(i));
}
// generate invalidation data
for (int i = 0; i < size; i++) {
map1.put(keys.get(i), i);
}
NearCache nearCache1 = ((NearCachedMapProxyImpl) map1).getNearCache();
NearCache nearCache2 = ((NearCachedMapProxyImpl) map2).getNearCache();
// Near Cache on one node should be invalidated wholly, other node should not receive any event.
// Due to the higher batch-size to sent invalidation.
assertEquals(size, nearCache1.size() + nearCache2.size());
}
Aggregations