@Test
  public void testRemoveReplicasFromDataNode() throws Exception {
    assumeTrue(dataNodeConfigSourceType == DataNodeConfigSourceType.PROPERTY_STORE);

    props.setProperty("clustermap.update.datanode.info", Boolean.toString(true));
    ClusterMapConfig clusterMapConfig = new ClusterMapConfig(new VerifiableProperties(props));
    HelixParticipant participant =
        new HelixParticipant(mock(HelixClusterManager.class), clusterMapConfig, new HelixFactory(),
            new MetricRegistry(), getDefaultZkConnectStr(clusterMapConfig), true);
    participant.markDisablePartitionComplete();
    // create InstanceConfig for local node. Also, put existing replica into sealed list
    String instanceName = ClusterMapUtils.getInstanceName("localhost", clusterMapConfig.clusterMapPort);
    HelixAdmin helixAdmin = participant.getHelixAdmin();
    DataNodeConfig dataNodeConfig = getDataNodeConfigInHelix(helixAdmin, instanceName);

    ClusterMap cm = new StaticClusterManager(testPartitionLayout.partitionLayout, dcName, new MetricRegistry());
    List<? extends ReplicaId> replicaIds =
        cm.getReplicaIds(cm.getDataNodeId("localhost", clusterMapConfig.clusterMapPort));
    DataNodeConfig.DiskConfig diskConfig = dataNodeConfig.getDiskConfigs().values().iterator().next();
    List<ReplicaId> replicaIdsOnDisk = replicaIds.stream()
        .filter(replicaId -> diskConfig.getReplicaConfigs().containsKey(replicaId.getPartitionId().toPathString()))
        .collect(Collectors.toList());
    List<ReplicaId> otherReplicas = new ArrayList<>(replicaIds);
    otherReplicas.removeAll(replicaIdsOnDisk);
    // The case to remove empty list
    try {
      participant.removeReplicasFromDataNode(null);
      fail("Null list should fail");
    } catch (Exception e) {
    }
    assertTrue("Remove an empty list of replicas should succeed",
        participant.removeReplicasFromDataNode(Collections.emptyList()));

    // The case to remove all the replicas in one disk
    assertTrue(participant.removeReplicasFromDataNode(replicaIdsOnDisk));
    Thread.sleep(50);
    replicaIdsOnDisk.forEach(
        replicaId -> verifyReplicaInfoInDataNodeConfig(getDataNodeConfigInHelix(helixAdmin, instanceName), replicaId,
            false));
    otherReplicas.forEach(
        replicaId -> verifyReplicaInfoInDataNodeConfig(getDataNodeConfigInHelix(helixAdmin, instanceName), replicaId,
            true));

    // The case to remove the replicas again
    assertTrue(participant.removeReplicasFromDataNode(replicaIdsOnDisk));
    Thread.sleep(50);
    replicaIdsOnDisk.forEach(
        replicaId -> verifyReplicaInfoInDataNodeConfig(getDataNodeConfigInHelix(helixAdmin, instanceName), replicaId,
            false));
    otherReplicas.forEach(
        replicaId -> verifyReplicaInfoInDataNodeConfig(getDataNodeConfigInHelix(helixAdmin, instanceName), replicaId,
            true));

    // Add replicas on another disk to the list
    DataNodeConfig.DiskConfig anotherDiskConfig =
        dataNodeConfig.getDiskConfigs().values().stream().filter(dc -> !dc.equals(diskConfig)).findFirst().get();
    replicaIdsOnDisk.addAll(replicaIds.stream()
        .filter(
            replicaId -> anotherDiskConfig.getReplicaConfigs().containsKey(replicaId.getPartitionId().toPathString()))
        .collect(Collectors.toList()));
    otherReplicas.removeAll(replicaIdsOnDisk);

    // The case to remove some replicas that are already removed and some new replicas
    assertTrue(participant.removeReplicasFromDataNode(replicaIdsOnDisk));
    Thread.sleep(50);
    replicaIdsOnDisk.forEach(
        replicaId -> verifyReplicaInfoInDataNodeConfig(getDataNodeConfigInHelix(helixAdmin, instanceName), replicaId,
            false));
    otherReplicas.forEach(
        replicaId -> verifyReplicaInfoInDataNodeConfig(getDataNodeConfigInHelix(helixAdmin, instanceName), replicaId,
            true));

    participant.close();
    props.setProperty("clustermap.update.datanode.info", Boolean.toString(false));
  }
Test both replica info addition and removal cases when updating node info in Helix cluster.
@throws Exception
ambry-clustermap/src/test/java/com/github/ambry/clustermap/HelixParticipantTest.java