[samplecode] Implement rpc default method sample code#594
[samplecode] Implement rpc default method sample code#594summer-ji-eng merged 5 commits intosamplecode-masterfrom
Conversation
src/main/java/com/google/api/generator/gapic/composer/ServiceClientSampleCodeComposer.java
Show resolved
Hide resolved
src/main/java/com/google/api/generator/gapic/composer/ServiceClientSampleCodeComposer.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/api/generator/gapic/composer/ServiceClientSampleCodeComposer.java
Show resolved
Hide resolved
| .build(); | ||
| bodyStatements.add(loopIteratorStatement); | ||
| } else { | ||
| TypeNode methodOutputType = |
There was a problem hiding this comment.
Similarly, this could probably reuse composeUnaryRpcMethodSampleCode and composeUnaryLroRpcMethodSampleCode.
There was a problem hiding this comment.
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. 🙏
abc6879 to
25d6723
Compare
src/main/java/com/google/api/generator/gapic/composer/ServiceClientSampleCodeComposer.java
Outdated
Show resolved
Hide resolved
miraleung
left a comment
There was a problem hiding this comment.
This approach is much better, thanks! LGTM with last comments addressed.
| bodyStatements.addAll( | ||
| composeUnaryLroRpcMethodSampleCodeBodyStatements( | ||
| method, clientVarExpr, rpcMethodArgVarExprs, bodyExprs)); | ||
| } else { |
There was a problem hiding this comment.
Do we need any extra handling for streaming methods?
There was a problem hiding this comment.
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));
}
src/main/java/com/google/api/generator/gapic/composer/ServiceClientSampleCodeComposer.java
Outdated
Show resolved
Hide resolved
|
Thanks for reviewing @miraleung. Merge into |
[](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` | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](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#​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 ([#​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 ([#​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 ([#​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 ([#​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).
🤖 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).
RPC default method has 3 types sample code for:
or if method return void, the last line is
cloudRedisClient.upgradeInstanceAsync(request).get();3. pure unary (gapic-generator sample code)
Or if the method return void, the last line is
metricsClient.createLogMetric(request);