Search in sources :

Example 36 with TableName

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

the class BaseBigtableTableAdminClientTest method snapshotTableExceptionTest2.

@Test
public void snapshotTableExceptionTest2() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockBigtableTableAdmin.addException(exception);
    try {
        TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
        String cluster = "cluster872092154";
        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) ByteString(com.google.protobuf.ByteString) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 37 with TableName

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

the class BaseBigtableTableAdminClientTest method deleteTableExceptionTest.

@Test
public void deleteTableExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockBigtableTableAdmin.addException(exception);
    try {
        TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
        client.deleteTable(name);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : TableName(com.google.bigtable.admin.v2.TableName) InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) Test(org.junit.Test)

Example 38 with TableName

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

the class BigtableAdminTest method testDeleteRowRangeByPrefixNonUtf8.

@Test
public void testDeleteRowRangeByPrefixNonUtf8() throws IOException, InterruptedException {
    TableName tableName = TableName.valueOf(TABLE_ID);
    ByteString expectedKey = ByteString.copyFrom(new byte[] { 0, 0, 0, (byte) 128 });
    DropRowRangeRequest expectedRequest = DropRowRangeRequest.newBuilder().setName(TABLE_NAME).setRowKeyPrefix(expectedKey).build();
    responseQueue.put(Empty.getDefaultInstance());
    admin.deleteRowRangeByPrefix(tableName, expectedKey.toByteArray());
    assertEquals(expectedRequest, requestQueue.take());
}
Also used : TableName(org.apache.hadoop.hbase.TableName) DropRowRangeRequest(com.google.bigtable.admin.v2.DropRowRangeRequest) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 39 with TableName

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

the class TestBigtableAdmin method testDeleteRowRangeByPrefixNonUtf8.

@Test
public void testDeleteRowRangeByPrefixNonUtf8() throws IOException, InterruptedException {
    TableName tableName = TableName.valueOf(TABLE_ID);
    ByteString expectedKey = ByteString.copyFrom(new byte[] { 0, 0, 0, (byte) 128 });
    DropRowRangeRequest expectedRequest = DropRowRangeRequest.newBuilder().setName(TABLE_NAME).setRowKeyPrefix(expectedKey).build();
    responseQueue.put(Empty.getDefaultInstance());
    admin.deleteRowRangeByPrefix(tableName, expectedKey.toByteArray());
    assertEquals(expectedRequest, requestQueue.take());
}
Also used : TableName(org.apache.hadoop.hbase.TableName) DropRowRangeRequest(com.google.bigtable.admin.v2.DropRowRangeRequest) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 40 with TableName

use of com.google.bigtable.admin.v2.TableName in project beam by apache.

the class BigtableClientWrapper method deleteTable.

void deleteTable(String tableId) {
    final String tableName = bigtableOptions.getInstanceName().toTableNameStr(tableId);
    DeleteTableRequest.Builder deleteTableRequestBuilder = DeleteTableRequest.newBuilder().setName(tableName);
    tableAdminClient.deleteTable(deleteTableRequestBuilder.build());
}
Also used : DeleteTableRequest(com.google.bigtable.admin.v2.DeleteTableRequest) RowUtils.byteString(org.apache.beam.sdk.io.gcp.bigtable.RowUtils.byteString)

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