mapConfig.setTimeToLiveSeconds(ttl);
final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(instanceCount);
final HazelcastInstance instance1 = factory.newHazelcastInstance(cfg);
final HazelcastInstance instance2 = factory.newHazelcastInstance(cfg);
final HazelcastInstance instance3 = factory.newHazelcastInstance(cfg);
final IMap map1 = instance1.getMap(mapName);
final IMap map2 = instance2.getMap(mapName);
final IMap map3 = instance3.getMap(mapName);
//observe eviction
final CountDownLatch latch = new CountDownLatch(size);
map1.addEntryListener(new EntryAdapter() {
public void entryEvicted(EntryEvent event) {
latch.countDown();
}
}, false);
//populate map
for (int i = 0; i < size; i++) {
//populate.
map1.put(i, i);
//bring near caches. -- here is a time window
//that "i" already evicted. so a "get" brings
//a NULL object to the near cache.
map1.get(i);
map2.get(i);
map3.get(i);
}
//wait operations to complete
assertOpenEventually(latch);
//check map size after eviction.
assertEquals(0, map1.size());
assertEquals(0, map2.size());
assertEquals(0, map3.size());
//near cache sizes should be zero after eviction.
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(0, countNotNullValuesInNearCache(mapName, instance1));