Search in sources :

Example 1 with IBigtableTableAdminClient

use of com.google.cloud.bigtable.core.IBigtableTableAdminClient in project java-bigtable-hbase by googleapis.

the class SimpleIT method testConnection.

@Test
public void testConnection() throws Exception {
    String projectId = "fake-project";
    String instanceId = "fake-instance";
    String tableId = "myTable";
    String family = "cf";
    String key = "key";
    String value = "value";
    BigtableOptions opts = new BigtableOptions.Builder().setUserAgent("fake").setProjectId(projectId).setInstanceId(instanceId).build();
    try (BigtableSession session = new BigtableSession(opts)) {
        IBigtableTableAdminClient tableAdminClient = session.getTableAdminClientWrapper();
        tableAdminClient.createTable(CreateTableRequest.of(tableId).addFamily(family));
        IBigtableDataClient dataClient = session.getDataClientWrapper();
        dataClient.mutateRow(RowMutation.create(tableId, key).setCell(family, "", value));
        List<Row> results = dataClient.readRowsAsync(Query.create(tableId).rowKey(key)).get();
        Assert.assertEquals(ByteString.copyFromUtf8(value), results.get(0).getCells().get(0).getValue());
    }
}
Also used : IBigtableTableAdminClient(com.google.cloud.bigtable.core.IBigtableTableAdminClient) BigtableOptions(com.google.cloud.bigtable.config.BigtableOptions) IBigtableDataClient(com.google.cloud.bigtable.core.IBigtableDataClient) ByteString(com.google.protobuf.ByteString) BigtableSession(com.google.cloud.bigtable.grpc.BigtableSession) Row(com.google.cloud.bigtable.data.v2.models.Row) Test(org.junit.Test)

Aggregations

BigtableOptions (com.google.cloud.bigtable.config.BigtableOptions)1 IBigtableDataClient (com.google.cloud.bigtable.core.IBigtableDataClient)1 IBigtableTableAdminClient (com.google.cloud.bigtable.core.IBigtableTableAdminClient)1 Row (com.google.cloud.bigtable.data.v2.models.Row)1 BigtableSession (com.google.cloud.bigtable.grpc.BigtableSession)1 ByteString (com.google.protobuf.ByteString)1 Test (org.junit.Test)1