use of com.hazelcast.internal.nearcache.NearCache in project hazelcast by hazelcast.
the class NearCacheBatchInvalidationTest method testMapClear_shouldClearNearCaches_onOwnerAndBackupNodes.
@Test
public void testMapClear_shouldClearNearCaches_onOwnerAndBackupNodes() throws Exception {
String mapName = randomMapName();
Config config = newConfig(mapName);
config.setProperty(GroupProperty.PARTITION_COUNT.getName(), "1");
configureBatching(config, true, 5, 5);
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory();
HazelcastInstance node1 = factory.newHazelcastInstance(config);
HazelcastInstance node2 = factory.newHazelcastInstance(config);
final IMap<Integer, Integer> map1 = node1.getMap(mapName);
final IMap<Integer, Integer> map2 = node2.getMap(mapName);
int size = 1000;
// fill map-1
for (int i = 0; i < size; i++) {
map1.put(i, i);
}
// fill Near Cache on node-1
for (int i = 0; i < size; i++) {
map1.get(i);
}
// fill Near Cache on node-2
for (int i = 0; i < size; i++) {
map2.get(i);
}
map1.clear();
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
NearCache nearCache1 = ((NearCachedMapProxyImpl) map1).getNearCache();
NearCache nearCache2 = ((NearCachedMapProxyImpl) map2).getNearCache();
assertEquals(0, nearCache1.size() + nearCache2.size());
}
});
}
use of com.hazelcast.internal.nearcache.NearCache in project hazelcast by hazelcast.
the class LocalMapStatsProvider method addNearCacheStats.
private void addNearCacheStats(String mapName, LocalMapStatsImpl localMapStats, LocalMapOnDemandCalculatedStats onDemandStats) {
NearCache nearCache = mapNearCacheManager.getNearCache(mapName);
if (nearCache == null) {
return;
}
NearCacheStats nearCacheStats = nearCache.getNearCacheStats();
localMapStats.setNearCacheStats(nearCacheStats);
onDemandStats.incrementHeapCost(nearCacheStats.getOwnedEntryMemoryCost());
}
use of com.hazelcast.internal.nearcache.NearCache in project hazelcast by hazelcast.
the class ClientCacheNearCacheCacheOnUpdateTest method checkNearCacheInstance.
protected void checkNearCacheInstance(ICache iCacheOnClient) {
NearCache nearCache = ((NearCachedClientCacheProxy<Object, Object>) iCacheOnClient).getNearCache();
assertInstanceOf(DefaultNearCache.class, nearCache);
}
use of com.hazelcast.internal.nearcache.NearCache in project hazelcast by hazelcast.
the class MapNearCacheInvalidationFromClientTest method testClear.
@Test
public void testClear() {
IMap<Object, Object> map = client.getMap(mapName);
final int count = 100;
for (int i = 0; i < count; i++) {
map.put(i, i);
}
final IMap<Object, Object> liteMap = lite.getMap(mapName);
final NearCache nearCache = getNearCache(lite, mapName);
assertTrueEventually(new AssertTask() {
@Override
public void run() {
for (int i = 0; i < count; i++) {
liteMap.get(i);
}
assertEquals(count, nearCache.size());
}
});
map.clear();
assertTrueEventually(new AssertTask() {
@Override
public void run() {
assertEquals(0, nearCache.size());
}
});
}
use of com.hazelcast.internal.nearcache.NearCache in project hazelcast by hazelcast.
the class ClientMapNearCacheTest method receives_one_clearEvent_after_mapLoadAll_call_from_client.
@Test
public void receives_one_clearEvent_after_mapLoadAll_call_from_client() {
// configure map-store
Config config = newConfig();
config.getMapConfig("default").getMapStoreConfig().setEnabled(true).setImplementation(new SimpleMapStore());
// populate Near Cache
NearCacheConfig nearCacheConfig = newNearCacheConfig();
final IMap<Integer, Integer> clientMap = getNearCachedMapFromClient(config, nearCacheConfig, 2);
populateMap(clientMap, 1000);
populateNearCache(clientMap, 1000);
// create a new client to send events
HazelcastInstance anotherClient = hazelcastFactory.newHazelcastClient(newClientConfig());
IMap<Object, Object> anotherClientMap = anotherClient.getMap(clientMap.getName());
anotherClientMap.loadAll(true);
InternalSerializationService serializationService = getSerializationService(hazelcastFactory.getAllHazelcastInstances().iterator().next());
assertTrueEventually(new AssertTask() {
@Override
public void run() {
NearCache<Object, Object> nearCache = ((NearCachedClientMapProxy<Integer, Integer>) clientMap).getNearCache();
for (int i = 0; i < 1000; i++) {
Object key = i;
if (nearCacheConfig.isSerializeKeys()) {
key = serializationService.toData(i);
}
assertNull("Near Cache should be empty", nearCache.get(key));
}
}
});
}
Aggregations