@Test
  public void helixVcrClusterParticipant() throws Exception {
    StrictMatchExternalViewVerifier helixBalanceVerifier =
        new StrictMatchExternalViewVerifier(ZK_CONNECT_STRING, VCR_CLUSTER_NAME,
            Collections.singleton(VcrTestUtil.helixResource), null);
    // Create helixInstance1 and join the cluster. All partitions should be assigned to helixInstance1.
    VcrClusterParticipant helixInstance1 = createHelixVcrClusterParticipant(8123, 10123);
    Collection<? extends PartitionId> expectedPartitions =
        Collections.unmodifiableCollection(mockClusterMap.getAllPartitionIds(null));
    MockVcrParticipantListener mockVcrListener = new MockVcrParticipantListener();
    helixInstance1.addListener(mockVcrListener);
    helixInstance1.participate();
    TestUtils.checkAndSleep(true, () -> helixInstance1.getAssignedPartitionIds().size() > 0, 1000);
    Assert.assertTrue("Helix balance timeout.", helixBalanceVerifier.verify(5000));
    Assert.assertTrue("Partition assignment are not correct.",
        collectionEquals(helixInstance1.getAssignedPartitionIds(), expectedPartitions));

    // Create helixInstance2 and join the cluster. Half of partitions should be removed from helixInstance1.
    VcrClusterParticipant helixInstance2 = createHelixVcrClusterParticipant(8124, 10124);
    helixInstance2.participate();
    // Detect any ideal state change first.
    TestUtils.checkAndSleep(true, () -> helixInstance1.getAssignedPartitionIds().size() < expectedPartitions.size(),
        1000);
    Assert.assertTrue("Helix balance timeout.", helixBalanceVerifier.verify(5000));
    Assert.assertEquals("Number of partitions removed are not correct.", expectedPartitions.size() / 2,
        mockVcrListener.getPartitionSet().size());

    // Close helixInstance2. All partitions should back to helixInstance1.
    helixInstance2.close();
    // Detect any ideal state change first.
    TestUtils.checkAndSleep(true, () -> helixInstance1.getAssignedPartitionIds().size() > expectedPartitions.size() / 2,
        500);
    Assert.assertTrue("Helix balance timeout.", helixBalanceVerifier.verify(5000));
    Assert.assertTrue("Partition assignment are not correct.",
        collectionEquals(helixInstance1.getAssignedPartitionIds(), expectedPartitions));

    helixInstance1.close();
  }
Test addReplica and removeReplica of {@link HelixVcrClusterParticipant}
ambry-vcr/src/test/java/com/github/ambry/vcr/HelixVcrClusterParticipantTest.java