@Test
  public void adaptationTest() throws InterruptedException {
    primeTracker(localColoTracker, MIN_DATA_POINTS_REQUIRED, LOCAL_COLO_LATENCY_RANGE);
    primeTracker(crossColoTracker, MIN_DATA_POINTS_REQUIRED, CROSS_COLO_LATENCY_RANGE);
    double localColoCutoff = localColoTracker.getSnapshot().getValue(QUANTILE);
    double crossColoCutoff = crossColoTracker.getSnapshot().getValue(QUANTILE);

    OperationTracker ot = getOperationTracker(createRouterConfig(true, REPLICA_COUNT, 2, 6, null, true), mockPartition);
    // 3-0-0-0; 3-0-0-0
    sendRequests(ot, 2);
    // 1-2-0-0; 3-0-0-0
    // sleep for less than the cutoff
    time.sleep((long) localColoCutoff - 2);
    sendRequests(ot, 0);
    // push it over the edge
    time.sleep(5);
    // should send two requests because both of the oldest requests are past their due times
    // the second of the two requests is a cross colo request
    sendRequests(ot, 2);
    // 0-3-0-0; 2-1-0-0
    time.sleep((long) localColoCutoff + 2);
    // second cross colo request sent (local colo request is past due but the first cross colo request is not past due).
    sendRequests(ot, 1);
    // 0-3-0-0; 1-2-0-0
    long sleepTime = (long) localColoCutoff + 2;
    time.sleep(sleepTime);
    // no requests should be sent.
    // for first cross colo request, 2 * (localColoCutoff + 2) <= 2 * (57 * 0.9 + 2) = 106.6 < 120 * 0.9 <= crossColoCutoff
    sendRequests(ot, 0);
    // 0-3-0-0; 1-2-0-0
    sleepTime = (long) (crossColoCutoff - localColoCutoff) + 2;
    time.sleep(sleepTime);
    // third cross colo request sent (first cross colo request is past due)
    sendRequests(ot, 1);
    // 0-3-0-0; 0-3-0-0
    time.sleep((long) crossColoCutoff + 2);
    // no more replicas left to send requests to
    sendRequests(ot, 0);
    // generate a response for every request and make sure there are no errors
    for (int i = 0; i < REPLICA_COUNT; i++) {
      assertFalse("Operation should not be done", ot.isDone());
      ot.onResponse(partitionAndInflightReplicas.get(mockPartition).poll(), TrackedRequestFinalState.SUCCESS);
    }
    assertTrue("Operation should have succeeded", ot.hasSucceeded());
    // past due counter should be REPLICA_COUNT - 2 (note that pastDueCounter is updated only when Iterator.remove() is called)
    assertEquals("Past due counter is inconsistent", REPLICA_COUNT - 2, pastDueCounter.getCount());
  }
Tests that requests are discounted from the parallelism count once they move beyond the tolerance quantile.
@throws InterruptedException
ambry-router/src/test/java/com/github/ambry/router/AdaptiveOperationTrackerTest.java