@Test
  public void partialRecoveryWithFirstLogSegment() throws Exception {
    assumeTrue(isLogSegmented);
    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)),
              new StoreException(new IndexOutOfBoundsException(), StoreErrorCodes.LogFileFormatError), PUT_RECORD_SIZE);
        default:
          return new MessageStoreRecovery.RecoveryResult(Collections.emptyList(), null, endOffset);
      }
    };

    // Enable partial log segment recovery, and have a huge threshold to make sure the threshold is not an issue
    state.properties.setProperty(StoreConfig.storeEnablePartialLogSegmentRecoveryName, "true");
    state.properties.setProperty(StoreConfig.storePartialLogSegmentRecoveryRemainingDataSizeThresholdName,
        String.valueOf(100 * 1024 * 1024 * 1024));
    try {
      state.reloadLog(true);
      fail("Should fail due to first log segment");
    } catch (StoreException ex) {
      Assert.assertEquals(StoreErrorCodes.LogFileFormatError, ex.getErrorCode());
      Assert.assertTrue(ex.getCause() instanceof IndexOutOfBoundsException);
    }
  }
Tests success case for recovery when the last index segment file is corrupted.
@throws Exception
ambry-store/src/test/java/com/github/ambry/store/IndexTest.java