Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deps: upgrade gax to 1.53.0 #145

Merged
merged 6 commits into from Jan 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion google-cloud-bigtable-deps-bom/pom.xml
Expand Up @@ -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>
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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;
}
Expand All @@ -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);
}
}
}
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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());

kolea2 marked this conversation as resolved.
Show resolved Hide resolved
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());

kolea2 marked this conversation as resolved.
Show resolved Hide resolved
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);
}
Expand All @@ -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 =
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down