Search in sources :

Example 41 with TableName

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

the class TableTest method testFromProto.

@Test
public void testFromProto() {
    TableName testName = TableName.of("my-project", "my-instance", "my-table");
    com.google.bigtable.admin.v2.Table proto = com.google.bigtable.admin.v2.Table.newBuilder().setName(testName.toString()).setGranularity(TimestampGranularity.MILLIS).putClusterStates("cluster1", com.google.bigtable.admin.v2.Table.ClusterState.newBuilder().setReplicationState(com.google.bigtable.admin.v2.Table.ClusterState.ReplicationState.READY).build()).putClusterStates("cluster2", com.google.bigtable.admin.v2.Table.ClusterState.newBuilder().setReplicationState(com.google.bigtable.admin.v2.Table.ClusterState.ReplicationState.INITIALIZING).build()).putColumnFamilies("cf1", ColumnFamily.newBuilder().build()).putColumnFamilies("cf2", ColumnFamily.newBuilder().setGcRule(GcRule.newBuilder().setMaxNumVersions(1)).build()).putColumnFamilies("cf3", ColumnFamily.newBuilder().setGcRule(GcRule.newBuilder().setMaxAge(com.google.protobuf.Duration.newBuilder().setSeconds(1).setNanos(99))).build()).build();
    Table result = Table.fromProto(proto);
    assertThat(result.getInstanceId()).isEqualTo("my-instance");
    assertThat(result.getId()).isEqualTo("my-table");
    assertThat(result.getReplicationStatesByClusterId()).containsExactly("cluster1", Table.ReplicationState.READY, "cluster2", Table.ReplicationState.INITIALIZING);
    assertThat(result.getColumnFamilies()).hasSize(3);
    for (Entry<String, ColumnFamily> entry : proto.getColumnFamiliesMap().entrySet()) {
        assertThat(result.getColumnFamilies()).contains(com.google.cloud.bigtable.admin.v2.models.ColumnFamily.fromProto(entry.getKey(), entry.getValue()));
    }
}
Also used : TableName(com.google.bigtable.admin.v2.TableName) ColumnFamily(com.google.bigtable.admin.v2.ColumnFamily) Test(org.junit.Test)

Example 42 with TableName

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

the class SimpleGceRawRead method main.

public static void main(String[] args) {
    configureLogging();
    String projectId = System.getProperty("bigtable.project", "gcloud-devel");
    String instanceId = System.getProperty("bigtable.instance", "google-cloud-bigtable");
    String tableId = System.getProperty("bigtable.table", "integration-tests");
    String endpoint = System.getProperty("bigtable.data-endpoint", "bigtable.googleapis.com");
    String tableName = String.format("projects/%s/instances/%s/tables/%s", projectId, instanceId, tableId);
    System.out.printf(">>>>>>>>> Trying to connect to: %s, to read %s%n%n%n", endpoint, tableName);
    ManagedChannel channel = ComputeEngineChannelBuilder.forAddress(endpoint, 443).disableServiceConfigLookUp().defaultServiceConfig(newServiceConfig()).build();
    try {
        BigtableGrpc.BigtableBlockingStub stub = BigtableGrpc.newBlockingStub(channel);
        Iterator<ReadRowsResponse> iter = stub.readRows(ReadRowsRequest.newBuilder().setTableName(tableName).setRowsLimit(1).build());
        System.out.printf("%n%n>>>>>>>>> Success Rows Read: %d%n%n", Lists.newArrayList(iter).size());
    } finally {
        channel.shutdown();
    }
}
Also used : ReadRowsResponse(com.google.bigtable.v2.ReadRowsResponse) BigtableGrpc(com.google.bigtable.v2.BigtableGrpc) ManagedChannel(io.grpc.ManagedChannel)

Example 43 with TableName

use of com.google.bigtable.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 44 with TableName

use of com.google.bigtable.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 45 with TableName

use of com.google.bigtable.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)

Aggregations

ByteString (com.google.protobuf.ByteString)48 Test (org.junit.Test)46 ArrayList (java.util.ArrayList)39 Mutation (com.google.bigtable.v2.Mutation)25 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)19 AbstractMessage (com.google.protobuf.AbstractMessage)19 StatusRuntimeException (io.grpc.StatusRuntimeException)19 TableName (com.google.bigtable.v2.TableName)18 TableName (com.google.bigtable.admin.v2.TableName)17 CheckAndMutateRowResponse (com.google.bigtable.v2.CheckAndMutateRowResponse)12 ReadModifyWriteRule (com.google.bigtable.v2.ReadModifyWriteRule)12 RowFilter (com.google.bigtable.v2.RowFilter)12 BaseBigtableDataClient (com.google.cloud.bigtable.data.v2.BaseBigtableDataClient)12 JSONArray (org.json.JSONArray)9 JSONObject (org.json.JSONObject)9 CheckAndMutateRowRequest (com.google.bigtable.v2.CheckAndMutateRowRequest)8 MutateRowResponse (com.google.bigtable.v2.MutateRowResponse)8 ReadModifyWriteRowResponse (com.google.bigtable.v2.ReadModifyWriteRowResponse)8 ExecutionException (java.util.concurrent.ExecutionException)8 TableName (com.google.cloud.bigquery.storage.v1.TableName)7