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

    replicaThread.setTerminateCurrentContinuousReplicationCycle(false);

    RemoteReplicaGroupPoller poller = replicaThread.new RemoteReplicaGroupPoller();

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

    Assert.assertFalse("There should be inflight replica groups", inflightGroups.isEmpty());

    // now we will signal that cycle should be terminated
    replicaThread.setTerminateCurrentContinuousReplicationCycle(true);

    // now any new groups should not be generated

    //make all groups in done state
    inflightGroups.forEach((remoteReplicaGroup) -> {
      remoteReplicaGroup.setState(ReplicaThread.ReplicaGroupReplicationState.DONE);
    });

    // after this call all groups will be throttled
    inflightGroups = poller.enqueue();

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

    // limit is 3 , but no new groups should be created after this call
    inflightGroups = poller.enqueue();

    Assert.assertTrue("There should be no inflight groups", inflightGroups.isEmpty());
    Assert.assertFalse("All replicas haven't caught up early", poller.allReplicasCaughtUpEarly());
  }
Testing if setting shouldTerminateCurrentCycle, results in termination of group generation
Testing on intraColo thread, as behaviour will be same in crossColo
ambry-replication/src/test/java/com/github/ambry/replication/RemoteReplicaGroupPollerTest.java