Skip to content
Permalink
Browse files
deps: upgrade gax to 1.53.0 (#145)
* deps: upgrade gax to 1.53.0

* fix compile failures

* rename parameter

* rename test variables

* review feedback

* review feedback
  • Loading branch information
kolea2 committed Jan 9, 2020
1 parent 2ea6704 commit c3fc40df4358bd68cddcfc6f0a3fedb74dcdf465
@@ -73,7 +73,7 @@
<properties>
<autovalue.version>1.7</autovalue.version>
<!-- when updating, make sure to align the versions of transitive deps below -->
<gax.version>1.52.0</gax.version>
<gax.version>1.53.0</gax.version>
<google.api-common.version>1.8.1</google.api-common.version>
<google.common-protos.version>1.17.0</google.common-protos.version>
<google.core.version>1.92.1</google.core.version>
@@ -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<RowMutationEntry, BulkMutation> newRequestBuilder(
}

@Override
public void splitResponse(Void response, List<SettableApiFuture<Void>> batch) {
for (SettableApiFuture<Void> batchResponse : batch) {
batchResponse.set(null);
public void splitResponse(Void response, List<BatchEntry<RowMutationEntry, Void>> entries) {
for (BatchEntry<RowMutationEntry, Void> batchResponse : entries) {
batchResponse.getResultFuture().set(null);
}
}

@@ -58,10 +58,11 @@ public void splitResponse(Void response, List<SettableApiFuture<Void>> batch) {
* entries whose index is mentioned {@link MutateRowsException#getFailedMutations()}.
*/
@Override
public void splitException(Throwable throwable, List<SettableApiFuture<Void>> batch) {
public void splitException(
Throwable throwable, List<BatchEntry<RowMutationEntry, Void>> entries) {
if (!(throwable instanceof MutateRowsException)) {
for (SettableApiFuture<Void> future : batch) {
future.setException(throwable);
for (BatchEntry<RowMutationEntry, Void> entry : entries) {
entry.getResultFuture().setException(throwable);
}
return;
}
@@ -74,12 +75,12 @@ public void splitException(Throwable throwable, List<SettableApiFuture<Void>> ba
}

int i = 0;
for (SettableApiFuture<Void> entryResultFuture : batch) {
for (BatchEntry<RowMutationEntry, Void> 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);
}
}
}
@@ -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<SettableApiFuture<Void>> batchResponse =
ImmutableList.of(SettableApiFuture.<Void>create(), SettableApiFuture.<Void>create());
assertThat(batchResponse.get(0).isDone()).isFalse();
assertThat(batchResponse.get(1).isDone()).isFalse();
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());

List<BatchEntry<RowMutationEntry, Void>> 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<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());

MutateRowsBatchingDescriptor underTest = new MutateRowsBatchingDescriptor();
final RuntimeException expectedEx = new RuntimeException("Caused while batching");
List<SettableApiFuture<Void>> batchResponses =
ImmutableList.of(SettableApiFuture.<Void>create(), SettableApiFuture.<Void>create());
List<BatchEntry<RowMutationEntry, Void>> batchResponses =
ImmutableList.of(batchEntry1, batchEntry2);

underTest.splitException(expectedEx, batchResponses);

for (SettableApiFuture fu : batchResponses) {
for (BatchEntry<RowMutationEntry, Void> 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<Void> resultFuture1 = SettableApiFuture.create();
SettableApiFuture<Void> resultFuture2 = SettableApiFuture.create();
SettableApiFuture<Void> resultFuture3 = SettableApiFuture.create();
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 =
@@ -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,15 +163,15 @@ 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;
}
assertThat(actualThrowable).isNull();

actualThrowable = null;
try {
resultFuture3.get();
batchEntry3.getResultFuture().get();
} catch (ExecutionException | InterruptedException e) {
actualThrowable = e;
}

0 comments on commit c3fc40d

Please sign in to comment.