@Test
  public void justEnoughLocalReplicasTest() {
    int localReplicaSuccessTarget = 2;
    int remoteReplicaSuccessTarget = 1;
    localDcName = new String("dc-0");
    List<Port> portList = Collections.singletonList(new Port(PORT, PortType.PLAINTEXT));
    List<String> mountPaths = Collections.singletonList("mockMountPath");
    List<ReplicaSpec> testReplicas = new ArrayList<ReplicaSpec>(Arrays.asList(new ReplicaSpec[] {
        new ReplicaSpec(localDcName, ReplicaState.LEADER, portList, mountPaths),
        new ReplicaSpec(localDcName, ReplicaState.STANDBY, portList, mountPaths),
        new ReplicaSpec("remote-1", ReplicaState.LEADER, portList, mountPaths),
        new ReplicaSpec("remote-1", ReplicaState.STANDBY, portList, mountPaths),
        new ReplicaSpec("remote-1", ReplicaState.STANDBY, portList, mountPaths),
        new ReplicaSpec("remote-2", ReplicaState.LEADER, portList, mountPaths),
        new ReplicaSpec("remote-2", ReplicaState.STANDBY, portList, mountPaths),
        new ReplicaSpec("remote-2", ReplicaState.STANDBY, portList, mountPaths) }));

    mockPartition = new MockPartitionId();
    mockClusterMap = new MockClusterMap(false, buildDataNodeList(testReplicas), 1, Collections.singletonList(mockPartition), localDcName);
    populateReplicaList(testReplicas);

    responseReplicas.clear();
    ParanoidDurabilityOperationTracker ot = getParanoidDurabilityOperationTracker(2, 1, 2, 1, 2, true);
    while (!ot.hasSucceeded()) {
      sendRequests(ot, 3);
      for (int i = 0; i < 3; i++) {
        ReplicaId currentReplica = inflightReplicas.poll();
        responseReplicas.add(currentReplica);
        ot.onResponse(currentReplica, TrackedRequestFinalState.SUCCESS);
      }
    }
    assertTrue("Operation should have succeeded", ot.hasSucceeded());
    assertTrue("Operation should be done", ot.isDone());
    assertFalse("Operation should not have failed", ot.hasFailed());
    assertTrue(localReplicaSuccessTarget + " of the successful replicas should be local and " + remoteReplicaSuccessTarget +" should be remote",
        verifySuccessfulReplicas(responseReplicas, localReplicaSuccessTarget, remoteReplicaSuccessTarget));
  }
A test with just enough local replicas, and a successful outcome.
ambry-router/src/test/java/com/github/ambry/router/ParanoidDurabilityOperationTrackerTest.java