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]fix: add request with default value in regular paged callable method #690

Merged
merged 1 commit into from
Mar 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -592,18 +592,15 @@ public static String composeRegularCallableMethodHeaderSampleCode(
.setValueExpr(requestBuilderExpr)
.build();

List<Expr> bodyExprs = new ArrayList<>();
bodyExprs.add(requestAssignmentExpr);

List<Statement> bodyStatements = new ArrayList<>();
bodyStatements.add(ExprStatement.withExpr(requestAssignmentExpr));

if (method.isPaged()) {
bodyStatements.addAll(
composePagedCallableBodyStatements(method, clientVarExpr, requestVarExpr, messageTypes));
} else {
bodyStatements.addAll(
composeUnaryOrLroCallableBodyStatements(
method, clientVarExpr, requestVarExpr, bodyExprs));
composeUnaryOrLroCallableBodyStatements(method, clientVarExpr, requestVarExpr));
}

return SampleCodeWriter.write(
Expand Down Expand Up @@ -1061,10 +1058,7 @@ private static List<Statement> composeStreamClientBodyStatements(
}

private static List<Statement> composeUnaryOrLroCallableBodyStatements(
Method method,
VariableExpr clientVarExpr,
VariableExpr requestVarExpr,
List<Expr> bodyExprs) {
Method method, VariableExpr clientVarExpr, VariableExpr requestVarExpr) {
List<Statement> bodyStatements = new ArrayList<>();
// Create api future variable expression, and assign it with a value by invoking callable
// method.
Expand Down Expand Up @@ -1098,10 +1092,7 @@ private static List<Statement> composeUnaryOrLroCallableBodyStatements(
.setVariableExpr(apiFutureVarExpr.toBuilder().setIsDecl(true).build())
.setValueExpr(callableMethodInvocationExpr)
.build();
bodyExprs.add(futureAssignmentExpr);
bodyStatements.addAll(
bodyExprs.stream().map(e -> ExprStatement.withExpr(e)).collect(Collectors.toList()));
bodyExprs.clear();
bodyStatements.add(ExprStatement.withExpr(futureAssignmentExpr));
bodyStatements.add(CommentStatement.withComment(LineComment.withComment("Do something.")));

MethodInvocationExpr getMethodInvocationExpr =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,12 @@ public class EchoClient implements BackgroundResource {
*
* <pre>{@code
* try (EchoClient echoClient = EchoClient.create()) {
* PagedExpandRequest request =
* PagedExpandRequest.newBuilder()
* .setContent("content951530617")
* .setPageSize(883849137)
* .setPageToken("pageToken873572522")
* .build();
* while (true) {
* PagedExpandResponse response = echoClient.pagedExpandCallable().call(request);
* for (EchoResponse element : response.getResponsesList()) {
Expand Down Expand Up @@ -612,6 +618,12 @@ public class EchoClient implements BackgroundResource {
*
* <pre>{@code
* try (EchoClient echoClient = EchoClient.create()) {
* PagedExpandRequest request =
* PagedExpandRequest.newBuilder()
* .setContent("content951530617")
* .setPageSize(883849137)
* .setPageToken("pageToken873572522")
* .build();
* while (true) {
* PagedExpandResponse response = echoClient.simplePagedExpandCallable().call(request);
* for (EchoResponse element : response.getResponsesList()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,11 @@ public class IdentityClient implements BackgroundResource {
*
* <pre>{@code
* try (IdentityClient identityClient = IdentityClient.create()) {
* ListUsersRequest request =
* ListUsersRequest.newBuilder()
* .setPageSize(883849137)
* .setPageToken("pageToken873572522")
* .build();
* while (true) {
* ListUsersResponse response = identityClient.listUsersCallable().call(request);
* for (User element : response.getResponsesList()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2452,6 +2452,12 @@ public void validComposeRegularCallableMethodHeaderSampleCode_pageRpc() {
String expected =
LineFormatter.lines(
"try (EchoClient echoClient = EchoClient.create()) {\n",
" PagedExpandRequest request =\n",
" PagedExpandRequest.newBuilder()\n",
" .setContent(\"content951530617\")\n",
" .setPageSize(883849137)\n",
" .setPageToken(\"pageToken873572522\")\n",
" .build();\n",
" while (true) {\n",
" PagedExpandResponse response = echoClient.pagedExpandCallable().call(request);\n",
" for (EchoResponse element : response.getResponsesList()) {\n",
Expand Down
16 changes: 16 additions & 0 deletions test/integration/goldens/asset/AssetServiceClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,15 @@ public final SearchAllResourcesPagedResponse searchAllResources(
*
* <pre>{@code
* try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
* SearchAllResourcesRequest request =
* SearchAllResourcesRequest.newBuilder()
* .setScope("scope109264468")
* .setQuery("query107944136")
* .addAllAssetTypes(new ArrayList<String>())
* .setPageSize(883849137)
* .setPageToken("pageToken873572522")
* .setOrderBy("orderBy-1207110587")
* .build();
* while (true) {
* SearchAllResourcesResponse response =
* assetServiceClient.searchAllResourcesCallable().call(request);
Expand Down Expand Up @@ -1039,6 +1048,13 @@ public final SearchAllIamPoliciesPagedResponse searchAllIamPolicies(
*
* <pre>{@code
* try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
* SearchAllIamPoliciesRequest request =
* SearchAllIamPoliciesRequest.newBuilder()
* .setScope("scope109264468")
* .setQuery("query107944136")
* .setPageSize(883849137)
* .setPageToken("pageToken873572522")
* .build();
* while (true) {
* SearchAllIamPoliciesResponse response =
* assetServiceClient.searchAllIamPoliciesCallable().call(request);
Expand Down
34 changes: 34 additions & 0 deletions test/integration/goldens/kms/KeyManagementServiceClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,14 @@ public final ListKeyRingsPagedResponse listKeyRings(ListKeyRingsRequest request)
* <pre>{@code
* try (KeyManagementServiceClient keyManagementServiceClient =
* KeyManagementServiceClient.create()) {
* ListKeyRingsRequest request =
* ListKeyRingsRequest.newBuilder()
* .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
* .setPageSize(883849137)
* .setPageToken("pageToken873572522")
* .setFilter("filter-1274492040")
* .setOrderBy("orderBy-1207110587")
* .build();
* while (true) {
* ListKeyRingsResponse response =
* keyManagementServiceClient.listKeyRingsCallable().call(request);
Expand Down Expand Up @@ -438,6 +446,14 @@ public final ListCryptoKeysPagedResponse listCryptoKeys(ListCryptoKeysRequest re
* <pre>{@code
* try (KeyManagementServiceClient keyManagementServiceClient =
* KeyManagementServiceClient.create()) {
* ListCryptoKeysRequest request =
* ListCryptoKeysRequest.newBuilder()
* .setParent(KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]").toString())
* .setPageSize(883849137)
* .setPageToken("pageToken873572522")
* .setFilter("filter-1274492040")
* .setOrderBy("orderBy-1207110587")
* .build();
* while (true) {
* ListCryptoKeysResponse response =
* keyManagementServiceClient.listCryptoKeysCallable().call(request);
Expand Down Expand Up @@ -593,6 +609,16 @@ public final ListCryptoKeyVersionsPagedResponse listCryptoKeyVersions(
* <pre>{@code
* try (KeyManagementServiceClient keyManagementServiceClient =
* KeyManagementServiceClient.create()) {
* ListCryptoKeyVersionsRequest request =
* ListCryptoKeyVersionsRequest.newBuilder()
* .setParent(
* CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]")
* .toString())
* .setPageSize(883849137)
* .setPageToken("pageToken873572522")
* .setFilter("filter-1274492040")
* .setOrderBy("orderBy-1207110587")
* .build();
* while (true) {
* ListCryptoKeyVersionsResponse response =
* keyManagementServiceClient.listCryptoKeyVersionsCallable().call(request);
Expand Down Expand Up @@ -737,6 +763,14 @@ public final ListImportJobsPagedResponse listImportJobs(ListImportJobsRequest re
* <pre>{@code
* try (KeyManagementServiceClient keyManagementServiceClient =
* KeyManagementServiceClient.create()) {
* ListImportJobsRequest request =
* ListImportJobsRequest.newBuilder()
* .setParent(KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]").toString())
* .setPageSize(883849137)
* .setPageToken("pageToken873572522")
* .setFilter("filter-1274492040")
* .setOrderBy("orderBy-1207110587")
* .build();
* while (true) {
* ListImportJobsResponse response =
* keyManagementServiceClient.listImportJobsCallable().call(request);
Expand Down
11 changes: 11 additions & 0 deletions test/integration/goldens/library/LibraryServiceClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,11 @@ public final ListShelvesPagedResponse listShelves(ListShelvesRequest request) {
*
* <pre>{@code
* try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
* ListShelvesRequest request =
* ListShelvesRequest.newBuilder()
* .setPageSize(883849137)
* .setPageToken("pageToken873572522")
* .build();
* while (true) {
* ListShelvesResponse response = libraryServiceClient.listShelvesCallable().call(request);
* for (Shelf element : response.getResponsesList()) {
Expand Down Expand Up @@ -959,6 +964,12 @@ public final UnaryCallable<ListBooksRequest, ListBooksPagedResponse> listBooksPa
*
* <pre>{@code
* try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
* ListBooksRequest request =
* ListBooksRequest.newBuilder()
* .setName("name3373707")
* .setPageSize(883849137)
* .setPageToken("pageToken873572522")
* .build();
* while (true) {
* ListBooksResponse response = libraryServiceClient.listBooksCallable().call(request);
* for (Book element : response.getResponsesList()) {
Expand Down
27 changes: 27 additions & 0 deletions test/integration/goldens/logging/ConfigClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,14 @@ public final ListBucketsPagedResponse listBuckets(ListBucketsRequest request) {
*
* <pre>{@code
* try (ConfigClient configClient = ConfigClient.create()) {
* ListBucketsRequest request =
* ListBucketsRequest.newBuilder()
* .setParent(
* LogBucketName.ofProjectLocationBucketName("[PROJECT]", "[LOCATION]", "[BUCKET]")
* .toString())
* .setPageToken("pageToken873572522")
* .setPageSize(883849137)
* .build();
* while (true) {
* ListBucketsResponse response = configClient.listBucketsCallable().call(request);
* for (LogBucket element : response.getResponsesList()) {
Expand Down Expand Up @@ -800,6 +808,12 @@ public final UnaryCallable<ListViewsRequest, ListViewsPagedResponse> listViewsPa
*
* <pre>{@code
* try (ConfigClient configClient = ConfigClient.create()) {
* ListViewsRequest request =
* ListViewsRequest.newBuilder()
* .setParent("parent-995424086")
* .setPageToken("pageToken873572522")
* .setPageSize(883849137)
* .build();
* while (true) {
* ListViewsResponse response = configClient.listViewsCallable().call(request);
* for (LogView element : response.getResponsesList()) {
Expand Down Expand Up @@ -1211,6 +1225,12 @@ public final UnaryCallable<ListSinksRequest, ListSinksPagedResponse> listSinksPa
*
* <pre>{@code
* try (ConfigClient configClient = ConfigClient.create()) {
* ListSinksRequest request =
* ListSinksRequest.newBuilder()
* .setParent(LogSinkName.ofProjectSinkName("[PROJECT]", "[SINK]").toString())
* .setPageToken("pageToken873572522")
* .setPageSize(883849137)
* .build();
* while (true) {
* ListSinksResponse response = configClient.listSinksCallable().call(request);
* for (LogSink element : response.getResponsesList()) {
Expand Down Expand Up @@ -2091,6 +2111,13 @@ public final ListExclusionsPagedResponse listExclusions(ListExclusionsRequest re
*
* <pre>{@code
* try (ConfigClient configClient = ConfigClient.create()) {
* ListExclusionsRequest request =
* ListExclusionsRequest.newBuilder()
* .setParent(
* LogExclusionName.ofProjectExclusionName("[PROJECT]", "[EXCLUSION]").toString())
* .setPageToken("pageToken873572522")
* .setPageSize(883849137)
* .build();
* while (true) {
* ListExclusionsResponse response = configClient.listExclusionsCallable().call(request);
* for (LogExclusion element : response.getResponsesList()) {
Expand Down
20 changes: 20 additions & 0 deletions test/integration/goldens/logging/LoggingClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,14 @@ public final ListLogEntriesPagedResponse listLogEntries(ListLogEntriesRequest re
*
* <pre>{@code
* try (LoggingClient loggingClient = LoggingClient.create()) {
* ListLogEntriesRequest request =
* ListLogEntriesRequest.newBuilder()
* .addAllResourceNames(new ArrayList<String>())
* .setFilter("filter-1274492040")
* .setOrderBy("orderBy-1207110587")
* .setPageSize(883849137)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we assing something reasonable (i.e smaller, like 10 or 100) to these kind of fields (random huge number for page size is confusing and not realistic)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently, we use hashcode of field' name. source code

IMO, smaller number like 10 make more sense in reality. And PageSize is fixed filed to be set for default request variable. Looks like it is doable in code. @miraleung what is your opinion?

* .setPageToken("pageToken873572522")
Copy link
Contributor

@vam-google vam-google Mar 8, 2021

Choose a reason for hiding this comment

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

Setting page token in the initial request seems harmful, because before you start paginated call there is no page token (i.e. page token makes sense only for pages 2+, but the first page does not have page token).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

* .build();
* while (true) {
* ListLogEntriesResponse response = loggingClient.listLogEntriesCallable().call(request);
* for (LogEntry element : response.getResponsesList()) {
Expand Down Expand Up @@ -697,6 +705,11 @@ public final ListMonitoredResourceDescriptorsPagedResponse listMonitoredResource
*
* <pre>{@code
* try (LoggingClient loggingClient = LoggingClient.create()) {
* ListMonitoredResourceDescriptorsRequest request =
* ListMonitoredResourceDescriptorsRequest.newBuilder()
* .setPageSize(883849137)
* .setPageToken("pageToken873572522")
* .build();
* while (true) {
* ListMonitoredResourceDescriptorsResponse response =
* loggingClient.listMonitoredResourceDescriptorsCallable().call(request);
Expand Down Expand Up @@ -919,6 +932,13 @@ public final UnaryCallable<ListLogsRequest, ListLogsPagedResponse> listLogsPaged
*
* <pre>{@code
* try (LoggingClient loggingClient = LoggingClient.create()) {
* ListLogsRequest request =
* ListLogsRequest.newBuilder()
* .setParent(LogName.ofProjectLogName("[PROJECT]", "[LOG]").toString())
* .setPageSize(883849137)
* .setPageToken("pageToken873572522")
* .addAllResourceNames(new ArrayList<String>())
* .build();
* while (true) {
* ListLogsResponse response = loggingClient.listLogsCallable().call(request);
* for (String element : response.getResponsesList()) {
Expand Down
6 changes: 6 additions & 0 deletions test/integration/goldens/logging/MetricsClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,12 @@ public final ListLogMetricsPagedResponse listLogMetrics(ListLogMetricsRequest re
*
* <pre>{@code
* try (MetricsClient metricsClient = MetricsClient.create()) {
* ListLogMetricsRequest request =
* ListLogMetricsRequest.newBuilder()
* .setParent(ProjectName.of("[PROJECT]").toString())
* .setPageToken("pageToken873572522")
* .setPageSize(883849137)
* .build();
* while (true) {
* ListLogMetricsResponse response = metricsClient.listLogMetricsCallable().call(request);
* for (LogMetric element : response.getResponsesList()) {
Expand Down
6 changes: 6 additions & 0 deletions test/integration/goldens/redis/CloudRedisClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,12 @@ public final ListInstancesPagedResponse listInstances(ListInstancesRequest reque
*
* <pre>{@code
* try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
* ListInstancesRequest request =
* ListInstancesRequest.newBuilder()
* .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
* .setPageSize(883849137)
* .setPageToken("pageToken873572522")
* .build();
* while (true) {
* ListInstancesResponse response = cloudRedisClient.listInstancesCallable().call(request);
* for (Instance element : response.getResponsesList()) {
Expand Down