Search in sources :

Example 6 with TableName

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

the class BaseBigtableTableAdminClientTest method modifyColumnFamiliesExceptionTest.

@Test
public void modifyColumnFamiliesExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockBigtableTableAdmin.addException(exception);
    try {
        TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
        List<ModifyColumnFamiliesRequest.Modification> modifications = new ArrayList<>();
        client.modifyColumnFamilies(name, modifications);
        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) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 7 with TableName

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

the class BaseBigtableTableAdminClientTest method getTableExceptionTest.

@Test
public void getTableExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockBigtableTableAdmin.addException(exception);
    try {
        TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
        client.getTable(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 8 with TableName

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

the class BaseBigtableTableAdminClientTest method generateConsistencyTokenExceptionTest.

@Test
public void generateConsistencyTokenExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockBigtableTableAdmin.addException(exception);
    try {
        TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
        client.generateConsistencyToken(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 9 with TableName

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

the class BaseBigtableTableAdminClientTest method checkConsistencyTest.

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

Example 10 with TableName

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

Aggregations

Test (org.junit.Test)35 ByteString (com.google.protobuf.ByteString)30 ArrayList (java.util.ArrayList)20 TableName (com.google.bigtable.v2.TableName)18 TableName (com.google.bigtable.admin.v2.TableName)16 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 TableName (com.google.cloud.bigquery.storage.v1.TableName)7 ExecutionException (java.util.concurrent.ExecutionException)7 CheckAndMutateRowResponse (com.google.bigtable.v2.CheckAndMutateRowResponse)6 ReadModifyWriteRule (com.google.bigtable.v2.ReadModifyWriteRule)6 RowFilter (com.google.bigtable.v2.RowFilter)6 BaseBigtableDataClient (com.google.cloud.bigtable.data.v2.BaseBigtableDataClient)6 AppendRowsResponse (com.google.cloud.bigquery.storage.v1.AppendRowsResponse)5 JsonStreamWriter (com.google.cloud.bigquery.storage.v1.JsonStreamWriter)5 ColumnFamily (com.google.bigtable.admin.v2.ColumnFamily)4