Search in sources :

Example 1 with DisabledTableSnapshotHandler

use of org.apache.hadoop.hbase.master.snapshot.DisabledTableSnapshotHandler in project hbase by apache.

the class TestSnapshotFromMaster method testIsDoneContract.

/**
 * Test that the contract from the master for checking on a snapshot are valid.
 * <p>
 * <ol>
 * <li>If a snapshot fails with an error, we expect to get the source error.</li>
 * <li>If there is no snapshot name supplied, we should get an error.</li>
 * <li>If asking about a snapshot has hasn't occurred, you should get an error.</li>
 * </ol>
 */
@Test
public void testIsDoneContract() throws Exception {
    IsSnapshotDoneRequest.Builder builder = IsSnapshotDoneRequest.newBuilder();
    String snapshotName = "asyncExpectedFailureTest";
    // check that we get an exception when looking up snapshot where one hasn't happened
    SnapshotTestingUtils.expectSnapshotDoneException(master, builder.build(), UnknownSnapshotException.class);
    // and that we get the same issue, even if we specify a name
    SnapshotDescription desc = SnapshotDescription.newBuilder().setName(snapshotName).setTable(TABLE_NAME.getNameAsString()).build();
    builder.setSnapshot(desc);
    SnapshotTestingUtils.expectSnapshotDoneException(master, builder.build(), 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(Boolean.TRUE);
    Mockito.when(mockHandler.getCompletionTimestamp()).thenReturn(EnvironmentEdgeManager.currentTime());
    master.getSnapshotManager().setSnapshotHandlerForTesting(TABLE_NAME, mockHandler);
    // if we do a lookup without a snapshot name, we should fail - you should always know your name
    builder = IsSnapshotDoneRequest.newBuilder();
    SnapshotTestingUtils.expectSnapshotDoneException(master, builder.build(), UnknownSnapshotException.class);
    // then do the lookup for the snapshot that it is done
    builder.setSnapshot(desc);
    IsSnapshotDoneResponse response = master.getMasterRpcServices().isSnapshotDone(null, builder.build());
    assertTrue("Snapshot didn't complete when it should have.", response.getDone());
    // now try the case where we are looking for a snapshot we didn't take
    builder.setSnapshot(SnapshotDescription.newBuilder().setName("Not A Snapshot").build());
    SnapshotTestingUtils.expectSnapshotDoneException(master, builder.build(), UnknownSnapshotException.class);
    // then create a snapshot to the fs and make sure that we can find it when checking done
    snapshotName = "completed";
    desc = createSnapshot(snapshotName);
    builder.setSnapshot(desc);
    response = master.getMasterRpcServices().isSnapshotDone(null, builder.build());
    assertTrue("Completed, on-disk snapshot not found", response.getDone());
}
Also used : IsSnapshotDoneResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.IsSnapshotDoneResponse) SnapshotDescription(org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos.SnapshotDescription) IsSnapshotDoneRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.IsSnapshotDoneRequest) DisabledTableSnapshotHandler(org.apache.hadoop.hbase.master.snapshot.DisabledTableSnapshotHandler) Test(org.junit.Test)

Aggregations

DisabledTableSnapshotHandler (org.apache.hadoop.hbase.master.snapshot.DisabledTableSnapshotHandler)1 IsSnapshotDoneRequest (org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.IsSnapshotDoneRequest)1 IsSnapshotDoneResponse (org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.IsSnapshotDoneResponse)1 SnapshotDescription (org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos.SnapshotDescription)1 Test (org.junit.Test)1