Program: 49616
Project: 49616
Buggy source:
@Test public void testPartitionAndCMapRecordCounts() throws InterruptedException {
  final int[] clusterSize=new int[]{3,5,7,6,4,2,1};
  final int entryCount=10000;
  final int totalPartitionCount=271;
  final int mapBackupCount=2;
  Config config=new Config();
  config.getProperties().put(GroupProperties.PROP_CLEANUP_DELAY_SECONDS,"String_Node_Str");
  config.getProperties().put(GroupProperties.PROP_PARTITION_MIGRATION_INTERVAL,"String_Node_Str");
  config.getProperties().put(GroupProperties.PROP_IMMEDIATE_BACKUP_INTERVAL,"String_Node_Str");
  config.getProperties().put(GroupProperties.PROP_PARTITION_TABLE_SEND_INTERVAL,"String_Node_Str");
  final String mapName="String_Node_Str";
  int testMapReplicaCount=mapBackupCount + 1;
  config.getMapConfig(mapName).setBackupCount(mapBackupCount);
  final IMap<Integer,Integer> testMap=Hazelcast.newHazelcastInstance(config).getMap(mapName);
  for (int i=0; i < entryCount; i++) {
    testMap.put(i,i);
  }
  int k=0;
  for (int i=0; i < clusterSize.length; i++) {
    int size=clusterSize[k++ % clusterSize.length];
    System.out.println("String_Node_Str" + size);
    while (Hazelcast.getAllHazelcastInstances().size() < size) {
      Hazelcast.newHazelcastInstance(config);
    }
    while (Hazelcast.getAllHazelcastInstances().size() > size) {
      Collection<HazelcastInstance> all=Hazelcast.getAllHazelcastInstances();
      for (      HazelcastInstance hz : all) {
        if (hz.getCluster().getMembers().iterator().next().localMember()) {
          hz.getLifecycleService().shutdown();
          break;
        }
      }
    }
    Collection<HazelcastInstance> set=Hazelcast.getAllHazelcastInstances();
    final int replicaMax=set.size();
    int wait=replicaMax * 3;
    System.out.println("String_Node_Str" + wait + "String_Node_Str");
    Thread.sleep(1000 * wait);
    int[] partitionCounts=new int[PartitionInfo.MAX_REPLICA_COUNT];
    for (    HazelcastInstance hazelcastInstance : set) {
      int[] pc=getPartitionCounts(getNode(hazelcastInstance));
      for (int j=0; j < pc.length; j++) {
        partitionCounts[j]+=pc[j];
      }
    }
    for (int j=0; j < partitionCounts.length; j++) {
      int partitionCount=partitionCounts[j];
      if (j < replicaMax) {
        assertTrue("String_Node_Str" + j + "String_Node_Str"+ partitionCount+ "String_Node_Str"+ replicaMax,partitionCount == totalPartitionCount);
      }
 else {
        assertTrue("String_Node_Str" + j + "String_Node_Str"+ partitionCount+ "String_Node_Str"+ replicaMax,partitionCount == 0);
      }
    }
    int[] recordCounts=new int[PartitionInfo.MAX_REPLICA_COUNT];
    for (    HazelcastInstance hazelcastInstance : set) {
      int[] rc=getCMapRecordCounts(getNode(hazelcastInstance),mapName);
      for (int j=0; j < rc.length; j++) {
        recordCounts[j]+=rc[j];
      }
    }
    for (int j=0; j < recordCounts.length; j++) {
      int recordCount=recordCounts[j];
      if (j < Math.min(testMapReplicaCount,replicaMax)) {
        assertTrue("String_Node_Str" + j + "String_Node_Str"+ recordCount+ "String_Node_Str"+ replicaMax,recordCount == entryCount);
      }
 else {
        assertTrue("String_Node_Str" + j + "String_Node_Str"+ recordCount+ "String_Node_Str"+ replicaMax,recordCount == 0);
      }
    }
  }
}

