Search in sources :

Example 1 with MutateRowsException

use of com.google.cloud.bigtable.data.v2.models.MutateRowsException in project java-bigtable by googleapis.

the class MutateRowsBatchingDescriptorTest method splitExceptionWithFailedMutationsTest.

@Test
public void splitExceptionWithFailedMutationsTest() {
    MutateRowsBatchingDescriptor underTest = new MutateRowsBatchingDescriptor();
    Throwable actualThrowable = null;
    BatchEntry<RowMutationEntry, Void> batchEntry1 = BatchEntry.create(RowMutationEntry.create("key1").deleteRow(), SettableApiFuture.<Void>create());
    BatchEntry<RowMutationEntry, Void> batchEntry2 = BatchEntry.create(RowMutationEntry.create("key2").deleteRow(), SettableApiFuture.<Void>create());
    BatchEntry<RowMutationEntry, Void> batchEntry3 = BatchEntry.create(RowMutationEntry.create("key3").deleteRow(), SettableApiFuture.<Void>create());
    // Threw an exception at 1st and 3rd entry
    MutateRowsException serverError = new MutateRowsException(null, ImmutableList.of(MutateRowsException.FailedMutation.create(0, new UnavailableException(null, GrpcStatusCode.of(Status.Code.UNAVAILABLE), true)), MutateRowsException.FailedMutation.create(2, new DeadlineExceededException(null, GrpcStatusCode.of(Status.Code.DEADLINE_EXCEEDED), true))), true);
    underTest.splitException(serverError, ImmutableList.of(batchEntry1, batchEntry2, batchEntry3));
    try {
        batchEntry1.getResultFuture().get();
    } catch (ExecutionException | InterruptedException e) {
        actualThrowable = e;
    }
    assertThat(actualThrowable).hasCauseThat().isEqualTo(serverError.getFailedMutations().get(0).getError());
    // As there is no exception for 2nd entry so it should not throw any exception
    actualThrowable = null;
    try {
        batchEntry2.getResultFuture().get();
    } catch (ExecutionException | InterruptedException e) {
        actualThrowable = e;
    }
    assertThat(actualThrowable).isNull();
    actualThrowable = null;
    try {
        batchEntry3.getResultFuture().get();
    } catch (ExecutionException | InterruptedException e) {
        actualThrowable = e;
    }
    // The third response should has the last found failed mutation error.
    assertThat(actualThrowable).hasCauseThat().isEqualTo(serverError.getFailedMutations().get(1).getError());
}
Also used : MutateRowsException(com.google.cloud.bigtable.data.v2.models.MutateRowsException) RowMutationEntry(com.google.cloud.bigtable.data.v2.models.RowMutationEntry) UnavailableException(com.google.api.gax.rpc.UnavailableException) DeadlineExceededException(com.google.api.gax.rpc.DeadlineExceededException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 2 with MutateRowsException

use of com.google.cloud.bigtable.data.v2.models.MutateRowsException in project java-bigtable by googleapis.

the class MutateRowsAttemptCallableTest method mixedTest.

@Test
public void mixedTest() {
    // Setup the request & response
    MutateRowsRequest request = MutateRowsRequest.newBuilder().addEntries(Entry.getDefaultInstance()).addEntries(Entry.getDefaultInstance()).addEntries(Entry.getDefaultInstance()).build();
    innerCallable.response.add(MutateRowsResponse.newBuilder().addEntries(MutateRowsResponse.Entry.newBuilder().setIndex(0).setStatus(OK_STATUS_PROTO)).addEntries(MutateRowsResponse.Entry.newBuilder().setIndex(1).setStatus(TRANSIENT_ERROR_STATUS_PROTO)).addEntries(MutateRowsResponse.Entry.newBuilder().setIndex(2).setStatus(PERMENANT_ERROR_STATUS_PROTO)).build());
    MutateRowsAttemptCallable attemptCallable = new MutateRowsAttemptCallable(innerCallable, request, callContext, retryCodes);
    attemptCallable.setExternalFuture(parentFuture);
    // Make the only call
    attemptCallable.call();
    // Overall error expectations
    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
    @SuppressWarnings("ConstantConditions") List<FailedMutation> failedMutations = ((MutateRowsException) actualError).getFailedMutations();
    assertThat(failedMutations).hasSize(2);
    assertThat(failedMutations.get(0).getIndex()).isEqualTo(1);
    assertThat(failedMutations.get(0).getError().getStatusCode().getCode()).isEqualTo(Code.UNAVAILABLE);
    assertThat(failedMutations.get(0).getError().isRetryable()).isTrue();
    assertThat(failedMutations.get(1).getIndex()).isEqualTo(2);
    assertThat(failedMutations.get(1).getError().getStatusCode().getCode()).isEqualTo(Code.INVALID_ARGUMENT);
    assertThat(failedMutations.get(1).getError().isRetryable()).isFalse();
}
Also used : MutateRowsException(com.google.cloud.bigtable.data.v2.models.MutateRowsException) MutateRowsRequest(com.google.bigtable.v2.MutateRowsRequest) FailedMutation(com.google.cloud.bigtable.data.v2.models.MutateRowsException.FailedMutation) Test(org.junit.Test)

Example 3 with MutateRowsException

use of com.google.cloud.bigtable.data.v2.models.MutateRowsException 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 4 with MutateRowsException

use of com.google.cloud.bigtable.data.v2.models.MutateRowsException 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)

