@Test
  public void trackersGenerationTest() {
    ReplicaThread replicaThread = intraColoReplicaThread;
    Map<DataNodeId, List<RemoteReplicaInfo>> dataNodeToReplicaMap = replicaThread.getRemoteReplicaInfos();

    RemoteReplicaGroupPoller remoteReplicaGroupPoller = replicaThread.new RemoteReplicaGroupPoller();

    List<DataNodeTracker> dataNodeTrackers = remoteReplicaGroupPoller.getDataNodeTrackers();

    // check if data node trackers are generated correctly

    Assert.assertEquals("Count of data nodes assigned to thread and count of data node trackers should be same",
        dataNodeToReplicaMap.size(), dataNodeTrackers.size());

    Set<DataNodeId> dataNodeIdsAddedInTracker =
        dataNodeTrackers.stream().map(DataNodeTracker::getDataNodeId).collect(Collectors.toSet());

    // all data nodes should have trackers created
    dataNodeToReplicaMap.keySet().forEach(dataNodeId -> {
      Assert.assertTrue("DataNode should be present in data node trackers created",
          dataNodeIdsAddedInTracker.contains(dataNodeId));
    });

    // check if all group trackers are generated correctly inside data node tracker
    dataNodeTrackers.forEach(dataNodeTracker -> {
      TreeSet<Integer> allActiveGroupIds = dataNodeTracker.getActiveGroupTrackers()
          .stream()
          .map(GroupTracker::getGroupId)
          .distinct()
          .collect(Collectors.toCollection(TreeSet::new));
      int minimumActiveGroupId = allActiveGroupIds.first();
      int maximumActiveGroupId = allActiveGroupIds.last();

      Assert.assertEquals("All groups ids should exits from start and should be in serial consecutive order",
          maximumActiveGroupId - minimumActiveGroupId + 1, dataNodeTracker.getActiveGroupTrackers().size());

      Assert.assertEquals("Standby group id should be maximum and one more than maximum active group id",
          maximumActiveGroupId + 1, dataNodeTracker.getStandByGroupTracker().getGroupId());
    });

    // check if group tackers are generated correctly

    // check if all groupIds are unique across datanode tracker
    Set<Integer> allGroupIds = new HashSet<>();

    dataNodeTrackers.forEach(dataNodeTracker -> {
      dataNodeTracker.getActiveGroupTrackers().forEach(activeGroupTracker -> {
        Assert.assertFalse("Group id for group trackers should be unique",
            allGroupIds.contains(activeGroupTracker.getGroupId()));
        allGroupIds.add(activeGroupTracker.getGroupId());
      });

      Assert.assertFalse("Group id for group trackers should be unique",
          allGroupIds.contains(dataNodeTracker.getStandByGroupTracker().getGroupId()));
      allGroupIds.add(dataNodeTracker.getStandByGroupTracker().getGroupId());
    });

    // check if all replicas are added to correct datanode tracker and all replicas are added to active group trackers

    Set<RemoteReplicaInfo> allRemoteReplicasInTrackers = new HashSet<>();
    dataNodeTrackers.forEach(dataNodeTracker -> {
      dataNodeTracker.getActiveGroupTrackers().forEach(activeGroupTracker -> {
        activeGroupTracker.getPreAssignedReplicas().forEach(replicaTracker -> {
          Assert.assertEquals("Replica should be added to the tracker of data node on which it exists",
              dataNodeTracker.getDataNodeId(), replicaTracker.getRemoteReplicaInfo().getReplicaId().getDataNodeId());
          allRemoteReplicasInTrackers.add(replicaTracker.getRemoteReplicaInfo());
        });
      });
    });

    dataNodeToReplicaMap.forEach((dataNodeId, remoteReplicaInfos) -> {
      remoteReplicaInfos.forEach(remoteReplicaInfo -> {
        Assert.assertTrue("Replicas in replica thread should be present in trackers",
            allRemoteReplicasInTrackers.contains(remoteReplicaInfo));
      });
    });

    // check if active groups have maximum replicas as maxPartitionCountPerRequest
    dataNodeTrackers.forEach(dataNodeTracker -> {
      dataNodeTracker.getActiveGroupTrackers().forEach(activeGroupTracker -> {
        Assert.assertTrue(
            "active groups should have max preassigned replicas less than or equal to max partition per request",
            maxPartitionCountPerRequest >= activeGroupTracker.getPreAssignedReplicas().size());
      });
    });
  }
Testing to check if group trackers, data node trackers and replica trackers are getting generated correctly
Tested on intraColoReplicaThread Only as logic is same for intra-colo and cross-colo
ambry-replication/src/test/java/com/github/ambry/replication/RemoteReplicaGroupPollerTest.java