Search in sources :

Example 1 with MutateRowsBatchingDescriptor

use of com.google.cloud.bigtable.data.v2.stub.mutaterows.MutateRowsBatchingDescriptor in project java-bigtable by googleapis.

the class BigtableBatchingCallSettingsTest method testBuilderFromSettings.

@Test
public void testBuilderFromSettings() {
    BigtableBatchingCallSettings.Builder builder = BigtableBatchingCallSettings.newBuilder(new MutateRowsBatchingDescriptor());
    RetrySettings retrySettings = RetrySettings.newBuilder().setTotalTimeout(Duration.ofMinutes(1)).build();
    builder.setBatchingSettings(BATCHING_SETTINGS).setRetryableCodes(StatusCode.Code.UNAVAILABLE, StatusCode.Code.UNAUTHENTICATED).setRetrySettings(retrySettings).enableLatencyBasedThrottling(10L);
    BigtableBatchingCallSettings settings = builder.build();
    BigtableBatchingCallSettings.Builder newBuilder = settings.toBuilder();
    assertThat(newBuilder.getBatchingSettings()).isEqualTo(BATCHING_SETTINGS);
    assertThat(newBuilder.getRetryableCodes()).containsExactly(StatusCode.Code.UNAVAILABLE, StatusCode.Code.UNAUTHENTICATED);
    assertThat(newBuilder.getRetrySettings()).isEqualTo(retrySettings);
    assertThat(newBuilder.isLatencyBasedThrottlingEnabled()).isTrue();
    assertThat(newBuilder.getTargetRpcLatencyMs()).isEqualTo(10L);
    assertThat(newBuilder.getDynamicFlowControlSettings()).isNotNull();
    verifyFlowControlSettingWhenLatencyBasedThrottlingEnabled(newBuilder.getDynamicFlowControlSettings());
}
Also used : RetrySettings(com.google.api.gax.retrying.RetrySettings) MutateRowsBatchingDescriptor(com.google.cloud.bigtable.data.v2.stub.mutaterows.MutateRowsBatchingDescriptor) Test(org.junit.Test)

Example 2 with MutateRowsBatchingDescriptor

use of com.google.cloud.bigtable.data.v2.stub.mutaterows.MutateRowsBatchingDescriptor in project java-bigtable by googleapis.

the class MutateRowsBatchingDescriptorTest method countBytesTest.

@Test
public void countBytesTest() {
    RowMutationEntry request = RowMutationEntry.create(ROW_KEY).setCell(FAMILY, QUALIFIER, VALUE);
    long bytes = request.toProto().getSerializedSize();
    MutateRowsBatchingDescriptor underTest = new MutateRowsBatchingDescriptor();
    assertThat(underTest.countBytes(request)).isEqualTo(bytes);
}
Also used : RowMutationEntry(com.google.cloud.bigtable.data.v2.models.RowMutationEntry) Test(org.junit.Test)

Example 3 with MutateRowsBatchingDescriptor

use of com.google.cloud.bigtable.data.v2.stub.mutaterows.MutateRowsBatchingDescriptor 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 4 with MutateRowsBatchingDescriptor

use of com.google.cloud.bigtable.data.v2.stub.mutaterows.MutateRowsBatchingDescriptor in project java-bigtable by googleapis.

the class MutateRowsBatchingDescriptorTest method requestBuilderTest.

@Test
public void requestBuilderTest() {
    MutateRowsBatchingDescriptor underTest = new MutateRowsBatchingDescriptor();
    long timestamp = 10_000L;
    BulkMutation bulkMutation = BulkMutation.create("fake-table");
    BatchingRequestBuilder<RowMutationEntry, BulkMutation> requestBuilder = underTest.newRequestBuilder(bulkMutation);
    requestBuilder.add(RowMutationEntry.create(ROW_KEY).setCell(FAMILY, QUALIFIER, timestamp, VALUE));
    requestBuilder.add(RowMutationEntry.create("rowKey-2").setCell("family-2", "q", 20_000L, "some-value"));
    BulkMutation actualBulkMutation = requestBuilder.build();
    assertThat(actualBulkMutation.toProto(requestContext)).isEqualTo(BulkMutation.create("fake-table").add(ROW_KEY, Mutation.create().setCell(FAMILY, QUALIFIER, timestamp, VALUE)).add("rowKey-2", Mutation.create().setCell("family-2", "q", 20_000L, "some-value")).toProto(requestContext));
}
Also used : BulkMutation(com.google.cloud.bigtable.data.v2.models.BulkMutation) RowMutationEntry(com.google.cloud.bigtable.data.v2.models.RowMutationEntry) Test(org.junit.Test)

Example 5 with MutateRowsBatchingDescriptor

use of com.google.cloud.bigtable.data.v2.stub.mutaterows.MutateRowsBatchingDescriptor in project java-bigtable by googleapis.

the class BigtableBatchingCallSettingsTest method testEmptyBuilder.

@Test
public void testEmptyBuilder() {
    BigtableBatchingCallSettings.Builder builder = BigtableBatchingCallSettings.newBuilder(new MutateRowsBatchingDescriptor());
    assertThat(builder.getBatchingSettings()).isNull();
    assertThat(builder.getRetryableCodes()).isEmpty();
    assertThat(builder.getRetrySettings()).isNotNull();
    assertThat(builder.isLatencyBasedThrottlingEnabled()).isFalse();
    assertThat(builder.getTargetRpcLatencyMs()).isNull();
    assertThat(builder.getDynamicFlowControlSettings()).isNull();
}
Also used : MutateRowsBatchingDescriptor(com.google.cloud.bigtable.data.v2.stub.mutaterows.MutateRowsBatchingDescriptor) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)7 MutateRowsBatchingDescriptor (com.google.cloud.bigtable.data.v2.stub.mutaterows.MutateRowsBatchingDescriptor)4 RowMutationEntry (com.google.cloud.bigtable.data.v2.models.RowMutationEntry)3 RetrySettings (com.google.api.gax.retrying.RetrySettings)2 DeadlineExceededException (com.google.api.gax.rpc.DeadlineExceededException)1 StatusCode (com.google.api.gax.rpc.StatusCode)1 UnavailableException (com.google.api.gax.rpc.UnavailableException)1 BulkMutation (com.google.cloud.bigtable.data.v2.models.BulkMutation)1 MutateRowsException (com.google.cloud.bigtable.data.v2.models.MutateRowsException)1 ExecutionException (java.util.concurrent.ExecutionException)1