Example 5 with MutateRowsException

use of com.google.cloud.bigtable.data.v2.models.MutateRowsException in project java-bigtable by googleapis.

the class MutateRowsAttemptCallableTest method nextAttemptTest.

@Test
public void nextAttemptTest() {
    // Setup the request & response for the first call
    MutateRowsRequest request = MutateRowsRequest.newBuilder().addEntries(Entry.newBuilder().setRowKey(ByteString.copyFromUtf8("0-ok"))).addEntries(Entry.newBuilder().setRowKey(ByteString.copyFromUtf8("1-unavailable"))).addEntries(Entry.newBuilder().setRowKey(ByteString.copyFromUtf8("2-invalid"))).build();
    innerCallable.response.add(MutateRowsResponse.newBuilder().addEntries(MutateRowsResponse.Entry.newBuilder().setIndex(0).setStatus(OK_STATUS_PROTO)).addEntries(MutateRowsResponse.Entry.newBuilder().setIndex(1).setStatus(TRANSIENT_ERROR_STATUS_PROTO)).addEntries(MutateRowsResponse.Entry.newBuilder().setIndex(2).setStatus(PERMENANT_ERROR_STATUS_PROTO)).build());
    MutateRowsAttemptCallable attemptCallable = new MutateRowsAttemptCallable(innerCallable, request, callContext, retryCodes);
    attemptCallable.setExternalFuture(parentFuture);
    // Make the first call
    attemptCallable.call();
    // Setup the request & response for the next call
    innerCallable.response = Lists.newArrayList(MutateRowsResponse.newBuilder().addEntries(MutateRowsResponse.Entry.newBuilder().setIndex(0).setStatus(OK_STATUS_PROTO)).build());
    attemptCallable.call();
    // Make sure that only the entry with the transient error is resubmitted
    assertThat(innerCallable.lastRequest.getEntriesCount()).isEqualTo(1);
    assertThat(innerCallable.lastRequest.getEntries(0).getRowKey()).isEqualTo(ByteString.copyFromUtf8("1-unavailable"));
    // Overall error expectations
    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
    @SuppressWarnings("ConstantConditions") List<FailedMutation> failedMutations = ((MutateRowsException) actualError).getFailedMutations();
    assertThat(failedMutations).hasSize(1);
    assertThat(failedMutations.get(0).getIndex()).isEqualTo(2);
    assertThat(failedMutations.get(0).getError().getStatusCode().getCode()).isEqualTo(Code.INVALID_ARGUMENT);
    assertThat(failedMutations.get(0).getError().isRetryable()).isFalse();
}
Also used : MutateRowsException(com.google.cloud.bigtable.data.v2.models.MutateRowsException) MutateRowsRequest(com.google.bigtable.v2.MutateRowsRequest) FailedMutation(com.google.cloud.bigtable.data.v2.models.MutateRowsException.FailedMutation) Test(org.junit.Test)

Aggregations

MutateRowsException (com.google.cloud.bigtable.data.v2.models.MutateRowsException)8 FailedMutation (com.google.cloud.bigtable.data.v2.models.MutateRowsException.FailedMutation)7 MutateRowsRequest (com.google.bigtable.v2.MutateRowsRequest)6 Test (org.junit.Test)5 UnavailableException (com.google.api.gax.rpc.UnavailableException)3 MutateRowsResponse (com.google.bigtable.v2.MutateRowsResponse)3 ApiCallContext (com.google.api.gax.rpc.ApiCallContext)2 UnaryCallable (com.google.api.gax.rpc.UnaryCallable)2 Builder (com.google.bigtable.v2.MutateRowsRequest.Builder)2 RowMutationEntry (com.google.cloud.bigtable.data.v2.models.RowMutationEntry)2 List (java.util.List)2 ApiException (com.google.api.gax.rpc.ApiException)1 DeadlineExceededException (com.google.api.gax.rpc.DeadlineExceededException)1 Entry (com.google.bigtable.v2.MutateRowsResponse.Entry)1 ImmutableList (com.google.common.collect.ImmutableList)1 ExecutionException (java.util.concurrent.ExecutionException)1