Program: 48437
Project: 48437
Buggy source:
@Test public void testNearCacheEvictionByUsingMapTTLEviction() throws InterruptedException {
  final int maxSizePerNode=50;
  final int instanceCount=3;
  final Config cfg=new Config();
  final String mapName="String_Node_Str";
  final NearCacheConfig nearCacheConfig=new NearCacheConfig();
  nearCacheConfig.setInvalidateOnChange(true);
  cfg.getMapConfig(mapName).setNearCacheConfig(nearCacheConfig);
  final MapConfig mapConfig=cfg.getMapConfig(mapName);
  mapConfig.setEvictionPolicy(MapConfig.EvictionPolicy.LRU);
  final MaxSizeConfig maxSizeConfig=new MaxSizeConfig();
  maxSizeConfig.setMaxSizePolicy(MaxSizeConfig.MaxSizePolicy.PER_NODE);
  maxSizeConfig.setSize(maxSizePerNode);
  mapConfig.setMaxSizeConfig(maxSizeConfig);
  final int ttl=1;
  final int size=1000;
  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);
  final CountDownLatch latch=new CountDownLatch(size);
  map1.addEntryListener(new EntryAdapter(){
    public void entryEvicted(    EntryEvent event){
      latch.countDown();
    }
  }
,false);
  for (int i=0; i < size; i++) {
    map1.get(i);
    map2.get(i);
    map3.get(i);
    map1.put(i,i);
  }
  assertOpenEventually(latch);
  assertEquals(0,map1.size());
  assertEquals(0,map2.size());
  assertEquals(0,map3.size());
  assertEquals(0,getNearCache(mapName,instance1).size());
  assertEquals(0,getNearCache(mapName,instance2).size());
  assertEquals(0,getNearCache(mapName,instance3).size());
}

Fixed version (ground truth):
@Test public void testNearCacheEvictionByUsingMapTTLEviction() throws InterruptedException {
  final int instanceCount=3;
  final int ttl=1;
  final int size=1000;
  final Config cfg=new Config();
  final String mapName="String_Node_Str";
  final NearCacheConfig nearCacheConfig=new NearCacheConfig();
  nearCacheConfig.setInvalidateOnChange(true);
  nearCacheConfig.setInMemoryFormat(InMemoryFormat.OBJECT);
  cfg.getMapConfig(mapName).setNearCacheConfig(nearCacheConfig);
  final MapConfig mapConfig=cfg.getMapConfig(mapName);
  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);
  final CountDownLatch latch=new CountDownLatch(size);
  map1.addEntryListener(new EntryAdapter(){
    public void entryEvicted(    EntryEvent event){
      latch.countDown();
    }
  }
,false);
  for (int i=0; i < size; i++) {
    map1.put(i,i);
    map1.get(i);
    map2.get(i);
    map3.get(i);
  }
  assertOpenEventually(latch);
  assertEquals(0,map1.size());
  assertEquals(0,map2.size());
  assertEquals(0,map3.size());
  assertEquals(0,countNotNullValuesInNearCacheSize(mapName,instance1));
  assertEquals(0,countNotNullValuesInNearCacheSize(mapName,instance2));
  assertEquals(0,countNotNullValuesInNearCacheSize(mapName,instance3));
}