private void verifyIdealStateForPartition(ReplicaId replica, boolean shouldExist,
      int expectedReplicaCountForPartition, long expectedResourceCount) {
    String dcName = replica.getDataNodeId().getDatacenterName();
    ZkInfo zkInfo = dcsToZkInfo.get(dcName);
    String clusterName = CLUSTER_NAME_PREFIX + CLUSTER_NAME_IN_STATIC_CLUSTER_MAP;
    ZKHelixAdmin admin = new ZKHelixAdmin("localhost:" + zkInfo.getPort());
    if (!activeDcSet.contains(dcName)) {
      Assert.assertFalse("Cluster should not be present, as dc " + dcName + " is not enabled",
          admin.getClusters().contains(clusterName));
    } else {
      List<String> resources = admin.getResourcesInCluster(clusterName);
      assertEquals("Resource count mismatch", expectedResourceCount, resources.size());
      String partitionName = replica.getPartitionId().toPathString();
      boolean resourceFound = false;
      for (String resource : resources) {
        IdealState idealState = admin.getResourceIdealState(clusterName, resource);
        if (idealState.getPartitionSet().contains(partitionName)) {
          resourceFound = true;
          Set<String> instances = idealState.getInstanceSet(partitionName);
          assertEquals("Replica number is not expected", expectedReplicaCountForPartition, instances.size());
          String instanceNameOfNewReplica = getInstanceName(replica.getDataNodeId());
          if (shouldExist) {
            assertTrue("Instance set doesn't include new instance that holds added replica",
                instances.contains(instanceNameOfNewReplica));
          } else {
            assertFalse("Instance that holds deleted replica should not exist in the set",
                instances.contains(instanceNameOfNewReplica));
          }
          break;
        }
      }
      assertTrue("No corresponding resource found for partition " + partitionName, resourceFound);
    }
  }
A helper method to verify IdealState for given replica's partition. It checks number of replicas (represented by
instances) under certain partition and verifies new added replica exists or removed old replica is no longer present.
@param replica the replica to check if it exists (could be either added replica or removed replica)
@param shouldExist if {@code true}, it means the given replica is newly added and should exist in IdealState.
                   {@code false} otherwise.
@param expectedReplicaCountForPartition expected number of replicas under certain partition
@param expectedResourceCount expected total number resource count in this cluster.
ambry-tools/src/integration-test/java/com/github/ambry/clustermap/HelixBootstrapUpgradeToolTest.java