@Test
  public void readFromFileFailureTest() throws StoreException, IOException {
    LogSegmentName logSegmentName = LogSegmentName.fromPositionAndGeneration(0, 0);
    StoreKeyFactory mockStoreKeyFactory = Mockito.spy(STORE_KEY_FACTORY);
    Journal journal = new Journal(tempDir.getAbsolutePath(), 3, 3);
    IndexSegment indexSegment = generateIndexSegment(new Offset(logSegmentName, 0), mockStoreKeyFactory);
    MockId id1 = new MockId("0" + TestUtils.getRandomString(CUSTOM_ID_SIZE - 1));
    IndexValue value1 =
        IndexValueTest.getIndexValue(1000, new Offset(logSegmentName, 0), Utils.Infinite_Time, time.milliseconds(),
            Utils.getRandomShort(TestUtils.RANDOM), Utils.getRandomShort(TestUtils.RANDOM), (short) 0, formatVersion);
    indexSegment.addEntry(new IndexEntry(id1, value1), new Offset(logSegmentName, 1000));
    indexSegment.writeIndexSegmentToFile(new Offset(logSegmentName, 1000));
    // test IOException is captured and StoreException.IOError is thrown
    doThrow(new IOException(StoreException.IO_ERROR_STR)).when(mockStoreKeyFactory)
        .getStoreKey(any(DataInputStream.class));
    try {
      new IndexSegment(indexSegment.getFile(), false, mockStoreKeyFactory, config, metrics, journal, time);
      fail("should fail");
    } catch (StoreException e) {
      assertEquals("Mismatch in error code", StoreErrorCodes.IndexCreationFailure, e.getErrorCode());
    }
  }
Test cases where exceptions occurred while reading from file.
@throws IOException
@throws StoreException
ambry-store/src/test/java/com/github/ambry/store/IndexSegmentTest.java