Skip to content
This repository was archived by the owner on Sep 26, 2023. It is now read-only.

Conversation

@lqiu96
Copy link
Member

@lqiu96 lqiu96 commented Nov 14, 2022

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

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

90.9% 90.9% Coverage
0.0% 0.0% Duplication

@lqiu96 lqiu96 marked this pull request as ready for review November 15, 2022 02:22
@lqiu96 lqiu96 requested a review from a team November 15, 2022 02:22
@lqiu96 lqiu96 requested review from a team as code owners November 15, 2022 02:22
@lqiu96 lqiu96 requested a review from blakeli0 November 15, 2022 02:23
@lqiu96
Copy link
Member Author

lqiu96 commented Nov 15, 2022

Running java-compute ITs locally with this build of gax-java:

[INFO] Skipping execution
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for Google Compute Engine Parent 1.15.1-SNAPSHOT:
[INFO]
[INFO] Google Compute Engine Parent ....................... SUCCESS [  0.845 s]
[INFO] proto-google-cloud-compute-v1 ...................... SUCCESS [  0.723 s]
[INFO] Google Compute Engine .............................. SUCCESS [06:45 min]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  06:49 min (Wall Clock)
[INFO] Finished at: 2022-11-15T10:41:49-05:00
[INFO] ------------------------------------------------------------------------
Finished Integration Tests for:
java-compute

It passes with the httpjson changes!

@lqiu96
Copy link
Member Author

lqiu96 commented Nov 15, 2022

I'll need to complete part 2:

Test some of the server-streaming calls on any regapics. Server-side streaming logic relies heavily on listeners and stuff like that, so any messing with them may affect streaming logic. Search for `returns stream` across googleapis repository to find all server-streaming call candidates (Need to make sure that the methods also don't have `stream` in their input parameter as that would be a bidi-stream method)

Potential server-streaming call candidate from aiplatform:

  rpc StreamingReadFeatureValues(StreamingReadFeatureValuesRequest) returns (stream ReadFeatureValuesResponse) {
    option (google.api.http) = {
      post: "/v1/{entity_type=projects/*/locations/*/featurestores/*/entityTypes/*}:streamingReadFeatureValues"
      body: "*"
    };
    option (google.api.method_signature) = "entity_type";
  }

Seems like this proto doesn't have a Http Stub?

@lqiu96
Copy link
Member Author

lqiu96 commented Dec 6, 2022

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:

  rpc StreamingRead(ReadRequest) returns (stream PartialResultSet) {
    option (google.api.http) = {
      post: "/v1/{session=projects/*/instances/*/databases/*/sessions/*}:streamingRead"
      body: "*"
    };
  }

Trying to create a repro/ sample here: https://github.com/lqiu96/ServerSideStreamingHttpJson/tree/main

@lqiu96
Copy link
Member Author

lqiu96 commented Dec 7, 2022

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) {
Copy link
Contributor

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?

Copy link
Member Author

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

Copy link
Contributor

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.

Copy link
Member Author

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.

@lqiu96
Copy link
Member Author

lqiu96 commented Dec 15, 2022

Added a few more tests cases. The tests cover:

  • Successful Unary Call (200 status code + Message returned)
  • Error Response from Unary Call (404 status code)
  • Cases for multiple responses from Unary Call
  • Null Content Success Response (200 status code + Null returned)
  • Null Content Error Response (400 status code + Null returned)
  • Non 4xx Error response


Field request;
Field expectedResponse;
request = expectedResponse = createTestMessage(2);
Copy link
Contributor

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.

Copy link
Member Author

@lqiu96 lqiu96 Dec 15, 2022

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);

Comment on lines 145 to 148
} else if (statusCode < 200 || statusCode >= 400) {
LOGGER.log(
Level.WARNING, "Received error for unary call after receiving a successful response");
} else {
Copy link
Member Author

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?

Comment on lines 126 to 129
if (storedMessage != null) {
throw new IllegalStateException("More than one value received for unary call");
}
storedMessage = message;
Copy link
Member Author

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) {
Copy link
Member Author

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?

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

90.9% 90.9% Coverage
0.0% 0.0% Duplication

@lqiu96
Copy link
Member Author

lqiu96 commented Dec 19, 2022

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants