Program: 48430
Project: 48430
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 - maxSizePerNode);
  map1.addEntryListener(new EntryAdapter(){
    public void entryEvicted(    EntryEvent event){
      latch.countDown();
    }
  }
,false);
  for (int i=0; i < size; i++) {
    map1.put(i,i);
  }
  for (int i=0; i < maxSizePerNode * instanceCount; i++) {
    map1.get(i);
    map2.get(i);
    map3.get(i);
  }
  assertOpenEventually(latch);
  assertTrue(map1.size() <= instanceCount * maxSizePerNode);
  assertEquals(map1.size(),map2.size());
  assertEquals(map1.size(),map3.size());
  for (int i=maxSizePerNode * instanceCount; i < size; i++) {
    assertNull(map1.get(i));
    assertNull(map2.get(i));
    assertNull(map3.get(i));
  }
}

Fixed version (ground truth):
@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 - maxSizePerNode);
  map1.addEntryListener(new EntryAdapter(){
    public void entryEvicted(    EntryEvent event){
      latch.countDown();
    }
  }
,false);
  for (int i=0; i < size; i++) {
    map1.put(i,i);
  }
  final int expectedMaxSizeAfterEvictions=maxSizePerNode * instanceCount;
  for (int i=0; i < expectedMaxSizeAfterEvictions; i++) {
    map1.get(i);
    map2.get(i);
    map3.get(i);
  }
  assertOpenEventually(latch);
  assertTrue(map1.size() <= expectedMaxSizeAfterEvictions);
  assertEquals(map1.size(),map2.size());
  assertEquals(map1.size(),map3.size());
  for (int i=expectedMaxSizeAfterEvictions; i < size; i++) {
    assertNull(map1.get(i));
    assertNull(map2.get(i));
    assertNull(map3.get(i));
  }
}