-
Notifications
You must be signed in to change notification settings - Fork 53
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
Changes from 15 commits
b43a82a
45bdea1
5ef67e9
ba9fb82
1206c4c
5de06df
640e35f
46b0b1b
208c1ad
eed5def
4d26862
61ac41a
ca777dd
29c0516
2a7af58
5a13d48
a6a3676
533deec
d3453a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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; | ||
ApiException exception = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: this may not work but can the inner There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
|
There was a problem hiding this comment.
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
overCANCELLED
? Mostly wondering if the grpc tests should also be switched to use this.There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
orCANCELLED
, let's please make this andtestGrpc_serverResponseError_throwsException
consistent so we aren't implying a difference in behavior. If we want to test both behaviors, let's do so explicitly.There was a problem hiding this comment.
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.