private void singleSegmentRecoveryTest() throws StoreException {
    Offset indexEndOffsetBeforeRecovery = state.index.getCurrentEndOffset();
    // recover a few messages in a single segment
    final List<MessageInfo> infos = getCuratedSingleSegmentRecoveryInfos();
    final AtomicInteger returnTracker = new AtomicInteger(0);
    state.recovery = (read, startOffset, endOffset, factory) -> {
      switch (returnTracker.getAndIncrement()) {
        case 0:
          return new MessageStoreRecovery.RecoveryResult(infos, null, endOffset);
        default:
          throw new IllegalStateException("This function should not have been called more than once");
      }
    };
    // This test relies on log segment not spilling over. If that happens, this test will fail.
    LogSegment activeSegment = state.log.getSegment(indexEndOffsetBeforeRecovery.getName());
    long expectedSegmentEndOffset = activeSegment.getEndOffset();
    // write a little "extra" data
    state.appendToLog(2 * CuratedLogIndexState.PUT_RECORD_SIZE);

    state.reloadIndex(true, false);
    assertEquals("Journal should only include entry for last log segment",
        state.index.journal.getFirstOffset().getName(), state.index.log.getLastSegment().getName());
    assertEquals("End offset not as expected", expectedSegmentEndOffset, activeSegment.getEndOffset());
    infos.forEach(this::checkRecoveryInfoEquivalence);
  }
Test recovery of a single segment.
@throws StoreException
ambry-store/src/test/java/com/github/ambry/store/IndexTest.java