Program: 49673
Project: 49673
Buggy source:
@Test public void testCleanupAfterMigration() throws Exception {
  System.setProperty("String_Node_Str","String_Node_Str");
  final int size=10000;
  HazelcastInstance h1=Hazelcast.newHazelcastInstance(null);
  IMap map1=h1.getMap("String_Node_Str");
  for (int i=0; i < size; i++) {
    map1.put(i,"String_Node_Str" + i);
  }
  assertEquals(size,map1.size());
  HazelcastInstance h2=Hazelcast.newHazelcastInstance(new Config());
  HazelcastInstance h3=Hazelcast.newHazelcastInstance(new Config());
  IMap map2=h2.getMap("String_Node_Str");
  IMap map3=h3.getMap("String_Node_Str");
  for (int i=0; i < 100; i++) {
    assertEquals(size,map1.size());
    assertEquals(size,map2.size());
    assertEquals(size,map3.size());
  }
  ConcurrentMapManager c1=getConcurrentMapManager(h1);
  ConcurrentMapManager c2=getConcurrentMapManager(h2);
  ConcurrentMapManager c3=getConcurrentMapManager(h3);
  c1.startCleanup(true,false);
  c2.startCleanup(true,false);
  c3.startCleanup(true,false);
  CMap cmap1=c1.getMap("String_Node_Str");
  CMap cmap2=c2.getMap("String_Node_Str");
  CMap cmap3=c3.getMap("String_Node_Str");
  assertTrue(cmap1.mapRecords.size() <= size);
  assertTrue(cmap2.mapRecords.size() <= size);
  assertTrue(cmap3.mapRecords.size() <= size);
  assertEquals(cmap1.mapRecords.size(),getOwnedAndBackupCount(map1));
  assertEquals(cmap2.mapRecords.size(),getOwnedAndBackupCount(map2));
  assertEquals(cmap3.mapRecords.size(),getOwnedAndBackupCount(map3));
  HazelcastInstance h4=Hazelcast.newHazelcastInstance(new Config());
  IMap map4=h4.getMap("String_Node_Str");
  ConcurrentMapManager c4=getConcurrentMapManager(h4);
  CMap cmap4=c4.getMap("String_Node_Str");
  Thread.sleep(5000);
  c1.startCleanup(true,false);
  c2.startCleanup(true,false);
  c3.startCleanup(true,false);
  c4.startCleanup(true,false);
  assertEquals(cmap1.mapRecords.size(),getOwnedAndBackupCount(map1));
  assertEquals(cmap2.mapRecords.size(),getOwnedAndBackupCount(map2));
  assertEquals(cmap3.mapRecords.size(),getOwnedAndBackupCount(map3));
  assertEquals(cmap4.mapRecords.size(),getOwnedAndBackupCount(map4));
  h4.getLifecycleService().shutdown();
  Thread.sleep(15000);
  c1.startCleanup(true,false);
  c2.startCleanup(true,false);
  c3.startCleanup(true,false);
  assertEquals(cmap1.mapRecords.size(),getOwnedAndBackupCount(map1));
  assertEquals(cmap2.mapRecords.size(),getOwnedAndBackupCount(map2));
  assertEquals(cmap3.mapRecords.size(),getOwnedAndBackupCount(map3));
  System.setProperty("String_Node_Str","String_Node_Str");
}

Fixed version (ground truth):
@Test @Ignore public void testCleanupAfterMigration() throws Exception {
  System.setProperty("String_Node_Str","String_Node_Str");
  final int size=10000;
  HazelcastInstance h1=Hazelcast.newHazelcastInstance(null);
  IMap map1=h1.getMap("String_Node_Str");
  for (int i=0; i < size; i++) {
    map1.put(i,"String_Node_Str" + i);
  }
  assertEquals(size,map1.size());
  HazelcastInstance h2=Hazelcast.newHazelcastInstance(new Config());
  HazelcastInstance h3=Hazelcast.newHazelcastInstance(new Config());
  IMap map2=h2.getMap("String_Node_Str");
  IMap map3=h3.getMap("String_Node_Str");
  for (int i=0; i < 100; i++) {
    assertEquals(size,map1.size());
    assertEquals(size,map2.size());
    assertEquals(size,map3.size());
  }
  ConcurrentMapManager c1=getConcurrentMapManager(h1);
  ConcurrentMapManager c2=getConcurrentMapManager(h2);
  ConcurrentMapManager c3=getConcurrentMapManager(h3);
  c1.startCleanup(true,true);
  c2.startCleanup(true,true);
  c3.startCleanup(true,true);
  Thread.sleep(1000);
  CMap cmap1=c1.getMap("String_Node_Str");
  CMap cmap2=c2.getMap("String_Node_Str");
  CMap cmap3=c3.getMap("String_Node_Str");
  assertTrue(cmap1.mapRecords.size() <= size);
  assertTrue(cmap2.mapRecords.size() <= size);
  assertTrue(cmap3.mapRecords.size() <= size);
  assertEquals(cmap1.mapRecords.size(),getOwnedAndBackupCount(map1));
  assertEquals(cmap2.mapRecords.size(),getOwnedAndBackupCount(map2));
  assertEquals(cmap3.mapRecords.size(),getOwnedAndBackupCount(map3));
  HazelcastInstance h4=Hazelcast.newHazelcastInstance(new Config());
  IMap map4=h4.getMap("String_Node_Str");
  ConcurrentMapManager c4=getConcurrentMapManager(h4);
  CMap cmap4=c4.getMap("String_Node_Str");
  Thread.sleep(1000);
  c1.startCleanup(true,true);
  c2.startCleanup(true,true);
  c3.startCleanup(true,true);
  c4.startCleanup(true,true);
  Thread.sleep(8000);
  assertEquals(cmap1.mapRecords.size(),getOwnedAndBackupCount(map1));
  assertEquals(cmap2.mapRecords.size(),getOwnedAndBackupCount(map2));
  assertEquals(cmap3.mapRecords.size(),getOwnedAndBackupCount(map3));
  assertEquals(cmap4.mapRecords.size(),getOwnedAndBackupCount(map4));
  h4.getLifecycleService().shutdown();
  Thread.sleep(1000);
  c1.startCleanup(true,true);
  c2.startCleanup(true,true);
  c3.startCleanup(true,true);
  Thread.sleep(8000);
  assertEquals(cmap1.mapRecords.size(),getOwnedAndBackupCount(map1));
  assertEquals(cmap2.mapRecords.size(),getOwnedAndBackupCount(map2));
  assertEquals(cmap3.mapRecords.size(),getOwnedAndBackupCount(map3));
  System.setProperty("String_Node_Str","String_Node_Str");
}