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();
}
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);
}
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());
}
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);
}
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);
}
Aggregations