use of com.hazelcast.config.NearCacheConfig in project hazelcast by hazelcast.
the class MemberMapReconciliationTest method setUp.
@Before
public void setUp() {
NearCacheConfig nearCacheConfig = new NearCacheConfig(MAP_NAME).setInMemoryFormat(nearCacheInMemoryFormat).setInvalidateOnChange(true).setCacheLocalEntries(true);
MapConfig mapConfig = new MapConfig(MAP_NAME).setInMemoryFormat(mapInMemoryFormat).setNearCacheConfig(nearCacheConfig);
// we want to test that reconciliation doesn't cause any premature
// removal of entries by falsely assuming some entries as stale
config = getConfig().setProperty(MAX_TOLERATED_MISS_COUNT.getName(), "0").setProperty(RECONCILIATION_INTERVAL_SECONDS.getName(), valueOf(RECONCILIATION_INTERVAL_SECS)).setProperty(MIN_RECONCILIATION_INTERVAL_SECONDS.getName(), valueOf(RECONCILIATION_INTERVAL_SECS)).setProperty(MAP_INVALIDATION_MESSAGE_BATCH_FREQUENCY_SECONDS.getName(), valueOf(Integer.MAX_VALUE)).setProperty(MAP_INVALIDATION_MESSAGE_BATCH_SIZE.getName(), valueOf(Integer.MAX_VALUE)).addMapConfig(mapConfig);
server = factory.newHazelcastInstance(config);
serverMap = server.getMap(MAP_NAME);
nearCachedServerMap = nearCachedMapFromNewServer();
}
use of com.hazelcast.config.NearCacheConfig in project hazelcast by hazelcast.
the class NearCacheTest method testGetAll.
@Test
public void testGetAll() {
int mapSize = 1000;
String mapName = "testGetAllWithNearCache";
Config config = getConfig();
NearCacheConfig nearCacheConfig = newNearCacheConfig();
nearCacheConfig.setInvalidateOnChange(false);
config.getMapConfig(mapName).setNearCacheConfig(nearCacheConfig);
TestHazelcastInstanceFactory hazelcastInstanceFactory = createHazelcastInstanceFactory(2);
HazelcastInstance[] instances = hazelcastInstanceFactory.newInstances(config);
warmUpPartitions(instances);
HazelcastInstance hazelcastInstance = instances[0];
InternalPartitionService partitionService = getPartitionService(hazelcastInstance);
// populate map
IMap<Integer, Integer> map = hazelcastInstance.getMap(mapName);
populateMap(map, mapSize);
Set<Integer> keys = map.keySet();
// populate Near Cache
int expectedHits = 0;
for (int i = 0; i < mapSize; i++) {
map.get(i);
int partitionId = partitionService.getPartitionId(i);
if (!partitionService.isPartitionOwner(partitionId)) {
// map proxy stores non-owned entries (belong to partition which its not owner) inside its Near Cache
expectedHits++;
}
}
// generate Near Cache hits
Map<Integer, Integer> allEntries = map.getAll(keys);
for (int i = 0; i < mapSize; i++) {
assertEquals(i, (int) allEntries.get(i));
}
// check Near Cache hits
long hits = getNearCacheStats(map).getHits();
assertEquals(format("Near Cache hits should be %d but were %d", expectedHits, hits), expectedHits, hits);
}
use of com.hazelcast.config.NearCacheConfig in project hazelcast by hazelcast.
the class NearCacheTest method testNearCacheEviction.
@Test
public void testNearCacheEviction() {
String mapName = "testNearCacheEviction";
NearCacheConfig nearCacheConfig = newNearCacheConfigWithEntryCountEviction(EvictionPolicy.LRU, MAX_CACHE_SIZE);
Config config = getConfig();
config.getMapConfig(mapName).setNearCacheConfig(nearCacheConfig);
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(1);
HazelcastInstance hazelcastInstance = factory.newHazelcastInstance(config);
IMap<Integer, Integer> map = hazelcastInstance.getMap(mapName);
testNearCacheEviction(map, MAX_CACHE_SIZE);
}
use of com.hazelcast.config.NearCacheConfig in project hazelcast by hazelcast.
the class NearCacheTest method multiple_get_on_non_existing_key_generates_one_miss.
@Test
public void multiple_get_on_non_existing_key_generates_one_miss() {
String mapName = "test";
Config config = getConfig();
NearCacheConfig nearCacheConfig = newNearCacheConfig();
nearCacheConfig.setCacheLocalEntries(true);
config.getMapConfig(mapName).setNearCacheConfig(nearCacheConfig);
HazelcastInstance node = createHazelcastInstance(config);
IMap map = node.getMap(mapName);
map.get(1);
map.get(1);
map.get(1);
NearCacheStats nearCacheStats = map.getLocalMapStats().getNearCacheStats();
assertEquals(1, nearCacheStats.getMisses());
}
use of com.hazelcast.config.NearCacheConfig in project hazelcast by hazelcast.
the class EventListenerCounterTest method near_cache_invalidation_listener_does_not_cause_map_container_creation_on_join.
@Test
public void near_cache_invalidation_listener_does_not_cause_map_container_creation_on_join() {
Config config = smallInstanceConfig();
MapConfig mapConfig = config.getMapConfig("default");
mapConfig.setNearCacheConfig(new NearCacheConfig());
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
HazelcastInstance node1 = factory.newHazelcastInstance(config);
// here a near-cache enabled map adds an
// invalidation listener behind the scenes.
node1.getMap("test");
HazelcastInstance node2 = factory.newHazelcastInstance(config);
node1.shutdown();
assertNull("during join process, there shouldn't be any map-container created", getExistingMapContainer(node2, "test"));
}
Aggregations