@Test
  public void testUpdateIdealStateAdminOp() throws Exception {
    // This test case changes replica count for partitions, which is not compatible with full auto.
    assumeFalse(fullAutoCompatible);
    String clusterName = CLUSTER_NAME_PREFIX + CLUSTER_NAME_IN_STATIC_CLUSTER_MAP;
    // Test regular bootstrap. This is to ensure InstanceConfig and IdealState are there before testing changing
    // IdealState (to trigger replica movement)
    long expectedResourceCount =
        (testPartitionLayout.getPartitionLayout().getPartitionCount() - 1) / DEFAULT_MAX_PARTITIONS_PER_RESOURCE + 1;
    writeBootstrapOrUpgrade(expectedResourceCount, false);

    // Now, change the replica count for two partitions.
    int totalPartitionCount = testPartitionLayout.getPartitionCount();
    int firstPartitionIndex = RANDOM.nextInt(totalPartitionCount);
    int secondPartitionIndex = (firstPartitionIndex + 1) % totalPartitionCount;
    List<PartitionId> allPartitions = testPartitionLayout.getPartitionLayout().getPartitions(null);
    Partition partition1 = (Partition) allPartitions.get(firstPartitionIndex);
    Partition partition2 = (Partition) allPartitions.get(secondPartitionIndex);

    // Add a new replica for partition1. Find a disk on a data node that does not already have a replica for partition1.
    HashSet<DataNodeId> partition1Nodes = new HashSet<>();
    for (ReplicaId replica : partition1.getReplicas()) {
      partition1Nodes.add(replica.getDataNodeId());
    }
    Disk diskForNewReplica;
    do {
      diskForNewReplica = testHardwareLayout.getRandomDisk();
    } while (partition1Nodes.contains(diskForNewReplica.getDataNode()) || !diskForNewReplica.getDataNode()
        .getDatacenterName()
        .equals("DC1"));
    // Add new replica into partition1
    ReplicaId replicaToAdd = new Replica(partition1, diskForNewReplica, testHardwareLayout.clusterMapConfig);
    partition1.addReplica(replicaToAdd);
    // Remove a replica from partition2.
    ReplicaId removedReplica = partition2.getReplicas().remove(0);

    String dcName = replicaToAdd.getDataNodeId().getDatacenterName();
    ZkInfo zkInfo = dcsToZkInfo.get(dcName);
    ZKHelixAdmin admin = new ZKHelixAdmin("localhost:" + zkInfo.getPort());
    InstanceConfig instanceConfig = admin.getInstanceConfig(clusterName, getInstanceName(replicaToAdd.getDataNodeId()));
    // deep copy for subsequent verification
    InstanceConfig previousInstanceConfig = new InstanceConfig(instanceConfig.getRecord());
    Utils.writeJsonObjectToFile(zkJson, zkLayoutPath);
    Utils.writeJsonObjectToFile(testHardwareLayout.getHardwareLayout().toJSONObject(), hardwareLayoutPath);
    Utils.writeJsonObjectToFile(testPartitionLayout.getPartitionLayout().toJSONObject(), partitionLayoutPath);
    // upgrade Helix by updating IdealState: AdminOperation = UpdateIdealState
    HelixBootstrapUpgradeUtil.bootstrapOrUpgrade(hardwareLayoutPath, partitionLayoutPath, zkLayoutPath,
        CLUSTER_NAME_PREFIX, dcStr, DEFAULT_MAX_PARTITIONS_PER_RESOURCE, false, false, new HelixAdminFactory(), false,
        ClusterMapConfig.DEFAULT_STATE_MODEL_DEF, UpdateIdealState, dataNodeConfigSourceType, false,
        fullAutoCompatible ? 1000 : 0);
    verifyResourceCount(testHardwareLayout.getHardwareLayout(), expectedResourceCount);

    // verify IdealState has been updated
    // 1. new added replica is indeed present in the IdealState
    verifyIdealStateForPartition(replicaToAdd, true, 4, expectedResourceCount);
    // 2. removed old replica is no longer present in the IdealState
    verifyIdealStateForPartition(removedReplica, false, 2, expectedResourceCount);

    // verify the InstanceConfig stays unchanged
    InstanceConfig currentInstanceConfig =
        admin.getInstanceConfig(clusterName, getInstanceName(replicaToAdd.getDataNodeId()));
    assertEquals("InstanceConfig should stay unchanged", previousInstanceConfig.getRecord(),
        currentInstanceConfig.getRecord());
  }
Test that when AdminOperation is specified to UpdateIdealState, Helix bootstrap tool updates IdealState only without
changing InstanceConfig.
ambry-tools/src/integration-test/java/com/github/ambry/clustermap/HelixBootstrapUpgradeToolTest.java