private void totalIndexLossRecoveryTest() throws StoreException {
    state.closeAndClearIndex();
    final AtomicInteger returnTracker = new AtomicInteger(0);
    state.recovery = (read, startOffset, endOffset, factory) -> {
      switch (returnTracker.getAndIncrement()) {
        case 0:
          return new MessageStoreRecovery.RecoveryResult(Collections.singletonList(
              new MessageInfo(state.getUniqueId(), CuratedLogIndexState.PUT_RECORD_SIZE,
                  Utils.getRandomShort(TestUtils.RANDOM), Utils.getRandomShort(TestUtils.RANDOM), Utils.Infinite_Time)),
              null, endOffset);
        default:
          return new MessageStoreRecovery.RecoveryResult(Collections.emptyList(), null, endOffset);
      }
    };
    state.reloadIndex(true, false);
    assertEquals("Incorrect log segment count", 1, state.index.getLogSegmentCount());
    assertEquals("Index should contain exactly one index segment", 1, state.index.getIndexSegments().size());
    LogSegment segment = state.log.getFirstSegment();
    assertEquals("End offset not as expected",
        new Offset(segment.getName(), segment.getStartOffset() + CuratedLogIndexState.PUT_RECORD_SIZE),
        state.index.getCurrentEndOffset());
  }
Tests the case where the index is lost completely and needs to be recovered from scratch.
@throws StoreException
ambry-store/src/test/java/com/github/ambry/store/IndexTest.java