-
Notifications
You must be signed in to change notification settings - Fork 104
feat: Update to non-eager FutureListener #1878
Conversation
|
Kudos, SonarCloud Quality Gate passed! |
|
Running It passes with the httpjson changes! |
|
I'll need to complete part 2: Potential server-streaming call candidate from Seems like this proto doesn't have a Http Stub? |
|
Taking another look at this PR now. Seems like AIPlatform module is only GRPC based. I can't seem to find any other good candidates for server side streaming RPCs. Going to take a look at some of the handwritten libraries. Spanner: Trying to create a repro/ sample here: https://github.com/lqiu96/ServerSideStreamingHttpJson/tree/main |
|
Ran this with the httpjson module changes in the branch and it works. The modified code is being called and the result is valid. |
| @Override | ||
| public void onMessage(T message) { | ||
| if (!future.set(message)) { | ||
| if (isMessageReceived) { |
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.
Looks like isMessageReceived and message are always set together, can we just check if message is null?
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 think you're right. I wasn't sure if parameter message would ever be passed in as null, but it seems like that won't be the case. I think unknown fields will be ignored and null values will be set to their default values and any invalid JSON would have an exception throw so we should be good. I'll make the change
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 gave it more thought and I think we should revert to your previous approach. The logic is fine in onMessage, but in onClose, we can not use if(storedMessage == null) to determine anything because we cannot distinguish if the response itself is null or we haven't received response yet.
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.
Sounds good. I can revert to the previous way.
|
Added a few more tests cases. The tests cover:
|
|
|
||
| Field request; | ||
| Field expectedResponse; | ||
| request = expectedResponse = createTestMessage(2); |
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 feel like
Field request = createTestMessage(2);
Field expectedResponse = createTestMessage(2);
is clearer.
Also I'm not sure if the name makes sense, if we are asserting actual response to be randomResponse1, then we should probably rename randomResponse1 to expectedResponse.
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.
Sure, I can update.
I wanted the assertions below to show that it wasn't the expected response (given that it's not throwing an exception but just returning the first response back):
// Gax returns the first response for Unary Call
assertThat(actualResponse).isEqualTo(randomResponse1);
assertThat(actualResponse).isNotEqualTo(expectedResponse);
| } else if (statusCode < 200 || statusCode >= 400) { | ||
| LOGGER.log( | ||
| Level.WARNING, "Received error for unary call after receiving a successful response"); | ||
| } else { |
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.
Confirm: Can this be removed?
| if (storedMessage != null) { | ||
| throw new IllegalStateException("More than one value received for unary call"); | ||
| } | ||
| storedMessage = message; |
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.
Confirm: Is the future done on here? What if the runnableResult has an exception?
| @Override | ||
| public void onClose(int statusCode, HttpJsonMetadata trailers) { | ||
| if (!future.isDone()) { | ||
| if (storedMessage == null) { |
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.
Should the logic for this be done via Status Code? Check for 2xx Status Codes?
|
Kudos, SonarCloud Quality Gate passed! |
gax-httpjson/src/test/java/com/google/api/gax/httpjson/HttpJsonDirectCallableTest.java
Show resolved
Hide resolved
|
Since we're migrating to the gapic monorepo, I will create a patch file and apply the changes in the monorepo. Once that's been done I will close this issue. I'll reference this PR in that repo. |








Works on issue found in googleapis/sdk-platform-java#1322