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

[samplecode] Implement rpc default method sample code #594

Merged
merged 5 commits into from
Dec 17, 2020

Conversation

summer-ji-eng
Copy link
Contributor

@summer-ji-eng summer-ji-eng commented Dec 10, 2020

RPC default method has 3 types sample code for:

  1. paged (gapic-generator sample code)
  * try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
  *   ListShelvesRequest request =
  *       ListShelvesRequest.newBuilder()
  *           .setPageSize(883849137)
  *           .setPageToken("pageToken873572522")
  *           .build();
  *   for (Shelf element : libraryServiceClient.listShelves(request).iterateAll()) {
  *     // doThingsWith(element);
  *   }
  * }
  1. lro (gapic-generator sample code)
   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
   *   UpgradeInstanceRequest request =
   *       UpgradeInstanceRequest.newBuilder()
   *           .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString())
   *           .setRedisVersion("redisVersion-1972584739")
   *           .build();
   *   Instance response = cloudRedisClient.upgradeInstanceAsync(request).get();
   * }

or if method return void, the last line is cloudRedisClient.upgradeInstanceAsync(request).get();
3. pure unary (gapic-generator sample code)

   * try (MetricsClient metricsClient = MetricsClient.create()) {
   *   CreateLogMetricRequest request =
   *       CreateLogMetricRequest.newBuilder()
   *           .setParent(LogMetricName.of("[PROJECT]", "[METRIC]").toString())
   *           .setMetric(LogMetric.newBuilder().build())
   *           .build();
   *   LogMetric response = metricsClient.createLogMetric(request);
   * }

Or if the method return void, the last line is metricsClient.createLogMetric(request);

