use of com.google.bigtable.v2.MutateRowsResponse.Entry in project java-bigtable by googleapis.
the class EnhancedBigtableStub method createMutateRowsBaseCallable.
/**
* Internal helper to create the base MutateRows callable chain. The chain is responsible for
* retrying individual entry in case of error.
*
* <p>NOTE: the caller is responsible for adding tracing & metrics.
*
* @see MutateRowsRetryingCallable for more details
*/
private UnaryCallable<MutateRowsRequest, Void> createMutateRowsBaseCallable() {
ServerStreamingCallable<MutateRowsRequest, MutateRowsResponse> base = GrpcRawCallableFactory.createServerStreamingCallable(GrpcCallSettings.<MutateRowsRequest, MutateRowsResponse>newBuilder().setMethodDescriptor(BigtableGrpc.getMutateRowsMethod()).setParamsExtractor(new RequestParamsExtractor<MutateRowsRequest>() {
@Override
public Map<String, String> extract(MutateRowsRequest mutateRowsRequest) {
return ImmutableMap.of("table_name", mutateRowsRequest.getTableName(), "app_profile_id", mutateRowsRequest.getAppProfileId());
}
}).build(), settings.bulkMutateRowsSettings().getRetryableCodes());
ServerStreamingCallable<MutateRowsRequest, MutateRowsResponse> withStatsHeaders = new StatsHeadersServerStreamingCallable<>(base);
RetryAlgorithm<Void> retryAlgorithm = new RetryAlgorithm<>(new ApiResultRetryAlgorithm<Void>(), new ExponentialRetryAlgorithm(settings.bulkMutateRowsSettings().getRetrySettings(), clientContext.getClock()));
RetryingExecutorWithContext<Void> retryingExecutor = new ScheduledRetryingExecutor<>(retryAlgorithm, clientContext.getExecutor());
return new MutateRowsRetryingCallable(clientContext.getDefaultCallContext(), withStatsHeaders, retryingExecutor, settings.bulkMutateRowsSettings().getRetryableCodes());
}
use of com.google.bigtable.v2.MutateRowsResponse.Entry in project java-bigtable by googleapis.
the class RowMutationEntryTest method unsafeMutationTest.
@Test
public void unsafeMutationTest() {
ByteString rowKey = ByteString.copyFromUtf8("row-key");
RowMutationEntry rowMutationEntry = RowMutationEntry.createUnsafe(rowKey).setCell("family-1", "qualifier-1", 10_000L, "fake-values").deleteFamily("family-2");
MutateRowsRequest.Entry entry = rowMutationEntry.toProto();
assertThat(entry.getMutationsCount()).isEqualTo(2);
assertThat(entry.getMutationsList()).isEqualTo(ImmutableList.of(Mutation.newBuilder().setSetCell(Mutation.SetCell.newBuilder().setFamilyName("family-1").setColumnQualifier(ByteString.copyFromUtf8("qualifier-1")).setTimestampMicros(10_000L).setValue(ByteString.copyFromUtf8("fake-values"))).build(), Mutation.newBuilder().setDeleteFromFamily(Mutation.DeleteFromFamily.newBuilder().setFamilyName("family-2")).build()));
}
use of com.google.bigtable.v2.MutateRowsResponse.Entry 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();
}
use of com.google.bigtable.v2.MutateRowsResponse.Entry 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);
}
use of com.google.bigtable.v2.MutateRowsResponse.Entry in project beam by apache.
the class BigtableServiceImplTest method testWrite.
/**
* This test ensures that protobuf creation and interactions with {@link BulkMutation} work as
* expected.
*
* @throws IOException
* @throws InterruptedException
*/
@Test
public void testWrite() throws IOException, InterruptedException {
BigtableService.Writer underTest = new BigtableServiceImpl.BigtableWriterImpl(mockSession, TABLE_NAME);
Mutation mutation = Mutation.newBuilder().setSetCell(SetCell.newBuilder().setFamilyName("Family").build()).build();
ByteString key = ByteString.copyFromUtf8("key");
SettableFuture<MutateRowResponse> fakeResponse = SettableFuture.create();
when(mockBulkMutation.add(any(MutateRowsRequest.Entry.class))).thenReturn(fakeResponse);
underTest.writeRecord(KV.of(key, ImmutableList.of(mutation)));
Entry expected = MutateRowsRequest.Entry.newBuilder().setRowKey(key).addMutations(mutation).build();
verify(mockBulkMutation, times(1)).add(expected);
underTest.close();
verify(mockBulkMutation, times(1)).flush();
}
Aggregations