@Test
  public void helixInitiatedLivenessChangeTest() {
    // this test is not intended for the composite cluster manager and override enabled cases.
    assumeTrue(!useComposite && !overrideEnabled);

    // all instances are up initially.
    assertStateEquivalency(helixCluster.getDownInstances(), helixCluster.getUpInstances());

    // Bring one instance (not current host) down in each dc
    for (String zkAddr : helixCluster.getZkAddrs()) {
      String instance =
          helixCluster.getUpInstances(zkAddr).stream().filter(name -> !name.equals(selfInstanceName)).findFirst().get();
      helixCluster.bringInstanceDown(instance);
    }

    assertStateEquivalency(helixCluster.getDownInstances(), helixCluster.getUpInstances());

    // Bring all instances down in all dcs.
    helixCluster.bringAllInstancesDown();
    Set<String> expectedDownInstances = helixCluster.getDownInstances();
    Set<String> expectedUpInstances = helixCluster.getUpInstances();
    expectedDownInstances.remove(selfInstanceName);
    expectedUpInstances.add(selfInstanceName);
    assertStateEquivalency(expectedDownInstances, expectedUpInstances);

    // Bring one instance up in each dc.
    boolean selfInstanceIsChosen = false;
    for (String zkAddr : helixCluster.getZkAddrs()) {
      String instanceName = helixCluster.getDownInstances(zkAddr).get(0);
      selfInstanceIsChosen = instanceName.equals(selfInstanceName);
      helixCluster.bringInstanceUp(instanceName);
    }
    expectedDownInstances = helixCluster.getDownInstances();
    expectedUpInstances = helixCluster.getUpInstances();
    if (!selfInstanceIsChosen) {
      expectedDownInstances.remove(selfInstanceName);
      expectedUpInstances.add(selfInstanceName);
    }
    assertStateEquivalency(expectedDownInstances, expectedUpInstances);
  }
Test that everything works as expected in the presence of liveness changes initiated by Helix itself.
ambry-clustermap/src/test/java/com/github/ambry/clustermap/HelixClusterManagerTest.java