@Test
  public void testTotalTimerExpiresEvenIfDeferralTimerIsExtended() throws InterruptedException {
    // Arrange
    AtomicBoolean deferralHandlerCalled = new AtomicBoolean(false);
    AtomicBoolean totalHandlerCalled = new AtomicBoolean(false);

    BootstrapSession session = new BootstrapSession(mockPartitionId, "snapshot1", "node1",
        diskManagerConfig, (nodeId, partitionId) -> deferralHandlerCalled.set(true), (nodeId, partitionId) -> totalHandlerCalled.set(true));
    session.start();

    // Act
    // Repeatedly extend the deferral timer before it expires
    for (int i = 0; i < 3; i++) {
      Thread.sleep(250);  // less than deferralTimeout
      session.extendDeferralTimer(300);  // push it further each time
    }

    // Wait a bit longer to allow total timer to expire
    Thread.sleep(300);  // 4 * 250 + 300 = ~1300ms > 1000ms

    // Assert
    // The deferral timer should not have fired as it was restarted multiple times
    assertFalse(deferralHandlerCalled.get());

    // The total timer should have fired once, despite extensions
    assertTrue(totalHandlerCalled.get());
  }
Test that the total timer expires even if the deferral timer is extended.
ambry-store/src/test/java/com/github/ambry/store/BootstrapSessionTest.java