Program: 49548
Project: 49548
Buggy source:
/** 
 * Fix for the issue 275.
 * @throws Exception
 */
@Test(timeout=60000) public void testDataRecovery2() throws Exception {
  final int size=1000;
  HazelcastInstance h1=Hazelcast.newHazelcastInstance(new Config());
  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());
  sleep(3000);
  IMap map2=h2.getMap("String_Node_Str");
  assertEquals(size,map1.size());
  assertEquals(size,map2.size());
  assertEquals(size,getTotalOwnedEntryCount(map1,map2));
  assertEquals(size,getTotalBackupEntryCount(map1,map2));
  HazelcastInstance h3=Hazelcast.newHazelcastInstance(new Config());
  IMap map3=h3.getMap("String_Node_Str");
  sleep(3000);
  assertEquals(size,map1.size());
  assertEquals(size,map2.size());
  assertEquals(size,map3.size());
  assertEquals(size,getTotalOwnedEntryCount(map1,map2,map3));
  assertEquals(size,getTotalBackupEntryCount(map1,map2,map3));
  MemberImpl member2=(MemberImpl)h2.getCluster().getLocalMember();
  h2.getLifecycleService().shutdown();
  sleep(3000);
  assertEquals(size,map1.size());
  assertEquals(size,map3.size());
  assertEquals(size,getTotalOwnedEntryCount(map1,map3));
  assertEquals(size,getTotalBackupEntryCount(map1,map3));
  MemberImpl member1=(MemberImpl)h1.getCluster().getLocalMember();
  h1.getLifecycleService().shutdown();
  assertEquals(size,map3.size());
  ConcurrentMapManager c3=getConcurrentMapManager(h3);
  MemberImpl member3=(MemberImpl)h3.getCluster().getLocalMember();
  for (int i=0; i < 271; i++) {
    PartitionInfo p=c3.getPartitionInfo(i);
    assertTrue(p.toString(),member3.getAddress().equals(p.getOwner()));
    assertFalse(p.toString(),p.isOwnerOrBackup(member1.getAddress(),PartitionInfo.MAX_REPLICA_COUNT));
    assertFalse(p.toString(),p.isOwnerOrBackup(member2.getAddress(),PartitionInfo.MAX_REPLICA_COUNT));
  }
}

Fixed version (ground truth):
/** 
 * Fix for the issue 275.
 * @throws Exception
 */
@Test(timeout=60000) public void testDataRecovery2() throws Exception {
  final int size=1000;
  HazelcastInstance h1=Hazelcast.newHazelcastInstance(new Config());
  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());
  sleep(3000);
  IMap map2=h2.getMap("String_Node_Str");
  assertEquals(size,map1.size());
  assertEquals(size,map2.size());
  assertEquals(size,getTotalOwnedEntryCount(map1,map2));
  assertEquals(size,getTotalBackupEntryCount(map1,map2));
  HazelcastInstance h3=Hazelcast.newHazelcastInstance(new Config());
  IMap map3=h3.getMap("String_Node_Str");
  sleep(3000);
  assertEquals(size,map1.size());
  assertEquals(size,map2.size());
  assertEquals(size,map3.size());
  assertEquals(size,getTotalOwnedEntryCount(map1,map2,map3));
  assertEquals(size,getTotalBackupEntryCount(map1,map2,map3));
  MemberImpl member2=(MemberImpl)h2.getCluster().getLocalMember();
  h2.getLifecycleService().shutdown();
  sleep(5000);
  assertEquals(size,map1.size());
  assertEquals(size,map3.size());
  assertEquals(size,getTotalOwnedEntryCount(map1,map3));
  assertEquals(size,getTotalBackupEntryCount(map1,map3));
  MemberImpl member1=(MemberImpl)h1.getCluster().getLocalMember();
  h1.getLifecycleService().shutdown();
  assertEquals(size,map3.size());
  ConcurrentMapManager c3=getConcurrentMapManager(h3);
  MemberImpl member3=(MemberImpl)h3.getCluster().getLocalMember();
  for (int i=0; i < 271; i++) {
    PartitionInfo p=c3.getPartitionInfo(i);
    assertTrue(p.toString(),member3.getAddress().equals(p.getOwner()));
    assertFalse(p.toString(),p.isOwnerOrBackup(member1.getAddress(),PartitionInfo.MAX_REPLICA_COUNT));
    assertFalse(p.toString(),p.isOwnerOrBackup(member2.getAddress(),PartitionInfo.MAX_REPLICA_COUNT));
  }
}