@Test
  public void participantsWithMismatchTest() throws Exception {
    List<ClusterParticipant> participants = new ArrayList<>();
    // create a latch with init value = 2 and add it to second participant. This latch will count down under certain condition
    CountDownLatch invocationLatch = new CountDownLatch(3);
    MockClusterParticipant participant1 =
        new MockClusterParticipant(new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), null, null, null);
    MockClusterParticipant participant2 =
        new MockClusterParticipant(new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), null, null,
            invocationLatch);
    participants.add(participant1);
    participants.add(participant2);
    clusterAgentsFactory.setClusterParticipants(participants);
    AmbryServer server =
        new AmbryServer(new VerifiableProperties(props), clusterAgentsFactory, notificationSystem, time);
    server.startup();
    // initially, two participants have consistent sealed/stopped replicas. Verify that:
    // 1. checker is instantiated 2. no mismatch event is emitted.
    assertNotNull("The mismatch metric should be created",
        server.getServerMetrics().sealedReplicasMismatchCount);
    assertNotNull("The mismatch metric should be created",
        server.getServerMetrics().partiallySealedReplicasMismatchCount);
    assertEquals("Sealed replicas mismatch count should be 0", 0,
        server.getServerMetrics().sealedReplicasMismatchCount.getCount());
    assertEquals("Sealed replicas mismatch count should be 0", 0,
        server.getServerMetrics().partiallySealedReplicasMismatchCount.getCount());
    assertEquals("Stopped replicas mismatch count should be 0", 0,
        server.getServerMetrics().stoppedReplicasMismatchCount.getCount());
    // induce mismatch for sealed and stopped replica list
    // add 1 sealed replica to participant1
    ReplicaId mockReplica1 = Mockito.mock(ReplicaId.class);
    when(mockReplica1.getReplicaPath()).thenReturn("12");
    participant1.setReplicaSealedState(mockReplica1, ReplicaSealStatus.SEALED);
    // add 1 stopped replica to participant2
    ReplicaId mockReplica2 = Mockito.mock(ReplicaId.class);
    when(mockReplica2.getReplicaPath()).thenReturn("4");
    participant2.setReplicaStoppedState(Collections.singletonList(mockReplica2), true);
    // add 1 partially sealed replica to participant2
    ReplicaId mockReplica3 = Mockito.mock(ReplicaId.class);
    when(mockReplica2.getReplicaPath()).thenReturn("5");
    participant2.setReplicaSealedState(mockReplica3, ReplicaSealStatus.PARTIALLY_SEALED);
    assertTrue("The latch didn't count to zero within 5 secs", invocationLatch.await(5, TimeUnit.SECONDS));
    assertTrue("Sealed replicas mismatch count should be non-zero",
        server.getServerMetrics().sealedReplicasMismatchCount.getCount() > 0);
    assertTrue("Partially sealed replicas mismatch count should be non-zero",
        server.getServerMetrics().partiallySealedReplicasMismatchCount.getCount() > 0);
    assertTrue("Stopped replicas mismatch count should be non-zero",
        server.getServerMetrics().stoppedReplicasMismatchCount.getCount() > 0);
    server.shutdown();
  }
Test that there is a mismatch between two participants.
@throws Exception
ambry-server/src/test/java/com/github/ambry/server/ParticipantsConsistencyTest.java