diff --git a/google-cloud-bigtable-deps-bom/pom.xml b/google-cloud-bigtable-deps-bom/pom.xml index 753d501d9..b4de658d7 100644 --- a/google-cloud-bigtable-deps-bom/pom.xml +++ b/google-cloud-bigtable-deps-bom/pom.xml @@ -73,7 +73,7 @@ 1.7 - 1.52.0 + 1.53.0 1.8.1 1.17.0 1.92.1 diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsBatchingDescriptor.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsBatchingDescriptor.java index 60a330795..a3ec50bc2 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsBatchingDescriptor.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsBatchingDescriptor.java @@ -16,7 +16,7 @@ package com.google.cloud.bigtable.data.v2.stub.mutaterows; import com.google.api.core.InternalApi; -import com.google.api.core.SettableApiFuture; +import com.google.api.gax.batching.BatchEntry; import com.google.api.gax.batching.BatchingDescriptor; import com.google.api.gax.batching.BatchingRequestBuilder; import com.google.cloud.bigtable.data.v2.models.BulkMutation; @@ -45,9 +45,9 @@ public BatchingRequestBuilder newRequestBuilder( } @Override - public void splitResponse(Void response, List> batch) { - for (SettableApiFuture batchResponse : batch) { - batchResponse.set(null); + public void splitResponse(Void response, List> entries) { + for (BatchEntry batchResponse : entries) { + batchResponse.getResultFuture().set(null); } } @@ -58,10 +58,11 @@ public void splitResponse(Void response, List> batch) { * entries whose index is mentioned {@link MutateRowsException#getFailedMutations()}. */ @Override - public void splitException(Throwable throwable, List> batch) { + public void splitException( + Throwable throwable, List> entries) { if (!(throwable instanceof MutateRowsException)) { - for (SettableApiFuture future : batch) { - future.setException(throwable); + for (BatchEntry entry : entries) { + entry.getResultFuture().setException(throwable); } return; } @@ -74,12 +75,12 @@ public void splitException(Throwable throwable, List> ba } int i = 0; - for (SettableApiFuture entryResultFuture : batch) { + for (BatchEntry entry : entries) { Throwable entryError = entryErrors.get(i++); if (entryError == null) { - entryResultFuture.set(null); + entry.getResultFuture().set(null); } else { - entryResultFuture.setException(entryError); + entry.getResultFuture().setException(entryError); } } } diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsBatchingDescriptorTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsBatchingDescriptorTest.java index c43dea15f..875a8e388 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsBatchingDescriptorTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MutateRowsBatchingDescriptorTest.java @@ -18,6 +18,7 @@ import static com.google.common.truth.Truth.assertThat; import com.google.api.core.SettableApiFuture; +import com.google.api.gax.batching.BatchEntry; import com.google.api.gax.batching.BatchingRequestBuilder; import com.google.api.gax.grpc.GrpcStatusCode; import com.google.api.gax.rpc.DeadlineExceededException; @@ -77,29 +78,43 @@ public void requestBuilderTest() { @Test public void splitResponseTest() { - List> batchResponse = - ImmutableList.of(SettableApiFuture.create(), SettableApiFuture.create()); - assertThat(batchResponse.get(0).isDone()).isFalse(); - assertThat(batchResponse.get(1).isDone()).isFalse(); + BatchEntry batchEntry1 = + BatchEntry.create( + RowMutationEntry.create("key1").deleteRow(), SettableApiFuture.create()); + BatchEntry batchEntry2 = + BatchEntry.create( + RowMutationEntry.create("key2").deleteRow(), SettableApiFuture.create()); + + List> batchResponse = + ImmutableList.of(batchEntry1, batchEntry2); + assertThat(batchResponse.get(0).getResultFuture().isDone()).isFalse(); + assertThat(batchResponse.get(1).getResultFuture().isDone()).isFalse(); MutateRowsBatchingDescriptor underTest = new MutateRowsBatchingDescriptor(); underTest.splitResponse(null, batchResponse); - assertThat(batchResponse.get(0).isDone()).isTrue(); - assertThat(batchResponse.get(1).isDone()).isTrue(); + assertThat(batchResponse.get(0).getResultFuture().isDone()).isTrue(); + assertThat(batchResponse.get(1).getResultFuture().isDone()).isTrue(); } @Test public void splitExceptionTest() { + BatchEntry batchEntry1 = + BatchEntry.create( + RowMutationEntry.create("key1").deleteRow(), SettableApiFuture.create()); + BatchEntry batchEntry2 = + BatchEntry.create( + RowMutationEntry.create("key2").deleteRow(), SettableApiFuture.create()); + MutateRowsBatchingDescriptor underTest = new MutateRowsBatchingDescriptor(); final RuntimeException expectedEx = new RuntimeException("Caused while batching"); - List> batchResponses = - ImmutableList.of(SettableApiFuture.create(), SettableApiFuture.create()); + List> batchResponses = + ImmutableList.of(batchEntry1, batchEntry2); underTest.splitException(expectedEx, batchResponses); - for (SettableApiFuture fu : batchResponses) { + for (BatchEntry response : batchResponses) { try { - fu.get(); + response.getResultFuture().get(); } catch (ExecutionException | InterruptedException ex) { assertThat(ex).hasCauseThat().isSameInstanceAs(expectedEx); } @@ -110,9 +125,15 @@ public void splitExceptionTest() { public void splitExceptionWithFailedMutationsTest() { MutateRowsBatchingDescriptor underTest = new MutateRowsBatchingDescriptor(); Throwable actualThrowable = null; - SettableApiFuture resultFuture1 = SettableApiFuture.create(); - SettableApiFuture resultFuture2 = SettableApiFuture.create(); - SettableApiFuture resultFuture3 = SettableApiFuture.create(); + BatchEntry batchEntry1 = + BatchEntry.create( + RowMutationEntry.create("key1").deleteRow(), SettableApiFuture.create()); + BatchEntry batchEntry2 = + BatchEntry.create( + RowMutationEntry.create("key2").deleteRow(), SettableApiFuture.create()); + BatchEntry batchEntry3 = + BatchEntry.create( + RowMutationEntry.create("key3").deleteRow(), SettableApiFuture.create()); // Threw an exception at 1st and 3rd entry MutateRowsException serverError = @@ -128,11 +149,10 @@ public void splitExceptionWithFailedMutationsTest() { new DeadlineExceededException( null, GrpcStatusCode.of(Status.Code.DEADLINE_EXCEEDED), true))), true); - underTest.splitException( - serverError, ImmutableList.of(resultFuture1, resultFuture2, resultFuture3)); + underTest.splitException(serverError, ImmutableList.of(batchEntry1, batchEntry2, batchEntry3)); try { - resultFuture1.get(); + batchEntry1.getResultFuture().get(); } catch (ExecutionException | InterruptedException e) { actualThrowable = e; } @@ -143,7 +163,7 @@ public void splitExceptionWithFailedMutationsTest() { // As there is no exception for 2nd entry so it should not throw any exception actualThrowable = null; try { - resultFuture2.get(); + batchEntry2.getResultFuture().get(); } catch (ExecutionException | InterruptedException e) { actualThrowable = e; } @@ -151,7 +171,7 @@ public void splitExceptionWithFailedMutationsTest() { actualThrowable = null; try { - resultFuture3.get(); + batchEntry3.getResultFuture().get(); } catch (ExecutionException | InterruptedException e) { actualThrowable = e; }