@Test
  public void testFinalBlobCompletedBeforeOtherChunks() throws Exception {
    // test if final blob is the first blob to be completed.
    BatchOperationCallbackTracker tracker =
        new BatchOperationCallbackTracker(chunkIds, finalBlobId, new FutureResult<>(), callback, quotaChargeCallback,
            finalOperation, router);
    tracker.getCallback(finalBlobId).onCompletion(null, null);
    Assert.assertTrue(trackerException instanceof RouterException);
    Assert.assertTrue(tracker.isCompleted());
    Assert.assertFalse(finalOperationCalled.get());

    // test if final blob completion arrives after some blobs (but not all blobs) are completed.
    for (int i = 0; i < NUM_CHUNKS - 1; i++) {
      tracker =
          new BatchOperationCallbackTracker(chunkIds, finalBlobId, new FutureResult<>(), callback, quotaChargeCallback,
              finalOperation, router);
      for (int j = 0; j <= i; j++) {
        tracker.getCallback(chunkIds.get(j)).onCompletion(null, null);
        Assert.assertFalse(finalOperationCalled.get());
      }
      tracker.getCallback(finalBlobId).onCompletion(null, null);
      Assert.assertTrue(trackerException instanceof RouterException);
      Assert.assertTrue(tracker.isCompleted());
      Assert.assertFalse(finalOperationCalled.get());
    }
  }
Test that if final blob id is completed before any other blob, it causes an error.
ambry-router/src/test/java/com/github/ambry/router/BatchOperationCallbackTrackerTest.java