Fixed version (ground truth):
@Test public void testPartitionAndCMapRecordCounts() throws InterruptedException {
  final int[] clusterSize=new int[]{3,5,7,6,4,2,1};
  final int entryCount=10000;
  final int totalPartitionCount=271;
  final int mapBackupCount=2;
  Config config=new Config();
  config.getProperties().put(GroupProperties.PROP_CLEANUP_DELAY_SECONDS,"String_Node_Str");
  config.getProperties().put(GroupProperties.PROP_PARTITION_MIGRATION_INTERVAL,"String_Node_Str");
  config.getProperties().put(GroupProperties.PROP_IMMEDIATE_BACKUP_INTERVAL,"String_Node_Str");
  config.getProperties().put(GroupProperties.PROP_PARTITION_TABLE_SEND_INTERVAL,"String_Node_Str");
  final String mapName="String_Node_Str";
  int testMapReplicaCount=mapBackupCount + 1;
  config.getMapConfig(mapName).setBackupCount(mapBackupCount);
  final IMap<Integer,Integer> testMap=Hazelcast.newHazelcastInstance(config).getMap(mapName);
  for (int i=0; i < entryCount; i++) {
    testMap.put(i,i);
  }
  int k=0;
  for (int i=0; i < clusterSize.length; i++) {
    int size=clusterSize[k++ % clusterSize.length];
    System.out.println("String_Node_Str" + size);
    while (Hazelcast.getAllHazelcastInstances().size() < size) {
      Hazelcast.newHazelcastInstance(config);
    }
    while (Hazelcast.getAllHazelcastInstances().size() > size) {
      Collection<HazelcastInstance> all=Hazelcast.getAllHazelcastInstances();
      for (      HazelcastInstance hz : all) {
        if (hz.getCluster().getMembers().iterator().next().localMember()) {
          hz.getLifecycleService().shutdown();
          break;
        }
      }
    }
    Collection<HazelcastInstance> set=Hazelcast.getAllHazelcastInstances();
    final int replicaMax=set.size();
    int wait=replicaMax * 5;
    System.out.println("String_Node_Str" + wait + "String_Node_Str");
    Thread.sleep(1000 * wait);
    int[] partitionCounts=new int[PartitionInfo.MAX_REPLICA_COUNT];
    for (    HazelcastInstance hazelcastInstance : set) {
      int[] pc=getPartitionCounts(getNode(hazelcastInstance));
      for (int j=0; j < pc.length; j++) {
        partitionCounts[j]+=pc[j];
      }
    }
    for (int j=0; j < partitionCounts.length; j++) {
      int partitionCount=partitionCounts[j];
      if (j < replicaMax) {
        assertTrue("String_Node_Str" + j + "String_Node_Str"+ partitionCount+ "String_Node_Str"+ replicaMax,partitionCount == totalPartitionCount);
      }
 else {
        assertTrue("String_Node_Str" + j + "String_Node_Str"+ partitionCount+ "String_Node_Str"+ replicaMax,partitionCount == 0);
      }
    }
    int[] recordCounts=new int[PartitionInfo.MAX_REPLICA_COUNT];
    for (    HazelcastInstance hazelcastInstance : set) {
      int[] rc=getCMapRecordCounts(getNode(hazelcastInstance),mapName);
      for (int j=0; j < rc.length; j++) {
        recordCounts[j]+=rc[j];
      }
    }
    for (int j=0; j < recordCounts.length; j++) {
      int recordCount=recordCounts[j];
      if (j < Math.min(testMapReplicaCount,replicaMax)) {
        assertTrue("String_Node_Str" + j + "String_Node_Str"+ recordCount+ "String_Node_Str"+ replicaMax,recordCount == entryCount);
      }
 else {
        assertTrue("String_Node_Str" + j + "String_Node_Str"+ recordCount+ "String_Node_Str"+ replicaMax,recordCount == 0);
      }
    }
  }
}