Program: 48436
Project: 48436
Buggy source:
@Test @Category(ProblematicTest.class) public void testNearCacheEvictionByUsingMapTTLEviction() throws InterruptedException {
  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 mc=cfg.getMapConfig(mapName);
  mc.setEvictionPolicy(MapConfig.EvictionPolicy.LRU);
  final MaxSizeConfig msc=new MaxSizeConfig();
  msc.setMaxSizePolicy(MaxSizeConfig.MaxSizePolicy.PER_NODE);
  msc.setSize(50);
  mc.setMaxSizeConfig(msc);
  final int maxTTL=2;
  final int size=100000;
  final int nsize=size / 5;
  mc.setTimeToLiveSeconds(maxTTL);
  final TestHazelcastInstanceFactory factory=createHazelcastInstanceFactory(3);
  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 - nsize);
  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 < nsize; i++) {
    map1.get(i);
    map2.get(i);
    map3.get(i);
  }
  latch.await(30,TimeUnit.SECONDS);
  assertEquals(0,map1.size());
  assertEquals(map1.size(),map2.size());
  assertEquals(map1.size(),map3.size());
  for (int i=0; i < nsize; 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" + randomString();
  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));
  }
}