@Test
  public void closeLogSegmentWithExceptionTest() throws Exception {
    Pair<LogSegment, FileChannel> segmentAndFileChannel =
        getSegmentAndFileChannel(LogSegmentName.SINGLE_SEGMENT_LOG_FILE_NAME);
    LogSegment segment = segmentAndFileChannel.getFirst();
    FileChannel mockFileChannel = segmentAndFileChannel.getSecond();
    verify(mockFileChannel).force(true);

    // test that log segment is being closed due to disk I/O error (shouldSkipDiskFlush = true) and exception occurs
    // when closing file channel
    doThrow(new IOException("close channel failure")).when(mockFileChannel).close();
    segment.close(true);
    verify(mockFileChannel).force(true);
    assertTrue("File couldn't be deleted.", (new File(tempDir, LogSegmentName.SINGLE_SEGMENT_LOG_FILE_NAME).delete()));

    segmentAndFileChannel = getSegmentAndFileChannel(LogSegmentName.SINGLE_SEGMENT_LOG_FILE_NAME);
    segment = segmentAndFileChannel.getFirst();
    mockFileChannel = segmentAndFileChannel.getSecond();
    verify(mockFileChannel).force(true);

    // test that log segment is being closed during normal shutdown (shouldSkipDiskFlush = false) and exception occurs
    doThrow(new IOException("close channel failure")).when(mockFileChannel).close();
    try {
      segment.close(false);
      fail("should fail because IOException occurred");
    } catch (IOException e) {
      //expected
    }
    verify(mockFileChannel, times(2)).force(true);
    assertTrue("File couldn't be deleted.", (new File(tempDir, LogSegmentName.SINGLE_SEGMENT_LOG_FILE_NAME).delete()));
  }
Test that closing log segment (skip disk flush) and exception occurs. The shutdown process should continue.
ambry-store/src/test/java/com/github/ambry/store/LogSegmentTest.java