Search in sources :

Example 31 with TableName

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

the class BaseBigtableTableAdminClient method deleteTable.

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
 * Permanently deletes a specified table and all of its data.
 *
 * <p>Sample code:
 *
 * <pre>{@code
 * // This snippet has been automatically generated for illustrative purposes only.
 * // It may require modifications to work in your environment.
 * try (BaseBigtableTableAdminClient baseBigtableTableAdminClient =
 *     BaseBigtableTableAdminClient.create()) {
 *   TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
 *   baseBigtableTableAdminClient.deleteTable(name);
 * }
 * }</pre>
 *
 * @param name Required. The unique name of the table to be deleted. Values are of the form
 *     `projects/{project}/instances/{instance}/tables/{table}`.
 * @throws com.google.api.gax.rpc.ApiException if the remote call fails
 */
public final void deleteTable(TableName name) {
    DeleteTableRequest request = DeleteTableRequest.newBuilder().setName(name == null ? null : name.toString()).build();
    deleteTable(request);
}
Also used : DeleteTableRequest(com.google.bigtable.admin.v2.DeleteTableRequest)

Example 32 with TableName

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

the class BaseBigtableTableAdminClientTest method snapshotTableExceptionTest.

@Test
public void snapshotTableExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockBigtableTableAdmin.addException(exception);
    try {
        TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
        ClusterName cluster = ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]");
        String snapshotId = "snapshotId-1113817601";
        String description = "description-1724546052";
        client.snapshotTableAsync(name, cluster, snapshotId, description).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 : TableName(com.google.bigtable.admin.v2.TableName) InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) ClusterName(com.google.bigtable.admin.v2.ClusterName) ByteString(com.google.protobuf.ByteString) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 33 with TableName

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

the class BaseBigtableTableAdminClientTest method getTableTest.

@Test
public void getTableTest() 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();
    mockBigtableTableAdmin.addResponse(expectedResponse);
    TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
    Table actualResponse = client.getTable(name);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockBigtableTableAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    GetTableRequest actualRequest = ((GetTableRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : TableName(com.google.bigtable.admin.v2.TableName) GetTableRequest(com.google.bigtable.admin.v2.GetTableRequest) Table(com.google.bigtable.admin.v2.Table) AbstractMessage(com.google.protobuf.AbstractMessage) HashMap(java.util.HashMap) ByteString(com.google.protobuf.ByteString) ColumnFamily(com.google.bigtable.admin.v2.ColumnFamily) Test(org.junit.Test)

Example 34 with TableName

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

the class BaseBigtableTableAdminClientTest method deleteTableTest.

@Test
public void deleteTableTest() throws Exception {
    Empty expectedResponse = Empty.newBuilder().build();
    mockBigtableTableAdmin.addResponse(expectedResponse);
    TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
    client.deleteTable(name);
    List<AbstractMessage> actualRequests = mockBigtableTableAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    DeleteTableRequest actualRequest = ((DeleteTableRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : DeleteTableRequest(com.google.bigtable.admin.v2.DeleteTableRequest) TableName(com.google.bigtable.admin.v2.TableName) Empty(com.google.protobuf.Empty) AbstractMessage(com.google.protobuf.AbstractMessage) Test(org.junit.Test)

Example 35 with TableName

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

the class BaseBigtableTableAdminClientTest method generateConsistencyTokenTest.

@Test
public void generateConsistencyTokenTest() throws Exception {
    GenerateConsistencyTokenResponse expectedResponse = GenerateConsistencyTokenResponse.newBuilder().setConsistencyToken("consistencyToken-1985152319").build();
    mockBigtableTableAdmin.addResponse(expectedResponse);
    TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
    GenerateConsistencyTokenResponse actualResponse = client.generateConsistencyToken(name);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockBigtableTableAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    GenerateConsistencyTokenRequest actualRequest = ((GenerateConsistencyTokenRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : TableName(com.google.bigtable.admin.v2.TableName) AbstractMessage(com.google.protobuf.AbstractMessage) GenerateConsistencyTokenRequest(com.google.bigtable.admin.v2.GenerateConsistencyTokenRequest) GenerateConsistencyTokenResponse(com.google.bigtable.admin.v2.GenerateConsistencyTokenResponse) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)36 ByteString (com.google.protobuf.ByteString)31 ArrayList (java.util.ArrayList)20 TableName (com.google.bigtable.v2.TableName)18 TableName (com.google.bigtable.admin.v2.TableName)17 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)13 Mutation (com.google.bigtable.v2.Mutation)13 AbstractMessage (com.google.protobuf.AbstractMessage)13 StatusRuntimeException (io.grpc.StatusRuntimeException)13 JSONArray (org.json.JSONArray)9 JSONObject (org.json.JSONObject)9 ExecutionException (java.util.concurrent.ExecutionException)8 TableName (com.google.cloud.bigquery.storage.v1.TableName)7 ReadModifyWriteRule (com.google.bigtable.v2.ReadModifyWriteRule)6 RowFilter (com.google.bigtable.v2.RowFilter)6 BaseBigtableDataClient (com.google.cloud.bigtable.data.v2.BaseBigtableDataClient)6 ColumnFamily (com.google.bigtable.admin.v2.ColumnFamily)5 Table (com.google.bigtable.admin.v2.Table)4 CheckAndMutateRowResponse (com.google.bigtable.v2.CheckAndMutateRowResponse)4 ReadModifyWriteRowResponse (com.google.bigtable.v2.ReadModifyWriteRowResponse)4