Search in sources :

Example 1 with RestoreTableRequest

use of com.google.bigtable.admin.v2.RestoreTableRequest in project java-bigtable by googleapis.

the class BaseBigtableTableAdminClientTest method restoreTableTest.

@Test
public void restoreTableTest() throws Exception {
    Table expectedResponse = Table.newBuilder().setName(TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]").toString()).putAllClusterStates(new HashMap<String, Table.ClusterState>()).putAllColumnFamilies(new HashMap<String, ColumnFamily>()).setRestoreInfo(RestoreInfo.newBuilder().build()).build();
    Operation resultOperation = Operation.newBuilder().setName("restoreTableTest").setDone(true).setResponse(Any.pack(expectedResponse)).build();
    mockBigtableTableAdmin.addResponse(resultOperation);
    RestoreTableRequest request = RestoreTableRequest.newBuilder().setParent(InstanceName.of("[PROJECT]", "[INSTANCE]").toString()).setTableId("tableId-1552905847").build();
    Table actualResponse = client.restoreTableAsync(request).get();
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockBigtableTableAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    RestoreTableRequest actualRequest = ((RestoreTableRequest) actualRequests.get(0));
    Assert.assertEquals(request.getParent(), actualRequest.getParent());
    Assert.assertEquals(request.getTableId(), actualRequest.getTableId());
    Assert.assertEquals(request.getBackup(), actualRequest.getBackup());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : RestoreTableRequest(com.google.bigtable.admin.v2.RestoreTableRequest) Table(com.google.bigtable.admin.v2.Table) AbstractMessage(com.google.protobuf.AbstractMessage) HashMap(java.util.HashMap) ByteString(com.google.protobuf.ByteString) Operation(com.google.longrunning.Operation) ColumnFamily(com.google.bigtable.admin.v2.ColumnFamily) Test(org.junit.Test)

Example 2 with RestoreTableRequest

use of com.google.bigtable.admin.v2.RestoreTableRequest in project java-bigtable by googleapis.

the class BaseBigtableTableAdminClientTest method restoreTableExceptionTest.

@Test
public void restoreTableExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockBigtableTableAdmin.addException(exception);
    try {
        RestoreTableRequest request = RestoreTableRequest.newBuilder().setParent(InstanceName.of("[PROJECT]", "[INSTANCE]").toString()).setTableId("tableId-1552905847").build();
        client.restoreTableAsync(request).get();
        Assert.fail("No exception raised");
    } catch (ExecutionException e) {
        Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass());
        InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause());
        Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode());
    }
}
Also used : RestoreTableRequest(com.google.bigtable.admin.v2.RestoreTableRequest) InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Aggregations

RestoreTableRequest (com.google.bigtable.admin.v2.RestoreTableRequest)2 Test (org.junit.Test)2 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)1 ColumnFamily (com.google.bigtable.admin.v2.ColumnFamily)1 Table (com.google.bigtable.admin.v2.Table)1 Operation (com.google.longrunning.Operation)1 AbstractMessage (com.google.protobuf.AbstractMessage)1 ByteString (com.google.protobuf.ByteString)1 StatusRuntimeException (io.grpc.StatusRuntimeException)1 HashMap (java.util.HashMap)1 ExecutionException (java.util.concurrent.ExecutionException)1