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

fix: make sure to propagate the response when throttling is enabled #1908

Merged
merged 1 commit into from
Sep 12, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ protected void onResponseImpl(MutateRowsResponse response) {
Duration.ofSeconds(com.google.protobuf.util.Durations.toSeconds(info.getPeriod())));
}
}
outerObserver.onResponse(response);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@
import com.google.api.gax.rpc.StreamController;
import com.google.bigtable.v2.MutateRowsRequest;
import com.google.bigtable.v2.MutateRowsResponse;
import com.google.bigtable.v2.Mutation;
import com.google.bigtable.v2.RateLimitInfo;
import com.google.cloud.bigtable.gaxx.testing.FakeStatusCode;
import com.google.protobuf.ByteString;
import com.google.protobuf.Duration;
import com.google.rpc.Code;
import com.google.rpc.Status;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -138,6 +142,46 @@ public void testErrorInfoLowerQPS() throws Exception {
assertThat(newQps).isWithin(0.1).of(oldQps * RateLimitingServerStreamingCallable.MIN_FACTOR);
}

@Test
public void testResponseIsPropagated() {
MutateRowsResponse expectedResponse =
MutateRowsResponse.newBuilder()
.addEntries(
MutateRowsResponse.Entry.newBuilder()
.setIndex(0)
.setStatus(Status.newBuilder().setCode(Code.PERMISSION_DENIED_VALUE)))
.build();
innerCallable =
new MockCallable() {
@Override
public void call(
MutateRowsRequest mutateRowsRequest,
ResponseObserver<MutateRowsResponse> responseObserver,
ApiCallContext apiCallContext) {
responseObserver.onResponse(expectedResponse);
responseObserver.onComplete();
}
};

callableToTest = new RateLimitingServerStreamingCallable(innerCallable);

ResponseObserver<MutateRowsResponse> mockObserver = Mockito.mock(ResponseObserver.class);

MutateRowsRequest req =
MutateRowsRequest.newBuilder()
.addEntries(
MutateRowsRequest.Entry.newBuilder()
.setRowKey(ByteString.copyFromUtf8("k1"))
.addMutations(
Mutation.newBuilder()
.setDeleteFromRow(Mutation.DeleteFromRow.getDefaultInstance())))
.build();

callableToTest.call(req, mockObserver, context);

Mockito.verify(mockObserver, Mockito.times(1)).onResponse(Mockito.eq(expectedResponse));
}

private static class MockResponseObserver implements ResponseObserver<MutateRowsResponse> {

private ResponseObserver<MutateRowsResponse> observer;
Expand Down
Loading