From b26117bc0a88801a31b514235d6439304d62cbbb Mon Sep 17 00:00:00 2001 From: Xiaozhen Liu Date: Mon, 26 Oct 2020 15:44:51 -0700 Subject: [PATCH 1/4] [ggj][infra][3/5]feat: add goldens update bazel rules for Redis API (#396) * goldens update bazel rules * clean up --- rules_bazel/java/integration_test.bzl | 83 +++++++++++++++++++++++++++ test/integration/BUILD.bazel | 7 +++ 2 files changed, 90 insertions(+) diff --git a/rules_bazel/java/integration_test.bzl b/rules_bazel/java/integration_test.bzl index ff00ae983c..9ab7c917f7 100644 --- a/rules_bazel/java/integration_test.bzl +++ b/rules_bazel/java/integration_test.bzl @@ -97,3 +97,86 @@ def integration_test(name, target, data): test_library = "%s_test" % target, srcs = data, ) + +def _overwrite_golden_impl(ctx): + # Extract the Java source files from the generated 3 srcjars from API bazel target, + # and put them in the temporary folder `codegen_tmp`, zip as `goldens_output_zip`. + # Overwrite the goldens folder e.g `test/integration/goldens/redis` with the + # code generation in `goldens_output_zip`. + + gapic_library = ctx.attr.gapic_library + resource_name_library = ctx.attr.resource_name_library + test_library = ctx.attr.test_library + srcs = ctx.files.srcs + # Convert the name of bazel rules e.g. `redis_update` to `redis` + # because we will need to overwrite the goldens files in `redis` folder. + api_name = "_".join(ctx.attr.name.split("_")[:-1]) + goldens_output_zip = ctx.outputs.goldens_output_zip + + script = """ + mkdir codegen_tmp + unzip -j {input} -d codegen_tmp + unzip -j {input_resource_name} -d codegen_tmp + unzip -j {input_test} -d codegen_tmp + cd codegen_tmp + # Remove unneeded non-Java files, like MANIFEST + rm -rf $(find . -type f ! -name "*.java") + zip -r ../{goldens_output_zip} . + """.format( + goldens_output_zip = goldens_output_zip.path, + input = gapic_library[JavaInfo].source_jars[0].path, + input_resource_name = resource_name_library[JavaInfo].source_jars[0].path, + input_test = test_library[JavaInfo].source_jars[0].path, + ) + + ctx.actions.run_shell( + inputs = srcs + [ + gapic_library[JavaInfo].source_jars[0], + resource_name_library[JavaInfo].source_jars[0], + test_library[JavaInfo].source_jars[0], + ], + outputs = [goldens_output_zip], + command = script, + ) + + # Overwrite the goldens. + golden_update_script_content = """ + cd ${{BUILD_WORKSPACE_DIRECTORY}} + unzip -ao {goldens_output_zip} -d test/integration/goldens/{api_name} + """.format( + goldens_output_zip = goldens_output_zip.path, + api_name = api_name, + ) + ctx.actions.write( + output = ctx.outputs.golden_update_script, + content = golden_update_script_content, + is_executable = True, + ) + return [DefaultInfo(executable = ctx.outputs.golden_update_script)] + +overwrite_golden = rule( + attrs = { + "gapic_library": attr.label(), + "resource_name_library": attr.label(), + "test_library": attr.label(), + "srcs": attr.label_list( + allow_files = True, + mandatory = True, + ), + }, + outputs = { + "goldens_output_zip": "%{name}.zip", + "golden_update_script": "%{name}.sh", + }, + executable = True, + implementation = _overwrite_golden_impl, +) + +def golden_update(name, target, data): + overwrite_golden( + name = name, + gapic_library = target, + resource_name_library = "%s_resource_name" % target, + test_library = "%s_test" % target, + srcs = data, + ) diff --git a/test/integration/BUILD.bazel b/test/integration/BUILD.bazel index 086f641051..79f2015e71 100644 --- a/test/integration/BUILD.bazel +++ b/test/integration/BUILD.bazel @@ -6,6 +6,7 @@ load( load( "//:rules_bazel/java/integration_test.bzl", "integration_test", + "golden_update", ) package(default_visibility = ["//visibility:public"]) @@ -26,6 +27,12 @@ integration_test( data = ["//test/integration/goldens/asset:goldens_files"], ) +golden_update( + name = "redis_update", + target = ":redis_java_gapic", + data = ["//test/integration/goldens/redis:goldens_files"], +) + #################################################### # API Library Rules #################################################### From ae4e7aed73087783d02f42bcccef422eb59b7912 Mon Sep 17 00:00:00 2001 From: Xiaozhen Liu Date: Mon, 26 Oct 2020 16:02:20 -0700 Subject: [PATCH 2/4] [ggj][infra][5/5]doc: update development.md for running integration test (#398) * update development.md * clean --- DEVELOPMENT.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 4320c37a42..b6b5fb825f 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -105,3 +105,16 @@ below are temporary and better ones will be coming. ```sh bazel run //src/test/java/com/google/api/generator/engine:JavaCodeGeneratorTest_update ``` + +- Run a single integration test for API like `Redis`, it generates Java source code using +the Java microgenerator and compares them with the goldens files in `test/integration/goldens/redis`. + + ```sh + bazel test //test/integration:redis + ``` + +- Update goldens files based on code generation in integration test, for example `Redis`. It generates Java source code using the Java microgenerator and overwrites the goldens files in `test/integration/goldens/redis` based on code generation. + + ```sh + bazel run //test/integration:redis_update + ``` \ No newline at end of file From 00b21d8d0bf078814e8c89b3f9ead7b6e516b52c Mon Sep 17 00:00:00 2001 From: Xiaozhen Liu Date: Wed, 28 Oct 2020 15:15:12 -0700 Subject: [PATCH 3/4] [ggj][infra][4/5]feat: add goldens update bazel rules for Asset API (#397) * goldens update bazel rules * clean up * goldens update rule for asset API * update goldens --- test/integration/BUILD.bazel | 7 ++ .../goldens/asset/AssetServiceClientTest.java | 45 +++++----- test/integration/goldens/asset/FeedName.java | 18 ++-- .../goldens/asset/GrpcAssetServiceStub.java | 84 +++++++++++++++++++ .../goldens/asset/package-info.java | 31 +++++++ .../goldens/redis/CloudRedisClientTest.java | 44 +++++----- .../goldens/redis/GrpcCloudRedisStub.java | 84 +++++++++++++++++++ .../goldens/redis/package-info.java | 39 +++++++++ 8 files changed, 301 insertions(+), 51 deletions(-) create mode 100644 test/integration/goldens/asset/package-info.java create mode 100644 test/integration/goldens/redis/package-info.java diff --git a/test/integration/BUILD.bazel b/test/integration/BUILD.bazel index 79f2015e71..f778566ed1 100644 --- a/test/integration/BUILD.bazel +++ b/test/integration/BUILD.bazel @@ -33,6 +33,12 @@ golden_update( data = ["//test/integration/goldens/redis:goldens_files"], ) +golden_update( + name = "asset_update", + target = ":asset_java_gapic", + data = ["//test/integration/goldens/asset:goldens_files"], +) + #################################################### # API Library Rules #################################################### @@ -94,3 +100,4 @@ java_gapic_library( "@com_google_googleapis//google/logging/v2:logging_java_proto", ], ) + diff --git a/test/integration/goldens/asset/AssetServiceClientTest.java b/test/integration/goldens/asset/AssetServiceClientTest.java index 4587e17e1c..3dc55843af 100644 --- a/test/integration/goldens/asset/AssetServiceClientTest.java +++ b/test/integration/goldens/asset/AssetServiceClientTest.java @@ -16,6 +16,9 @@ package com.google.cloud.asset.v1; +import static com.google.cloud.asset.v1.AssetServiceClient.SearchAllIamPoliciesPagedResponse; +import static com.google.cloud.asset.v1.AssetServiceClient.SearchAllResourcesPagedResponse; + import com.google.api.gax.core.NoCredentialsProvider; import com.google.api.gax.grpc.GaxGrpcProperties; import com.google.api.gax.grpc.testing.LocalChannelProvider; @@ -83,7 +86,7 @@ public void tearDown() throws Exception { } @Test - public void exportAssetsTest() { + public void exportAssetsTest() throws Exception { ExportAssetsResponse expectedResponse = ExportAssetsResponse.newBuilder() .setOutputConfig(OutputConfig.newBuilder().build()) @@ -99,7 +102,7 @@ public void exportAssetsTest() { ExportAssetsRequest request = ExportAssetsRequest.newBuilder() - .setParent(ProjectName.of("[PROJECT]").toString()) + .setParent(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString()) .addAllAssetTypes(new ArrayList<>()) .setOutputConfig(OutputConfig.newBuilder().build()) .build(); @@ -130,7 +133,7 @@ public void exportAssetsExceptionTest() throws Exception { try { ExportAssetsRequest request = ExportAssetsRequest.newBuilder() - .setParent(ProjectName.of("[PROJECT]").toString()) + .setParent(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString()) .addAllAssetTypes(new ArrayList<>()) .setOutputConfig(OutputConfig.newBuilder().build()) .build(); @@ -144,14 +147,14 @@ public void exportAssetsExceptionTest() throws Exception { } @Test - public void batchGetAssetsHistoryTest() { + public void batchGetAssetsHistoryTest() throws Exception { BatchGetAssetsHistoryResponse expectedResponse = BatchGetAssetsHistoryResponse.newBuilder().addAllAssets(new ArrayList<>()).build(); mockAssetService.addResponse(expectedResponse); BatchGetAssetsHistoryRequest request = BatchGetAssetsHistoryRequest.newBuilder() - .setParent(ProjectName.of("[PROJECT]").toString()) + .setParent(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString()) .addAllAssetNames(new ArrayList<>()) .setReadTimeWindow(TimeWindow.newBuilder().build()) .build(); @@ -182,7 +185,7 @@ public void batchGetAssetsHistoryExceptionTest() throws Exception { try { BatchGetAssetsHistoryRequest request = BatchGetAssetsHistoryRequest.newBuilder() - .setParent(ProjectName.of("[PROJECT]").toString()) + .setParent(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString()) .addAllAssetNames(new ArrayList<>()) .setReadTimeWindow(TimeWindow.newBuilder().build()) .build(); @@ -194,7 +197,7 @@ public void batchGetAssetsHistoryExceptionTest() throws Exception { } @Test - public void createFeedTest() { + public void createFeedTest() throws Exception { Feed expectedResponse = Feed.newBuilder() .setName(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString()) @@ -235,7 +238,7 @@ public void createFeedExceptionTest() throws Exception { } @Test - public void getFeedTest() { + public void getFeedTest() throws Exception { Feed expectedResponse = Feed.newBuilder() .setName(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString()) @@ -276,7 +279,7 @@ public void getFeedExceptionTest() throws Exception { } @Test - public void getFeedTest2() { + public void getFeedTest2() throws Exception { Feed expectedResponse = Feed.newBuilder() .setName(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString()) @@ -317,7 +320,7 @@ public void getFeedExceptionTest2() throws Exception { } @Test - public void listFeedsTest() { + public void listFeedsTest() throws Exception { ListFeedsResponse expectedResponse = ListFeedsResponse.newBuilder().addAllFeeds(new ArrayList<>()).build(); mockAssetService.addResponse(expectedResponse); @@ -353,7 +356,7 @@ public void listFeedsExceptionTest() throws Exception { } @Test - public void updateFeedTest() { + public void updateFeedTest() throws Exception { Feed expectedResponse = Feed.newBuilder() .setName(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString()) @@ -394,7 +397,7 @@ public void updateFeedExceptionTest() throws Exception { } @Test - public void deleteFeedTest() { + public void deleteFeedTest() throws Exception { Empty expectedResponse = Empty.newBuilder().build(); mockAssetService.addResponse(expectedResponse); @@ -429,7 +432,7 @@ public void deleteFeedExceptionTest() throws Exception { } @Test - public void deleteFeedTest2() { + public void deleteFeedTest2() throws Exception { Empty expectedResponse = Empty.newBuilder().build(); mockAssetService.addResponse(expectedResponse); @@ -464,12 +467,12 @@ public void deleteFeedExceptionTest2() throws Exception { } @Test - public void searchAllResourcesTest() { + public void searchAllResourcesTest() throws Exception { ResourceSearchResult responsesElement = ResourceSearchResult.newBuilder().build(); SearchAllResourcesResponse expectedResponse = SearchAllResourcesResponse.newBuilder() .setNextPageToken("") - .addAllResponses(Arrays.asList(responsesElement)) + .addAllResults(Arrays.asList(responsesElement)) .build(); mockAssetService.addResponse(expectedResponse); @@ -477,13 +480,13 @@ public void searchAllResourcesTest() { String query = "query107944136"; List assetTypes = new ArrayList<>(); - SearchAllResourcesResponse pagedListResponse = + SearchAllResourcesPagedResponse pagedListResponse = client.searchAllResources(scope, query, assetTypes); List resources = Lists.newArrayList(pagedListResponse.iterateAll()); Assert.assertEquals(1, resources.size()); - Assert.assertEquals(expectedResponse.getResponsesList().get(0), resources.get(0)); + Assert.assertEquals(expectedResponse.getResultsList().get(0), resources.get(0)); List actualRequests = mockAssetService.getRequests(); Assert.assertEquals(1, actualRequests.size()); @@ -515,24 +518,24 @@ public void searchAllResourcesExceptionTest() throws Exception { } @Test - public void searchAllIamPoliciesTest() { + public void searchAllIamPoliciesTest() throws Exception { IamPolicySearchResult responsesElement = IamPolicySearchResult.newBuilder().build(); SearchAllIamPoliciesResponse expectedResponse = SearchAllIamPoliciesResponse.newBuilder() .setNextPageToken("") - .addAllResponses(Arrays.asList(responsesElement)) + .addAllResults(Arrays.asList(responsesElement)) .build(); mockAssetService.addResponse(expectedResponse); String scope = "scope109264468"; String query = "query107944136"; - SearchAllIamPoliciesResponse pagedListResponse = client.searchAllIamPolicies(scope, query); + SearchAllIamPoliciesPagedResponse pagedListResponse = client.searchAllIamPolicies(scope, query); List resources = Lists.newArrayList(pagedListResponse.iterateAll()); Assert.assertEquals(1, resources.size()); - Assert.assertEquals(expectedResponse.getResponsesList().get(0), resources.get(0)); + Assert.assertEquals(expectedResponse.getResultsList().get(0), resources.get(0)); List actualRequests = mockAssetService.getRequests(); Assert.assertEquals(1, actualRequests.size()); diff --git a/test/integration/goldens/asset/FeedName.java b/test/integration/goldens/asset/FeedName.java index 45b2273d2d..f05af8f2e6 100644 --- a/test/integration/goldens/asset/FeedName.java +++ b/test/integration/goldens/asset/FeedName.java @@ -113,17 +113,17 @@ public static FeedName of(String project, String feed) { } @BetaApi("The static create methods are not stable yet and may be changed in the future.") - public static FeedName ofProjectFeedBuilder(String project, String feed) { + public static FeedName ofProjectFeedName(String project, String feed) { return newBuilder().setProject(project).setFeed(feed).build(); } @BetaApi("The static create methods are not stable yet and may be changed in the future.") - public static FeedName ofFolderFeedBuilder(String folder, String feed) { + public static FeedName ofFolderFeedName(String folder, String feed) { return newFolderFeedBuilder().setFolder(folder).setFeed(feed).build(); } @BetaApi("The static create methods are not stable yet and may be changed in the future.") - public static FeedName ofOrganizationFeedBuilder(String organization, String feed) { + public static FeedName ofOrganizationFeedName(String organization, String feed) { return newOrganizationFeedBuilder().setOrganization(organization).setFeed(feed).build(); } @@ -132,17 +132,17 @@ public static String format(String project, String feed) { } @BetaApi("The static format methods are not stable yet and may be changed in the future.") - public static String formatProjectFeedBuilder(String project, String feed) { + public static String formatProjectFeedName(String project, String feed) { return newBuilder().setProject(project).setFeed(feed).build().toString(); } @BetaApi("The static format methods are not stable yet and may be changed in the future.") - public static String formatFolderFeedBuilder(String folder, String feed) { + public static String formatFolderFeedName(String folder, String feed) { return newFolderFeedBuilder().setFolder(folder).setFeed(feed).build().toString(); } @BetaApi("The static format methods are not stable yet and may be changed in the future.") - public static String formatOrganizationFeedBuilder(String organization, String feed) { + public static String formatOrganizationFeedName(String organization, String feed) { return newOrganizationFeedBuilder() .setOrganization(organization) .setFeed(feed) @@ -156,13 +156,13 @@ public static FeedName parse(String formattedString) { } if (PROJECT_FEED.matches(formattedString)) { Map matchMap = PROJECT_FEED.match(formattedString); - return ofProjectFeedBuilder(matchMap.get("project"), matchMap.get("feed")); + return ofProjectFeedName(matchMap.get("project"), matchMap.get("feed")); } else if (FOLDER_FEED.matches(formattedString)) { Map matchMap = FOLDER_FEED.match(formattedString); - return ofFolderFeedBuilder(matchMap.get("folder"), matchMap.get("feed")); + return ofFolderFeedName(matchMap.get("folder"), matchMap.get("feed")); } else if (ORGANIZATION_FEED.matches(formattedString)) { Map matchMap = ORGANIZATION_FEED.match(formattedString); - return ofOrganizationFeedBuilder(matchMap.get("organization"), matchMap.get("feed")); + return ofOrganizationFeedName(matchMap.get("organization"), matchMap.get("feed")); } throw new ValidationException("FeedName.parse: formattedString not in valid format"); } diff --git a/test/integration/goldens/asset/GrpcAssetServiceStub.java b/test/integration/goldens/asset/GrpcAssetServiceStub.java index 7b4daba7a0..f6b39ad969 100644 --- a/test/integration/goldens/asset/GrpcAssetServiceStub.java +++ b/test/integration/goldens/asset/GrpcAssetServiceStub.java @@ -25,6 +25,7 @@ import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.RequestParamsExtractor; import com.google.api.gax.rpc.UnaryCallable; import com.google.cloud.asset.v1.BatchGetAssetsHistoryRequest; import com.google.cloud.asset.v1.BatchGetAssetsHistoryResponse; @@ -41,12 +42,14 @@ import com.google.cloud.asset.v1.SearchAllResourcesRequest; import com.google.cloud.asset.v1.SearchAllResourcesResponse; import com.google.cloud.asset.v1.UpdateFeedRequest; +import com.google.common.collect.ImmutableMap; import com.google.longrunning.Operation; import com.google.longrunning.stub.GrpcOperationsStub; import com.google.protobuf.Empty; import io.grpc.MethodDescriptor; import io.grpc.protobuf.ProtoUtils; import java.io.IOException; +import java.util.Map; import java.util.concurrent.TimeUnit; import javax.annotation.Generated; @@ -195,42 +198,123 @@ protected GrpcAssetServiceStub( GrpcCallSettings exportAssetsTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(exportAssetsMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(ExportAssetsRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("parent", String.valueOf(request.getParent())); + return params.build(); + } + }) .build(); GrpcCallSettings batchGetAssetsHistoryTransportSettings = GrpcCallSettings .newBuilder() .setMethodDescriptor(batchGetAssetsHistoryMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(BatchGetAssetsHistoryRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("parent", String.valueOf(request.getParent())); + return params.build(); + } + }) .build(); GrpcCallSettings createFeedTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(createFeedMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(CreateFeedRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("parent", String.valueOf(request.getParent())); + return params.build(); + } + }) .build(); GrpcCallSettings getFeedTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(getFeedMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(GetFeedRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("name", String.valueOf(request.getName())); + return params.build(); + } + }) .build(); GrpcCallSettings listFeedsTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(listFeedsMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(ListFeedsRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("parent", String.valueOf(request.getParent())); + return params.build(); + } + }) .build(); GrpcCallSettings updateFeedTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(updateFeedMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(UpdateFeedRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("feed.name", String.valueOf(request.getFeed().getName())); + return params.build(); + } + }) .build(); GrpcCallSettings deleteFeedTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(deleteFeedMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(DeleteFeedRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("name", String.valueOf(request.getName())); + return params.build(); + } + }) .build(); GrpcCallSettings searchAllResourcesTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(searchAllResourcesMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(SearchAllResourcesRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("scope", String.valueOf(request.getScope())); + return params.build(); + } + }) .build(); GrpcCallSettings searchAllIamPoliciesTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(searchAllIamPoliciesMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(SearchAllIamPoliciesRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("scope", String.valueOf(request.getScope())); + return params.build(); + } + }) .build(); this.exportAssetsCallable = diff --git a/test/integration/goldens/asset/package-info.java b/test/integration/goldens/asset/package-info.java new file mode 100644 index 0000000000..519d666f43 --- /dev/null +++ b/test/integration/goldens/asset/package-info.java @@ -0,0 +1,31 @@ +/* + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * A client to Cloud Asset API + * + *

The interfaces provided are listed below, along with usage samples. + * + *

======================= AssetServiceClient ======================= + * + *

Service Description: Asset service definition. + * + *

Sample for AssetServiceClient: + */ +@Generated("by gapic-generator-java") +package com.google.cloud.asset.v1; + +import javax.annotation.Generated; diff --git a/test/integration/goldens/redis/CloudRedisClientTest.java b/test/integration/goldens/redis/CloudRedisClientTest.java index fcbd325315..6e37f465ec 100644 --- a/test/integration/goldens/redis/CloudRedisClientTest.java +++ b/test/integration/goldens/redis/CloudRedisClientTest.java @@ -16,6 +16,8 @@ package com.google.cloud.redis.v1; +import static com.google.cloud.redis.v1.CloudRedisClient.ListInstancesPagedResponse; + import com.google.api.gax.core.NoCredentialsProvider; import com.google.api.gax.grpc.GaxGrpcProperties; import com.google.api.gax.grpc.testing.LocalChannelProvider; @@ -84,23 +86,23 @@ public void tearDown() throws Exception { } @Test - public void listInstancesTest() { + public void listInstancesTest() throws Exception { Instance responsesElement = Instance.newBuilder().build(); ListInstancesResponse expectedResponse = ListInstancesResponse.newBuilder() .setNextPageToken("") - .addAllResponses(Arrays.asList(responsesElement)) + .addAllInstances(Arrays.asList(responsesElement)) .build(); mockCloudRedis.addResponse(expectedResponse); LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); - ListInstancesResponse pagedListResponse = client.listInstances(parent); + ListInstancesPagedResponse pagedListResponse = client.listInstances(parent); List resources = Lists.newArrayList(pagedListResponse.iterateAll()); Assert.assertEquals(1, resources.size()); - Assert.assertEquals(expectedResponse.getResponsesList().get(0), resources.get(0)); + Assert.assertEquals(expectedResponse.getInstancesList().get(0), resources.get(0)); List actualRequests = mockCloudRedis.getRequests(); Assert.assertEquals(1, actualRequests.size()); @@ -128,23 +130,23 @@ public void listInstancesExceptionTest() throws Exception { } @Test - public void listInstancesTest2() { + public void listInstancesTest2() throws Exception { Instance responsesElement = Instance.newBuilder().build(); ListInstancesResponse expectedResponse = ListInstancesResponse.newBuilder() .setNextPageToken("") - .addAllResponses(Arrays.asList(responsesElement)) + .addAllInstances(Arrays.asList(responsesElement)) .build(); mockCloudRedis.addResponse(expectedResponse); String parent = "parent-995424086"; - ListInstancesResponse pagedListResponse = client.listInstances(parent); + ListInstancesPagedResponse pagedListResponse = client.listInstances(parent); List resources = Lists.newArrayList(pagedListResponse.iterateAll()); Assert.assertEquals(1, resources.size()); - Assert.assertEquals(expectedResponse.getResponsesList().get(0), resources.get(0)); + Assert.assertEquals(expectedResponse.getInstancesList().get(0), resources.get(0)); List actualRequests = mockCloudRedis.getRequests(); Assert.assertEquals(1, actualRequests.size()); @@ -172,7 +174,7 @@ public void listInstancesExceptionTest2() throws Exception { } @Test - public void getInstanceTest() { + public void getInstanceTest() throws Exception { Instance expectedResponse = Instance.newBuilder() .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) @@ -224,7 +226,7 @@ public void getInstanceExceptionTest() throws Exception { } @Test - public void getInstanceTest2() { + public void getInstanceTest2() throws Exception { Instance expectedResponse = Instance.newBuilder() .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) @@ -276,7 +278,7 @@ public void getInstanceExceptionTest2() throws Exception { } @Test - public void createInstanceTest() { + public void createInstanceTest() throws Exception { Instance expectedResponse = Instance.newBuilder() .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) @@ -342,7 +344,7 @@ public void createInstanceExceptionTest() throws Exception { } @Test - public void createInstanceTest2() { + public void createInstanceTest2() throws Exception { Instance expectedResponse = Instance.newBuilder() .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) @@ -408,7 +410,7 @@ public void createInstanceExceptionTest2() throws Exception { } @Test - public void updateInstanceTest() { + public void updateInstanceTest() throws Exception { Instance expectedResponse = Instance.newBuilder() .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) @@ -471,7 +473,7 @@ public void updateInstanceExceptionTest() throws Exception { } @Test - public void upgradeInstanceTest() { + public void upgradeInstanceTest() throws Exception { Instance expectedResponse = Instance.newBuilder() .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) @@ -534,7 +536,7 @@ public void upgradeInstanceExceptionTest() throws Exception { } @Test - public void upgradeInstanceTest2() { + public void upgradeInstanceTest2() throws Exception { Instance expectedResponse = Instance.newBuilder() .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) @@ -597,7 +599,7 @@ public void upgradeInstanceExceptionTest2() throws Exception { } @Test - public void importInstanceTest() { + public void importInstanceTest() throws Exception { Instance expectedResponse = Instance.newBuilder() .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) @@ -660,7 +662,7 @@ public void importInstanceExceptionTest() throws Exception { } @Test - public void exportInstanceTest() { + public void exportInstanceTest() throws Exception { Instance expectedResponse = Instance.newBuilder() .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) @@ -723,7 +725,7 @@ public void exportInstanceExceptionTest() throws Exception { } @Test - public void failoverInstanceTest() { + public void failoverInstanceTest() throws Exception { Instance expectedResponse = Instance.newBuilder() .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) @@ -788,7 +790,7 @@ public void failoverInstanceExceptionTest() throws Exception { } @Test - public void failoverInstanceTest2() { + public void failoverInstanceTest2() throws Exception { Instance expectedResponse = Instance.newBuilder() .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) @@ -853,7 +855,7 @@ public void failoverInstanceExceptionTest2() throws Exception { } @Test - public void deleteInstanceTest() { + public void deleteInstanceTest() throws Exception { Empty expectedResponse = Empty.newBuilder().build(); Operation resultOperation = Operation.newBuilder() @@ -896,7 +898,7 @@ public void deleteInstanceExceptionTest() throws Exception { } @Test - public void deleteInstanceTest2() { + public void deleteInstanceTest2() throws Exception { Empty expectedResponse = Empty.newBuilder().build(); Operation resultOperation = Operation.newBuilder() diff --git a/test/integration/goldens/redis/GrpcCloudRedisStub.java b/test/integration/goldens/redis/GrpcCloudRedisStub.java index 64ffc5d17c..910f039502 100644 --- a/test/integration/goldens/redis/GrpcCloudRedisStub.java +++ b/test/integration/goldens/redis/GrpcCloudRedisStub.java @@ -24,6 +24,7 @@ import com.google.api.gax.grpc.GrpcStubCallableFactory; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.RequestParamsExtractor; import com.google.api.gax.rpc.UnaryCallable; import com.google.cloud.redis.v1.CreateInstanceRequest; import com.google.cloud.redis.v1.DeleteInstanceRequest; @@ -37,12 +38,14 @@ import com.google.cloud.redis.v1.OperationMetadata; import com.google.cloud.redis.v1.UpdateInstanceRequest; import com.google.cloud.redis.v1.UpgradeInstanceRequest; +import com.google.common.collect.ImmutableMap; import com.google.longrunning.Operation; import com.google.longrunning.stub.GrpcOperationsStub; import com.google.protobuf.Empty; import io.grpc.MethodDescriptor; import io.grpc.protobuf.ProtoUtils; import java.io.IOException; +import java.util.Map; import java.util.concurrent.TimeUnit; import javax.annotation.Generated; @@ -204,38 +207,119 @@ protected GrpcCloudRedisStub( GrpcCallSettings listInstancesTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(listInstancesMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(ListInstancesRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("parent", String.valueOf(request.getParent())); + return params.build(); + } + }) .build(); GrpcCallSettings getInstanceTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(getInstanceMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(GetInstanceRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("name", String.valueOf(request.getName())); + return params.build(); + } + }) .build(); GrpcCallSettings createInstanceTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(createInstanceMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(CreateInstanceRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("parent", String.valueOf(request.getParent())); + return params.build(); + } + }) .build(); GrpcCallSettings updateInstanceTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(updateInstanceMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(UpdateInstanceRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("instance.name", String.valueOf(request.getInstance().getName())); + return params.build(); + } + }) .build(); GrpcCallSettings upgradeInstanceTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(upgradeInstanceMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(UpgradeInstanceRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("name", String.valueOf(request.getName())); + return params.build(); + } + }) .build(); GrpcCallSettings importInstanceTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(importInstanceMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(ImportInstanceRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("name", String.valueOf(request.getName())); + return params.build(); + } + }) .build(); GrpcCallSettings exportInstanceTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(exportInstanceMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(ExportInstanceRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("name", String.valueOf(request.getName())); + return params.build(); + } + }) .build(); GrpcCallSettings failoverInstanceTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(failoverInstanceMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(FailoverInstanceRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("name", String.valueOf(request.getName())); + return params.build(); + } + }) .build(); GrpcCallSettings deleteInstanceTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(deleteInstanceMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(DeleteInstanceRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("name", String.valueOf(request.getName())); + return params.build(); + } + }) .build(); this.listInstancesCallable = diff --git a/test/integration/goldens/redis/package-info.java b/test/integration/goldens/redis/package-info.java new file mode 100644 index 0000000000..8e1e2d6fb8 --- /dev/null +++ b/test/integration/goldens/redis/package-info.java @@ -0,0 +1,39 @@ +/* + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * A client to Google Cloud Memorystore for Redis API + * + *

The interfaces provided are listed below, along with usage samples. + * + *

======================= CloudRedisClient ======================= + * + *

Service Description: Configures and manages Cloud Memorystore for Redis instances Google Cloud + * Memorystore for Redis v1 The `redis.googleapis.com` service implements the Google Cloud + * Memorystore for Redis API and defines the following resource model for managing Redis instances: + * * The service works with a collection of cloud projects, named: `/projects/*` * Each project has + * a collection of available locations, named: `/locations/*` * Each location has a collection of + * Redis instances, named: `/instances/*` * As such, Redis instances are resources of the form: + * `/projects/{project_id}/locations/{location_id}/instances/{instance_id}` Note that location_id + * must be referring to a GCP `region`; for example: * + * `projects/redpepper-1290/locations/us-central1/instances/my-redis` + * + *

Sample for CloudRedisClient: + */ +@Generated("by gapic-generator-java") +package com.google.cloud.redis.v1; + +import javax.annotation.Generated; From 11bde65b4006fa31c983453b0e503371e3efc942 Mon Sep 17 00:00:00 2001 From: Mira Leung Date: Thu, 29 Oct 2020 15:41:51 -0700 Subject: [PATCH 4/4] build: remove include_source_info from bazelrc (#425) --- .bazelrc | 1 - 1 file changed, 1 deletion(-) diff --git a/.bazelrc b/.bazelrc index f9a59a1983..48b81165fe 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1,4 +1,3 @@ startup --batch -build --protocopt=--include_source_info build --protocopt=--experimental_allow_proto3_optional