Search in sources :

Example 16 with Mutation

use of com.google.spanner.v1.Mutation in project gapic-generator-java by googleapis.

the class BaseBigtableDataClientTest method checkAndMutateRowTest2.

@Test
public void checkAndMutateRowTest2() throws Exception {
    CheckAndMutateRowResponse expectedResponse = CheckAndMutateRowResponse.newBuilder().setPredicateMatched(true).build();
    mockBigtable.addResponse(expectedResponse);
    String tableName = "tableName-1988717703";
    ByteString rowKey = ByteString.EMPTY;
    RowFilter predicateFilter = RowFilter.newBuilder().build();
    List<Mutation> trueMutations = new ArrayList<>();
    List<Mutation> falseMutations = new ArrayList<>();
    CheckAndMutateRowResponse actualResponse = client.checkAndMutateRow(tableName, rowKey, predicateFilter, trueMutations, falseMutations);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockBigtable.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CheckAndMutateRowRequest actualRequest = ((CheckAndMutateRowRequest) actualRequests.get(0));
    Assert.assertEquals(tableName, actualRequest.getTableName());
    Assert.assertEquals(rowKey, actualRequest.getRowKey());
    Assert.assertEquals(predicateFilter, actualRequest.getPredicateFilter());
    Assert.assertEquals(trueMutations, actualRequest.getTrueMutationsList());
    Assert.assertEquals(falseMutations, actualRequest.getFalseMutationsList());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : RowFilter(com.google.bigtable.v2.RowFilter) AbstractMessage(com.google.protobuf.AbstractMessage) ByteString(com.google.protobuf.ByteString) CheckAndMutateRowResponse(com.google.bigtable.v2.CheckAndMutateRowResponse) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) Mutation(com.google.bigtable.v2.Mutation) CheckAndMutateRowRequest(com.google.bigtable.v2.CheckAndMutateRowRequest) Test(org.junit.Test)

Example 17 with Mutation

use of com.google.spanner.v1.Mutation in project gapic-generator-java by googleapis.

the class BaseBigtableDataClientTest method mutateRowTest4.

@Test
public void mutateRowTest4() throws Exception {
    MutateRowResponse expectedResponse = MutateRowResponse.newBuilder().build();
    mockBigtable.addResponse(expectedResponse);
    String tableName = "tableName-1988717703";
    ByteString rowKey = ByteString.EMPTY;
    List<Mutation> mutations = new ArrayList<>();
    String appProfileId = "appProfileId704923523";
    MutateRowResponse actualResponse = client.mutateRow(tableName, rowKey, mutations, appProfileId);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockBigtable.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    MutateRowRequest actualRequest = ((MutateRowRequest) actualRequests.get(0));
    Assert.assertEquals(tableName, actualRequest.getTableName());
    Assert.assertEquals(rowKey, actualRequest.getRowKey());
    Assert.assertEquals(mutations, actualRequest.getMutationsList());
    Assert.assertEquals(appProfileId, actualRequest.getAppProfileId());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : CheckAndMutateRowRequest(com.google.bigtable.v2.CheckAndMutateRowRequest) MutateRowRequest(com.google.bigtable.v2.MutateRowRequest) CheckAndMutateRowResponse(com.google.bigtable.v2.CheckAndMutateRowResponse) MutateRowResponse(com.google.bigtable.v2.MutateRowResponse) AbstractMessage(com.google.protobuf.AbstractMessage) ByteString(com.google.protobuf.ByteString) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) Mutation(com.google.bigtable.v2.Mutation) Test(org.junit.Test)

Example 18 with Mutation

use of com.google.spanner.v1.Mutation in project gapic-generator-java by googleapis.

the class SyncMutateRowStringBytestringListmutationString method syncMutateRowStringBytestringListmutationString.

public static void syncMutateRowStringBytestringListmutationString() throws Exception {
    // It may require modifications to work in your environment.
    try (BaseBigtableDataClient baseBigtableDataClient = BaseBigtableDataClient.create()) {
        String tableName = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]").toString();
        ByteString rowKey = ByteString.EMPTY;
        List<Mutation> mutations = new ArrayList<>();
        String appProfileId = "appProfileId704923523";
        MutateRowResponse response = baseBigtableDataClient.mutateRow(tableName, rowKey, mutations, appProfileId);
    }
}
Also used : MutateRowResponse(com.google.bigtable.v2.MutateRowResponse) ByteString(com.google.protobuf.ByteString) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) Mutation(com.google.bigtable.v2.Mutation) BaseBigtableDataClient(com.google.cloud.bigtable.data.v2.BaseBigtableDataClient)

Example 19 with Mutation

use of com.google.spanner.v1.Mutation in project gapic-generator-java by googleapis.

the class SyncMutateRowTablenameBytestringListmutationString method syncMutateRowTablenameBytestringListmutationString.

public static void syncMutateRowTablenameBytestringListmutationString() throws Exception {
    // It may require modifications to work in your environment.
    try (BaseBigtableDataClient baseBigtableDataClient = BaseBigtableDataClient.create()) {
        TableName tableName = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
        ByteString rowKey = ByteString.EMPTY;
        List<Mutation> mutations = new ArrayList<>();
        String appProfileId = "appProfileId704923523";
        MutateRowResponse response = baseBigtableDataClient.mutateRow(tableName, rowKey, mutations, appProfileId);
    }
}
Also used : TableName(com.google.bigtable.v2.TableName) MutateRowResponse(com.google.bigtable.v2.MutateRowResponse) ByteString(com.google.protobuf.ByteString) ArrayList(java.util.ArrayList) Mutation(com.google.bigtable.v2.Mutation) ByteString(com.google.protobuf.ByteString) BaseBigtableDataClient(com.google.cloud.bigtable.data.v2.BaseBigtableDataClient)

Example 20 with Mutation

use of com.google.spanner.v1.Mutation in project gapic-generator-java by googleapis.

the class BaseBigtableDataClientTest method mutateRowExceptionTest2.

@Test
public void mutateRowExceptionTest2() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockBigtable.addException(exception);
    try {
        String tableName = "tableName-1988717703";
        ByteString rowKey = ByteString.EMPTY;
        List<Mutation> mutations = new ArrayList<>();
        client.mutateRow(tableName, rowKey, mutations);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) ByteString(com.google.protobuf.ByteString) StatusRuntimeException(io.grpc.StatusRuntimeException) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) Mutation(com.google.bigtable.v2.Mutation) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)70 Mutation (com.google.bigtable.v2.Mutation)62 ArrayList (java.util.ArrayList)59 ByteString (com.google.protobuf.ByteString)56 CommitRequest (com.google.spanner.v1.CommitRequest)15 KV (org.apache.beam.sdk.values.KV)15 CheckAndMutateRowResponse (com.google.bigtable.v2.CheckAndMutateRowResponse)14 AbstractMessage (com.google.protobuf.AbstractMessage)13 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)12 RowFilter (com.google.bigtable.v2.RowFilter)12 TableName (com.google.bigtable.v2.TableName)12 StatusRuntimeException (io.grpc.StatusRuntimeException)12 CheckAndMutateRowRequest (com.google.bigtable.v2.CheckAndMutateRowRequest)11 MutateRowRequest (com.google.bigtable.v2.MutateRowRequest)11 Mutation (com.google.spanner.v1.Mutation)11 BaseBigtableDataClient (com.google.cloud.bigtable.data.v2.BaseBigtableDataClient)10 MutateRowResponse (com.google.bigtable.v2.MutateRowResponse)9 SetCell (com.google.bigtable.v2.Mutation.SetCell)9 Mutation (com.google.datastore.v1.Mutation)9 CommitResponse (com.google.spanner.v1.CommitResponse)9