@Test
public void recreateFailingCheckpoint() throws IOException {

    FileSystem fsMock = mock(FileSystem.class);
    FSDataOutputStream outputStreamMock = mock(FSDataOutputStream.class);
    Path returnedPath = new Path("testPath");
    FsBasedCheckpointer cptr = new FsBasedCheckpointer(fsMock, (ignored, alsoIgnored) -> returnedPath);
    // Fail to check that checkpoint exists
    doThrow(new IOException("Ayo")).when(fsMock).exists(returnedPath);
    Assert.assertFalse(cptr.tryCheckpoint(1, Instant.MIN));
    // Fail to write checkpoint
    doReturn(false).when(fsMock).exists(returnedPath);
    doThrow(new IOException("Ayo")).when(fsMock).create(returnedPath);
    Assert.assertFalse(cptr.tryCheckpoint(1, Instant.MIN));
    // Should succeed now
    doReturn(outputStreamMock).when(fsMock).create(returnedPath);
    Assert.assertTrue(cptr.tryCheckpoint(1, Instant.MIN));
    // Succeeds once, fails once
    verify(fsMock, times(2)).create(returnedPath);
    verify(outputStreamMock, times(1)).close();
    verifyNoMoreInteractions(outputStreamMock);
}