@Test
  public void getReplicasByStateTest() {
    List<Port> portList = Collections.singletonList(new Port(PORT, PortType.PLAINTEXT));
    List<String> mountPaths = Collections.singletonList("mockMountPath");
    assumeTrue(operationTrackerType.equals(SIMPLE_OP_TRACKER));
    int totalReplicaCount = 9;
    for (int bootStrapCount = 0; bootStrapCount < totalReplicaCount; bootStrapCount++) {
      int remainingCount = totalReplicaCount - bootStrapCount;
      for (int standByCount = 0; standByCount < remainingCount; standByCount++) {
        remainingCount = totalReplicaCount - standByCount - bootStrapCount;
        for (int leaderCount = 0; leaderCount < remainingCount; leaderCount++) {
          remainingCount = totalReplicaCount - leaderCount - standByCount - bootStrapCount;
          for (int inactiveCount = 0; inactiveCount < remainingCount; inactiveCount++) {
            remainingCount = totalReplicaCount - leaderCount - standByCount - bootStrapCount - inactiveCount;
            for (int offlineCount = 0; offlineCount < remainingCount; offlineCount++) {
              List<Pair<Integer, ReplicaState>> replicaStateCountPairList =
                  fillMapWithReplicaState(bootStrapCount, standByCount, leaderCount, inactiveCount, offlineCount);
              populateReplicaList(replicaStateCountPairList);
              datanodes = new ArrayList<>(Arrays.asList(new MockDataNodeId(portList, mountPaths, "dc-0"),
                  new MockDataNodeId(portList, mountPaths, "dc-1"), new MockDataNodeId(portList, mountPaths, "dc-2"),
                  new MockDataNodeId(portList, mountPaths, "dc-3")));
              localDcName = datanodes.get(0).getDatacenterName();
              mockPartition = new MockPartitionId();
              mockClusterMap =
                  new MockClusterMap(false, datanodes, 1, Collections.singletonList(mockPartition), localDcName);
              SimpleOperationTracker ot = null;
              try {
                ot = (SimpleOperationTracker) getOperationTrackerForGetOrPut(true, 1, 3, RouterOperation.PutOperation,
                    true);
              } catch (IllegalArgumentException exception) {
                continue;
              }
              assertEquals(bootStrapCount, ot.getReplicasByState(null, EnumSet.of(ReplicaState.BOOTSTRAP))
                  .values()
                  .stream()
                  .mapToInt(l -> l.size())
                  .sum());
              assertEquals(standByCount, ot.getReplicasByState(null, EnumSet.of(ReplicaState.STANDBY))
                  .values()
                  .stream()
                  .mapToInt(l -> l.size())
                  .sum());
              assertEquals(leaderCount, ot.getReplicasByState(null, EnumSet.of(ReplicaState.LEADER))
                  .values()
                  .stream()
                  .mapToInt(l -> l.size())
                  .sum());
              assertEquals(inactiveCount, ot.getReplicasByState(null, EnumSet.of(ReplicaState.INACTIVE))
                  .values()
                  .stream()
                  .mapToInt(l -> l.size())
                  .sum());
              assertEquals(offlineCount, ot.getReplicasByState(null, EnumSet.of(ReplicaState.OFFLINE))
                  .values()
                  .stream()
                  .mapToInt(l -> l.size())
                  .sum());
              assertEquals(bootStrapCount + standByCount,
                  ot.getReplicasByState(null, EnumSet.of(ReplicaState.BOOTSTRAP, ReplicaState.STANDBY))
                      .values()
                      .stream()
                      .mapToInt(l -> l.size())
                      .sum());
              assertEquals(bootStrapCount + standByCount + leaderCount, ot.getReplicasByState(null,
                      EnumSet.of(ReplicaState.BOOTSTRAP, ReplicaState.STANDBY, ReplicaState.LEADER))
                  .values()
                  .stream()
                  .mapToInt(l -> l.size())
                  .sum());
              assertEquals(bootStrapCount + standByCount + leaderCount + inactiveCount, ot.getReplicasByState(null,
                      EnumSet.of(ReplicaState.BOOTSTRAP, ReplicaState.STANDBY, ReplicaState.LEADER, ReplicaState.INACTIVE))
                  .values()
                  .stream()
                  .mapToInt(l -> l.size())
                  .sum());
              assertEquals(bootStrapCount + standByCount + leaderCount + inactiveCount + offlineCount,
                  ot.getReplicasByState(null,
                          EnumSet.of(ReplicaState.BOOTSTRAP, ReplicaState.STANDBY, ReplicaState.LEADER,
                              ReplicaState.INACTIVE, ReplicaState.OFFLINE))
                      .values()
                      .stream()
                      .mapToInt(l -> l.size())
                      .sum());
            }
          }
        }
      }
    }
  }
Test cases where some replicas have changed their state in the middle of constructing operation tracker. The code
should be able to get correct number of replicas even with concurrent state transition. The most common case is
replica changes from OFFLINE to BOOTSTRAP/STANDBY while the replica pool is being populated in the tracker.
ambry-router/src/test/java/com/github/ambry/router/OperationTrackerTest.java