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

chore: Add Showcase Callables IT #1483

Merged
merged 19 commits into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from 15 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
1 change: 0 additions & 1 deletion showcase/gapic-showcase/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.google.truth</groupId>
<artifactId>truth</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.google.api.gax.core.NoCredentialsProvider;
import com.google.api.gax.grpc.GrpcStatusCode;
import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
import com.google.api.gax.rpc.ApiException;
import com.google.api.gax.rpc.CancelledException;
import com.google.api.gax.rpc.StatusCode;
import com.google.rpc.Status;
Expand Down Expand Up @@ -100,11 +101,38 @@ public void testGrpc_shutdown() {
}

@Test
public void testHttpJson() {
public void testHttpJson_receiveContent() {
assertThat(echoHttpJson("http-echo?")).isEqualTo("http-echo?");
assertThat(echoHttpJson("http-echo!")).isEqualTo("http-echo!");
}

/*
This tests has the server return an error back as the result.
We use 404 NOT_FOUND Status as that has the same gRPC <-> HttpJson code mapping
(showcase sever has a map that translates the code). The showcase server expects
a gRPC Status Code and the result is the HttpJson's mapped value
*/
@Test
public void testHttpJson_serverResponseError_throwsException() {
StatusCode.Code notFoundStatusCode = StatusCode.Code.NOT_FOUND;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may have already covered this in the javadoc but is there an advantage of using NOT_FOUND over CANCELLED? Mostly wondering if the grpc tests should also be switched to use this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just picked NOT_FOUND instead of CANCELLED since the docs seem to suggest that CANCELLED status is from a user action (https://chromium.googlesource.com/external/github.com/grpc/grpc/+/refs/tags/v1.21.4-pre1/doc/statuscodes.md). Any error code should be fine since we just need the server to respond back with the error.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whether we choose NOT_FOUND or CANCELLED, let's please make this and testGrpc_serverResponseError_throwsException consistent so we aren't implying a difference in behavior. If we want to test both behaviors, let's do so explicitly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll update to CANCELLED.

ApiException exception =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we can make the exception more specific here? To make sure that the test doesn't pass for a false positive case since ApiException can occur for a number of reasons.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah changed.

assertThrows(
ApiException.class,
() ->
httpJsonClient.echo(
EchoRequest.newBuilder()
.setError(Status.newBuilder().setCode(notFoundStatusCode.ordinal()).build())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this may not work but can the inner build() call be omitted when we nest builders? i.e. does EchoRequest.newBuilder().setError(Status.newBuilder().setCode(notFoundStatusCode.ordinal())).build() work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved it out to a variable

.build()));
assertThat(exception.getStatusCode().getCode()).isEqualTo(notFoundStatusCode);
}

@Test
public void testHttpJson_shutdown() {
assertThat(httpJsonClient.isShutdown()).isFalse();
httpJsonClient.shutdown();
assertThat(httpJsonClient.isShutdown()).isTrue();
}

private String echoGrpc(String value) {
EchoResponse response = grpcClient.echo(EchoRequest.newBuilder().setContent(value).build());
return response.getContent();
Expand Down