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

    replicaThread.setTerminateCurrentContinuousReplicationCycle(false);

    RemoteReplicaGroupPoller poller = replicaThread.new RemoteReplicaGroupPoller();

    List<RemoteReplicaGroup> inflightGroups = poller.enqueue();

    // set all remote replicas groups to done
    inflightGroups.forEach(group -> group.setState(ReplicaThread.ReplicaGroupReplicationState.DONE));

    // all groups will be throttled now, no new groups will be created, so all replica will have caught up early
    inflightGroups = poller.enqueue();

    Assert.assertTrue("all replicas should have caught up early", poller.allReplicasCaughtUpEarly());
    Assert.assertEquals("no inflight groups should be created", 0, inflightGroups.size());

    // move time forward till throttling limit
    time.setCurrentMilliseconds(
        time.milliseconds() + replicationConfig.replicationIntraReplicaThreadThrottleSleepDurationMs + 1);

    // now we make all replicas in backoff mode
    dataNodeToReplicaMap.values().stream().flatMap(Collection::stream).forEach(remoteReplicaInfo -> {
      remoteReplicaInfo.setReEnableReplicationTime(
          time.milliseconds() + replicationConfig.replicationSyncedReplicaBackoffDurationMs + 1);
    });

    // all groups will be throttled now, no new groups will be created, so all replica will have caught up early
    inflightGroups = poller.enqueue();

    Assert.assertTrue("all replicas should have caught up early", poller.allReplicasCaughtUpEarly());
    Assert.assertEquals("no inflight groups should be created", 0, inflightGroups.size());
  }
Tests for when all replicas have caught up early or are in backoff mode or throttled
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