@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Dec 10, 2020
@product-auto-label product-auto-label bot added the samples Issues that are directly related to samples. label Dec 10, 2020
.build();
bodyStatements.add(loopIteratorStatement);
} else {
TypeNode methodOutputType =
Copy link
Contributor

Choose a reason for hiding this comment

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

Similarly, this could probably reuse composeUnaryRpcMethodSampleCode and composeUnaryLroRpcMethodSampleCode.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @miraleung, thanks for the valuable suggestion.

Make composeUnaryRpcMethodSampleCode, composeUnaryPagedRpcMethodSampleCode, and composeUnaryLroRpcMethodSampleCode re-usable for default method.

Update the unit test based on the new approach.

Open to discuss a better approach to re-use the utility methods. 🙏

Copy link
Contributor

@miraleung miraleung left a comment

Choose a reason for hiding this comment

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

This approach is much better, thanks! LGTM with last comments addressed.

bodyStatements.addAll(
composeUnaryLroRpcMethodSampleCodeBodyStatements(
method, clientVarExpr, rpcMethodArgVarExprs, bodyExprs));
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need any extra handling for streaming methods?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No need to handle streaming methods here in composeRpcMethodHeaderSampleCode.
The caller is createMethodVariants only pass in the non-stream method in:

if (method.stream().equals(Stream.NONE)) {
        javaMethods.addAll(
            createMethodVariants(method, clientName, messageTypes, types, resourceNames));
        javaMethods.add(
            createMethodDefaultMethod(method, clientName, messageTypes, types, resourceNames));
      }

@summer-ji-eng
Copy link
Contributor Author

Thanks for reviewing @miraleung. Merge into samplecode-master now.

@summer-ji-eng summer-ji-eng deleted the default_unary_samplecode_1 branch January 19, 2021 23:18
suztomo pushed a commit that referenced this pull request Mar 21, 2023
suztomo pushed a commit that referenced this pull request Mar 21, 2023
[![WhiteSource Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [com.google.api:gax-bom](https://togithub.com/googleapis/gax-java) | `2.5.0` -> `2.6.0` | [![age](https://badges.renovateapi.com/packages/maven/com.google.api:gax-bom/2.6.0/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/maven/com.google.api:gax-bom/2.6.0/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/maven/com.google.api:gax-bom/2.6.0/compatibility-slim/2.5.0)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/maven/com.google.api:gax-bom/2.6.0/confidence-slim/2.5.0)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>googleapis/gax-java</summary>

### [`v2.6.0`](https://togithub.com/googleapis/gax-java/blob/master/CHANGELOG.md#&#8203;260-httpswwwgithubcomgoogleapisgax-javacomparev253v260-2021-10-15)

[Compare Source](https://togithub.com/googleapis/gax-java/compare/v2.5.0...v2.6.0)

##### Features

-   remove deprecated Generated annotation ([2d76bff](https://www.github.com/googleapis/gax-java/commit/2d76bff6d64da818a3aff7ea0bdf5a36b82c3464))

##### Bug Fixes

-   Fix com.google.rpc.Code to StatusCode.Code conversion logic ([2d76bff](https://www.github.com/googleapis/gax-java/commit/2d76bff6d64da818a3aff7ea0bdf5a36b82c3464))

##### Dependencies

-   update api-common to 2.0.5 ([2d76bff](https://www.github.com/googleapis/gax-java/commit/2d76bff6d64da818a3aff7ea0bdf5a36b82c3464))
-   update auto-value to 1.8.2 ([2d76bff](https://www.github.com/googleapis/gax-java/commit/2d76bff6d64da818a3aff7ea0bdf5a36b82c3464))
-   update com_google_protobuf to 3.18.1 ([#&#8203;1519](https://www.togithub.com/googleapis/gax-java/issues/1519)) ([2d76bff](https://www.github.com/googleapis/gax-java/commit/2d76bff6d64da818a3aff7ea0bdf5a36b82c3464))
-   update google-http-client to 1.40.1 ([2d76bff](https://www.github.com/googleapis/gax-java/commit/2d76bff6d64da818a3aff7ea0bdf5a36b82c3464))
-   update grpc to 1.41.0 ([2d76bff](https://www.github.com/googleapis/gax-java/commit/2d76bff6d64da818a3aff7ea0bdf5a36b82c3464))
-   update guava to v31 ([2d76bff](https://www.github.com/googleapis/gax-java/commit/2d76bff6d64da818a3aff7ea0bdf5a36b82c3464))

##### [2.5.3](https://www.github.com/googleapis/gax-java/compare/v2.5.2...v2.5.3) (2021-10-13)

##### Bug Fixes

-   Fix `com.google.rpc.Code` to `StatusCode.Code` conversion  logic ([#&#8203;1508](https://www.togithub.com/googleapis/gax-java/issues/1508)) ([61b1617](https://www.github.com/googleapis/gax-java/commit/61b161799faf292be1394111381f8a35e757b85a))

##### [2.5.2](https://www.github.com/googleapis/gax-java/compare/v2.5.1...v2.5.2) (2021-10-13)

##### Dependencies

-   release multiple artifacts at once ([#&#8203;1506](https://www.togithub.com/googleapis/gax-java/issues/1506)) ([8c022f6](https://www.github.com/googleapis/gax-java/commit/8c022f69f7878280e00f200f65a931ff0f8cfe45))

##### [2.5.1](https://www.github.com/googleapis/gax-java/compare/v2.5.0...v2.5.1) (2021-10-08)

##### Dependencies

-   fix release pipeline ([#&#8203;1500](https://www.togithub.com/googleapis/gax-java/issues/1500)) ([f8ae03b](https://www.github.com/googleapis/gax-java/commit/f8ae03bbf0389d5fd943d214c1058ee012be757b))

</details>

---

### Configuration

📅 **Schedule**: At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box.

---

This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/java-core).
suztomo pushed a commit that referenced this pull request Mar 21, 2023
🤖 I have created a release \*beep\* \*boop\*
---
### [2.1.8](https://www.github.com/googleapis/java-core/compare/v2.1.7...v2.1.8) (2021-10-15)


### Dependencies

* update dependency com.google.api-client:google-api-client-bom to v1.32.2 ([#593](https://www.github.com/googleapis/java-core/issues/593)) ([5471efd](https://www.github.com/googleapis/java-core/commit/5471efda5271fc21df2ace74d4aa59dfff610a53))
* update dependency com.google.api:api-common to v2.0.4 ([#585](https://www.github.com/googleapis/java-core/issues/585)) ([3063023](https://www.github.com/googleapis/java-core/commit/3063023e34e10deef2a65d82a39a36d03296f145))
* update dependency com.google.api:api-common to v2.0.5 ([#589](https://www.github.com/googleapis/java-core/issues/589)) ([354ff97](https://www.github.com/googleapis/java-core/commit/354ff97f777f7b151744fc542bb43cb9caa3ba4a))
* update dependency com.google.api:gax-bom to v2.6.0 ([#594](https://www.github.com/googleapis/java-core/issues/594)) ([123ebcc](https://www.github.com/googleapis/java-core/commit/123ebcc927585ff42e4b6cdbde26deb527b45621))
* update dependency com.google.api.grpc:proto-google-common-protos to v2.6.0 ([#578](https://www.github.com/googleapis/java-core/issues/578)) ([cfd5d51](https://www.github.com/googleapis/java-core/commit/cfd5d51c5e82690a2eac536fbd75e3c789c52e36))
* update dependency com.google.api.grpc:proto-google-iam-v1 to v1.1.3 ([#574](https://www.github.com/googleapis/java-core/issues/574)) ([92c2a59](https://www.github.com/googleapis/java-core/commit/92c2a599d916d0103ad152c380c1f4c1a8bcfd81))
* update dependency com.google.api.grpc:proto-google-iam-v1 to v1.1.4 ([#584](https://www.github.com/googleapis/java-core/issues/584)) ([6984a40](https://www.github.com/googleapis/java-core/commit/6984a407a1b8f3466d0d695465f988d9138c95f6))
* update dependency com.google.api.grpc:proto-google-iam-v1 to v1.1.5 ([#587](https://www.github.com/googleapis/java-core/issues/587)) ([30e3d99](https://www.github.com/googleapis/java-core/commit/30e3d99f893da41af9ae3ac22356bed2bddc1fa8))
* update dependency com.google.api.grpc:proto-google-iam-v1 to v1.1.6 ([#590](https://www.github.com/googleapis/java-core/issues/590)) ([e7446c8](https://www.github.com/googleapis/java-core/commit/e7446c8475ee339abcf3f77bb993689501235014))
* update dependency com.google.auth:google-auth-library-bom to v1.2.0 ([#581](https://www.github.com/googleapis/java-core/issues/581)) ([3390141](https://www.github.com/googleapis/java-core/commit/3390141b28f90690956222c0d6661d502f91c706))
* update dependency com.google.auth:google-auth-library-bom to v1.2.1 ([#591](https://www.github.com/googleapis/java-core/issues/591)) ([7c4a658](https://www.github.com/googleapis/java-core/commit/7c4a6580faed1201d7e136d40f71a8805235e8ba))
* update dependency com.google.guava:guava-bom to v31 ([#577](https://www.github.com/googleapis/java-core/issues/577)) ([a72fd39](https://www.github.com/googleapis/java-core/commit/a72fd395d4eded744fb110dd01bac12906d7c564))
* update dependency com.google.http-client:google-http-client-bom to v1.40.1 ([#588](https://www.github.com/googleapis/java-core/issues/588)) ([a9402ff](https://www.github.com/googleapis/java-core/commit/a9402ff2d38eb220988550c04f2c27975ca9c6b9))
* update dependency com.google.protobuf:protobuf-bom to v3.18.1 ([#583](https://www.github.com/googleapis/java-core/issues/583)) ([6ccb52f](https://www.github.com/googleapis/java-core/commit/6ccb52f7386abbc2232178678523befc7e4b7e16))
---


This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement. samples Issues that are directly related to samples.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants