Search in sources :

Example 6 with MutateRowsRequest

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

the class MutateRowsAttemptCallableTest method testNoRpcTimeout.

@Test
public void testNoRpcTimeout() {
    parentFuture.timedAttemptSettings = parentFuture.timedAttemptSettings.toBuilder().setRpcTimeout(Duration.ZERO).build();
    MutateRowsRequest request = MutateRowsRequest.newBuilder().addEntries(Entry.getDefaultInstance()).build();
    innerCallable.response.add(MutateRowsResponse.newBuilder().addEntries(MutateRowsResponse.Entry.newBuilder().setIndex(0).setStatus(OK_STATUS_PROTO)).build());
    MutateRowsAttemptCallable attemptCallable = new MutateRowsAttemptCallable(innerCallable, request, callContext, retryCodes);
    attemptCallable.setExternalFuture(parentFuture);
    attemptCallable.call();
    assertThat(innerCallable.lastContext.getTimeout()).isNull();
}
Also used : MutateRowsRequest(com.google.bigtable.v2.MutateRowsRequest) Test(org.junit.Test)

Example 7 with MutateRowsRequest

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

the class MutateRowsAttemptCallableTest method rpcPermanentError.

@Test
public void rpcPermanentError() {
    // Setup the request & response
    MutateRowsRequest request = MutateRowsRequest.newBuilder().addEntries(Entry.getDefaultInstance()).addEntries(Entry.getDefaultInstance()).build();
    final UnavailableException rpcError = new UnavailableException("fake error", null, GrpcStatusCode.of(io.grpc.Status.Code.INVALID_ARGUMENT), false);
    UnaryCallable<MutateRowsRequest, List<MutateRowsResponse>> innerCallable = new UnaryCallable<MutateRowsRequest, List<MutateRowsResponse>>() {

        @Override
        public ApiFuture<List<MutateRowsResponse>> futureCall(MutateRowsRequest request, ApiCallContext context) {
            return ApiFutures.immediateFailedFuture(rpcError);
        }
    };
    // Make the call
    MutateRowsAttemptCallable attemptCallable = new MutateRowsAttemptCallable(innerCallable, request, callContext, retryCodes);
    attemptCallable.setExternalFuture(parentFuture);
    attemptCallable.call();
    // Overall expectations: retryable error
    Throwable actualError = null;
    try {
        parentFuture.attemptFuture.get();
    } catch (Throwable t) {
        actualError = t.getCause();
    }
    assertThat(actualError).isInstanceOf(MutateRowsException.class);
    assertThat(((MutateRowsException) actualError).isRetryable()).isFalse();
    // Entry expectations: both entries failed with an error whose cause is the rpc error
    @SuppressWarnings("ConstantConditions") List<FailedMutation> failedMutations = ((MutateRowsException) actualError).getFailedMutations();
    assertThat(failedMutations).hasSize(2);
    assertThat(failedMutations.get(0).getIndex()).isEqualTo(0);
    assertThat(failedMutations.get(0).getError().isRetryable()).isFalse();
    assertThat(failedMutations.get(0).getError().getCause()).isEqualTo(rpcError);
    assertThat(failedMutations.get(1).getIndex()).isEqualTo(1);
    assertThat(failedMutations.get(1).getError().isRetryable()).isFalse();
    assertThat(failedMutations.get(1).getError().getCause()).isEqualTo(rpcError);
}
Also used : UnaryCallable(com.google.api.gax.rpc.UnaryCallable) UnavailableException(com.google.api.gax.rpc.UnavailableException) ApiCallContext(com.google.api.gax.rpc.ApiCallContext) FailedMutation(com.google.cloud.bigtable.data.v2.models.MutateRowsException.FailedMutation) MutateRowsResponse(com.google.bigtable.v2.MutateRowsResponse) MutateRowsException(com.google.cloud.bigtable.data.v2.models.MutateRowsException) MutateRowsRequest(com.google.bigtable.v2.MutateRowsRequest) List(java.util.List) Test(org.junit.Test)

Example 8 with MutateRowsRequest

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

the class BulkMutationTest method test.

@Test
public void test() throws ParseException {
    BulkMutation m = BulkMutation.create(TABLE_ID).add("key-a", Mutation.create().setCell("fake-family1", "fake-qualifier1", 1_000, "fake-value1").setCell("fake-family2", "fake-qualifier2", 2_000, "fake-value2")).add(ByteString.copyFromUtf8("key-b"), Mutation.create().setCell("fake-family3", "fake-qualifier3", 3_000, "fake-value3"));
    MutateRowsRequest actual = m.toProto(REQUEST_CONTEXT);
    MutateRowsRequest.Builder expected = MutateRowsRequest.newBuilder().setTableName(NameUtil.formatTableName(PROJECT_ID, INSTANCE_ID, TABLE_ID)).setAppProfileId(APP_PROFILE);
    TextFormat.merge("entries {" + "  row_key: 'key-a'" + "  mutations {" + "    set_cell {" + "      family_name: 'fake-family1'" + "      column_qualifier: 'fake-qualifier1'" + "      timestamp_micros: 1000" + "      value: 'fake-value1'" + "    }" + "  }" + "  mutations {" + "    set_cell {" + "      family_name: 'fake-family2'" + "      column_qualifier: 'fake-qualifier2'" + "      timestamp_micros: 2000" + "      value: 'fake-value2'" + "    }" + "  }" + "}" + "entries {" + "  row_key: 'key-b'" + "  mutations {" + "    set_cell {" + "      family_name: 'fake-family3'" + "      column_qualifier: 'fake-qualifier3'" + "      timestamp_micros: 3000" + "      value: 'fake-value3'" + "    }" + "  }" + "}", expected);
    assertThat(actual).isEqualTo(expected.build());
}
Also used : MutateRowsRequest(com.google.bigtable.v2.MutateRowsRequest) Test(org.junit.Test)

Example 9 with MutateRowsRequest

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

the class BulkMutationTest method fromProtoTest.

@Test
public void fromProtoTest() {
    BulkMutation expected = BulkMutation.create(TABLE_ID).add("key", Mutation.create().setCell("fake-family", "fake-qualifier", 10_000L, "fake-value"));
    MutateRowsRequest protoRequest = expected.toProto(REQUEST_CONTEXT);
    BulkMutation actualBulkMutation = BulkMutation.fromProto(protoRequest);
    assertThat(actualBulkMutation.toProto(REQUEST_CONTEXT)).isEqualTo(protoRequest);
    String projectId = "fresh-project";
    String instanceId = "fresh-instance";
    String appProfile = "fresh-app-profile";
    MutateRowsRequest overriddenRequest = actualBulkMutation.toProto(RequestContext.create(projectId, instanceId, appProfile));
    assertThat(overriddenRequest).isNotEqualTo(protoRequest);
    assertThat(overriddenRequest.getTableName()).matches(NameUtil.formatTableName(projectId, instanceId, TABLE_ID));
    assertThat(overriddenRequest.getAppProfileId()).matches(appProfile);
}
Also used : MutateRowsRequest(com.google.bigtable.v2.MutateRowsRequest) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 10 with MutateRowsRequest

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

the class MutateRowsAttemptCallableTest method rpcRetryableError.

@Test
public void rpcRetryableError() {
    // Setup the request & response
    MutateRowsRequest request = MutateRowsRequest.newBuilder().addEntries(Entry.getDefaultInstance()).addEntries(Entry.getDefaultInstance()).build();
    final UnavailableException rpcError = new UnavailableException("fake error", null, GrpcStatusCode.of(io.grpc.Status.Code.UNAVAILABLE), true);
    UnaryCallable<MutateRowsRequest, List<MutateRowsResponse>> innerCallable = new UnaryCallable<MutateRowsRequest, List<MutateRowsResponse>>() {

        @Override
        public ApiFuture<List<MutateRowsResponse>> futureCall(MutateRowsRequest request, ApiCallContext context) {
            return ApiFutures.immediateFailedFuture(rpcError);
        }
    };
    // Make the call
    MutateRowsAttemptCallable attemptCallable = new MutateRowsAttemptCallable(innerCallable, request, callContext, retryCodes);
    attemptCallable.setExternalFuture(parentFuture);
    attemptCallable.call();
    // Overall expectations: retryable error
    Throwable actualError = null;
    try {
        parentFuture.attemptFuture.get();
    } catch (Throwable t) {
        actualError = t.getCause();
    }
    assertThat(actualError).isInstanceOf(MutateRowsException.class);
    assertThat(((MutateRowsException) actualError).isRetryable()).isTrue();
    // Entry expectations: both entries failed with an error whose cause is the rpc error
    @SuppressWarnings("ConstantConditions") List<FailedMutation> failedMutations = ((MutateRowsException) actualError).getFailedMutations();
    assertThat(failedMutations).hasSize(2);
    assertThat(failedMutations.get(0).getIndex()).isEqualTo(0);
    assertThat(failedMutations.get(0).getError().isRetryable()).isTrue();
    assertThat(failedMutations.get(0).getError().getCause()).isEqualTo(rpcError);
    assertThat(failedMutations.get(1).getIndex()).isEqualTo(1);
    assertThat(failedMutations.get(1).getError().isRetryable()).isTrue();
    assertThat(failedMutations.get(1).getError().getCause()).isEqualTo(rpcError);
}
Also used : UnaryCallable(com.google.api.gax.rpc.UnaryCallable) UnavailableException(com.google.api.gax.rpc.UnavailableException) ApiCallContext(com.google.api.gax.rpc.ApiCallContext) FailedMutation(com.google.cloud.bigtable.data.v2.models.MutateRowsException.FailedMutation) MutateRowsResponse(com.google.bigtable.v2.MutateRowsResponse) MutateRowsException(com.google.cloud.bigtable.data.v2.models.MutateRowsException) MutateRowsRequest(com.google.bigtable.v2.MutateRowsRequest) List(java.util.List) Test(org.junit.Test)

Aggregations

MutateRowsRequest (com.google.bigtable.v2.MutateRowsRequest)14 Test (org.junit.Test)10 MutateRowsException (com.google.cloud.bigtable.data.v2.models.MutateRowsException)6 FailedMutation (com.google.cloud.bigtable.data.v2.models.MutateRowsException.FailedMutation)6 MutateRowsResponse (com.google.bigtable.v2.MutateRowsResponse)4 ApiCallContext (com.google.api.gax.rpc.ApiCallContext)2 UnaryCallable (com.google.api.gax.rpc.UnaryCallable)2 UnavailableException (com.google.api.gax.rpc.UnavailableException)2 Builder (com.google.bigtable.v2.MutateRowsRequest.Builder)2 List (java.util.List)2 ExponentialRetryAlgorithm (com.google.api.gax.retrying.ExponentialRetryAlgorithm)1 RetryAlgorithm (com.google.api.gax.retrying.RetryAlgorithm)1 ScheduledRetryingExecutor (com.google.api.gax.retrying.ScheduledRetryingExecutor)1 ApiException (com.google.api.gax.rpc.ApiException)1 SpanName (com.google.api.gax.tracing.SpanName)1 TracedUnaryCallable (com.google.api.gax.tracing.TracedUnaryCallable)1 Entry (com.google.bigtable.v2.MutateRowsResponse.Entry)1 BulkMutation (com.google.cloud.bigtable.data.v2.models.BulkMutation)1 HeaderTracerUnaryCallable (com.google.cloud.bigtable.data.v2.stub.metrics.HeaderTracerUnaryCallable)1 StatsHeadersServerStreamingCallable (com.google.cloud.bigtable.data.v2.stub.metrics.StatsHeadersServerStreamingCallable)1