public void testIsDoneContract() throws Exception {
String snapshotName = "asyncExpectedFailureTest";
// check that we get an exception when looking up snapshot where one hasn't happened
SnapshotTestingUtils.expectSnapshotDoneException(master, new HSnapshotDescription(),
UnknownSnapshotException.class);
// and that we get the same issue, even if we specify a name
SnapshotDescription desc = SnapshotDescription.newBuilder()
.setName(snapshotName).build();
SnapshotTestingUtils.expectSnapshotDoneException(master, new HSnapshotDescription(desc),
UnknownSnapshotException.class);
// set a mock handler to simulate a snapshot
DisabledTableSnapshotHandler mockHandler = Mockito.mock(DisabledTableSnapshotHandler.class);
Mockito.when(mockHandler.getException()).thenReturn(null);
Mockito.when(mockHandler.getSnapshot()).thenReturn(desc);
Mockito.when(mockHandler.isFinished()).thenReturn(new Boolean(true));
master.getSnapshotManagerForTesting().setSnapshotHandlerForTesting(mockHandler);
// if we do a lookup without a snapshot name, we should fail - you should always know your name
SnapshotTestingUtils.expectSnapshotDoneException(master, new HSnapshotDescription(),
UnknownSnapshotException.class);
// then do the lookup for the snapshot that it is done
boolean isDone = master.isSnapshotDone(new HSnapshotDescription(desc));
assertTrue("Snapshot didn't complete when it should have.", isDone);
// now try the case where we are looking for a snapshot we didn't take
desc = SnapshotDescription.newBuilder().setName("Not A Snapshot").build();
SnapshotTestingUtils.expectSnapshotDoneException(master, new HSnapshotDescription(desc),
UnknownSnapshotException.class);
// then create a snapshot to the fs and make sure that we can find it when checking done
snapshotName = "completed";
Path snapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(snapshotName, rootDir);
desc = desc.toBuilder().setName(snapshotName).build();
SnapshotDescriptionUtils.writeSnapshotInfo(desc, snapshotDir, fs);
isDone = master.isSnapshotDone(new HSnapshotDescription(desc));
assertTrue("Completed, on-disk snapshot not found", isDone);
}