From 9ad33d2a9ac02c06a247866af5ae0cc6a5374268 Mon Sep 17 00:00:00 2001 From: Xiaozhen Liu Date: Thu, 8 Oct 2020 21:20:25 +0000 Subject: [PATCH 01/17] add goldens files for redis client lib --- .../goldens/redis/CloudRedisClient.java | 1634 +++++++++++++++++ .../goldens/redis/CloudRedisClientTest.java | 738 ++++++++ .../goldens/redis/CloudRedisSettings.java | 380 ++++ .../goldens/redis/CloudRedisStub.java | 141 ++ .../goldens/redis/CloudRedisStubSettings.java | 868 +++++++++ .../redis/GrpcCloudRedisCallableFactory.java | 115 ++ .../goldens/redis/GrpcCloudRedisStub.java | 523 ++++++ .../goldens/redis/InstanceName.java | 214 +++ .../goldens/redis/LocationName.java | 191 ++ .../goldens/redis/MockCloudRedis.java | 57 + .../goldens/redis/MockCloudRedisImpl.java | 193 ++ .../goldens/redis/package-info.java | 52 + 12 files changed, 5106 insertions(+) create mode 100644 test/integration/goldens/redis/CloudRedisClient.java create mode 100644 test/integration/goldens/redis/CloudRedisClientTest.java create mode 100644 test/integration/goldens/redis/CloudRedisSettings.java create mode 100644 test/integration/goldens/redis/CloudRedisStub.java create mode 100644 test/integration/goldens/redis/CloudRedisStubSettings.java create mode 100644 test/integration/goldens/redis/GrpcCloudRedisCallableFactory.java create mode 100644 test/integration/goldens/redis/GrpcCloudRedisStub.java create mode 100644 test/integration/goldens/redis/InstanceName.java create mode 100644 test/integration/goldens/redis/LocationName.java create mode 100644 test/integration/goldens/redis/MockCloudRedis.java create mode 100644 test/integration/goldens/redis/MockCloudRedisImpl.java create mode 100644 test/integration/goldens/redis/package-info.java diff --git a/test/integration/goldens/redis/CloudRedisClient.java b/test/integration/goldens/redis/CloudRedisClient.java new file mode 100644 index 0000000000..98d07aa2a7 --- /dev/null +++ b/test/integration/goldens/redis/CloudRedisClient.java @@ -0,0 +1,1634 @@ +/* + * 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. + */ +package com.google.cloud.redis.v1; + +import com.google.api.core.ApiFunction; +import com.google.api.core.ApiFuture; +import com.google.api.core.ApiFutures; +import com.google.api.core.BetaApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.longrunning.OperationFuture; +import com.google.api.gax.paging.AbstractFixedSizeCollection; +import com.google.api.gax.paging.AbstractPage; +import com.google.api.gax.paging.AbstractPagedListResponse; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PageContext; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.cloud.redis.v1.stub.CloudRedisStub; +import com.google.cloud.redis.v1.stub.CloudRedisStubSettings; +import com.google.common.util.concurrent.MoreExecutors; +import com.google.longrunning.Operation; +import com.google.longrunning.OperationsClient; +import com.google.protobuf.Empty; +import com.google.protobuf.FieldMask; +import java.io.IOException; +import java.util.List; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND SERVICE +/** + * 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` + * + *

This class provides the ability to make remote calls to the backing service through method + * calls that map to API methods. Sample code to get started: + * + *

+ * 
+ * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
+ *   InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]");
+ *   Instance response = cloudRedisClient.getInstance(name);
+ * }
+ * 
+ * 
+ * + *

Note: close() needs to be called on the cloudRedisClient object to clean up resources such as + * threads. In the example above, try-with-resources is used, which automatically calls close(). + * + *

The surface of this class includes several types of Java methods for each of the API's + * methods: + * + *

    + *
  1. A "flattened" method. With this type of method, the fields of the request type have been + * converted into function parameters. It may be the case that not all fields are available as + * parameters, and not every API method will have a flattened method entry point. + *
  2. A "request object" method. This type of method only takes one parameter, a request object, + * which must be constructed before the call. Not every API method will have a request object + * method. + *
  3. A "callable" method. This type of method takes no parameters and returns an immutable API + * callable object, which can be used to initiate calls to the service. + *
+ * + *

See the individual methods for example code. + * + *

Many parameters require resource names to be formatted in a particular way. To assist with + * these names, this class includes a format method for each type of name, and additionally a parse + * method to extract the individual identifiers contained within names that are returned. + * + *

This class can be customized by passing in a custom instance of CloudRedisSettings to + * create(). For example: + * + *

To customize credentials: + * + *

+ * 
+ * CloudRedisSettings cloudRedisSettings =
+ *     CloudRedisSettings.newBuilder()
+ *         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
+ *         .build();
+ * CloudRedisClient cloudRedisClient =
+ *     CloudRedisClient.create(cloudRedisSettings);
+ * 
+ * 
+ * + * To customize the endpoint: + * + *
+ * 
+ * CloudRedisSettings cloudRedisSettings =
+ *     CloudRedisSettings.newBuilder().setEndpoint(myEndpoint).build();
+ * CloudRedisClient cloudRedisClient =
+ *     CloudRedisClient.create(cloudRedisSettings);
+ * 
+ * 
+ */ +@Generated("by gapic-generator") +@BetaApi +public class CloudRedisClient implements BackgroundResource { + private final CloudRedisSettings settings; + private final CloudRedisStub stub; + private final OperationsClient operationsClient; + + /** Constructs an instance of CloudRedisClient with default settings. */ + public static final CloudRedisClient create() throws IOException { + return create(CloudRedisSettings.newBuilder().build()); + } + + /** + * Constructs an instance of CloudRedisClient, using the given settings. The channels are created + * based on the settings passed in, or defaults for any settings that are not set. + */ + public static final CloudRedisClient create(CloudRedisSettings settings) throws IOException { + return new CloudRedisClient(settings); + } + + /** + * Constructs an instance of CloudRedisClient, using the given stub for making calls. This is for + * advanced usage - prefer to use CloudRedisSettings}. + */ + @BetaApi("A restructuring of stub classes is planned, so this may break in the future") + public static final CloudRedisClient create(CloudRedisStub stub) { + return new CloudRedisClient(stub); + } + + /** + * Constructs an instance of CloudRedisClient, using the given settings. This is protected so that + * it is easy to make a subclass, but otherwise, the static factory methods should be preferred. + */ + protected CloudRedisClient(CloudRedisSettings settings) throws IOException { + this.settings = settings; + this.stub = ((CloudRedisStubSettings) settings.getStubSettings()).createStub(); + this.operationsClient = OperationsClient.create(this.stub.getOperationsStub()); + } + + @BetaApi("A restructuring of stub classes is planned, so this may break in the future") + protected CloudRedisClient(CloudRedisStub stub) { + this.settings = null; + this.stub = stub; + this.operationsClient = OperationsClient.create(this.stub.getOperationsStub()); + } + + public final CloudRedisSettings getSettings() { + return settings; + } + + @BetaApi("A restructuring of stub classes is planned, so this may break in the future") + public CloudRedisStub getStub() { + return stub; + } + + /** + * Returns the OperationsClient that can be used to query the status of a long-running operation + * returned by another API method call. + */ + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + public final OperationsClient getOperationsClient() { + return operationsClient; + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Creates a Redis instance based on the specified tier and memory size. + * + *

By default, the instance is accessible from the project's [default + * network](https://cloud.google.com/vpc/docs/vpc). + * + *

The creation is executed asynchronously and callers may check the returned operation to + * track its progress. Once the operation is completed the Redis instance will be fully + * functional. Completed longrunning.Operation will contain the new instance object in the + * response field. + * + *

The returned operation is automatically deleted after a few hours, so there is no need to + * call DeleteOperation. + * + *

Sample code: + * + *


+   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
+   *   LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
+   *   String instanceId = "test_instance";
+   *   Instance.Tier tier = Instance.Tier.BASIC;
+   *   int memorySizeGb = 1;
+   *   Instance instance = Instance.newBuilder()
+   *     .setTier(tier)
+   *     .setMemorySizeGb(memorySizeGb)
+   *     .build();
+   *   Instance response = cloudRedisClient.createInstanceAsync(parent, instanceId, instance).get();
+   * }
+   * 
+ * + * @param parent Required. The resource name of the instance location using the form: + * `projects/{project_id}/locations/{location_id}` where `location_id` refers to a GCP region. + * @param instanceId Required. The logical name of the Redis instance in the customer project with + * the following restrictions: + *

* Must contain only lowercase letters, numbers, and hyphens. * Must start with a + * letter. * Must be between 1-40 characters. * Must end with a number or a letter. + * * Must be unique within the customer project / location + * @param instance Required. A Redis [Instance] resource + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + public final OperationFuture createInstanceAsync( + LocationName parent, String instanceId, Instance instance) { + CreateInstanceRequest request = + CreateInstanceRequest.newBuilder() + .setParent(parent == null ? null : parent.toString()) + .setInstanceId(instanceId) + .setInstance(instance) + .build(); + return createInstanceAsync(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Creates a Redis instance based on the specified tier and memory size. + * + *

By default, the instance is accessible from the project's [default + * network](https://cloud.google.com/vpc/docs/vpc). + * + *

The creation is executed asynchronously and callers may check the returned operation to + * track its progress. Once the operation is completed the Redis instance will be fully + * functional. Completed longrunning.Operation will contain the new instance object in the + * response field. + * + *

The returned operation is automatically deleted after a few hours, so there is no need to + * call DeleteOperation. + * + *

Sample code: + * + *


+   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
+   *   LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
+   *   String instanceId = "test_instance";
+   *   Instance.Tier tier = Instance.Tier.BASIC;
+   *   int memorySizeGb = 1;
+   *   Instance instance = Instance.newBuilder()
+   *     .setTier(tier)
+   *     .setMemorySizeGb(memorySizeGb)
+   *     .build();
+   *   Instance response = cloudRedisClient.createInstanceAsync(parent.toString(), instanceId, instance).get();
+   * }
+   * 
+ * + * @param parent Required. The resource name of the instance location using the form: + * `projects/{project_id}/locations/{location_id}` where `location_id` refers to a GCP region. + * @param instanceId Required. The logical name of the Redis instance in the customer project with + * the following restrictions: + *

* Must contain only lowercase letters, numbers, and hyphens. * Must start with a + * letter. * Must be between 1-40 characters. * Must end with a number or a letter. + * * Must be unique within the customer project / location + * @param instance Required. A Redis [Instance] resource + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + public final OperationFuture createInstanceAsync( + String parent, String instanceId, Instance instance) { + CreateInstanceRequest request = + CreateInstanceRequest.newBuilder() + .setParent(parent) + .setInstanceId(instanceId) + .setInstance(instance) + .build(); + return createInstanceAsync(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Creates a Redis instance based on the specified tier and memory size. + * + *

By default, the instance is accessible from the project's [default + * network](https://cloud.google.com/vpc/docs/vpc). + * + *

The creation is executed asynchronously and callers may check the returned operation to + * track its progress. Once the operation is completed the Redis instance will be fully + * functional. Completed longrunning.Operation will contain the new instance object in the + * response field. + * + *

The returned operation is automatically deleted after a few hours, so there is no need to + * call DeleteOperation. + * + *

Sample code: + * + *


+   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
+   *   LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
+   *   String instanceId = "test_instance";
+   *   Instance.Tier tier = Instance.Tier.BASIC;
+   *   int memorySizeGb = 1;
+   *   Instance instance = Instance.newBuilder()
+   *     .setTier(tier)
+   *     .setMemorySizeGb(memorySizeGb)
+   *     .build();
+   *   CreateInstanceRequest request = CreateInstanceRequest.newBuilder()
+   *     .setParent(parent.toString())
+   *     .setInstanceId(instanceId)
+   *     .setInstance(instance)
+   *     .build();
+   *   Instance response = cloudRedisClient.createInstanceAsync(request).get();
+   * }
+   * 
+ * + * @param request The request object containing all of the parameters for the API call. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + public final OperationFuture createInstanceAsync( + CreateInstanceRequest request) { + return createInstanceOperationCallable().futureCall(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Creates a Redis instance based on the specified tier and memory size. + * + *

By default, the instance is accessible from the project's [default + * network](https://cloud.google.com/vpc/docs/vpc). + * + *

The creation is executed asynchronously and callers may check the returned operation to + * track its progress. Once the operation is completed the Redis instance will be fully + * functional. Completed longrunning.Operation will contain the new instance object in the + * response field. + * + *

The returned operation is automatically deleted after a few hours, so there is no need to + * call DeleteOperation. + * + *

Sample code: + * + *


+   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
+   *   LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
+   *   String instanceId = "test_instance";
+   *   Instance.Tier tier = Instance.Tier.BASIC;
+   *   int memorySizeGb = 1;
+   *   Instance instance = Instance.newBuilder()
+   *     .setTier(tier)
+   *     .setMemorySizeGb(memorySizeGb)
+   *     .build();
+   *   CreateInstanceRequest request = CreateInstanceRequest.newBuilder()
+   *     .setParent(parent.toString())
+   *     .setInstanceId(instanceId)
+   *     .setInstance(instance)
+   *     .build();
+   *   OperationFuture<Instance, OperationMetadata> future = cloudRedisClient.createInstanceOperationCallable().futureCall(request);
+   *   // Do something
+   *   Instance response = future.get();
+   * }
+   * 
+ */ + @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") + public final OperationCallable + createInstanceOperationCallable() { + return stub.createInstanceOperationCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Creates a Redis instance based on the specified tier and memory size. + * + *

By default, the instance is accessible from the project's [default + * network](https://cloud.google.com/vpc/docs/vpc). + * + *

The creation is executed asynchronously and callers may check the returned operation to + * track its progress. Once the operation is completed the Redis instance will be fully + * functional. Completed longrunning.Operation will contain the new instance object in the + * response field. + * + *

The returned operation is automatically deleted after a few hours, so there is no need to + * call DeleteOperation. + * + *

Sample code: + * + *


+   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
+   *   LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
+   *   String instanceId = "test_instance";
+   *   Instance.Tier tier = Instance.Tier.BASIC;
+   *   int memorySizeGb = 1;
+   *   Instance instance = Instance.newBuilder()
+   *     .setTier(tier)
+   *     .setMemorySizeGb(memorySizeGb)
+   *     .build();
+   *   CreateInstanceRequest request = CreateInstanceRequest.newBuilder()
+   *     .setParent(parent.toString())
+   *     .setInstanceId(instanceId)
+   *     .setInstance(instance)
+   *     .build();
+   *   ApiFuture<Operation> future = cloudRedisClient.createInstanceCallable().futureCall(request);
+   *   // Do something
+   *   Operation response = future.get();
+   * }
+   * 
+ */ + public final UnaryCallable createInstanceCallable() { + return stub.createInstanceCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Updates the metadata and configuration of a specific Redis instance. + * + *

Completed longrunning.Operation will contain the new instance object in the response field. + * The returned operation is automatically deleted after a few hours, so there is no need to call + * DeleteOperation. + * + *

Sample code: + * + *


+   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
+   *   String pathsElement = "display_name";
+   *   String pathsElement2 = "memory_size_gb";
+   *   List<String> paths = Arrays.asList(pathsElement, pathsElement2);
+   *   FieldMask updateMask = FieldMask.newBuilder()
+   *     .addAllPaths(paths)
+   *     .build();
+   *   String displayName = "UpdatedDisplayName";
+   *   String name = "projects/<project-name>/locations/<location>/instances/<instance>";
+   *   int memorySizeGb = 4;
+   *   Instance instance = Instance.newBuilder()
+   *     .setDisplayName(displayName)
+   *     .setName(name)
+   *     .setMemorySizeGb(memorySizeGb)
+   *     .build();
+   *   Instance response = cloudRedisClient.updateInstanceAsync(updateMask, instance).get();
+   * }
+   * 
+ * + * @param updateMask Required. Mask of fields to update. At least one path must be supplied in + * this field. The elements of the repeated paths field may only include these fields from + * [Instance][google.cloud.redis.v1.Instance]: + *

* `displayName` * `labels` * `memorySizeGb` * `redisConfig` + * @param instance Required. Update description. Only fields specified in update_mask are updated. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + public final OperationFuture updateInstanceAsync( + FieldMask updateMask, Instance instance) { + UpdateInstanceRequest request = + UpdateInstanceRequest.newBuilder().setUpdateMask(updateMask).setInstance(instance).build(); + return updateInstanceAsync(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Updates the metadata and configuration of a specific Redis instance. + * + *

Completed longrunning.Operation will contain the new instance object in the response field. + * The returned operation is automatically deleted after a few hours, so there is no need to call + * DeleteOperation. + * + *

Sample code: + * + *


+   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
+   *   String pathsElement = "display_name";
+   *   String pathsElement2 = "memory_size_gb";
+   *   List<String> paths = Arrays.asList(pathsElement, pathsElement2);
+   *   FieldMask updateMask = FieldMask.newBuilder()
+   *     .addAllPaths(paths)
+   *     .build();
+   *   String displayName = "UpdatedDisplayName";
+   *   String name = "projects/<project-name>/locations/<location>/instances/<instance>";
+   *   int memorySizeGb = 4;
+   *   Instance instance = Instance.newBuilder()
+   *     .setDisplayName(displayName)
+   *     .setName(name)
+   *     .setMemorySizeGb(memorySizeGb)
+   *     .build();
+   *   UpdateInstanceRequest request = UpdateInstanceRequest.newBuilder()
+   *     .setUpdateMask(updateMask)
+   *     .setInstance(instance)
+   *     .build();
+   *   Instance response = cloudRedisClient.updateInstanceAsync(request).get();
+   * }
+   * 
+ * + * @param request The request object containing all of the parameters for the API call. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + public final OperationFuture updateInstanceAsync( + UpdateInstanceRequest request) { + return updateInstanceOperationCallable().futureCall(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Updates the metadata and configuration of a specific Redis instance. + * + *

Completed longrunning.Operation will contain the new instance object in the response field. + * The returned operation is automatically deleted after a few hours, so there is no need to call + * DeleteOperation. + * + *

Sample code: + * + *


+   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
+   *   String pathsElement = "display_name";
+   *   String pathsElement2 = "memory_size_gb";
+   *   List<String> paths = Arrays.asList(pathsElement, pathsElement2);
+   *   FieldMask updateMask = FieldMask.newBuilder()
+   *     .addAllPaths(paths)
+   *     .build();
+   *   String displayName = "UpdatedDisplayName";
+   *   String name = "projects/<project-name>/locations/<location>/instances/<instance>";
+   *   int memorySizeGb = 4;
+   *   Instance instance = Instance.newBuilder()
+   *     .setDisplayName(displayName)
+   *     .setName(name)
+   *     .setMemorySizeGb(memorySizeGb)
+   *     .build();
+   *   UpdateInstanceRequest request = UpdateInstanceRequest.newBuilder()
+   *     .setUpdateMask(updateMask)
+   *     .setInstance(instance)
+   *     .build();
+   *   OperationFuture<Instance, OperationMetadata> future = cloudRedisClient.updateInstanceOperationCallable().futureCall(request);
+   *   // Do something
+   *   Instance response = future.get();
+   * }
+   * 
+ */ + @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") + public final OperationCallable + updateInstanceOperationCallable() { + return stub.updateInstanceOperationCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Updates the metadata and configuration of a specific Redis instance. + * + *

Completed longrunning.Operation will contain the new instance object in the response field. + * The returned operation is automatically deleted after a few hours, so there is no need to call + * DeleteOperation. + * + *

Sample code: + * + *


+   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
+   *   String pathsElement = "display_name";
+   *   String pathsElement2 = "memory_size_gb";
+   *   List<String> paths = Arrays.asList(pathsElement, pathsElement2);
+   *   FieldMask updateMask = FieldMask.newBuilder()
+   *     .addAllPaths(paths)
+   *     .build();
+   *   String displayName = "UpdatedDisplayName";
+   *   String name = "projects/<project-name>/locations/<location>/instances/<instance>";
+   *   int memorySizeGb = 4;
+   *   Instance instance = Instance.newBuilder()
+   *     .setDisplayName(displayName)
+   *     .setName(name)
+   *     .setMemorySizeGb(memorySizeGb)
+   *     .build();
+   *   UpdateInstanceRequest request = UpdateInstanceRequest.newBuilder()
+   *     .setUpdateMask(updateMask)
+   *     .setInstance(instance)
+   *     .build();
+   *   ApiFuture<Operation> future = cloudRedisClient.updateInstanceCallable().futureCall(request);
+   *   // Do something
+   *   Operation response = future.get();
+   * }
+   * 
+ */ + public final UnaryCallable updateInstanceCallable() { + return stub.updateInstanceCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Import a Redis RDB snapshot file from Cloud Storage into a Redis instance. + * + *

Redis may stop serving during this operation. Instance state will be IMPORTING for entire + * operation. When complete, the instance will contain only data from the imported file. + * + *

The returned operation is automatically deleted after a few hours, so there is no need to + * call DeleteOperation. + * + *

Sample code: + * + *


+   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
+   *   String name = "";
+   *   InputConfig inputConfig = InputConfig.newBuilder().build();
+   *   Instance response = cloudRedisClient.importInstanceAsync(name, inputConfig).get();
+   * }
+   * 
+ * + * @param name Required. Redis instance resource name using the form: + * `projects/{project_id}/locations/{location_id}/instances/{instance_id}` where `location_id` + * refers to a GCP region. + * @param inputConfig Required. Specify data to be imported. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + public final OperationFuture importInstanceAsync( + String name, InputConfig inputConfig) { + ImportInstanceRequest request = + ImportInstanceRequest.newBuilder().setName(name).setInputConfig(inputConfig).build(); + return importInstanceAsync(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Import a Redis RDB snapshot file from Cloud Storage into a Redis instance. + * + *

Redis may stop serving during this operation. Instance state will be IMPORTING for entire + * operation. When complete, the instance will contain only data from the imported file. + * + *

The returned operation is automatically deleted after a few hours, so there is no need to + * call DeleteOperation. + * + *

Sample code: + * + *


+   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
+   *   String name = "";
+   *   InputConfig inputConfig = InputConfig.newBuilder().build();
+   *   ImportInstanceRequest request = ImportInstanceRequest.newBuilder()
+   *     .setName(name)
+   *     .setInputConfig(inputConfig)
+   *     .build();
+   *   Instance response = cloudRedisClient.importInstanceAsync(request).get();
+   * }
+   * 
+ * + * @param request The request object containing all of the parameters for the API call. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + public final OperationFuture importInstanceAsync( + ImportInstanceRequest request) { + return importInstanceOperationCallable().futureCall(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Import a Redis RDB snapshot file from Cloud Storage into a Redis instance. + * + *

Redis may stop serving during this operation. Instance state will be IMPORTING for entire + * operation. When complete, the instance will contain only data from the imported file. + * + *

The returned operation is automatically deleted after a few hours, so there is no need to + * call DeleteOperation. + * + *

Sample code: + * + *


+   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
+   *   String name = "";
+   *   InputConfig inputConfig = InputConfig.newBuilder().build();
+   *   ImportInstanceRequest request = ImportInstanceRequest.newBuilder()
+   *     .setName(name)
+   *     .setInputConfig(inputConfig)
+   *     .build();
+   *   OperationFuture<Instance, OperationMetadata> future = cloudRedisClient.importInstanceOperationCallable().futureCall(request);
+   *   // Do something
+   *   Instance response = future.get();
+   * }
+   * 
+ */ + @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") + public final OperationCallable + importInstanceOperationCallable() { + return stub.importInstanceOperationCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Import a Redis RDB snapshot file from Cloud Storage into a Redis instance. + * + *

Redis may stop serving during this operation. Instance state will be IMPORTING for entire + * operation. When complete, the instance will contain only data from the imported file. + * + *

The returned operation is automatically deleted after a few hours, so there is no need to + * call DeleteOperation. + * + *

Sample code: + * + *


+   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
+   *   String name = "";
+   *   InputConfig inputConfig = InputConfig.newBuilder().build();
+   *   ImportInstanceRequest request = ImportInstanceRequest.newBuilder()
+   *     .setName(name)
+   *     .setInputConfig(inputConfig)
+   *     .build();
+   *   ApiFuture<Operation> future = cloudRedisClient.importInstanceCallable().futureCall(request);
+   *   // Do something
+   *   Operation response = future.get();
+   * }
+   * 
+ */ + public final UnaryCallable importInstanceCallable() { + return stub.importInstanceCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Export Redis instance data into a Redis RDB format file in Cloud Storage. + * + *

Redis will continue serving during this operation. + * + *

The returned operation is automatically deleted after a few hours, so there is no need to + * call DeleteOperation. + * + *

Sample code: + * + *


+   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
+   *   String name = "";
+   *   OutputConfig outputConfig = OutputConfig.newBuilder().build();
+   *   Instance response = cloudRedisClient.exportInstanceAsync(name, outputConfig).get();
+   * }
+   * 
+ * + * @param name Required. Redis instance resource name using the form: + * `projects/{project_id}/locations/{location_id}/instances/{instance_id}` where `location_id` + * refers to a GCP region. + * @param outputConfig Required. Specify data to be exported. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + public final OperationFuture exportInstanceAsync( + String name, OutputConfig outputConfig) { + ExportInstanceRequest request = + ExportInstanceRequest.newBuilder().setName(name).setOutputConfig(outputConfig).build(); + return exportInstanceAsync(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Export Redis instance data into a Redis RDB format file in Cloud Storage. + * + *

Redis will continue serving during this operation. + * + *

The returned operation is automatically deleted after a few hours, so there is no need to + * call DeleteOperation. + * + *

Sample code: + * + *


+   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
+   *   String name = "";
+   *   OutputConfig outputConfig = OutputConfig.newBuilder().build();
+   *   ExportInstanceRequest request = ExportInstanceRequest.newBuilder()
+   *     .setName(name)
+   *     .setOutputConfig(outputConfig)
+   *     .build();
+   *   Instance response = cloudRedisClient.exportInstanceAsync(request).get();
+   * }
+   * 
+ * + * @param request The request object containing all of the parameters for the API call. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + public final OperationFuture exportInstanceAsync( + ExportInstanceRequest request) { + return exportInstanceOperationCallable().futureCall(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Export Redis instance data into a Redis RDB format file in Cloud Storage. + * + *

Redis will continue serving during this operation. + * + *

The returned operation is automatically deleted after a few hours, so there is no need to + * call DeleteOperation. + * + *

Sample code: + * + *


+   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
+   *   String name = "";
+   *   OutputConfig outputConfig = OutputConfig.newBuilder().build();
+   *   ExportInstanceRequest request = ExportInstanceRequest.newBuilder()
+   *     .setName(name)
+   *     .setOutputConfig(outputConfig)
+   *     .build();
+   *   OperationFuture<Instance, OperationMetadata> future = cloudRedisClient.exportInstanceOperationCallable().futureCall(request);
+   *   // Do something
+   *   Instance response = future.get();
+   * }
+   * 
+ */ + @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") + public final OperationCallable + exportInstanceOperationCallable() { + return stub.exportInstanceOperationCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Export Redis instance data into a Redis RDB format file in Cloud Storage. + * + *

Redis will continue serving during this operation. + * + *

The returned operation is automatically deleted after a few hours, so there is no need to + * call DeleteOperation. + * + *

Sample code: + * + *


+   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
+   *   String name = "";
+   *   OutputConfig outputConfig = OutputConfig.newBuilder().build();
+   *   ExportInstanceRequest request = ExportInstanceRequest.newBuilder()
+   *     .setName(name)
+   *     .setOutputConfig(outputConfig)
+   *     .build();
+   *   ApiFuture<Operation> future = cloudRedisClient.exportInstanceCallable().futureCall(request);
+   *   // Do something
+   *   Operation response = future.get();
+   * }
+   * 
+ */ + public final UnaryCallable exportInstanceCallable() { + return stub.exportInstanceCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Initiates a failover of the master node to current replica node for a specific STANDARD tier + * Cloud Memorystore for Redis instance. + * + *

Sample code: + * + *


+   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
+   *   InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]");
+   *   FailoverInstanceRequest.DataProtectionMode dataProtectionMode = FailoverInstanceRequest.DataProtectionMode.DATA_PROTECTION_MODE_UNSPECIFIED;
+   *   Instance response = cloudRedisClient.failoverInstanceAsync(name, dataProtectionMode).get();
+   * }
+   * 
+ * + * @param name Required. Redis instance resource name using the form: + * `projects/{project_id}/locations/{location_id}/instances/{instance_id}` where `location_id` + * refers to a GCP region. + * @param dataProtectionMode Optional. Available data protection modes that the user can choose. + * If it's unspecified, data protection mode will be LIMITED_DATA_LOSS by default. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + public final OperationFuture failoverInstanceAsync( + InstanceName name, FailoverInstanceRequest.DataProtectionMode dataProtectionMode) { + FailoverInstanceRequest request = + FailoverInstanceRequest.newBuilder() + .setName(name == null ? null : name.toString()) + .setDataProtectionMode(dataProtectionMode) + .build(); + return failoverInstanceAsync(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Initiates a failover of the master node to current replica node for a specific STANDARD tier + * Cloud Memorystore for Redis instance. + * + *

Sample code: + * + *


+   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
+   *   InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]");
+   *   FailoverInstanceRequest.DataProtectionMode dataProtectionMode = FailoverInstanceRequest.DataProtectionMode.DATA_PROTECTION_MODE_UNSPECIFIED;
+   *   Instance response = cloudRedisClient.failoverInstanceAsync(name.toString(), dataProtectionMode).get();
+   * }
+   * 
+ * + * @param name Required. Redis instance resource name using the form: + * `projects/{project_id}/locations/{location_id}/instances/{instance_id}` where `location_id` + * refers to a GCP region. + * @param dataProtectionMode Optional. Available data protection modes that the user can choose. + * If it's unspecified, data protection mode will be LIMITED_DATA_LOSS by default. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + public final OperationFuture failoverInstanceAsync( + String name, FailoverInstanceRequest.DataProtectionMode dataProtectionMode) { + FailoverInstanceRequest request = + FailoverInstanceRequest.newBuilder() + .setName(name) + .setDataProtectionMode(dataProtectionMode) + .build(); + return failoverInstanceAsync(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Initiates a failover of the master node to current replica node for a specific STANDARD tier + * Cloud Memorystore for Redis instance. + * + *

Sample code: + * + *


+   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
+   *   InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]");
+   *   FailoverInstanceRequest request = FailoverInstanceRequest.newBuilder()
+   *     .setName(name.toString())
+   *     .build();
+   *   Instance response = cloudRedisClient.failoverInstanceAsync(request).get();
+   * }
+   * 
+ * + * @param request The request object containing all of the parameters for the API call. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + public final OperationFuture failoverInstanceAsync( + FailoverInstanceRequest request) { + return failoverInstanceOperationCallable().futureCall(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Initiates a failover of the master node to current replica node for a specific STANDARD tier + * Cloud Memorystore for Redis instance. + * + *

Sample code: + * + *


+   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
+   *   InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]");
+   *   FailoverInstanceRequest request = FailoverInstanceRequest.newBuilder()
+   *     .setName(name.toString())
+   *     .build();
+   *   OperationFuture<Instance, OperationMetadata> future = cloudRedisClient.failoverInstanceOperationCallable().futureCall(request);
+   *   // Do something
+   *   Instance response = future.get();
+   * }
+   * 
+ */ + @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") + public final OperationCallable + failoverInstanceOperationCallable() { + return stub.failoverInstanceOperationCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Initiates a failover of the master node to current replica node for a specific STANDARD tier + * Cloud Memorystore for Redis instance. + * + *

Sample code: + * + *


+   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
+   *   InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]");
+   *   FailoverInstanceRequest request = FailoverInstanceRequest.newBuilder()
+   *     .setName(name.toString())
+   *     .build();
+   *   ApiFuture<Operation> future = cloudRedisClient.failoverInstanceCallable().futureCall(request);
+   *   // Do something
+   *   Operation response = future.get();
+   * }
+   * 
+ */ + public final UnaryCallable failoverInstanceCallable() { + return stub.failoverInstanceCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Deletes a specific Redis instance. Instance stops serving and data is deleted. + * + *

Sample code: + * + *


+   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
+   *   InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]");
+   *   cloudRedisClient.deleteInstanceAsync(name).get();
+   * }
+   * 
+ * + * @param name Required. Redis instance resource name using the form: + * `projects/{project_id}/locations/{location_id}/instances/{instance_id}` where `location_id` + * refers to a GCP region. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + public final OperationFuture deleteInstanceAsync(InstanceName name) { + DeleteInstanceRequest request = + DeleteInstanceRequest.newBuilder().setName(name == null ? null : name.toString()).build(); + return deleteInstanceAsync(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Deletes a specific Redis instance. Instance stops serving and data is deleted. + * + *

Sample code: + * + *


+   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
+   *   InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]");
+   *   cloudRedisClient.deleteInstanceAsync(name.toString()).get();
+   * }
+   * 
+ * + * @param name Required. Redis instance resource name using the form: + * `projects/{project_id}/locations/{location_id}/instances/{instance_id}` where `location_id` + * refers to a GCP region. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + public final OperationFuture deleteInstanceAsync(String name) { + DeleteInstanceRequest request = DeleteInstanceRequest.newBuilder().setName(name).build(); + return deleteInstanceAsync(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Deletes a specific Redis instance. Instance stops serving and data is deleted. + * + *

Sample code: + * + *


+   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
+   *   InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]");
+   *   DeleteInstanceRequest request = DeleteInstanceRequest.newBuilder()
+   *     .setName(name.toString())
+   *     .build();
+   *   cloudRedisClient.deleteInstanceAsync(request).get();
+   * }
+   * 
+ * + * @param request The request object containing all of the parameters for the API call. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + public final OperationFuture deleteInstanceAsync( + DeleteInstanceRequest request) { + return deleteInstanceOperationCallable().futureCall(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Deletes a specific Redis instance. Instance stops serving and data is deleted. + * + *

Sample code: + * + *


+   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
+   *   InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]");
+   *   DeleteInstanceRequest request = DeleteInstanceRequest.newBuilder()
+   *     .setName(name.toString())
+   *     .build();
+   *   OperationFuture<Empty, OperationMetadata> future = cloudRedisClient.deleteInstanceOperationCallable().futureCall(request);
+   *   // Do something
+   *   future.get();
+   * }
+   * 
+ */ + @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") + public final OperationCallable + deleteInstanceOperationCallable() { + return stub.deleteInstanceOperationCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Deletes a specific Redis instance. Instance stops serving and data is deleted. + * + *

Sample code: + * + *


+   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
+   *   InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]");
+   *   DeleteInstanceRequest request = DeleteInstanceRequest.newBuilder()
+   *     .setName(name.toString())
+   *     .build();
+   *   ApiFuture<Operation> future = cloudRedisClient.deleteInstanceCallable().futureCall(request);
+   *   // Do something
+   *   future.get();
+   * }
+   * 
+ */ + public final UnaryCallable deleteInstanceCallable() { + return stub.deleteInstanceCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Lists all Redis instances owned by a project in either the specified location (region) or all + * locations. + * + *

The location should have the following format: + * + *

* `projects/{project_id}/locations/{location_id}` + * + *

If `location_id` is specified as `-` (wildcard), then all regions available to the project + * are queried, and the results are aggregated. + * + *

Sample code: + * + *


+   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
+   *   LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
+   *   for (Instance element : cloudRedisClient.listInstances(parent).iterateAll()) {
+   *     // doThingsWith(element);
+   *   }
+   * }
+   * 
+ * + * @param parent Required. The resource name of the instance location using the form: + * `projects/{project_id}/locations/{location_id}` where `location_id` refers to a GCP region. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final ListInstancesPagedResponse listInstances(LocationName parent) { + ListInstancesRequest request = + ListInstancesRequest.newBuilder() + .setParent(parent == null ? null : parent.toString()) + .build(); + return listInstances(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Lists all Redis instances owned by a project in either the specified location (region) or all + * locations. + * + *

The location should have the following format: + * + *

* `projects/{project_id}/locations/{location_id}` + * + *

If `location_id` is specified as `-` (wildcard), then all regions available to the project + * are queried, and the results are aggregated. + * + *

Sample code: + * + *


+   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
+   *   LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
+   *   for (Instance element : cloudRedisClient.listInstances(parent.toString()).iterateAll()) {
+   *     // doThingsWith(element);
+   *   }
+   * }
+   * 
+ * + * @param parent Required. The resource name of the instance location using the form: + * `projects/{project_id}/locations/{location_id}` where `location_id` refers to a GCP region. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final ListInstancesPagedResponse listInstances(String parent) { + ListInstancesRequest request = ListInstancesRequest.newBuilder().setParent(parent).build(); + return listInstances(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Lists all Redis instances owned by a project in either the specified location (region) or all + * locations. + * + *

The location should have the following format: + * + *

* `projects/{project_id}/locations/{location_id}` + * + *

If `location_id` is specified as `-` (wildcard), then all regions available to the project + * are queried, and the results are aggregated. + * + *

Sample code: + * + *


+   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
+   *   LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
+   *   ListInstancesRequest request = ListInstancesRequest.newBuilder()
+   *     .setParent(parent.toString())
+   *     .build();
+   *   for (Instance element : cloudRedisClient.listInstances(request).iterateAll()) {
+   *     // doThingsWith(element);
+   *   }
+   * }
+   * 
+ * + * @param request The request object containing all of the parameters for the API call. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final ListInstancesPagedResponse listInstances(ListInstancesRequest request) { + return listInstancesPagedCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Lists all Redis instances owned by a project in either the specified location (region) or all + * locations. + * + *

The location should have the following format: + * + *

* `projects/{project_id}/locations/{location_id}` + * + *

If `location_id` is specified as `-` (wildcard), then all regions available to the project + * are queried, and the results are aggregated. + * + *

Sample code: + * + *


+   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
+   *   LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
+   *   ListInstancesRequest request = ListInstancesRequest.newBuilder()
+   *     .setParent(parent.toString())
+   *     .build();
+   *   ApiFuture<ListInstancesPagedResponse> future = cloudRedisClient.listInstancesPagedCallable().futureCall(request);
+   *   // Do something
+   *   for (Instance element : future.get().iterateAll()) {
+   *     // doThingsWith(element);
+   *   }
+   * }
+   * 
+ */ + public final UnaryCallable + listInstancesPagedCallable() { + return stub.listInstancesPagedCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Lists all Redis instances owned by a project in either the specified location (region) or all + * locations. + * + *

The location should have the following format: + * + *

* `projects/{project_id}/locations/{location_id}` + * + *

If `location_id` is specified as `-` (wildcard), then all regions available to the project + * are queried, and the results are aggregated. + * + *

Sample code: + * + *


+   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
+   *   LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
+   *   ListInstancesRequest request = ListInstancesRequest.newBuilder()
+   *     .setParent(parent.toString())
+   *     .build();
+   *   while (true) {
+   *     ListInstancesResponse response = cloudRedisClient.listInstancesCallable().call(request);
+   *     for (Instance element : response.getInstancesList()) {
+   *       // doThingsWith(element);
+   *     }
+   *     String nextPageToken = response.getNextPageToken();
+   *     if (!Strings.isNullOrEmpty(nextPageToken)) {
+   *       request = request.toBuilder().setPageToken(nextPageToken).build();
+   *     } else {
+   *       break;
+   *     }
+   *   }
+   * }
+   * 
+ */ + public final UnaryCallable listInstancesCallable() { + return stub.listInstancesCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Gets the details of a specific Redis instance. + * + *

Sample code: + * + *


+   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
+   *   InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]");
+   *   Instance response = cloudRedisClient.getInstance(name);
+   * }
+   * 
+ * + * @param name Required. Redis instance resource name using the form: + * `projects/{project_id}/locations/{location_id}/instances/{instance_id}` where `location_id` + * refers to a GCP region. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final Instance getInstance(InstanceName name) { + GetInstanceRequest request = + GetInstanceRequest.newBuilder().setName(name == null ? null : name.toString()).build(); + return getInstance(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Gets the details of a specific Redis instance. + * + *

Sample code: + * + *


+   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
+   *   InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]");
+   *   Instance response = cloudRedisClient.getInstance(name.toString());
+   * }
+   * 
+ * + * @param name Required. Redis instance resource name using the form: + * `projects/{project_id}/locations/{location_id}/instances/{instance_id}` where `location_id` + * refers to a GCP region. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final Instance getInstance(String name) { + GetInstanceRequest request = GetInstanceRequest.newBuilder().setName(name).build(); + return getInstance(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Gets the details of a specific Redis instance. + * + *

Sample code: + * + *


+   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
+   *   InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]");
+   *   GetInstanceRequest request = GetInstanceRequest.newBuilder()
+   *     .setName(name.toString())
+   *     .build();
+   *   Instance response = cloudRedisClient.getInstance(request);
+   * }
+   * 
+ * + * @param request The request object containing all of the parameters for the API call. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final Instance getInstance(GetInstanceRequest request) { + return getInstanceCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Gets the details of a specific Redis instance. + * + *

Sample code: + * + *


+   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
+   *   InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]");
+   *   GetInstanceRequest request = GetInstanceRequest.newBuilder()
+   *     .setName(name.toString())
+   *     .build();
+   *   ApiFuture<Instance> future = cloudRedisClient.getInstanceCallable().futureCall(request);
+   *   // Do something
+   *   Instance response = future.get();
+   * }
+   * 
+ */ + public final UnaryCallable getInstanceCallable() { + return stub.getInstanceCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Upgrades Redis instance to the newer Redis version specified in the request. + * + *

Sample code: + * + *


+   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
+   *   InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]");
+   *   String redisVersion = "";
+   *   Instance response = cloudRedisClient.upgradeInstanceAsync(name, redisVersion).get();
+   * }
+   * 
+ * + * @param name Required. Redis instance resource name using the form: + * `projects/{project_id}/locations/{location_id}/instances/{instance_id}` where `location_id` + * refers to a GCP region. + * @param redisVersion Required. Specifies the target version of Redis software to upgrade to. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + public final OperationFuture upgradeInstanceAsync( + InstanceName name, String redisVersion) { + UpgradeInstanceRequest request = + UpgradeInstanceRequest.newBuilder() + .setName(name == null ? null : name.toString()) + .setRedisVersion(redisVersion) + .build(); + return upgradeInstanceAsync(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Upgrades Redis instance to the newer Redis version specified in the request. + * + *

Sample code: + * + *


+   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
+   *   InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]");
+   *   String redisVersion = "";
+   *   Instance response = cloudRedisClient.upgradeInstanceAsync(name.toString(), redisVersion).get();
+   * }
+   * 
+ * + * @param name Required. Redis instance resource name using the form: + * `projects/{project_id}/locations/{location_id}/instances/{instance_id}` where `location_id` + * refers to a GCP region. + * @param redisVersion Required. Specifies the target version of Redis software to upgrade to. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + public final OperationFuture upgradeInstanceAsync( + String name, String redisVersion) { + UpgradeInstanceRequest request = + UpgradeInstanceRequest.newBuilder().setName(name).setRedisVersion(redisVersion).build(); + return upgradeInstanceAsync(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Upgrades Redis instance to the newer Redis version specified in the request. + * + *

Sample code: + * + *


+   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
+   *   InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]");
+   *   String redisVersion = "";
+   *   UpgradeInstanceRequest request = UpgradeInstanceRequest.newBuilder()
+   *     .setName(name.toString())
+   *     .setRedisVersion(redisVersion)
+   *     .build();
+   *   Instance response = cloudRedisClient.upgradeInstanceAsync(request).get();
+   * }
+   * 
+ * + * @param request The request object containing all of the parameters for the API call. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + public final OperationFuture upgradeInstanceAsync( + UpgradeInstanceRequest request) { + return upgradeInstanceOperationCallable().futureCall(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Upgrades Redis instance to the newer Redis version specified in the request. + * + *

Sample code: + * + *


+   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
+   *   InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]");
+   *   String redisVersion = "";
+   *   UpgradeInstanceRequest request = UpgradeInstanceRequest.newBuilder()
+   *     .setName(name.toString())
+   *     .setRedisVersion(redisVersion)
+   *     .build();
+   *   OperationFuture<Instance, OperationMetadata> future = cloudRedisClient.upgradeInstanceOperationCallable().futureCall(request);
+   *   // Do something
+   *   Instance response = future.get();
+   * }
+   * 
+ */ + @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") + public final OperationCallable + upgradeInstanceOperationCallable() { + return stub.upgradeInstanceOperationCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Upgrades Redis instance to the newer Redis version specified in the request. + * + *

Sample code: + * + *


+   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
+   *   InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]");
+   *   String redisVersion = "";
+   *   UpgradeInstanceRequest request = UpgradeInstanceRequest.newBuilder()
+   *     .setName(name.toString())
+   *     .setRedisVersion(redisVersion)
+   *     .build();
+   *   ApiFuture<Operation> future = cloudRedisClient.upgradeInstanceCallable().futureCall(request);
+   *   // Do something
+   *   Operation response = future.get();
+   * }
+   * 
+ */ + public final UnaryCallable upgradeInstanceCallable() { + return stub.upgradeInstanceCallable(); + } + + @Override + public final void close() { + stub.close(); + } + + @Override + public void shutdown() { + stub.shutdown(); + } + + @Override + public boolean isShutdown() { + return stub.isShutdown(); + } + + @Override + public boolean isTerminated() { + return stub.isTerminated(); + } + + @Override + public void shutdownNow() { + stub.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return stub.awaitTermination(duration, unit); + } + + public static class ListInstancesPagedResponse + extends AbstractPagedListResponse< + ListInstancesRequest, + ListInstancesResponse, + Instance, + ListInstancesPage, + ListInstancesFixedSizeCollection> { + + public static ApiFuture createAsync( + PageContext context, + ApiFuture futureResponse) { + ApiFuture futurePage = + ListInstancesPage.createEmptyPage().createPageAsync(context, futureResponse); + return ApiFutures.transform( + futurePage, + new ApiFunction() { + @Override + public ListInstancesPagedResponse apply(ListInstancesPage input) { + return new ListInstancesPagedResponse(input); + } + }, + MoreExecutors.directExecutor()); + } + + private ListInstancesPagedResponse(ListInstancesPage page) { + super(page, ListInstancesFixedSizeCollection.createEmptyCollection()); + } + } + + public static class ListInstancesPage + extends AbstractPage< + ListInstancesRequest, ListInstancesResponse, Instance, ListInstancesPage> { + + private ListInstancesPage( + PageContext context, + ListInstancesResponse response) { + super(context, response); + } + + private static ListInstancesPage createEmptyPage() { + return new ListInstancesPage(null, null); + } + + @Override + protected ListInstancesPage createPage( + PageContext context, + ListInstancesResponse response) { + return new ListInstancesPage(context, response); + } + + @Override + public ApiFuture createPageAsync( + PageContext context, + ApiFuture futureResponse) { + return super.createPageAsync(context, futureResponse); + } + } + + public static class ListInstancesFixedSizeCollection + extends AbstractFixedSizeCollection< + ListInstancesRequest, + ListInstancesResponse, + Instance, + ListInstancesPage, + ListInstancesFixedSizeCollection> { + + private ListInstancesFixedSizeCollection(List pages, int collectionSize) { + super(pages, collectionSize); + } + + private static ListInstancesFixedSizeCollection createEmptyCollection() { + return new ListInstancesFixedSizeCollection(null, 0); + } + + @Override + protected ListInstancesFixedSizeCollection createCollection( + List pages, int collectionSize) { + return new ListInstancesFixedSizeCollection(pages, collectionSize); + } + } +} diff --git a/test/integration/goldens/redis/CloudRedisClientTest.java b/test/integration/goldens/redis/CloudRedisClientTest.java new file mode 100644 index 0000000000..a012313099 --- /dev/null +++ b/test/integration/goldens/redis/CloudRedisClientTest.java @@ -0,0 +1,738 @@ +/* + * 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. + */ +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; +import com.google.api.gax.grpc.testing.MockGrpcService; +import com.google.api.gax.grpc.testing.MockServiceHelper; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.InvalidArgumentException; +import com.google.api.gax.rpc.StatusCode; +import com.google.common.collect.Lists; +import com.google.longrunning.Operation; +import com.google.protobuf.AbstractMessage; +import com.google.protobuf.Any; +import com.google.protobuf.Empty; +import com.google.protobuf.FieldMask; +import io.grpc.Status; +import io.grpc.StatusRuntimeException; +import java.io.IOException; +import java.util.Arrays; +import java.util.List; +import java.util.UUID; +import java.util.concurrent.ExecutionException; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +@javax.annotation.Generated("by GAPIC") +public class CloudRedisClientTest { + private static MockCloudRedis mockCloudRedis; + private static MockServiceHelper serviceHelper; + private CloudRedisClient client; + private LocalChannelProvider channelProvider; + + @BeforeClass + public static void startStaticServer() { + mockCloudRedis = new MockCloudRedis(); + serviceHelper = + new MockServiceHelper( + UUID.randomUUID().toString(), Arrays.asList(mockCloudRedis)); + serviceHelper.start(); + } + + @AfterClass + public static void stopServer() { + serviceHelper.stop(); + } + + @Before + public void setUp() throws IOException { + serviceHelper.reset(); + channelProvider = serviceHelper.createChannelProvider(); + CloudRedisSettings settings = + CloudRedisSettings.newBuilder() + .setTransportChannelProvider(channelProvider) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = CloudRedisClient.create(settings); + } + + @After + public void tearDown() throws Exception { + client.close(); + } + + @Test + @SuppressWarnings("all") + public void createInstanceTest() throws Exception { + InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + String displayName = "displayName1615086568"; + String locationId = "locationId552319461"; + String alternativeLocationId = "alternativeLocationId-718920621"; + String redisVersion = "redisVersion-685310444"; + String reservedIpRange = "reservedIpRange-1082940580"; + String host = "host3208616"; + int port = 3446913; + String currentLocationId = "currentLocationId1312712735"; + String statusMessage = "statusMessage-239442758"; + int memorySizeGb2 = 1493816946; + String authorizedNetwork = "authorizedNetwork-1733809270"; + String persistenceIamIdentity = "persistenceIamIdentity1061944584"; + Instance expectedResponse = + Instance.newBuilder() + .setName(name.toString()) + .setDisplayName(displayName) + .setLocationId(locationId) + .setAlternativeLocationId(alternativeLocationId) + .setRedisVersion(redisVersion) + .setReservedIpRange(reservedIpRange) + .setHost(host) + .setPort(port) + .setCurrentLocationId(currentLocationId) + .setStatusMessage(statusMessage) + .setMemorySizeGb(memorySizeGb2) + .setAuthorizedNetwork(authorizedNetwork) + .setPersistenceIamIdentity(persistenceIamIdentity) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("createInstanceTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockCloudRedis.addResponse(resultOperation); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + String instanceId = "test_instance"; + Instance.Tier tier = Instance.Tier.BASIC; + int memorySizeGb = 1; + Instance instance = Instance.newBuilder().setTier(tier).setMemorySizeGb(memorySizeGb).build(); + + Instance actualResponse = client.createInstanceAsync(parent, instanceId, instance).get(); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockCloudRedis.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + CreateInstanceRequest actualRequest = (CreateInstanceRequest) actualRequests.get(0); + + Assert.assertEquals(parent, LocationName.parse(actualRequest.getParent())); + Assert.assertEquals(instanceId, actualRequest.getInstanceId()); + Assert.assertEquals(instance, actualRequest.getInstance()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + @SuppressWarnings("all") + public void createInstanceExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); + mockCloudRedis.addException(exception); + + try { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + String instanceId = "test_instance"; + Instance.Tier tier = Instance.Tier.BASIC; + int memorySizeGb = 1; + Instance instance = Instance.newBuilder().setTier(tier).setMemorySizeGb(memorySizeGb).build(); + + client.createInstanceAsync(parent, instanceId, instance).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); + InvalidArgumentException apiException = (InvalidArgumentException) e.getCause(); + Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); + } + } + + @Test + @SuppressWarnings("all") + public void updateInstanceTest() throws Exception { + InstanceName name2 = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + String displayName2 = "displayName21615000987"; + String locationId = "locationId552319461"; + String alternativeLocationId = "alternativeLocationId-718920621"; + String redisVersion = "redisVersion-685310444"; + String reservedIpRange = "reservedIpRange-1082940580"; + String host = "host3208616"; + int port = 3446913; + String currentLocationId = "currentLocationId1312712735"; + String statusMessage = "statusMessage-239442758"; + int memorySizeGb2 = 1493816946; + String authorizedNetwork = "authorizedNetwork-1733809270"; + String persistenceIamIdentity = "persistenceIamIdentity1061944584"; + Instance expectedResponse = + Instance.newBuilder() + .setName(name2.toString()) + .setDisplayName(displayName2) + .setLocationId(locationId) + .setAlternativeLocationId(alternativeLocationId) + .setRedisVersion(redisVersion) + .setReservedIpRange(reservedIpRange) + .setHost(host) + .setPort(port) + .setCurrentLocationId(currentLocationId) + .setStatusMessage(statusMessage) + .setMemorySizeGb(memorySizeGb2) + .setAuthorizedNetwork(authorizedNetwork) + .setPersistenceIamIdentity(persistenceIamIdentity) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("updateInstanceTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockCloudRedis.addResponse(resultOperation); + + String pathsElement = "display_name"; + String pathsElement2 = "memory_size_gb"; + List paths = Arrays.asList(pathsElement, pathsElement2); + FieldMask updateMask = FieldMask.newBuilder().addAllPaths(paths).build(); + String displayName = "UpdatedDisplayName"; + String name = "projects//locations//instances/"; + int memorySizeGb = 4; + Instance instance = + Instance.newBuilder() + .setDisplayName(displayName) + .setName(name) + .setMemorySizeGb(memorySizeGb) + .build(); + + Instance actualResponse = client.updateInstanceAsync(updateMask, instance).get(); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockCloudRedis.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + UpdateInstanceRequest actualRequest = (UpdateInstanceRequest) actualRequests.get(0); + + Assert.assertEquals(updateMask, actualRequest.getUpdateMask()); + Assert.assertEquals(instance, actualRequest.getInstance()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + @SuppressWarnings("all") + public void updateInstanceExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); + mockCloudRedis.addException(exception); + + try { + String pathsElement = "display_name"; + String pathsElement2 = "memory_size_gb"; + List paths = Arrays.asList(pathsElement, pathsElement2); + FieldMask updateMask = FieldMask.newBuilder().addAllPaths(paths).build(); + String displayName = "UpdatedDisplayName"; + String name = "projects//locations//instances/"; + int memorySizeGb = 4; + Instance instance = + Instance.newBuilder() + .setDisplayName(displayName) + .setName(name) + .setMemorySizeGb(memorySizeGb) + .build(); + + client.updateInstanceAsync(updateMask, instance).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); + InvalidArgumentException apiException = (InvalidArgumentException) e.getCause(); + Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); + } + } + + @Test + @SuppressWarnings("all") + public void importInstanceTest() throws Exception { + InstanceName name2 = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + String displayName = "displayName1615086568"; + String locationId = "locationId552319461"; + String alternativeLocationId = "alternativeLocationId-718920621"; + String redisVersion = "redisVersion-685310444"; + String reservedIpRange = "reservedIpRange-1082940580"; + String host = "host3208616"; + int port = 3446913; + String currentLocationId = "currentLocationId1312712735"; + String statusMessage = "statusMessage-239442758"; + int memorySizeGb = 34199707; + String authorizedNetwork = "authorizedNetwork-1733809270"; + String persistenceIamIdentity = "persistenceIamIdentity1061944584"; + Instance expectedResponse = + Instance.newBuilder() + .setName(name2.toString()) + .setDisplayName(displayName) + .setLocationId(locationId) + .setAlternativeLocationId(alternativeLocationId) + .setRedisVersion(redisVersion) + .setReservedIpRange(reservedIpRange) + .setHost(host) + .setPort(port) + .setCurrentLocationId(currentLocationId) + .setStatusMessage(statusMessage) + .setMemorySizeGb(memorySizeGb) + .setAuthorizedNetwork(authorizedNetwork) + .setPersistenceIamIdentity(persistenceIamIdentity) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("importInstanceTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockCloudRedis.addResponse(resultOperation); + + String name = "name3373707"; + InputConfig inputConfig = InputConfig.newBuilder().build(); + + Instance actualResponse = client.importInstanceAsync(name, inputConfig).get(); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockCloudRedis.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + ImportInstanceRequest actualRequest = (ImportInstanceRequest) actualRequests.get(0); + + Assert.assertEquals(name, actualRequest.getName()); + Assert.assertEquals(inputConfig, actualRequest.getInputConfig()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + @SuppressWarnings("all") + public void importInstanceExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); + mockCloudRedis.addException(exception); + + try { + String name = "name3373707"; + InputConfig inputConfig = InputConfig.newBuilder().build(); + + client.importInstanceAsync(name, inputConfig).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); + InvalidArgumentException apiException = (InvalidArgumentException) e.getCause(); + Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); + } + } + + @Test + @SuppressWarnings("all") + public void exportInstanceTest() throws Exception { + InstanceName name2 = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + String displayName = "displayName1615086568"; + String locationId = "locationId552319461"; + String alternativeLocationId = "alternativeLocationId-718920621"; + String redisVersion = "redisVersion-685310444"; + String reservedIpRange = "reservedIpRange-1082940580"; + String host = "host3208616"; + int port = 3446913; + String currentLocationId = "currentLocationId1312712735"; + String statusMessage = "statusMessage-239442758"; + int memorySizeGb = 34199707; + String authorizedNetwork = "authorizedNetwork-1733809270"; + String persistenceIamIdentity = "persistenceIamIdentity1061944584"; + Instance expectedResponse = + Instance.newBuilder() + .setName(name2.toString()) + .setDisplayName(displayName) + .setLocationId(locationId) + .setAlternativeLocationId(alternativeLocationId) + .setRedisVersion(redisVersion) + .setReservedIpRange(reservedIpRange) + .setHost(host) + .setPort(port) + .setCurrentLocationId(currentLocationId) + .setStatusMessage(statusMessage) + .setMemorySizeGb(memorySizeGb) + .setAuthorizedNetwork(authorizedNetwork) + .setPersistenceIamIdentity(persistenceIamIdentity) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("exportInstanceTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockCloudRedis.addResponse(resultOperation); + + String name = "name3373707"; + OutputConfig outputConfig = OutputConfig.newBuilder().build(); + + Instance actualResponse = client.exportInstanceAsync(name, outputConfig).get(); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockCloudRedis.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + ExportInstanceRequest actualRequest = (ExportInstanceRequest) actualRequests.get(0); + + Assert.assertEquals(name, actualRequest.getName()); + Assert.assertEquals(outputConfig, actualRequest.getOutputConfig()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + @SuppressWarnings("all") + public void exportInstanceExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); + mockCloudRedis.addException(exception); + + try { + String name = "name3373707"; + OutputConfig outputConfig = OutputConfig.newBuilder().build(); + + client.exportInstanceAsync(name, outputConfig).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); + InvalidArgumentException apiException = (InvalidArgumentException) e.getCause(); + Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); + } + } + + @Test + @SuppressWarnings("all") + public void failoverInstanceTest() throws Exception { + InstanceName name2 = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + String displayName = "displayName1615086568"; + String locationId = "locationId552319461"; + String alternativeLocationId = "alternativeLocationId-718920621"; + String redisVersion = "redisVersion-685310444"; + String reservedIpRange = "reservedIpRange-1082940580"; + String host = "host3208616"; + int port = 3446913; + String currentLocationId = "currentLocationId1312712735"; + String statusMessage = "statusMessage-239442758"; + int memorySizeGb = 34199707; + String authorizedNetwork = "authorizedNetwork-1733809270"; + String persistenceIamIdentity = "persistenceIamIdentity1061944584"; + Instance expectedResponse = + Instance.newBuilder() + .setName(name2.toString()) + .setDisplayName(displayName) + .setLocationId(locationId) + .setAlternativeLocationId(alternativeLocationId) + .setRedisVersion(redisVersion) + .setReservedIpRange(reservedIpRange) + .setHost(host) + .setPort(port) + .setCurrentLocationId(currentLocationId) + .setStatusMessage(statusMessage) + .setMemorySizeGb(memorySizeGb) + .setAuthorizedNetwork(authorizedNetwork) + .setPersistenceIamIdentity(persistenceIamIdentity) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("failoverInstanceTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockCloudRedis.addResponse(resultOperation); + + InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + FailoverInstanceRequest.DataProtectionMode dataProtectionMode = + FailoverInstanceRequest.DataProtectionMode.DATA_PROTECTION_MODE_UNSPECIFIED; + + Instance actualResponse = client.failoverInstanceAsync(name, dataProtectionMode).get(); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockCloudRedis.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + FailoverInstanceRequest actualRequest = (FailoverInstanceRequest) actualRequests.get(0); + + Assert.assertEquals(name, InstanceName.parse(actualRequest.getName())); + Assert.assertEquals(dataProtectionMode, actualRequest.getDataProtectionMode()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + @SuppressWarnings("all") + public void failoverInstanceExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); + mockCloudRedis.addException(exception); + + try { + InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + FailoverInstanceRequest.DataProtectionMode dataProtectionMode = + FailoverInstanceRequest.DataProtectionMode.DATA_PROTECTION_MODE_UNSPECIFIED; + + client.failoverInstanceAsync(name, dataProtectionMode).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); + InvalidArgumentException apiException = (InvalidArgumentException) e.getCause(); + Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); + } + } + + @Test + @SuppressWarnings("all") + public void deleteInstanceTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + Operation resultOperation = + Operation.newBuilder() + .setName("deleteInstanceTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockCloudRedis.addResponse(resultOperation); + + InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + + Empty actualResponse = client.deleteInstanceAsync(name).get(); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockCloudRedis.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + DeleteInstanceRequest actualRequest = (DeleteInstanceRequest) actualRequests.get(0); + + Assert.assertEquals(name, InstanceName.parse(actualRequest.getName())); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + @SuppressWarnings("all") + public void deleteInstanceExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); + mockCloudRedis.addException(exception); + + try { + InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + + client.deleteInstanceAsync(name).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); + InvalidArgumentException apiException = (InvalidArgumentException) e.getCause(); + Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); + } + } + + @Test + @SuppressWarnings("all") + public void listInstancesTest() { + String nextPageToken = ""; + Instance instancesElement = Instance.newBuilder().build(); + List instances = Arrays.asList(instancesElement); + ListInstancesResponse expectedResponse = + ListInstancesResponse.newBuilder() + .setNextPageToken(nextPageToken) + .addAllInstances(instances) + .build(); + mockCloudRedis.addResponse(expectedResponse); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + + ListInstancesPagedResponse pagedListResponse = client.listInstances(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getInstancesList().get(0), resources.get(0)); + + List actualRequests = mockCloudRedis.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + ListInstancesRequest actualRequest = (ListInstancesRequest) actualRequests.get(0); + + Assert.assertEquals(parent, LocationName.parse(actualRequest.getParent())); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + @SuppressWarnings("all") + public void listInstancesExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); + mockCloudRedis.addException(exception); + + try { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + + client.listInstances(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception + } + } + + @Test + @SuppressWarnings("all") + public void getInstanceTest() { + InstanceName name2 = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + String displayName = "displayName1615086568"; + String locationId = "locationId552319461"; + String alternativeLocationId = "alternativeLocationId-718920621"; + String redisVersion = "redisVersion-685310444"; + String reservedIpRange = "reservedIpRange-1082940580"; + String host = "host3208616"; + int port = 3446913; + String currentLocationId = "currentLocationId1312712735"; + String statusMessage = "statusMessage-239442758"; + int memorySizeGb = 34199707; + String authorizedNetwork = "authorizedNetwork-1733809270"; + String persistenceIamIdentity = "persistenceIamIdentity1061944584"; + Instance expectedResponse = + Instance.newBuilder() + .setName(name2.toString()) + .setDisplayName(displayName) + .setLocationId(locationId) + .setAlternativeLocationId(alternativeLocationId) + .setRedisVersion(redisVersion) + .setReservedIpRange(reservedIpRange) + .setHost(host) + .setPort(port) + .setCurrentLocationId(currentLocationId) + .setStatusMessage(statusMessage) + .setMemorySizeGb(memorySizeGb) + .setAuthorizedNetwork(authorizedNetwork) + .setPersistenceIamIdentity(persistenceIamIdentity) + .build(); + mockCloudRedis.addResponse(expectedResponse); + + InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + + Instance actualResponse = client.getInstance(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockCloudRedis.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + GetInstanceRequest actualRequest = (GetInstanceRequest) actualRequests.get(0); + + Assert.assertEquals(name, InstanceName.parse(actualRequest.getName())); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + @SuppressWarnings("all") + public void getInstanceExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); + mockCloudRedis.addException(exception); + + try { + InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + + client.getInstance(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception + } + } + + @Test + @SuppressWarnings("all") + public void upgradeInstanceTest() throws Exception { + InstanceName name2 = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + String displayName = "displayName1615086568"; + String locationId = "locationId552319461"; + String alternativeLocationId = "alternativeLocationId-718920621"; + String redisVersion2 = "redisVersion2-1453337401"; + String reservedIpRange = "reservedIpRange-1082940580"; + String host = "host3208616"; + int port = 3446913; + String currentLocationId = "currentLocationId1312712735"; + String statusMessage = "statusMessage-239442758"; + int memorySizeGb = 34199707; + String authorizedNetwork = "authorizedNetwork-1733809270"; + String persistenceIamIdentity = "persistenceIamIdentity1061944584"; + Instance expectedResponse = + Instance.newBuilder() + .setName(name2.toString()) + .setDisplayName(displayName) + .setLocationId(locationId) + .setAlternativeLocationId(alternativeLocationId) + .setRedisVersion(redisVersion2) + .setReservedIpRange(reservedIpRange) + .setHost(host) + .setPort(port) + .setCurrentLocationId(currentLocationId) + .setStatusMessage(statusMessage) + .setMemorySizeGb(memorySizeGb) + .setAuthorizedNetwork(authorizedNetwork) + .setPersistenceIamIdentity(persistenceIamIdentity) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("upgradeInstanceTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockCloudRedis.addResponse(resultOperation); + + InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + String redisVersion = "redisVersion-685310444"; + + Instance actualResponse = client.upgradeInstanceAsync(name, redisVersion).get(); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockCloudRedis.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + UpgradeInstanceRequest actualRequest = (UpgradeInstanceRequest) actualRequests.get(0); + + Assert.assertEquals(name, InstanceName.parse(actualRequest.getName())); + Assert.assertEquals(redisVersion, actualRequest.getRedisVersion()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + @SuppressWarnings("all") + public void upgradeInstanceExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); + mockCloudRedis.addException(exception); + + try { + InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + String redisVersion = "redisVersion-685310444"; + + client.upgradeInstanceAsync(name, redisVersion).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); + InvalidArgumentException apiException = (InvalidArgumentException) e.getCause(); + Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); + } + } +} diff --git a/test/integration/goldens/redis/CloudRedisSettings.java b/test/integration/goldens/redis/CloudRedisSettings.java new file mode 100644 index 0000000000..b54865d04f --- /dev/null +++ b/test/integration/goldens/redis/CloudRedisSettings.java @@ -0,0 +1,380 @@ +/* + * 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. + */ +package com.google.cloud.redis.v1; + +import static com.google.cloud.redis.v1.CloudRedisClient.ListInstancesPagedResponse; + +import com.google.api.core.ApiFunction; +import com.google.api.core.BetaApi; +import com.google.api.gax.core.GoogleCredentialsProvider; +import com.google.api.gax.core.InstantiatingExecutorProvider; +import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientSettings; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.TransportChannelProvider; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.cloud.redis.v1.stub.CloudRedisStubSettings; +import com.google.longrunning.Operation; +import com.google.protobuf.Empty; +import java.io.IOException; +import java.util.List; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * Settings class to configure an instance of {@link CloudRedisClient}. + * + *

The default instance has everything set to sensible defaults: + * + *

    + *
  • The default service address (redis.googleapis.com) and default port (443) are used. + *
  • Credentials are acquired automatically through Application Default Credentials. + *
  • Retries are configured for idempotent methods but not for non-idempotent methods. + *
+ * + *

The builder of this class is recursive, so contained classes are themselves builders. When + * build() is called, the tree of builders is called to create the complete settings object. + * + *

For example, to set the total timeout of getInstance to 30 seconds: + * + *

+ * 
+ * CloudRedisSettings.Builder cloudRedisSettingsBuilder =
+ *     CloudRedisSettings.newBuilder();
+ * cloudRedisSettingsBuilder
+ *     .getInstanceSettings()
+ *     .setRetrySettings(
+ *         cloudRedisSettingsBuilder.getInstanceSettings().getRetrySettings().toBuilder()
+ *             .setTotalTimeout(Duration.ofSeconds(30))
+ *             .build());
+ * CloudRedisSettings cloudRedisSettings = cloudRedisSettingsBuilder.build();
+ * 
+ * 
+ */ +@Generated("by gapic-generator") +@BetaApi +public class CloudRedisSettings extends ClientSettings { + /** Returns the object with the settings used for calls to createInstance. */ + public UnaryCallSettings createInstanceSettings() { + return ((CloudRedisStubSettings) getStubSettings()).createInstanceSettings(); + } + + /** Returns the object with the settings used for calls to createInstance. */ + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + public OperationCallSettings + createInstanceOperationSettings() { + return ((CloudRedisStubSettings) getStubSettings()).createInstanceOperationSettings(); + } + + /** Returns the object with the settings used for calls to updateInstance. */ + public UnaryCallSettings updateInstanceSettings() { + return ((CloudRedisStubSettings) getStubSettings()).updateInstanceSettings(); + } + + /** Returns the object with the settings used for calls to updateInstance. */ + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + public OperationCallSettings + updateInstanceOperationSettings() { + return ((CloudRedisStubSettings) getStubSettings()).updateInstanceOperationSettings(); + } + + /** Returns the object with the settings used for calls to importInstance. */ + public UnaryCallSettings importInstanceSettings() { + return ((CloudRedisStubSettings) getStubSettings()).importInstanceSettings(); + } + + /** Returns the object with the settings used for calls to importInstance. */ + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + public OperationCallSettings + importInstanceOperationSettings() { + return ((CloudRedisStubSettings) getStubSettings()).importInstanceOperationSettings(); + } + + /** Returns the object with the settings used for calls to exportInstance. */ + public UnaryCallSettings exportInstanceSettings() { + return ((CloudRedisStubSettings) getStubSettings()).exportInstanceSettings(); + } + + /** Returns the object with the settings used for calls to exportInstance. */ + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + public OperationCallSettings + exportInstanceOperationSettings() { + return ((CloudRedisStubSettings) getStubSettings()).exportInstanceOperationSettings(); + } + + /** Returns the object with the settings used for calls to failoverInstance. */ + public UnaryCallSettings failoverInstanceSettings() { + return ((CloudRedisStubSettings) getStubSettings()).failoverInstanceSettings(); + } + + /** Returns the object with the settings used for calls to failoverInstance. */ + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + public OperationCallSettings + failoverInstanceOperationSettings() { + return ((CloudRedisStubSettings) getStubSettings()).failoverInstanceOperationSettings(); + } + + /** Returns the object with the settings used for calls to deleteInstance. */ + public UnaryCallSettings deleteInstanceSettings() { + return ((CloudRedisStubSettings) getStubSettings()).deleteInstanceSettings(); + } + + /** Returns the object with the settings used for calls to deleteInstance. */ + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + public OperationCallSettings + deleteInstanceOperationSettings() { + return ((CloudRedisStubSettings) getStubSettings()).deleteInstanceOperationSettings(); + } + + /** Returns the object with the settings used for calls to listInstances. */ + public PagedCallSettings + listInstancesSettings() { + return ((CloudRedisStubSettings) getStubSettings()).listInstancesSettings(); + } + + /** Returns the object with the settings used for calls to getInstance. */ + public UnaryCallSettings getInstanceSettings() { + return ((CloudRedisStubSettings) getStubSettings()).getInstanceSettings(); + } + + /** Returns the object with the settings used for calls to upgradeInstance. */ + public UnaryCallSettings upgradeInstanceSettings() { + return ((CloudRedisStubSettings) getStubSettings()).upgradeInstanceSettings(); + } + + /** Returns the object with the settings used for calls to upgradeInstance. */ + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + public OperationCallSettings + upgradeInstanceOperationSettings() { + return ((CloudRedisStubSettings) getStubSettings()).upgradeInstanceOperationSettings(); + } + + public static final CloudRedisSettings create(CloudRedisStubSettings stub) throws IOException { + return new CloudRedisSettings.Builder(stub.toBuilder()).build(); + } + + /** Returns a builder for the default ExecutorProvider for this service. */ + public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() { + return CloudRedisStubSettings.defaultExecutorProviderBuilder(); + } + + /** Returns the default service endpoint. */ + public static String getDefaultEndpoint() { + return CloudRedisStubSettings.getDefaultEndpoint(); + } + + /** Returns the default service scopes. */ + public static List getDefaultServiceScopes() { + return CloudRedisStubSettings.getDefaultServiceScopes(); + } + + /** Returns a builder for the default credentials for this service. */ + public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder() { + return CloudRedisStubSettings.defaultCredentialsProviderBuilder(); + } + + /** Returns a builder for the default ChannelProvider for this service. */ + public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { + return CloudRedisStubSettings.defaultGrpcTransportProviderBuilder(); + } + + public static TransportChannelProvider defaultTransportChannelProvider() { + return CloudRedisStubSettings.defaultTransportChannelProvider(); + } + + @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return CloudRedisStubSettings.defaultApiClientHeaderProviderBuilder(); + } + + /** Returns a new builder for this class. */ + public static Builder newBuilder() { + return Builder.createDefault(); + } + + /** Returns a new builder for this class. */ + public static Builder newBuilder(ClientContext clientContext) { + return new Builder(clientContext); + } + + /** Returns a builder containing all the values of this settings class. */ + public Builder toBuilder() { + return new Builder(this); + } + + protected CloudRedisSettings(Builder settingsBuilder) throws IOException { + super(settingsBuilder); + } + + /** Builder for CloudRedisSettings. */ + public static class Builder extends ClientSettings.Builder { + protected Builder() throws IOException { + this((ClientContext) null); + } + + protected Builder(ClientContext clientContext) { + super(CloudRedisStubSettings.newBuilder(clientContext)); + } + + private static Builder createDefault() { + return new Builder(CloudRedisStubSettings.newBuilder()); + } + + protected Builder(CloudRedisSettings settings) { + super(settings.getStubSettings().toBuilder()); + } + + protected Builder(CloudRedisStubSettings.Builder stubSettings) { + super(stubSettings); + } + + public CloudRedisStubSettings.Builder getStubSettingsBuilder() { + return ((CloudRedisStubSettings.Builder) getStubSettings()); + } + + // NEXT_MAJOR_VER: remove 'throws Exception' + /** + * Applies the given settings updater function to all of the unary API methods in this service. + * + *

Note: This method does not support applying settings to streaming methods. + */ + public Builder applyToAllUnaryMethods( + ApiFunction, Void> settingsUpdater) throws Exception { + super.applyToAllUnaryMethods( + getStubSettingsBuilder().unaryMethodSettingsBuilders(), settingsUpdater); + return this; + } + + /** Returns the builder for the settings used for calls to createInstance. */ + public UnaryCallSettings.Builder createInstanceSettings() { + return getStubSettingsBuilder().createInstanceSettings(); + } + + /** Returns the builder for the settings used for calls to createInstance. */ + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + public OperationCallSettings.Builder + createInstanceOperationSettings() { + return getStubSettingsBuilder().createInstanceOperationSettings(); + } + + /** Returns the builder for the settings used for calls to updateInstance. */ + public UnaryCallSettings.Builder updateInstanceSettings() { + return getStubSettingsBuilder().updateInstanceSettings(); + } + + /** Returns the builder for the settings used for calls to updateInstance. */ + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + public OperationCallSettings.Builder + updateInstanceOperationSettings() { + return getStubSettingsBuilder().updateInstanceOperationSettings(); + } + + /** Returns the builder for the settings used for calls to importInstance. */ + public UnaryCallSettings.Builder importInstanceSettings() { + return getStubSettingsBuilder().importInstanceSettings(); + } + + /** Returns the builder for the settings used for calls to importInstance. */ + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + public OperationCallSettings.Builder + importInstanceOperationSettings() { + return getStubSettingsBuilder().importInstanceOperationSettings(); + } + + /** Returns the builder for the settings used for calls to exportInstance. */ + public UnaryCallSettings.Builder exportInstanceSettings() { + return getStubSettingsBuilder().exportInstanceSettings(); + } + + /** Returns the builder for the settings used for calls to exportInstance. */ + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + public OperationCallSettings.Builder + exportInstanceOperationSettings() { + return getStubSettingsBuilder().exportInstanceOperationSettings(); + } + + /** Returns the builder for the settings used for calls to failoverInstance. */ + public UnaryCallSettings.Builder + failoverInstanceSettings() { + return getStubSettingsBuilder().failoverInstanceSettings(); + } + + /** Returns the builder for the settings used for calls to failoverInstance. */ + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + public OperationCallSettings.Builder + failoverInstanceOperationSettings() { + return getStubSettingsBuilder().failoverInstanceOperationSettings(); + } + + /** Returns the builder for the settings used for calls to deleteInstance. */ + public UnaryCallSettings.Builder deleteInstanceSettings() { + return getStubSettingsBuilder().deleteInstanceSettings(); + } + + /** Returns the builder for the settings used for calls to deleteInstance. */ + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + public OperationCallSettings.Builder + deleteInstanceOperationSettings() { + return getStubSettingsBuilder().deleteInstanceOperationSettings(); + } + + /** Returns the builder for the settings used for calls to listInstances. */ + public PagedCallSettings.Builder< + ListInstancesRequest, ListInstancesResponse, ListInstancesPagedResponse> + listInstancesSettings() { + return getStubSettingsBuilder().listInstancesSettings(); + } + + /** Returns the builder for the settings used for calls to getInstance. */ + public UnaryCallSettings.Builder getInstanceSettings() { + return getStubSettingsBuilder().getInstanceSettings(); + } + + /** Returns the builder for the settings used for calls to upgradeInstance. */ + public UnaryCallSettings.Builder upgradeInstanceSettings() { + return getStubSettingsBuilder().upgradeInstanceSettings(); + } + + /** Returns the builder for the settings used for calls to upgradeInstance. */ + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + public OperationCallSettings.Builder + upgradeInstanceOperationSettings() { + return getStubSettingsBuilder().upgradeInstanceOperationSettings(); + } + + @Override + public CloudRedisSettings build() throws IOException { + return new CloudRedisSettings(this); + } + } +} diff --git a/test/integration/goldens/redis/CloudRedisStub.java b/test/integration/goldens/redis/CloudRedisStub.java new file mode 100644 index 0000000000..68cfb9523f --- /dev/null +++ b/test/integration/goldens/redis/CloudRedisStub.java @@ -0,0 +1,141 @@ +/* + * 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. + */ +package com.google.cloud.redis.v1.stub; + +import static com.google.cloud.redis.v1.CloudRedisClient.ListInstancesPagedResponse; + +import com.google.api.core.BetaApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.cloud.redis.v1.CreateInstanceRequest; +import com.google.cloud.redis.v1.DeleteInstanceRequest; +import com.google.cloud.redis.v1.ExportInstanceRequest; +import com.google.cloud.redis.v1.FailoverInstanceRequest; +import com.google.cloud.redis.v1.GetInstanceRequest; +import com.google.cloud.redis.v1.ImportInstanceRequest; +import com.google.cloud.redis.v1.Instance; +import com.google.cloud.redis.v1.ListInstancesRequest; +import com.google.cloud.redis.v1.ListInstancesResponse; +import com.google.cloud.redis.v1.OperationMetadata; +import com.google.cloud.redis.v1.UpdateInstanceRequest; +import com.google.cloud.redis.v1.UpgradeInstanceRequest; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import com.google.protobuf.Empty; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * Base stub class for Google Cloud Memorystore for Redis API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@Generated("by gapic-generator") +@BetaApi("A restructuring of stub classes is planned, so this may break in the future") +public abstract class CloudRedisStub implements BackgroundResource { + + @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") + public OperationsStub getOperationsStub() { + throw new UnsupportedOperationException("Not implemented: getOperationsStub()"); + } + + @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") + public OperationCallable + createInstanceOperationCallable() { + throw new UnsupportedOperationException("Not implemented: createInstanceOperationCallable()"); + } + + public UnaryCallable createInstanceCallable() { + throw new UnsupportedOperationException("Not implemented: createInstanceCallable()"); + } + + @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") + public OperationCallable + updateInstanceOperationCallable() { + throw new UnsupportedOperationException("Not implemented: updateInstanceOperationCallable()"); + } + + public UnaryCallable updateInstanceCallable() { + throw new UnsupportedOperationException("Not implemented: updateInstanceCallable()"); + } + + @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") + public OperationCallable + importInstanceOperationCallable() { + throw new UnsupportedOperationException("Not implemented: importInstanceOperationCallable()"); + } + + public UnaryCallable importInstanceCallable() { + throw new UnsupportedOperationException("Not implemented: importInstanceCallable()"); + } + + @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") + public OperationCallable + exportInstanceOperationCallable() { + throw new UnsupportedOperationException("Not implemented: exportInstanceOperationCallable()"); + } + + public UnaryCallable exportInstanceCallable() { + throw new UnsupportedOperationException("Not implemented: exportInstanceCallable()"); + } + + @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") + public OperationCallable + failoverInstanceOperationCallable() { + throw new UnsupportedOperationException("Not implemented: failoverInstanceOperationCallable()"); + } + + public UnaryCallable failoverInstanceCallable() { + throw new UnsupportedOperationException("Not implemented: failoverInstanceCallable()"); + } + + @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") + public OperationCallable + deleteInstanceOperationCallable() { + throw new UnsupportedOperationException("Not implemented: deleteInstanceOperationCallable()"); + } + + public UnaryCallable deleteInstanceCallable() { + throw new UnsupportedOperationException("Not implemented: deleteInstanceCallable()"); + } + + public UnaryCallable + listInstancesPagedCallable() { + throw new UnsupportedOperationException("Not implemented: listInstancesPagedCallable()"); + } + + public UnaryCallable listInstancesCallable() { + throw new UnsupportedOperationException("Not implemented: listInstancesCallable()"); + } + + public UnaryCallable getInstanceCallable() { + throw new UnsupportedOperationException("Not implemented: getInstanceCallable()"); + } + + @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") + public OperationCallable + upgradeInstanceOperationCallable() { + throw new UnsupportedOperationException("Not implemented: upgradeInstanceOperationCallable()"); + } + + public UnaryCallable upgradeInstanceCallable() { + throw new UnsupportedOperationException("Not implemented: upgradeInstanceCallable()"); + } + + @Override + public abstract void close(); +} diff --git a/test/integration/goldens/redis/CloudRedisStubSettings.java b/test/integration/goldens/redis/CloudRedisStubSettings.java new file mode 100644 index 0000000000..c31ed11904 --- /dev/null +++ b/test/integration/goldens/redis/CloudRedisStubSettings.java @@ -0,0 +1,868 @@ +/* + * 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. + */ +package com.google.cloud.redis.v1.stub; + +import static com.google.cloud.redis.v1.CloudRedisClient.ListInstancesPagedResponse; + +import com.google.api.core.ApiFunction; +import com.google.api.core.ApiFuture; +import com.google.api.core.BetaApi; +import com.google.api.gax.core.GaxProperties; +import com.google.api.gax.core.GoogleCredentialsProvider; +import com.google.api.gax.core.InstantiatingExecutorProvider; +import com.google.api.gax.grpc.GaxGrpcProperties; +import com.google.api.gax.grpc.GrpcTransportChannel; +import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.grpc.ProtoOperationTransformers; +import com.google.api.gax.longrunning.OperationSnapshot; +import com.google.api.gax.longrunning.OperationTimedPollAlgorithm; +import com.google.api.gax.retrying.RetrySettings; +import com.google.api.gax.rpc.ApiCallContext; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.PageContext; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.PagedListDescriptor; +import com.google.api.gax.rpc.PagedListResponseFactory; +import com.google.api.gax.rpc.StatusCode; +import com.google.api.gax.rpc.StubSettings; +import com.google.api.gax.rpc.TransportChannelProvider; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.cloud.redis.v1.CreateInstanceRequest; +import com.google.cloud.redis.v1.DeleteInstanceRequest; +import com.google.cloud.redis.v1.ExportInstanceRequest; +import com.google.cloud.redis.v1.FailoverInstanceRequest; +import com.google.cloud.redis.v1.GetInstanceRequest; +import com.google.cloud.redis.v1.ImportInstanceRequest; +import com.google.cloud.redis.v1.Instance; +import com.google.cloud.redis.v1.ListInstancesRequest; +import com.google.cloud.redis.v1.ListInstancesResponse; +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.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Lists; +import com.google.longrunning.Operation; +import com.google.protobuf.Empty; +import java.io.IOException; +import java.util.List; +import javax.annotation.Generated; +import org.threeten.bp.Duration; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * Settings class to configure an instance of {@link CloudRedisStub}. + * + *

The default instance has everything set to sensible defaults: + * + *

    + *
  • The default service address (redis.googleapis.com) and default port (443) are used. + *
  • Credentials are acquired automatically through Application Default Credentials. + *
  • Retries are configured for idempotent methods but not for non-idempotent methods. + *
+ * + *

The builder of this class is recursive, so contained classes are themselves builders. When + * build() is called, the tree of builders is called to create the complete settings object. + * + *

For example, to set the total timeout of getInstance to 30 seconds: + * + *

+ * 
+ * CloudRedisStubSettings.Builder cloudRedisSettingsBuilder =
+ *     CloudRedisStubSettings.newBuilder();
+ * cloudRedisSettingsBuilder
+ *     .getInstanceSettings()
+ *     .setRetrySettings(
+ *         cloudRedisSettingsBuilder.getInstanceSettings().getRetrySettings().toBuilder()
+ *             .setTotalTimeout(Duration.ofSeconds(30))
+ *             .build());
+ * CloudRedisStubSettings cloudRedisSettings = cloudRedisSettingsBuilder.build();
+ * 
+ * 
+ */ +@Generated("by gapic-generator") +@BetaApi +public class CloudRedisStubSettings extends StubSettings { + /** The default scopes of the service. */ + private static final ImmutableList DEFAULT_SERVICE_SCOPES = + ImmutableList.builder().add("https://www.googleapis.com/auth/cloud-platform").build(); + + private final UnaryCallSettings createInstanceSettings; + private final OperationCallSettings + createInstanceOperationSettings; + private final UnaryCallSettings updateInstanceSettings; + private final OperationCallSettings + updateInstanceOperationSettings; + private final UnaryCallSettings importInstanceSettings; + private final OperationCallSettings + importInstanceOperationSettings; + private final UnaryCallSettings exportInstanceSettings; + private final OperationCallSettings + exportInstanceOperationSettings; + private final UnaryCallSettings failoverInstanceSettings; + private final OperationCallSettings + failoverInstanceOperationSettings; + private final UnaryCallSettings deleteInstanceSettings; + private final OperationCallSettings + deleteInstanceOperationSettings; + private final PagedCallSettings< + ListInstancesRequest, ListInstancesResponse, ListInstancesPagedResponse> + listInstancesSettings; + private final UnaryCallSettings getInstanceSettings; + private final UnaryCallSettings upgradeInstanceSettings; + private final OperationCallSettings + upgradeInstanceOperationSettings; + + /** Returns the object with the settings used for calls to createInstance. */ + public UnaryCallSettings createInstanceSettings() { + return createInstanceSettings; + } + + /** Returns the object with the settings used for calls to createInstance. */ + @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") + public OperationCallSettings + createInstanceOperationSettings() { + return createInstanceOperationSettings; + } + + /** Returns the object with the settings used for calls to updateInstance. */ + public UnaryCallSettings updateInstanceSettings() { + return updateInstanceSettings; + } + + /** Returns the object with the settings used for calls to updateInstance. */ + @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") + public OperationCallSettings + updateInstanceOperationSettings() { + return updateInstanceOperationSettings; + } + + /** Returns the object with the settings used for calls to importInstance. */ + public UnaryCallSettings importInstanceSettings() { + return importInstanceSettings; + } + + /** Returns the object with the settings used for calls to importInstance. */ + @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") + public OperationCallSettings + importInstanceOperationSettings() { + return importInstanceOperationSettings; + } + + /** Returns the object with the settings used for calls to exportInstance. */ + public UnaryCallSettings exportInstanceSettings() { + return exportInstanceSettings; + } + + /** Returns the object with the settings used for calls to exportInstance. */ + @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") + public OperationCallSettings + exportInstanceOperationSettings() { + return exportInstanceOperationSettings; + } + + /** Returns the object with the settings used for calls to failoverInstance. */ + public UnaryCallSettings failoverInstanceSettings() { + return failoverInstanceSettings; + } + + /** Returns the object with the settings used for calls to failoverInstance. */ + @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") + public OperationCallSettings + failoverInstanceOperationSettings() { + return failoverInstanceOperationSettings; + } + + /** Returns the object with the settings used for calls to deleteInstance. */ + public UnaryCallSettings deleteInstanceSettings() { + return deleteInstanceSettings; + } + + /** Returns the object with the settings used for calls to deleteInstance. */ + @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") + public OperationCallSettings + deleteInstanceOperationSettings() { + return deleteInstanceOperationSettings; + } + + /** Returns the object with the settings used for calls to listInstances. */ + public PagedCallSettings + listInstancesSettings() { + return listInstancesSettings; + } + + /** Returns the object with the settings used for calls to getInstance. */ + public UnaryCallSettings getInstanceSettings() { + return getInstanceSettings; + } + + /** Returns the object with the settings used for calls to upgradeInstance. */ + public UnaryCallSettings upgradeInstanceSettings() { + return upgradeInstanceSettings; + } + + /** Returns the object with the settings used for calls to upgradeInstance. */ + @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") + public OperationCallSettings + upgradeInstanceOperationSettings() { + return upgradeInstanceOperationSettings; + } + + @BetaApi("A restructuring of stub classes is planned, so this may break in the future") + public CloudRedisStub createStub() throws IOException { + if (getTransportChannelProvider() + .getTransportName() + .equals(GrpcTransportChannel.getGrpcTransportName())) { + return GrpcCloudRedisStub.create(this); + } else { + throw new UnsupportedOperationException( + "Transport not supported: " + getTransportChannelProvider().getTransportName()); + } + } + + /** Returns a builder for the default ExecutorProvider for this service. */ + public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() { + return InstantiatingExecutorProvider.newBuilder(); + } + + /** Returns the default service endpoint. */ + public static String getDefaultEndpoint() { + return "redis.googleapis.com:443"; + } + + /** Returns the default service scopes. */ + public static List getDefaultServiceScopes() { + return DEFAULT_SERVICE_SCOPES; + } + + /** Returns a builder for the default credentials for this service. */ + public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder() { + return GoogleCredentialsProvider.newBuilder().setScopesToApply(DEFAULT_SERVICE_SCOPES); + } + + /** Returns a builder for the default ChannelProvider for this service. */ + public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { + return InstantiatingGrpcChannelProvider.newBuilder() + .setMaxInboundMessageSize(Integer.MAX_VALUE); + } + + public static TransportChannelProvider defaultTransportChannelProvider() { + return defaultGrpcTransportProviderBuilder().build(); + } + + @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return ApiClientHeaderProvider.newBuilder() + .setGeneratedLibToken( + "gapic", GaxProperties.getLibraryVersion(CloudRedisStubSettings.class)) + .setTransportToken( + GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion()); + } + + /** Returns a new builder for this class. */ + public static Builder newBuilder() { + return Builder.createDefault(); + } + + /** Returns a new builder for this class. */ + public static Builder newBuilder(ClientContext clientContext) { + return new Builder(clientContext); + } + + /** Returns a builder containing all the values of this settings class. */ + public Builder toBuilder() { + return new Builder(this); + } + + protected CloudRedisStubSettings(Builder settingsBuilder) throws IOException { + super(settingsBuilder); + + createInstanceSettings = settingsBuilder.createInstanceSettings().build(); + createInstanceOperationSettings = settingsBuilder.createInstanceOperationSettings().build(); + updateInstanceSettings = settingsBuilder.updateInstanceSettings().build(); + updateInstanceOperationSettings = settingsBuilder.updateInstanceOperationSettings().build(); + importInstanceSettings = settingsBuilder.importInstanceSettings().build(); + importInstanceOperationSettings = settingsBuilder.importInstanceOperationSettings().build(); + exportInstanceSettings = settingsBuilder.exportInstanceSettings().build(); + exportInstanceOperationSettings = settingsBuilder.exportInstanceOperationSettings().build(); + failoverInstanceSettings = settingsBuilder.failoverInstanceSettings().build(); + failoverInstanceOperationSettings = settingsBuilder.failoverInstanceOperationSettings().build(); + deleteInstanceSettings = settingsBuilder.deleteInstanceSettings().build(); + deleteInstanceOperationSettings = settingsBuilder.deleteInstanceOperationSettings().build(); + listInstancesSettings = settingsBuilder.listInstancesSettings().build(); + getInstanceSettings = settingsBuilder.getInstanceSettings().build(); + upgradeInstanceSettings = settingsBuilder.upgradeInstanceSettings().build(); + upgradeInstanceOperationSettings = settingsBuilder.upgradeInstanceOperationSettings().build(); + } + + private static final PagedListDescriptor + LIST_INSTANCES_PAGE_STR_DESC = + new PagedListDescriptor() { + @Override + public String emptyToken() { + return ""; + } + + @Override + public ListInstancesRequest injectToken(ListInstancesRequest payload, String token) { + return ListInstancesRequest.newBuilder(payload).setPageToken(token).build(); + } + + @Override + public ListInstancesRequest injectPageSize(ListInstancesRequest payload, int pageSize) { + return ListInstancesRequest.newBuilder(payload).setPageSize(pageSize).build(); + } + + @Override + public Integer extractPageSize(ListInstancesRequest payload) { + return payload.getPageSize(); + } + + @Override + public String extractNextToken(ListInstancesResponse payload) { + return payload.getNextPageToken(); + } + + @Override + public Iterable extractResources(ListInstancesResponse payload) { + return payload.getInstancesList() != null + ? payload.getInstancesList() + : ImmutableList.of(); + } + }; + + private static final PagedListResponseFactory< + ListInstancesRequest, ListInstancesResponse, ListInstancesPagedResponse> + LIST_INSTANCES_PAGE_STR_FACT = + new PagedListResponseFactory< + ListInstancesRequest, ListInstancesResponse, ListInstancesPagedResponse>() { + @Override + public ApiFuture getFuturePagedResponse( + UnaryCallable callable, + ListInstancesRequest request, + ApiCallContext context, + ApiFuture futureResponse) { + PageContext pageContext = + PageContext.create(callable, LIST_INSTANCES_PAGE_STR_DESC, request, context); + return ListInstancesPagedResponse.createAsync(pageContext, futureResponse); + } + }; + + /** Builder for CloudRedisStubSettings. */ + public static class Builder extends StubSettings.Builder { + private final ImmutableList> unaryMethodSettingsBuilders; + + private final UnaryCallSettings.Builder + createInstanceSettings; + private final OperationCallSettings.Builder + createInstanceOperationSettings; + private final UnaryCallSettings.Builder + updateInstanceSettings; + private final OperationCallSettings.Builder + updateInstanceOperationSettings; + private final UnaryCallSettings.Builder + importInstanceSettings; + private final OperationCallSettings.Builder + importInstanceOperationSettings; + private final UnaryCallSettings.Builder + exportInstanceSettings; + private final OperationCallSettings.Builder + exportInstanceOperationSettings; + private final UnaryCallSettings.Builder + failoverInstanceSettings; + private final OperationCallSettings.Builder< + FailoverInstanceRequest, Instance, OperationMetadata> + failoverInstanceOperationSettings; + private final UnaryCallSettings.Builder + deleteInstanceSettings; + private final OperationCallSettings.Builder + deleteInstanceOperationSettings; + private final PagedCallSettings.Builder< + ListInstancesRequest, ListInstancesResponse, ListInstancesPagedResponse> + listInstancesSettings; + private final UnaryCallSettings.Builder getInstanceSettings; + private final UnaryCallSettings.Builder + upgradeInstanceSettings; + private final OperationCallSettings.Builder + upgradeInstanceOperationSettings; + + private static final ImmutableMap> + RETRYABLE_CODE_DEFINITIONS; + + static { + ImmutableMap.Builder> definitions = + ImmutableMap.builder(); + definitions.put("no_retry_codes", ImmutableSet.copyOf(Lists.newArrayList())); + definitions.put( + "no_retry_1_codes", ImmutableSet.copyOf(Lists.newArrayList())); + RETRYABLE_CODE_DEFINITIONS = definitions.build(); + } + + private static final ImmutableMap RETRY_PARAM_DEFINITIONS; + + static { + ImmutableMap.Builder definitions = ImmutableMap.builder(); + RetrySettings settings = null; + settings = RetrySettings.newBuilder().setRpcTimeoutMultiplier(1.0).build(); + definitions.put("no_retry_params", settings); + settings = + RetrySettings.newBuilder() + .setInitialRpcTimeout(Duration.ofMillis(600000L)) + .setRpcTimeoutMultiplier(1.0) + .setMaxRpcTimeout(Duration.ofMillis(600000L)) + .setTotalTimeout(Duration.ofMillis(600000L)) + .build(); + definitions.put("no_retry_1_params", settings); + RETRY_PARAM_DEFINITIONS = definitions.build(); + } + + protected Builder() { + this((ClientContext) null); + } + + protected Builder(ClientContext clientContext) { + super(clientContext); + + createInstanceSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + createInstanceOperationSettings = OperationCallSettings.newBuilder(); + + updateInstanceSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + updateInstanceOperationSettings = OperationCallSettings.newBuilder(); + + importInstanceSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + importInstanceOperationSettings = OperationCallSettings.newBuilder(); + + exportInstanceSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + exportInstanceOperationSettings = OperationCallSettings.newBuilder(); + + failoverInstanceSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + failoverInstanceOperationSettings = OperationCallSettings.newBuilder(); + + deleteInstanceSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + deleteInstanceOperationSettings = OperationCallSettings.newBuilder(); + + listInstancesSettings = PagedCallSettings.newBuilder(LIST_INSTANCES_PAGE_STR_FACT); + + getInstanceSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + upgradeInstanceSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + upgradeInstanceOperationSettings = OperationCallSettings.newBuilder(); + + unaryMethodSettingsBuilders = + ImmutableList.>of( + createInstanceSettings, + updateInstanceSettings, + importInstanceSettings, + exportInstanceSettings, + failoverInstanceSettings, + deleteInstanceSettings, + listInstancesSettings, + getInstanceSettings, + upgradeInstanceSettings); + + initDefaults(this); + } + + private static Builder createDefault() { + Builder builder = new Builder((ClientContext) null); + builder.setTransportChannelProvider(defaultTransportChannelProvider()); + builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build()); + builder.setInternalHeaderProvider(defaultApiClientHeaderProviderBuilder().build()); + builder.setEndpoint(getDefaultEndpoint()); + return initDefaults(builder); + } + + private static Builder initDefaults(Builder builder) { + + builder + .createInstanceSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_1_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_1_params")); + + builder + .updateInstanceSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_1_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_1_params")); + + builder + .importInstanceSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_1_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_1_params")); + + builder + .exportInstanceSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_1_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_1_params")); + + builder + .failoverInstanceSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_1_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_1_params")); + + builder + .deleteInstanceSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_1_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_1_params")); + + builder + .listInstancesSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_1_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_1_params")); + + builder + .getInstanceSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_1_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_1_params")); + + builder + .upgradeInstanceSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_1_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_1_params")); + builder + .createInstanceOperationSettings() + .setInitialCallSettings( + UnaryCallSettings + .newUnaryCallSettingsBuilder() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_1_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_1_params")) + .build()) + .setResponseTransformer( + ProtoOperationTransformers.ResponseTransformer.create(Instance.class)) + .setMetadataTransformer( + ProtoOperationTransformers.MetadataTransformer.create(OperationMetadata.class)) + .setPollingAlgorithm( + OperationTimedPollAlgorithm.create( + RetrySettings.newBuilder() + .setInitialRetryDelay(Duration.ofMillis(60000L)) + .setRetryDelayMultiplier(1.5) + .setMaxRetryDelay(Duration.ofMillis(360000L)) + .setInitialRpcTimeout(Duration.ZERO) // ignored + .setRpcTimeoutMultiplier(1.0) // ignored + .setMaxRpcTimeout(Duration.ZERO) // ignored + .setTotalTimeout(Duration.ofMillis(7200000L)) + .build())); + builder + .updateInstanceOperationSettings() + .setInitialCallSettings( + UnaryCallSettings + .newUnaryCallSettingsBuilder() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_1_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_1_params")) + .build()) + .setResponseTransformer( + ProtoOperationTransformers.ResponseTransformer.create(Instance.class)) + .setMetadataTransformer( + ProtoOperationTransformers.MetadataTransformer.create(OperationMetadata.class)) + .setPollingAlgorithm( + OperationTimedPollAlgorithm.create( + RetrySettings.newBuilder() + .setInitialRetryDelay(Duration.ofMillis(60000L)) + .setRetryDelayMultiplier(1.5) + .setMaxRetryDelay(Duration.ofMillis(360000L)) + .setInitialRpcTimeout(Duration.ZERO) // ignored + .setRpcTimeoutMultiplier(1.0) // ignored + .setMaxRpcTimeout(Duration.ZERO) // ignored + .setTotalTimeout(Duration.ofMillis(7200000L)) + .build())); + builder + .importInstanceOperationSettings() + .setInitialCallSettings( + UnaryCallSettings + .newUnaryCallSettingsBuilder() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_1_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_1_params")) + .build()) + .setResponseTransformer( + ProtoOperationTransformers.ResponseTransformer.create(Instance.class)) + .setMetadataTransformer( + ProtoOperationTransformers.MetadataTransformer.create(OperationMetadata.class)) + .setPollingAlgorithm( + OperationTimedPollAlgorithm.create( + RetrySettings.newBuilder() + .setInitialRetryDelay(Duration.ofMillis(60000L)) + .setRetryDelayMultiplier(1.5) + .setMaxRetryDelay(Duration.ofMillis(360000L)) + .setInitialRpcTimeout(Duration.ZERO) // ignored + .setRpcTimeoutMultiplier(1.0) // ignored + .setMaxRpcTimeout(Duration.ZERO) // ignored + .setTotalTimeout(Duration.ofMillis(18000000L)) + .build())); + builder + .exportInstanceOperationSettings() + .setInitialCallSettings( + UnaryCallSettings + .newUnaryCallSettingsBuilder() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_1_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_1_params")) + .build()) + .setResponseTransformer( + ProtoOperationTransformers.ResponseTransformer.create(Instance.class)) + .setMetadataTransformer( + ProtoOperationTransformers.MetadataTransformer.create(OperationMetadata.class)) + .setPollingAlgorithm( + OperationTimedPollAlgorithm.create( + RetrySettings.newBuilder() + .setInitialRetryDelay(Duration.ofMillis(60000L)) + .setRetryDelayMultiplier(1.5) + .setMaxRetryDelay(Duration.ofMillis(360000L)) + .setInitialRpcTimeout(Duration.ZERO) // ignored + .setRpcTimeoutMultiplier(1.0) // ignored + .setMaxRpcTimeout(Duration.ZERO) // ignored + .setTotalTimeout(Duration.ofMillis(18000000L)) + .build())); + builder + .failoverInstanceOperationSettings() + .setInitialCallSettings( + UnaryCallSettings + .newUnaryCallSettingsBuilder() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_1_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_1_params")) + .build()) + .setResponseTransformer( + ProtoOperationTransformers.ResponseTransformer.create(Instance.class)) + .setMetadataTransformer( + ProtoOperationTransformers.MetadataTransformer.create(OperationMetadata.class)) + .setPollingAlgorithm( + OperationTimedPollAlgorithm.create( + RetrySettings.newBuilder() + .setInitialRetryDelay(Duration.ofMillis(60000L)) + .setRetryDelayMultiplier(1.5) + .setMaxRetryDelay(Duration.ofMillis(360000L)) + .setInitialRpcTimeout(Duration.ZERO) // ignored + .setRpcTimeoutMultiplier(1.0) // ignored + .setMaxRpcTimeout(Duration.ZERO) // ignored + .setTotalTimeout(Duration.ofMillis(1200000L)) + .build())); + builder + .deleteInstanceOperationSettings() + .setInitialCallSettings( + UnaryCallSettings + .newUnaryCallSettingsBuilder() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_1_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_1_params")) + .build()) + .setResponseTransformer( + ProtoOperationTransformers.ResponseTransformer.create(Empty.class)) + .setMetadataTransformer( + ProtoOperationTransformers.MetadataTransformer.create(OperationMetadata.class)) + .setPollingAlgorithm( + OperationTimedPollAlgorithm.create( + RetrySettings.newBuilder() + .setInitialRetryDelay(Duration.ofMillis(60000L)) + .setRetryDelayMultiplier(1.5) + .setMaxRetryDelay(Duration.ofMillis(360000L)) + .setInitialRpcTimeout(Duration.ZERO) // ignored + .setRpcTimeoutMultiplier(1.0) // ignored + .setMaxRpcTimeout(Duration.ZERO) // ignored + .setTotalTimeout(Duration.ofMillis(1200000L)) + .build())); + builder + .upgradeInstanceOperationSettings() + .setInitialCallSettings( + UnaryCallSettings + .newUnaryCallSettingsBuilder() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_1_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_1_params")) + .build()) + .setResponseTransformer( + ProtoOperationTransformers.ResponseTransformer.create(Instance.class)) + .setMetadataTransformer( + ProtoOperationTransformers.MetadataTransformer.create(OperationMetadata.class)) + .setPollingAlgorithm( + OperationTimedPollAlgorithm.create( + RetrySettings.newBuilder() + .setInitialRetryDelay(Duration.ofMillis(500L)) + .setRetryDelayMultiplier(1.5) + .setMaxRetryDelay(Duration.ofMillis(5000L)) + .setInitialRpcTimeout(Duration.ZERO) // ignored + .setRpcTimeoutMultiplier(1.0) // ignored + .setMaxRpcTimeout(Duration.ZERO) // ignored + .setTotalTimeout(Duration.ofMillis(300000L)) + .build())); + + return builder; + } + + protected Builder(CloudRedisStubSettings settings) { + super(settings); + + createInstanceSettings = settings.createInstanceSettings.toBuilder(); + createInstanceOperationSettings = settings.createInstanceOperationSettings.toBuilder(); + updateInstanceSettings = settings.updateInstanceSettings.toBuilder(); + updateInstanceOperationSettings = settings.updateInstanceOperationSettings.toBuilder(); + importInstanceSettings = settings.importInstanceSettings.toBuilder(); + importInstanceOperationSettings = settings.importInstanceOperationSettings.toBuilder(); + exportInstanceSettings = settings.exportInstanceSettings.toBuilder(); + exportInstanceOperationSettings = settings.exportInstanceOperationSettings.toBuilder(); + failoverInstanceSettings = settings.failoverInstanceSettings.toBuilder(); + failoverInstanceOperationSettings = settings.failoverInstanceOperationSettings.toBuilder(); + deleteInstanceSettings = settings.deleteInstanceSettings.toBuilder(); + deleteInstanceOperationSettings = settings.deleteInstanceOperationSettings.toBuilder(); + listInstancesSettings = settings.listInstancesSettings.toBuilder(); + getInstanceSettings = settings.getInstanceSettings.toBuilder(); + upgradeInstanceSettings = settings.upgradeInstanceSettings.toBuilder(); + upgradeInstanceOperationSettings = settings.upgradeInstanceOperationSettings.toBuilder(); + + unaryMethodSettingsBuilders = + ImmutableList.>of( + createInstanceSettings, + updateInstanceSettings, + importInstanceSettings, + exportInstanceSettings, + failoverInstanceSettings, + deleteInstanceSettings, + listInstancesSettings, + getInstanceSettings, + upgradeInstanceSettings); + } + + // NEXT_MAJOR_VER: remove 'throws Exception' + /** + * Applies the given settings updater function to all of the unary API methods in this service. + * + *

Note: This method does not support applying settings to streaming methods. + */ + public Builder applyToAllUnaryMethods( + ApiFunction, Void> settingsUpdater) throws Exception { + super.applyToAllUnaryMethods(unaryMethodSettingsBuilders, settingsUpdater); + return this; + } + + public ImmutableList> unaryMethodSettingsBuilders() { + return unaryMethodSettingsBuilders; + } + + /** Returns the builder for the settings used for calls to createInstance. */ + public UnaryCallSettings.Builder createInstanceSettings() { + return createInstanceSettings; + } + + /** Returns the builder for the settings used for calls to createInstance. */ + @BetaApi( + "The surface for use by generated code is not stable yet and may change in the future.") + public OperationCallSettings.Builder + createInstanceOperationSettings() { + return createInstanceOperationSettings; + } + + /** Returns the builder for the settings used for calls to updateInstance. */ + public UnaryCallSettings.Builder updateInstanceSettings() { + return updateInstanceSettings; + } + + /** Returns the builder for the settings used for calls to updateInstance. */ + @BetaApi( + "The surface for use by generated code is not stable yet and may change in the future.") + public OperationCallSettings.Builder + updateInstanceOperationSettings() { + return updateInstanceOperationSettings; + } + + /** Returns the builder for the settings used for calls to importInstance. */ + public UnaryCallSettings.Builder importInstanceSettings() { + return importInstanceSettings; + } + + /** Returns the builder for the settings used for calls to importInstance. */ + @BetaApi( + "The surface for use by generated code is not stable yet and may change in the future.") + public OperationCallSettings.Builder + importInstanceOperationSettings() { + return importInstanceOperationSettings; + } + + /** Returns the builder for the settings used for calls to exportInstance. */ + public UnaryCallSettings.Builder exportInstanceSettings() { + return exportInstanceSettings; + } + + /** Returns the builder for the settings used for calls to exportInstance. */ + @BetaApi( + "The surface for use by generated code is not stable yet and may change in the future.") + public OperationCallSettings.Builder + exportInstanceOperationSettings() { + return exportInstanceOperationSettings; + } + + /** Returns the builder for the settings used for calls to failoverInstance. */ + public UnaryCallSettings.Builder + failoverInstanceSettings() { + return failoverInstanceSettings; + } + + /** Returns the builder for the settings used for calls to failoverInstance. */ + @BetaApi( + "The surface for use by generated code is not stable yet and may change in the future.") + public OperationCallSettings.Builder + failoverInstanceOperationSettings() { + return failoverInstanceOperationSettings; + } + + /** Returns the builder for the settings used for calls to deleteInstance. */ + public UnaryCallSettings.Builder deleteInstanceSettings() { + return deleteInstanceSettings; + } + + /** Returns the builder for the settings used for calls to deleteInstance. */ + @BetaApi( + "The surface for use by generated code is not stable yet and may change in the future.") + public OperationCallSettings.Builder + deleteInstanceOperationSettings() { + return deleteInstanceOperationSettings; + } + + /** Returns the builder for the settings used for calls to listInstances. */ + public PagedCallSettings.Builder< + ListInstancesRequest, ListInstancesResponse, ListInstancesPagedResponse> + listInstancesSettings() { + return listInstancesSettings; + } + + /** Returns the builder for the settings used for calls to getInstance. */ + public UnaryCallSettings.Builder getInstanceSettings() { + return getInstanceSettings; + } + + /** Returns the builder for the settings used for calls to upgradeInstance. */ + public UnaryCallSettings.Builder upgradeInstanceSettings() { + return upgradeInstanceSettings; + } + + /** Returns the builder for the settings used for calls to upgradeInstance. */ + @BetaApi( + "The surface for use by generated code is not stable yet and may change in the future.") + public OperationCallSettings.Builder + upgradeInstanceOperationSettings() { + return upgradeInstanceOperationSettings; + } + + @Override + public CloudRedisStubSettings build() throws IOException { + return new CloudRedisStubSettings(this); + } + } +} diff --git a/test/integration/goldens/redis/GrpcCloudRedisCallableFactory.java b/test/integration/goldens/redis/GrpcCloudRedisCallableFactory.java new file mode 100644 index 0000000000..49a6cf4b7f --- /dev/null +++ b/test/integration/goldens/redis/GrpcCloudRedisCallableFactory.java @@ -0,0 +1,115 @@ +/* + * 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. + */ +package com.google.cloud.redis.v1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * gRPC callable factory implementation for Google Cloud Memorystore for Redis API. + * + *

This class is for advanced usage. + */ +@Generated("by gapic-generator") +@BetaApi("The surface for use by generated code is not stable yet and may change in the future.") +public class GrpcCloudRedisCallableFactory implements GrpcStubCallableFactory { + @Override + public UnaryCallable createUnaryCallable( + GrpcCallSettings grpcCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createUnaryCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + GrpcCallSettings grpcCallSettings, + PagedCallSettings pagedCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createPagedCallable( + grpcCallSettings, pagedCallSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + GrpcCallSettings grpcCallSettings, + BatchingCallSettings batchingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBatchingCallable( + grpcCallSettings, batchingCallSettings, clientContext); + } + + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + @Override + public + OperationCallable createOperationCallable( + GrpcCallSettings grpcCallSettings, + OperationCallSettings operationCallSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + return GrpcCallableFactory.createOperationCallable( + grpcCallSettings, operationCallSettings, clientContext, operationsStub); + } + + @Override + public + BidiStreamingCallable createBidiStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBidiStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + GrpcCallSettings grpcCallSettings, + ServerStreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createServerStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } + + @Override + public + ClientStreamingCallable createClientStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings streamingCallSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createClientStreamingCallable( + grpcCallSettings, streamingCallSettings, clientContext); + } +} diff --git a/test/integration/goldens/redis/GrpcCloudRedisStub.java b/test/integration/goldens/redis/GrpcCloudRedisStub.java new file mode 100644 index 0000000000..ceb42c9a1b --- /dev/null +++ b/test/integration/goldens/redis/GrpcCloudRedisStub.java @@ -0,0 +1,523 @@ +/* + * 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. + */ +package com.google.cloud.redis.v1.stub; + +import static com.google.cloud.redis.v1.CloudRedisClient.ListInstancesPagedResponse; + +import com.google.api.core.BetaApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.core.BackgroundResourceAggregation; +import com.google.api.gax.grpc.GrpcCallSettings; +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; +import com.google.cloud.redis.v1.ExportInstanceRequest; +import com.google.cloud.redis.v1.FailoverInstanceRequest; +import com.google.cloud.redis.v1.GetInstanceRequest; +import com.google.cloud.redis.v1.ImportInstanceRequest; +import com.google.cloud.redis.v1.Instance; +import com.google.cloud.redis.v1.ListInstancesRequest; +import com.google.cloud.redis.v1.ListInstancesResponse; +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; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * gRPC stub implementation for Google Cloud Memorystore for Redis API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@Generated("by gapic-generator") +@BetaApi("A restructuring of stub classes is planned, so this may break in the future") +public class GrpcCloudRedisStub extends CloudRedisStub { + + private static final MethodDescriptor + createInstanceMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.cloud.redis.v1.CloudRedis/CreateInstance") + .setRequestMarshaller( + ProtoUtils.marshaller(CreateInstanceRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Operation.getDefaultInstance())) + .build(); + private static final MethodDescriptor + updateInstanceMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.cloud.redis.v1.CloudRedis/UpdateInstance") + .setRequestMarshaller( + ProtoUtils.marshaller(UpdateInstanceRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Operation.getDefaultInstance())) + .build(); + private static final MethodDescriptor + importInstanceMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.cloud.redis.v1.CloudRedis/ImportInstance") + .setRequestMarshaller( + ProtoUtils.marshaller(ImportInstanceRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Operation.getDefaultInstance())) + .build(); + private static final MethodDescriptor + exportInstanceMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.cloud.redis.v1.CloudRedis/ExportInstance") + .setRequestMarshaller( + ProtoUtils.marshaller(ExportInstanceRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Operation.getDefaultInstance())) + .build(); + private static final MethodDescriptor + failoverInstanceMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.cloud.redis.v1.CloudRedis/FailoverInstance") + .setRequestMarshaller( + ProtoUtils.marshaller(FailoverInstanceRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Operation.getDefaultInstance())) + .build(); + private static final MethodDescriptor + deleteInstanceMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.cloud.redis.v1.CloudRedis/DeleteInstance") + .setRequestMarshaller( + ProtoUtils.marshaller(DeleteInstanceRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Operation.getDefaultInstance())) + .build(); + private static final MethodDescriptor + listInstancesMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.cloud.redis.v1.CloudRedis/ListInstances") + .setRequestMarshaller( + ProtoUtils.marshaller(ListInstancesRequest.getDefaultInstance())) + .setResponseMarshaller( + ProtoUtils.marshaller(ListInstancesResponse.getDefaultInstance())) + .build(); + private static final MethodDescriptor getInstanceMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.cloud.redis.v1.CloudRedis/GetInstance") + .setRequestMarshaller(ProtoUtils.marshaller(GetInstanceRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Instance.getDefaultInstance())) + .build(); + private static final MethodDescriptor + upgradeInstanceMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.cloud.redis.v1.CloudRedis/UpgradeInstance") + .setRequestMarshaller( + ProtoUtils.marshaller(UpgradeInstanceRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Operation.getDefaultInstance())) + .build(); + + private final BackgroundResource backgroundResources; + private final GrpcOperationsStub operationsStub; + + private final UnaryCallable createInstanceCallable; + private final OperationCallable + createInstanceOperationCallable; + private final UnaryCallable updateInstanceCallable; + private final OperationCallable + updateInstanceOperationCallable; + private final UnaryCallable importInstanceCallable; + private final OperationCallable + importInstanceOperationCallable; + private final UnaryCallable exportInstanceCallable; + private final OperationCallable + exportInstanceOperationCallable; + private final UnaryCallable failoverInstanceCallable; + private final OperationCallable + failoverInstanceOperationCallable; + private final UnaryCallable deleteInstanceCallable; + private final OperationCallable + deleteInstanceOperationCallable; + private final UnaryCallable listInstancesCallable; + private final UnaryCallable + listInstancesPagedCallable; + private final UnaryCallable getInstanceCallable; + private final UnaryCallable upgradeInstanceCallable; + private final OperationCallable + upgradeInstanceOperationCallable; + + private final GrpcStubCallableFactory callableFactory; + + public static final GrpcCloudRedisStub create(CloudRedisStubSettings settings) + throws IOException { + return new GrpcCloudRedisStub(settings, ClientContext.create(settings)); + } + + public static final GrpcCloudRedisStub create(ClientContext clientContext) throws IOException { + return new GrpcCloudRedisStub(CloudRedisStubSettings.newBuilder().build(), clientContext); + } + + public static final GrpcCloudRedisStub create( + ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { + return new GrpcCloudRedisStub( + CloudRedisStubSettings.newBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of GrpcCloudRedisStub, using the given settings. This is protected so + * that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected GrpcCloudRedisStub(CloudRedisStubSettings settings, ClientContext clientContext) + throws IOException { + this(settings, clientContext, new GrpcCloudRedisCallableFactory()); + } + + /** + * Constructs an instance of GrpcCloudRedisStub, using the given settings. This is protected so + * that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected GrpcCloudRedisStub( + CloudRedisStubSettings settings, + ClientContext clientContext, + GrpcStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory); + + 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 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(); + 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 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(); + + this.createInstanceCallable = + callableFactory.createUnaryCallable( + createInstanceTransportSettings, settings.createInstanceSettings(), clientContext); + this.createInstanceOperationCallable = + callableFactory.createOperationCallable( + createInstanceTransportSettings, + settings.createInstanceOperationSettings(), + clientContext, + this.operationsStub); + this.updateInstanceCallable = + callableFactory.createUnaryCallable( + updateInstanceTransportSettings, settings.updateInstanceSettings(), clientContext); + this.updateInstanceOperationCallable = + callableFactory.createOperationCallable( + updateInstanceTransportSettings, + settings.updateInstanceOperationSettings(), + clientContext, + this.operationsStub); + this.importInstanceCallable = + callableFactory.createUnaryCallable( + importInstanceTransportSettings, settings.importInstanceSettings(), clientContext); + this.importInstanceOperationCallable = + callableFactory.createOperationCallable( + importInstanceTransportSettings, + settings.importInstanceOperationSettings(), + clientContext, + this.operationsStub); + this.exportInstanceCallable = + callableFactory.createUnaryCallable( + exportInstanceTransportSettings, settings.exportInstanceSettings(), clientContext); + this.exportInstanceOperationCallable = + callableFactory.createOperationCallable( + exportInstanceTransportSettings, + settings.exportInstanceOperationSettings(), + clientContext, + this.operationsStub); + this.failoverInstanceCallable = + callableFactory.createUnaryCallable( + failoverInstanceTransportSettings, settings.failoverInstanceSettings(), clientContext); + this.failoverInstanceOperationCallable = + callableFactory.createOperationCallable( + failoverInstanceTransportSettings, + settings.failoverInstanceOperationSettings(), + clientContext, + this.operationsStub); + this.deleteInstanceCallable = + callableFactory.createUnaryCallable( + deleteInstanceTransportSettings, settings.deleteInstanceSettings(), clientContext); + this.deleteInstanceOperationCallable = + callableFactory.createOperationCallable( + deleteInstanceTransportSettings, + settings.deleteInstanceOperationSettings(), + clientContext, + this.operationsStub); + this.listInstancesCallable = + callableFactory.createUnaryCallable( + listInstancesTransportSettings, settings.listInstancesSettings(), clientContext); + this.listInstancesPagedCallable = + callableFactory.createPagedCallable( + listInstancesTransportSettings, settings.listInstancesSettings(), clientContext); + this.getInstanceCallable = + callableFactory.createUnaryCallable( + getInstanceTransportSettings, settings.getInstanceSettings(), clientContext); + this.upgradeInstanceCallable = + callableFactory.createUnaryCallable( + upgradeInstanceTransportSettings, settings.upgradeInstanceSettings(), clientContext); + this.upgradeInstanceOperationCallable = + callableFactory.createOperationCallable( + upgradeInstanceTransportSettings, + settings.upgradeInstanceOperationSettings(), + clientContext, + this.operationsStub); + + backgroundResources = new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") + public GrpcOperationsStub getOperationsStub() { + return operationsStub; + } + + @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") + public OperationCallable + createInstanceOperationCallable() { + return createInstanceOperationCallable; + } + + public UnaryCallable createInstanceCallable() { + return createInstanceCallable; + } + + @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") + public OperationCallable + updateInstanceOperationCallable() { + return updateInstanceOperationCallable; + } + + public UnaryCallable updateInstanceCallable() { + return updateInstanceCallable; + } + + @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") + public OperationCallable + importInstanceOperationCallable() { + return importInstanceOperationCallable; + } + + public UnaryCallable importInstanceCallable() { + return importInstanceCallable; + } + + @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") + public OperationCallable + exportInstanceOperationCallable() { + return exportInstanceOperationCallable; + } + + public UnaryCallable exportInstanceCallable() { + return exportInstanceCallable; + } + + @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") + public OperationCallable + failoverInstanceOperationCallable() { + return failoverInstanceOperationCallable; + } + + public UnaryCallable failoverInstanceCallable() { + return failoverInstanceCallable; + } + + @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") + public OperationCallable + deleteInstanceOperationCallable() { + return deleteInstanceOperationCallable; + } + + public UnaryCallable deleteInstanceCallable() { + return deleteInstanceCallable; + } + + public UnaryCallable + listInstancesPagedCallable() { + return listInstancesPagedCallable; + } + + public UnaryCallable listInstancesCallable() { + return listInstancesCallable; + } + + public UnaryCallable getInstanceCallable() { + return getInstanceCallable; + } + + @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") + public OperationCallable + upgradeInstanceOperationCallable() { + return upgradeInstanceOperationCallable; + } + + public UnaryCallable upgradeInstanceCallable() { + return upgradeInstanceCallable; + } + + @Override + public final void close() { + shutdown(); + } + + @Override + public void shutdown() { + backgroundResources.shutdown(); + } + + @Override + public boolean isShutdown() { + return backgroundResources.isShutdown(); + } + + @Override + public boolean isTerminated() { + return backgroundResources.isTerminated(); + } + + @Override + public void shutdownNow() { + backgroundResources.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return backgroundResources.awaitTermination(duration, unit); + } +} diff --git a/test/integration/goldens/redis/InstanceName.java b/test/integration/goldens/redis/InstanceName.java new file mode 100644 index 0000000000..7653fd9799 --- /dev/null +++ b/test/integration/goldens/redis/InstanceName.java @@ -0,0 +1,214 @@ +/* + * Copyright 2018 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 + * + * http://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. + */ + +package com.google.cloud.redis.v1; + +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableMap; +import com.google.api.pathtemplate.PathTemplate; +import com.google.api.resourcenames.ResourceName; +import java.util.Map; +import java.util.ArrayList; +import java.util.List; + +/** + * AUTO-GENERATED DOCUMENTATION AND CLASS + */ +@javax.annotation.Generated("by GAPIC protoc plugin") +public class InstanceName implements ResourceName { + + private static final PathTemplate PATH_TEMPLATE = + PathTemplate.createWithoutUrlEncoding("projects/{project}/locations/{location}/instances/{instance}"); + + private volatile Map fieldValuesMap; + + private final String project; + private final String location; + private final String instance; + + public String getProject() { + return project; + } + + public String getLocation() { + return location; + } + + public String getInstance() { + return instance; + } + + public static Builder newBuilder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder(this); + } + + private InstanceName(Builder builder) { + project = Preconditions.checkNotNull(builder.getProject()); + location = Preconditions.checkNotNull(builder.getLocation()); + instance = Preconditions.checkNotNull(builder.getInstance()); + } + + public static InstanceName of(String project, String location, String instance) { + return newBuilder() + .setProject(project) + .setLocation(location) + .setInstance(instance) + .build(); + } + + public static String format(String project, String location, String instance) { + return newBuilder() + .setProject(project) + .setLocation(location) + .setInstance(instance) + .build() + .toString(); + } + + public static InstanceName parse(String formattedString) { + if (formattedString.isEmpty()) { + return null; + } + Map matchMap = + PATH_TEMPLATE.validatedMatch(formattedString, "InstanceName.parse: formattedString not in valid format"); + return of(matchMap.get("project"), matchMap.get("location"), matchMap.get("instance")); + } + + public static List parseList(List formattedStrings) { + List list = new ArrayList<>(formattedStrings.size()); + for (String formattedString : formattedStrings) { + list.add(parse(formattedString)); + } + return list; + } + + public static List toStringList(List values) { + List list = new ArrayList(values.size()); + for (InstanceName value : values) { + if (value == null) { + list.add(""); + } else { + list.add(value.toString()); + } + } + return list; + } + + public static boolean isParsableFrom(String formattedString) { + return PATH_TEMPLATE.matches(formattedString); + } + + public Map getFieldValuesMap() { + if (fieldValuesMap == null) { + synchronized (this) { + if (fieldValuesMap == null) { + ImmutableMap.Builder fieldMapBuilder = ImmutableMap.builder(); + fieldMapBuilder.put("project", project); + fieldMapBuilder.put("location", location); + fieldMapBuilder.put("instance", instance); + fieldValuesMap = fieldMapBuilder.build(); + } + } + } + return fieldValuesMap; + } + + public String getFieldValue(String fieldName) { + return getFieldValuesMap().get(fieldName); + } + + @Override + public String toString() { + return PATH_TEMPLATE.instantiate("project", project, "location", location, "instance", instance); + } + + /** Builder for InstanceName. */ + public static class Builder { + + private String project; + private String location; + private String instance; + + public String getProject() { + return project; + } + + public String getLocation() { + return location; + } + + public String getInstance() { + return instance; + } + + public Builder setProject(String project) { + this.project = project; + return this; + } + + public Builder setLocation(String location) { + this.location = location; + return this; + } + + public Builder setInstance(String instance) { + this.instance = instance; + return this; + } + + private Builder() { + } + + private Builder(InstanceName instanceName) { + project = instanceName.project; + location = instanceName.location; + instance = instanceName.instance; + } + + public InstanceName build() { + return new InstanceName(this); + } + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (o instanceof InstanceName) { + InstanceName that = (InstanceName) o; + return (this.project.equals(that.project)) + && (this.location.equals(that.location)) + && (this.instance.equals(that.instance)); + } + return false; + } + + @Override + public int hashCode() { + int h = 1; + h *= 1000003; + h ^= project.hashCode(); + h *= 1000003; + h ^= location.hashCode(); + h *= 1000003; + h ^= instance.hashCode(); + return h; + } +} + diff --git a/test/integration/goldens/redis/LocationName.java b/test/integration/goldens/redis/LocationName.java new file mode 100644 index 0000000000..54b551b3f1 --- /dev/null +++ b/test/integration/goldens/redis/LocationName.java @@ -0,0 +1,191 @@ +/* + * Copyright 2018 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 + * + * http://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. + */ + +package com.google.cloud.redis.v1; + +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableMap; +import com.google.api.pathtemplate.PathTemplate; +import com.google.api.resourcenames.ResourceName; +import java.util.Map; +import java.util.ArrayList; +import java.util.List; + +/** + * AUTO-GENERATED DOCUMENTATION AND CLASS + */ +@javax.annotation.Generated("by GAPIC protoc plugin") +public class LocationName implements ResourceName { + + private static final PathTemplate PATH_TEMPLATE = + PathTemplate.createWithoutUrlEncoding("projects/{project}/locations/{location}"); + + private volatile Map fieldValuesMap; + + private final String project; + private final String location; + + public String getProject() { + return project; + } + + public String getLocation() { + return location; + } + + public static Builder newBuilder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder(this); + } + + private LocationName(Builder builder) { + project = Preconditions.checkNotNull(builder.getProject()); + location = Preconditions.checkNotNull(builder.getLocation()); + } + + public static LocationName of(String project, String location) { + return newBuilder() + .setProject(project) + .setLocation(location) + .build(); + } + + public static String format(String project, String location) { + return newBuilder() + .setProject(project) + .setLocation(location) + .build() + .toString(); + } + + public static LocationName parse(String formattedString) { + if (formattedString.isEmpty()) { + return null; + } + Map matchMap = + PATH_TEMPLATE.validatedMatch(formattedString, "LocationName.parse: formattedString not in valid format"); + return of(matchMap.get("project"), matchMap.get("location")); + } + + public static List parseList(List formattedStrings) { + List list = new ArrayList<>(formattedStrings.size()); + for (String formattedString : formattedStrings) { + list.add(parse(formattedString)); + } + return list; + } + + public static List toStringList(List values) { + List list = new ArrayList(values.size()); + for (LocationName value : values) { + if (value == null) { + list.add(""); + } else { + list.add(value.toString()); + } + } + return list; + } + + public static boolean isParsableFrom(String formattedString) { + return PATH_TEMPLATE.matches(formattedString); + } + + public Map getFieldValuesMap() { + if (fieldValuesMap == null) { + synchronized (this) { + if (fieldValuesMap == null) { + ImmutableMap.Builder fieldMapBuilder = ImmutableMap.builder(); + fieldMapBuilder.put("project", project); + fieldMapBuilder.put("location", location); + fieldValuesMap = fieldMapBuilder.build(); + } + } + } + return fieldValuesMap; + } + + public String getFieldValue(String fieldName) { + return getFieldValuesMap().get(fieldName); + } + + @Override + public String toString() { + return PATH_TEMPLATE.instantiate("project", project, "location", location); + } + + /** Builder for LocationName. */ + public static class Builder { + + private String project; + private String location; + + public String getProject() { + return project; + } + + public String getLocation() { + return location; + } + + public Builder setProject(String project) { + this.project = project; + return this; + } + + public Builder setLocation(String location) { + this.location = location; + return this; + } + + private Builder() { + } + + private Builder(LocationName locationName) { + project = locationName.project; + location = locationName.location; + } + + public LocationName build() { + return new LocationName(this); + } + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (o instanceof LocationName) { + LocationName that = (LocationName) o; + return (this.project.equals(that.project)) + && (this.location.equals(that.location)); + } + return false; + } + + @Override + public int hashCode() { + int h = 1; + h *= 1000003; + h ^= project.hashCode(); + h *= 1000003; + h ^= location.hashCode(); + return h; + } +} + diff --git a/test/integration/goldens/redis/MockCloudRedis.java b/test/integration/goldens/redis/MockCloudRedis.java new file mode 100644 index 0000000000..9145045390 --- /dev/null +++ b/test/integration/goldens/redis/MockCloudRedis.java @@ -0,0 +1,57 @@ +/* + * 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. + */ +package com.google.cloud.redis.v1; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.testing.MockGrpcService; +import com.google.protobuf.AbstractMessage; +import io.grpc.ServerServiceDefinition; +import java.util.List; + +@javax.annotation.Generated("by GAPIC") +@BetaApi +public class MockCloudRedis implements MockGrpcService { + private final MockCloudRedisImpl serviceImpl; + + public MockCloudRedis() { + serviceImpl = new MockCloudRedisImpl(); + } + + @Override + public List getRequests() { + return serviceImpl.getRequests(); + } + + @Override + public void addResponse(AbstractMessage response) { + serviceImpl.addResponse(response); + } + + @Override + public void addException(Exception exception) { + serviceImpl.addException(exception); + } + + @Override + public ServerServiceDefinition getServiceDefinition() { + return serviceImpl.bindService(); + } + + @Override + public void reset() { + serviceImpl.reset(); + } +} diff --git a/test/integration/goldens/redis/MockCloudRedisImpl.java b/test/integration/goldens/redis/MockCloudRedisImpl.java new file mode 100644 index 0000000000..c81719e881 --- /dev/null +++ b/test/integration/goldens/redis/MockCloudRedisImpl.java @@ -0,0 +1,193 @@ +/* + * 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. + */ +package com.google.cloud.redis.v1; + +import com.google.api.core.BetaApi; +import com.google.cloud.redis.v1.CloudRedisGrpc.CloudRedisImplBase; +import com.google.longrunning.Operation; +import com.google.protobuf.AbstractMessage; +import io.grpc.stub.StreamObserver; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; + +@javax.annotation.Generated("by GAPIC") +@BetaApi +public class MockCloudRedisImpl extends CloudRedisImplBase { + private List requests; + private Queue responses; + + public MockCloudRedisImpl() { + requests = new ArrayList<>(); + responses = new LinkedList<>(); + } + + public List getRequests() { + return requests; + } + + public void addResponse(AbstractMessage response) { + responses.add(response); + } + + public void setResponses(List responses) { + this.responses = new LinkedList(responses); + } + + public void addException(Exception exception) { + responses.add(exception); + } + + public void reset() { + requests = new ArrayList<>(); + responses = new LinkedList<>(); + } + + @Override + public void listInstances( + ListInstancesRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof ListInstancesResponse) { + requests.add(request); + responseObserver.onNext((ListInstancesResponse) response); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError((Exception) response); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void getInstance(GetInstanceRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof Instance) { + requests.add(request); + responseObserver.onNext((Instance) response); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError((Exception) response); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void createInstance( + CreateInstanceRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof Operation) { + requests.add(request); + responseObserver.onNext((Operation) response); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError((Exception) response); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void updateInstance( + UpdateInstanceRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof Operation) { + requests.add(request); + responseObserver.onNext((Operation) response); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError((Exception) response); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void upgradeInstance( + UpgradeInstanceRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof Operation) { + requests.add(request); + responseObserver.onNext((Operation) response); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError((Exception) response); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void importInstance( + ImportInstanceRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof Operation) { + requests.add(request); + responseObserver.onNext((Operation) response); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError((Exception) response); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void exportInstance( + ExportInstanceRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof Operation) { + requests.add(request); + responseObserver.onNext((Operation) response); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError((Exception) response); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void failoverInstance( + FailoverInstanceRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof Operation) { + requests.add(request); + responseObserver.onNext((Operation) response); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError((Exception) response); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void deleteInstance( + DeleteInstanceRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof Operation) { + requests.add(request); + responseObserver.onNext((Operation) response); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError((Exception) response); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } +} diff --git a/test/integration/goldens/redis/package-info.java b/test/integration/goldens/redis/package-info.java new file mode 100644 index 0000000000..7299e26c8d --- /dev/null +++ b/test/integration/goldens/redis/package-info.java @@ -0,0 +1,52 @@ +/* + * 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: + * + *

+ * 
+ * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
+ *   InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]");
+ *   Instance response = cloudRedisClient.getInstance(name);
+ * }
+ * 
+ * 
+ */ +@Generated("by gapic-generator") +package com.google.cloud.redis.v1; + +import javax.annotation.Generated; From 20a548ac6142f88ca159c7bd2fb13d34f0f8addc Mon Sep 17 00:00:00 2001 From: Xiaozhen Liu Date: Thu, 8 Oct 2020 21:26:00 +0000 Subject: [PATCH 02/17] add bazel file --- test/integration/goldens/redis/BUILD.bazel | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 test/integration/goldens/redis/BUILD.bazel diff --git a/test/integration/goldens/redis/BUILD.bazel b/test/integration/goldens/redis/BUILD.bazel new file mode 100644 index 0000000000..7feb266e2c --- /dev/null +++ b/test/integration/goldens/redis/BUILD.bazel @@ -0,0 +1,6 @@ +package(default_visibility = ["//visibility:public"]) + +filegroup( + name = "redis_goldens_files", + srcs = glob(["*.java"]), +) \ No newline at end of file From cad27bb551f72ba575dbaf56c1a264d95b9bc2c2 Mon Sep 17 00:00:00 2001 From: Xiaozhen Liu Date: Thu, 8 Oct 2020 21:27:52 +0000 Subject: [PATCH 03/17] format --- test/integration/goldens/redis/BUILD.bazel | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/goldens/redis/BUILD.bazel b/test/integration/goldens/redis/BUILD.bazel index 7feb266e2c..132766c072 100644 --- a/test/integration/goldens/redis/BUILD.bazel +++ b/test/integration/goldens/redis/BUILD.bazel @@ -3,4 +3,4 @@ package(default_visibility = ["//visibility:public"]) filegroup( name = "redis_goldens_files", srcs = glob(["*.java"]), -) \ No newline at end of file +) From 8e1edfb14e0d63889973fae858bcedcf87cfdfae Mon Sep 17 00:00:00 2001 From: Xiaozhen Liu Date: Fri, 9 Oct 2020 19:20:14 +0000 Subject: [PATCH 04/17] add todo comment for Redis client lib goldens --- test/integration/goldens/redis/BUILD.bazel | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/integration/goldens/redis/BUILD.bazel b/test/integration/goldens/redis/BUILD.bazel index 132766c072..ef2b2f7f5f 100644 --- a/test/integration/goldens/redis/BUILD.bazel +++ b/test/integration/goldens/redis/BUILD.bazel @@ -4,3 +4,6 @@ filegroup( name = "redis_goldens_files", srcs = glob(["*.java"]), ) + +# TODO(xiaozhenliu): remove the goldens files for Redis API once the integration test +# framework is supported and well tested. From 547746324f7ebec88b53c0b22cf8adb376ba0a10 Mon Sep 17 00:00:00 2001 From: Xiaozhen Liu Date: Fri, 9 Oct 2020 19:33:43 +0000 Subject: [PATCH 05/17] add README to integration test goldens folder --- test/integration/goldens/README.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 test/integration/goldens/README.md diff --git a/test/integration/goldens/README.md b/test/integration/goldens/README.md new file mode 100644 index 0000000000..09a1368027 --- /dev/null +++ b/test/integration/goldens/README.md @@ -0,0 +1,24 @@ +# Goldens Files For Integration Test + +This folder contains goldens files that are expected to be generated from Java Microgenerator +against differenct APIs. For example `redis` folder has all the Java source files in the generated +Redis client library. They are all actual Java files, but used as goldens. + +## Purpose + +When running integration test for the Java Microgenerator using the below command, +the goldens files in this folder will be used to compare with the actual generated Java source files. +If they are not identical, then the integration test will fail. + +```sh +bazel test //test/integration:redis_java_gapic +``` + +## How To Update Goldens + +If the actual generated Java source files are not identical with the goldens files, and we want to +update the goldens using source files. Run the command below to overwrite the goldens files in `redis` folder. + +```sh +bazel run //test/integration:redis_goldens_update +``` From d36f04044d26bd8522a8566cd539113f862934cd Mon Sep 17 00:00:00 2001 From: Xiaozhen Liu Date: Sat, 10 Oct 2020 06:05:32 +0000 Subject: [PATCH 06/17] update redis goldens using micro --- test/integration/goldens/redis/BUILD.bazel | 3 - .../goldens/redis/CloudRedisClient.java | 1399 +++++------------ .../goldens/redis/CloudRedisClientTest.java | 924 ++++++----- .../goldens/redis/CloudRedisSettings.java | 157 +- .../goldens/redis/CloudRedisStub.java | 61 +- .../goldens/redis/CloudRedisStubSettings.java | 572 ++++--- .../redis/GrpcCloudRedisCallableFactory.java | 40 +- .../goldens/redis/GrpcCloudRedisStub.java | 338 ++-- .../goldens/redis/InstanceName.java | 157 +- .../goldens/redis/LocationName.java | 137 +- .../goldens/redis/MockCloudRedis.java | 6 +- .../goldens/redis/MockCloudRedisImpl.java | 42 +- 12 files changed, 1587 insertions(+), 2249 deletions(-) diff --git a/test/integration/goldens/redis/BUILD.bazel b/test/integration/goldens/redis/BUILD.bazel index ef2b2f7f5f..132766c072 100644 --- a/test/integration/goldens/redis/BUILD.bazel +++ b/test/integration/goldens/redis/BUILD.bazel @@ -4,6 +4,3 @@ filegroup( name = "redis_goldens_files", srcs = glob(["*.java"]), ) - -# TODO(xiaozhenliu): remove the goldens files for Redis API once the integration test -# framework is supported and well tested. diff --git a/test/integration/goldens/redis/CloudRedisClient.java b/test/integration/goldens/redis/CloudRedisClient.java index 98d07aa2a7..83a43c2b11 100644 --- a/test/integration/goldens/redis/CloudRedisClient.java +++ b/test/integration/goldens/redis/CloudRedisClient.java @@ -5,7 +5,7 @@ * 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 + * 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, @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.google.cloud.redis.v1; import com.google.api.core.ApiFunction; @@ -36,38 +37,26 @@ import com.google.protobuf.FieldMask; import java.io.IOException; import java.util.List; +import java.util.Objects; import java.util.concurrent.TimeUnit; import javax.annotation.Generated; -// AUTO-GENERATED DOCUMENTATION AND SERVICE +// AUTO-GENERATED DOCUMENTATION AND CLASS. /** - * 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: * + * 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` * *

This class provides the ability to make remote calls to the backing service through method * calls that map to API methods. Sample code to get started: * - *

- * 
- * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
- *   InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]");
- *   Instance response = cloudRedisClient.getInstance(name);
- * }
- * 
- * 
- * - *

Note: close() needs to be called on the cloudRedisClient object to clean up resources such as + *

Note: close() needs to be called on the echoClient object to clean up resources such as * threads. In the example above, try-with-resources is used, which automatically calls close(). * *

The surface of this class includes several types of Java methods for each of the API's @@ -95,51 +84,31 @@ * *

To customize credentials: * - *

- * 
- * CloudRedisSettings cloudRedisSettings =
- *     CloudRedisSettings.newBuilder()
- *         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
- *         .build();
- * CloudRedisClient cloudRedisClient =
- *     CloudRedisClient.create(cloudRedisSettings);
- * 
- * 
- * - * To customize the endpoint: - * - *
- * 
- * CloudRedisSettings cloudRedisSettings =
- *     CloudRedisSettings.newBuilder().setEndpoint(myEndpoint).build();
- * CloudRedisClient cloudRedisClient =
- *     CloudRedisClient.create(cloudRedisSettings);
- * 
- * 
+ *

To customize the endpoint: */ -@Generated("by gapic-generator") @BetaApi +@Generated("by gapic-generator") public class CloudRedisClient implements BackgroundResource { private final CloudRedisSettings settings; private final CloudRedisStub stub; private final OperationsClient operationsClient; - /** Constructs an instance of CloudRedisClient with default settings. */ + /** Constructs an instance of EchoClient with default settings. */ public static final CloudRedisClient create() throws IOException { return create(CloudRedisSettings.newBuilder().build()); } /** - * Constructs an instance of CloudRedisClient, using the given settings. The channels are created - * based on the settings passed in, or defaults for any settings that are not set. + * Constructs an instance of EchoClient, using the given settings. The channels are created based + * on the settings passed in, or defaults for any settings that are not set. */ public static final CloudRedisClient create(CloudRedisSettings settings) throws IOException { return new CloudRedisClient(settings); } /** - * Constructs an instance of CloudRedisClient, using the given stub for making calls. This is for - * advanced usage - prefer to use CloudRedisSettings}. + * Constructs an instance of EchoClient, using the given stub for making calls. This is for + * advanced usage - prefer using create(CloudRedisSettings). */ @BetaApi("A restructuring of stub classes is planned, so this may break in the future") public static final CloudRedisClient create(CloudRedisStub stub) { @@ -147,8 +116,8 @@ public static final CloudRedisClient create(CloudRedisStub stub) { } /** - * Constructs an instance of CloudRedisClient, using the given settings. This is protected so that - * it is easy to make a subclass, but otherwise, the static factory methods should be preferred. + * Constructs an instance of EchoClient, using the given settings. This is protected so that it is + * easy to make a subclass, but otherwise, the static factory methods should be preferred. */ protected CloudRedisClient(CloudRedisSettings settings) throws IOException { this.settings = settings; @@ -176,109 +145,208 @@ public CloudRedisStub getStub() { * Returns the OperationsClient that can be used to query the status of a long-running operation * returned by another API method call. */ - @BetaApi( - "The surface for long-running operations is not stable yet and may change in the future.") public final OperationsClient getOperationsClient() { return operationsClient; } - // AUTO-GENERATED DOCUMENTATION AND METHOD + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** - * Creates a Redis instance based on the specified tier and memory size. + * Lists all Redis instances owned by a project in either the specified location (region) or all + * locations. The location should have the following format: * + * `projects/{project_id}/locations/{location_id}` If `location_id` is specified as `-` + * (wildcard), then all regions available to the project are queried, and the results are + * aggregated. * - *

By default, the instance is accessible from the project's [default - * network](https://cloud.google.com/vpc/docs/vpc). + *

Sample code: * - *

The creation is executed asynchronously and callers may check the returned operation to - * track its progress. Once the operation is completed the Redis instance will be fully - * functional. Completed longrunning.Operation will contain the new instance object in the - * response field. + * @param parent Required. The resource name of the instance location using the form: + * `projects/{project_id}/locations/{location_id}` where `location_id` refers to a GCP region. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final ListInstancesPagedResponse listInstances(LocationName parent) { + ListInstancesRequest request = + ListInstancesRequest.newBuilder() + .setParent(Objects.isNull(parent) ? null : parent.toString()) + .build(); + return listInstances(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Lists all Redis instances owned by a project in either the specified location (region) or all + * locations. The location should have the following format: * + * `projects/{project_id}/locations/{location_id}` If `location_id` is specified as `-` + * (wildcard), then all regions available to the project are queried, and the results are + * aggregated. * - *

The returned operation is automatically deleted after a few hours, so there is no need to - * call DeleteOperation. + *

Sample code: + * + * @param parent Required. The resource name of the instance location using the form: + * `projects/{project_id}/locations/{location_id}` where `location_id` refers to a GCP region. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final ListInstancesPagedResponse listInstances(String parent) { + ListInstancesRequest request = ListInstancesRequest.newBuilder().setParent(parent).build(); + return listInstances(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Lists all Redis instances owned by a project in either the specified location (region) or all + * locations. The location should have the following format: * + * `projects/{project_id}/locations/{location_id}` If `location_id` is specified as `-` + * (wildcard), then all regions available to the project are queried, and the results are + * aggregated. + * + *

Sample code: + * + * @param request The request object containing all of the parameters for the API call. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final ListInstancesPagedResponse listInstances(ListInstancesRequest request) { + return listInstancesPagedCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Lists all Redis instances owned by a project in either the specified location (region) or all + * locations. The location should have the following format: * + * `projects/{project_id}/locations/{location_id}` If `location_id` is specified as `-` + * (wildcard), then all regions available to the project are queried, and the results are + * aggregated. * *

Sample code: + */ + public final UnaryCallable + listInstancesPagedCallable() { + return stub.listInstancesPagedCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Lists all Redis instances owned by a project in either the specified location (region) or all + * locations. The location should have the following format: * + * `projects/{project_id}/locations/{location_id}` If `location_id` is specified as `-` + * (wildcard), then all regions available to the project are queried, and the results are + * aggregated. + * + *

Sample code: + */ + public final UnaryCallable listInstancesCallable() { + return stub.listInstancesCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Gets the details of a specific Redis instance. + * + *

Sample code: + * + * @param name Required. Redis instance resource name using the form: + * `projects/{project_id}/locations/{location_id}/instances/{instance_id}` where `location_id` + * refers to a GCP region. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final Instance getInstance(InstanceName name) { + GetInstanceRequest request = + GetInstanceRequest.newBuilder() + .setName(Objects.isNull(name) ? null : name.toString()) + .build(); + return getInstance(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Gets the details of a specific Redis instance. + * + *

Sample code: + * + * @param name Required. Redis instance resource name using the form: + * `projects/{project_id}/locations/{location_id}/instances/{instance_id}` where `location_id` + * refers to a GCP region. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final Instance getInstance(String name) { + GetInstanceRequest request = GetInstanceRequest.newBuilder().setName(name).build(); + return getInstance(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Gets the details of a specific Redis instance. + * + *

Sample code: + * + * @param request The request object containing all of the parameters for the API call. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final Instance getInstance(GetInstanceRequest request) { + return getInstanceCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Gets the details of a specific Redis instance. + * + *

Sample code: + */ + public final UnaryCallable getInstanceCallable() { + return stub.getInstanceCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Creates a Redis instance based on the specified tier and memory size. By default, the instance + * is accessible from the project's [default network](https://cloud.google.com/vpc/docs/vpc). The + * creation is executed asynchronously and callers may check the returned operation to track its + * progress. Once the operation is completed the Redis instance will be fully functional. + * Completed longrunning.Operation will contain the new instance object in the response field. The + * returned operation is automatically deleted after a few hours, so there is no need to call + * DeleteOperation. * - *


-   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
-   *   LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
-   *   String instanceId = "test_instance";
-   *   Instance.Tier tier = Instance.Tier.BASIC;
-   *   int memorySizeGb = 1;
-   *   Instance instance = Instance.newBuilder()
-   *     .setTier(tier)
-   *     .setMemorySizeGb(memorySizeGb)
-   *     .build();
-   *   Instance response = cloudRedisClient.createInstanceAsync(parent, instanceId, instance).get();
-   * }
-   * 
+ *

Sample code: * * @param parent Required. The resource name of the instance location using the form: * `projects/{project_id}/locations/{location_id}` where `location_id` refers to a GCP region. - * @param instanceId Required. The logical name of the Redis instance in the customer project with - * the following restrictions: - *

* Must contain only lowercase letters, numbers, and hyphens. * Must start with a - * letter. * Must be between 1-40 characters. * Must end with a number or a letter. - * * Must be unique within the customer project / location + * @param instance_id Required. The logical name of the Redis instance in the customer project + * with the following restrictions: * Must contain only lowercase letters, numbers, and + * hyphens. * Must start with a letter. * Must be between 1-40 characters. * Must end with a + * number or a letter. * Must be unique within the customer project / location * @param instance Required. A Redis [Instance] resource * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ - @BetaApi( - "The surface for long-running operations is not stable yet and may change in the future.") public final OperationFuture createInstanceAsync( LocationName parent, String instanceId, Instance instance) { CreateInstanceRequest request = CreateInstanceRequest.newBuilder() - .setParent(parent == null ? null : parent.toString()) + .setParent(Objects.isNull(parent) ? null : parent.toString()) .setInstanceId(instanceId) .setInstance(instance) .build(); return createInstanceAsync(request); } - // AUTO-GENERATED DOCUMENTATION AND METHOD + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** - * Creates a Redis instance based on the specified tier and memory size. - * - *

By default, the instance is accessible from the project's [default - * network](https://cloud.google.com/vpc/docs/vpc). - * - *

The creation is executed asynchronously and callers may check the returned operation to - * track its progress. Once the operation is completed the Redis instance will be fully - * functional. Completed longrunning.Operation will contain the new instance object in the - * response field. - * - *

The returned operation is automatically deleted after a few hours, so there is no need to - * call DeleteOperation. + * Creates a Redis instance based on the specified tier and memory size. By default, the instance + * is accessible from the project's [default network](https://cloud.google.com/vpc/docs/vpc). The + * creation is executed asynchronously and callers may check the returned operation to track its + * progress. Once the operation is completed the Redis instance will be fully functional. + * Completed longrunning.Operation will contain the new instance object in the response field. The + * returned operation is automatically deleted after a few hours, so there is no need to call + * DeleteOperation. * *

Sample code: * - *


-   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
-   *   LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
-   *   String instanceId = "test_instance";
-   *   Instance.Tier tier = Instance.Tier.BASIC;
-   *   int memorySizeGb = 1;
-   *   Instance instance = Instance.newBuilder()
-   *     .setTier(tier)
-   *     .setMemorySizeGb(memorySizeGb)
-   *     .build();
-   *   Instance response = cloudRedisClient.createInstanceAsync(parent.toString(), instanceId, instance).get();
-   * }
-   * 
- * * @param parent Required. The resource name of the instance location using the form: * `projects/{project_id}/locations/{location_id}` where `location_id` refers to a GCP region. - * @param instanceId Required. The logical name of the Redis instance in the customer project with - * the following restrictions: - *

* Must contain only lowercase letters, numbers, and hyphens. * Must start with a - * letter. * Must be between 1-40 characters. * Must end with a number or a letter. - * * Must be unique within the customer project / location + * @param instance_id Required. The logical name of the Redis instance in the customer project + * with the following restrictions: * Must contain only lowercase letters, numbers, and + * hyphens. * Must start with a letter. * Must be between 1-40 characters. * Must end with a + * number or a letter. * Must be unique within the customer project / location * @param instance Required. A Redis [Instance] resource * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ - @BetaApi( - "The surface for long-running operations is not stable yet and may change in the future.") public final OperationFuture createInstanceAsync( String parent, String instanceId, Instance instance) { CreateInstanceRequest request = @@ -290,177 +358,75 @@ public final OperationFuture createInstanceAsync( return createInstanceAsync(request); } - // AUTO-GENERATED DOCUMENTATION AND METHOD + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** - * Creates a Redis instance based on the specified tier and memory size. - * - *

By default, the instance is accessible from the project's [default - * network](https://cloud.google.com/vpc/docs/vpc). - * - *

The creation is executed asynchronously and callers may check the returned operation to - * track its progress. Once the operation is completed the Redis instance will be fully - * functional. Completed longrunning.Operation will contain the new instance object in the - * response field. - * - *

The returned operation is automatically deleted after a few hours, so there is no need to - * call DeleteOperation. + * Creates a Redis instance based on the specified tier and memory size. By default, the instance + * is accessible from the project's [default network](https://cloud.google.com/vpc/docs/vpc). The + * creation is executed asynchronously and callers may check the returned operation to track its + * progress. Once the operation is completed the Redis instance will be fully functional. + * Completed longrunning.Operation will contain the new instance object in the response field. The + * returned operation is automatically deleted after a few hours, so there is no need to call + * DeleteOperation. * *

Sample code: * - *


-   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
-   *   LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
-   *   String instanceId = "test_instance";
-   *   Instance.Tier tier = Instance.Tier.BASIC;
-   *   int memorySizeGb = 1;
-   *   Instance instance = Instance.newBuilder()
-   *     .setTier(tier)
-   *     .setMemorySizeGb(memorySizeGb)
-   *     .build();
-   *   CreateInstanceRequest request = CreateInstanceRequest.newBuilder()
-   *     .setParent(parent.toString())
-   *     .setInstanceId(instanceId)
-   *     .setInstance(instance)
-   *     .build();
-   *   Instance response = cloudRedisClient.createInstanceAsync(request).get();
-   * }
-   * 
- * * @param request The request object containing all of the parameters for the API call. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ - @BetaApi( - "The surface for long-running operations is not stable yet and may change in the future.") public final OperationFuture createInstanceAsync( CreateInstanceRequest request) { return createInstanceOperationCallable().futureCall(request); } - // AUTO-GENERATED DOCUMENTATION AND METHOD + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** - * Creates a Redis instance based on the specified tier and memory size. - * - *

By default, the instance is accessible from the project's [default - * network](https://cloud.google.com/vpc/docs/vpc). - * - *

The creation is executed asynchronously and callers may check the returned operation to - * track its progress. Once the operation is completed the Redis instance will be fully - * functional. Completed longrunning.Operation will contain the new instance object in the - * response field. - * - *

The returned operation is automatically deleted after a few hours, so there is no need to - * call DeleteOperation. + * Creates a Redis instance based on the specified tier and memory size. By default, the instance + * is accessible from the project's [default network](https://cloud.google.com/vpc/docs/vpc). The + * creation is executed asynchronously and callers may check the returned operation to track its + * progress. Once the operation is completed the Redis instance will be fully functional. + * Completed longrunning.Operation will contain the new instance object in the response field. The + * returned operation is automatically deleted after a few hours, so there is no need to call + * DeleteOperation. * *

Sample code: - * - *


-   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
-   *   LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
-   *   String instanceId = "test_instance";
-   *   Instance.Tier tier = Instance.Tier.BASIC;
-   *   int memorySizeGb = 1;
-   *   Instance instance = Instance.newBuilder()
-   *     .setTier(tier)
-   *     .setMemorySizeGb(memorySizeGb)
-   *     .build();
-   *   CreateInstanceRequest request = CreateInstanceRequest.newBuilder()
-   *     .setParent(parent.toString())
-   *     .setInstanceId(instanceId)
-   *     .setInstance(instance)
-   *     .build();
-   *   OperationFuture<Instance, OperationMetadata> future = cloudRedisClient.createInstanceOperationCallable().futureCall(request);
-   *   // Do something
-   *   Instance response = future.get();
-   * }
-   * 
*/ - @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") public final OperationCallable createInstanceOperationCallable() { return stub.createInstanceOperationCallable(); } - // AUTO-GENERATED DOCUMENTATION AND METHOD + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** - * Creates a Redis instance based on the specified tier and memory size. - * - *

By default, the instance is accessible from the project's [default - * network](https://cloud.google.com/vpc/docs/vpc). - * - *

The creation is executed asynchronously and callers may check the returned operation to - * track its progress. Once the operation is completed the Redis instance will be fully - * functional. Completed longrunning.Operation will contain the new instance object in the - * response field. - * - *

The returned operation is automatically deleted after a few hours, so there is no need to - * call DeleteOperation. + * Creates a Redis instance based on the specified tier and memory size. By default, the instance + * is accessible from the project's [default network](https://cloud.google.com/vpc/docs/vpc). The + * creation is executed asynchronously and callers may check the returned operation to track its + * progress. Once the operation is completed the Redis instance will be fully functional. + * Completed longrunning.Operation will contain the new instance object in the response field. The + * returned operation is automatically deleted after a few hours, so there is no need to call + * DeleteOperation. * *

Sample code: - * - *


-   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
-   *   LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
-   *   String instanceId = "test_instance";
-   *   Instance.Tier tier = Instance.Tier.BASIC;
-   *   int memorySizeGb = 1;
-   *   Instance instance = Instance.newBuilder()
-   *     .setTier(tier)
-   *     .setMemorySizeGb(memorySizeGb)
-   *     .build();
-   *   CreateInstanceRequest request = CreateInstanceRequest.newBuilder()
-   *     .setParent(parent.toString())
-   *     .setInstanceId(instanceId)
-   *     .setInstance(instance)
-   *     .build();
-   *   ApiFuture<Operation> future = cloudRedisClient.createInstanceCallable().futureCall(request);
-   *   // Do something
-   *   Operation response = future.get();
-   * }
-   * 
*/ public final UnaryCallable createInstanceCallable() { return stub.createInstanceCallable(); } - // AUTO-GENERATED DOCUMENTATION AND METHOD + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** - * Updates the metadata and configuration of a specific Redis instance. - * - *

Completed longrunning.Operation will contain the new instance object in the response field. - * The returned operation is automatically deleted after a few hours, so there is no need to call + * Updates the metadata and configuration of a specific Redis instance. Completed + * longrunning.Operation will contain the new instance object in the response field. The returned + * operation is automatically deleted after a few hours, so there is no need to call * DeleteOperation. * *

Sample code: * - *


-   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
-   *   String pathsElement = "display_name";
-   *   String pathsElement2 = "memory_size_gb";
-   *   List<String> paths = Arrays.asList(pathsElement, pathsElement2);
-   *   FieldMask updateMask = FieldMask.newBuilder()
-   *     .addAllPaths(paths)
-   *     .build();
-   *   String displayName = "UpdatedDisplayName";
-   *   String name = "projects/<project-name>/locations/<location>/instances/<instance>";
-   *   int memorySizeGb = 4;
-   *   Instance instance = Instance.newBuilder()
-   *     .setDisplayName(displayName)
-   *     .setName(name)
-   *     .setMemorySizeGb(memorySizeGb)
-   *     .build();
-   *   Instance response = cloudRedisClient.updateInstanceAsync(updateMask, instance).get();
-   * }
-   * 
- * - * @param updateMask Required. Mask of fields to update. At least one path must be supplied in + * @param update_mask Required. Mask of fields to update. At least one path must be supplied in * this field. The elements of the repeated paths field may only include these fields from - * [Instance][google.cloud.redis.v1.Instance]: - *

* `displayName` * `labels` * `memorySizeGb` * `redisConfig` + * [Instance][google.cloud.redis.v1.Instance]: * `displayName` * `labels` * `memorySizeGb` * + * `redisConfig` * @param instance Required. Update description. Only fields specified in update_mask are updated. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ - @BetaApi( - "The surface for long-running operations is not stable yet and may change in the future.") public final OperationFuture updateInstanceAsync( FieldMask updateMask, Instance instance) { UpdateInstanceRequest request = @@ -468,160 +434,141 @@ public final OperationFuture updateInstanceAsync( return updateInstanceAsync(request); } - // AUTO-GENERATED DOCUMENTATION AND METHOD + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** - * Updates the metadata and configuration of a specific Redis instance. - * - *

Completed longrunning.Operation will contain the new instance object in the response field. - * The returned operation is automatically deleted after a few hours, so there is no need to call + * Updates the metadata and configuration of a specific Redis instance. Completed + * longrunning.Operation will contain the new instance object in the response field. The returned + * operation is automatically deleted after a few hours, so there is no need to call * DeleteOperation. * *

Sample code: * - *


-   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
-   *   String pathsElement = "display_name";
-   *   String pathsElement2 = "memory_size_gb";
-   *   List<String> paths = Arrays.asList(pathsElement, pathsElement2);
-   *   FieldMask updateMask = FieldMask.newBuilder()
-   *     .addAllPaths(paths)
-   *     .build();
-   *   String displayName = "UpdatedDisplayName";
-   *   String name = "projects/<project-name>/locations/<location>/instances/<instance>";
-   *   int memorySizeGb = 4;
-   *   Instance instance = Instance.newBuilder()
-   *     .setDisplayName(displayName)
-   *     .setName(name)
-   *     .setMemorySizeGb(memorySizeGb)
-   *     .build();
-   *   UpdateInstanceRequest request = UpdateInstanceRequest.newBuilder()
-   *     .setUpdateMask(updateMask)
-   *     .setInstance(instance)
-   *     .build();
-   *   Instance response = cloudRedisClient.updateInstanceAsync(request).get();
-   * }
-   * 
- * * @param request The request object containing all of the parameters for the API call. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ - @BetaApi( - "The surface for long-running operations is not stable yet and may change in the future.") public final OperationFuture updateInstanceAsync( UpdateInstanceRequest request) { return updateInstanceOperationCallable().futureCall(request); } - // AUTO-GENERATED DOCUMENTATION AND METHOD + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** - * Updates the metadata and configuration of a specific Redis instance. - * - *

Completed longrunning.Operation will contain the new instance object in the response field. - * The returned operation is automatically deleted after a few hours, so there is no need to call + * Updates the metadata and configuration of a specific Redis instance. Completed + * longrunning.Operation will contain the new instance object in the response field. The returned + * operation is automatically deleted after a few hours, so there is no need to call * DeleteOperation. * *

Sample code: - * - *


-   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
-   *   String pathsElement = "display_name";
-   *   String pathsElement2 = "memory_size_gb";
-   *   List<String> paths = Arrays.asList(pathsElement, pathsElement2);
-   *   FieldMask updateMask = FieldMask.newBuilder()
-   *     .addAllPaths(paths)
-   *     .build();
-   *   String displayName = "UpdatedDisplayName";
-   *   String name = "projects/<project-name>/locations/<location>/instances/<instance>";
-   *   int memorySizeGb = 4;
-   *   Instance instance = Instance.newBuilder()
-   *     .setDisplayName(displayName)
-   *     .setName(name)
-   *     .setMemorySizeGb(memorySizeGb)
-   *     .build();
-   *   UpdateInstanceRequest request = UpdateInstanceRequest.newBuilder()
-   *     .setUpdateMask(updateMask)
-   *     .setInstance(instance)
-   *     .build();
-   *   OperationFuture<Instance, OperationMetadata> future = cloudRedisClient.updateInstanceOperationCallable().futureCall(request);
-   *   // Do something
-   *   Instance response = future.get();
-   * }
-   * 
*/ - @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") public final OperationCallable updateInstanceOperationCallable() { return stub.updateInstanceOperationCallable(); } - // AUTO-GENERATED DOCUMENTATION AND METHOD + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** - * Updates the metadata and configuration of a specific Redis instance. - * - *

Completed longrunning.Operation will contain the new instance object in the response field. - * The returned operation is automatically deleted after a few hours, so there is no need to call + * Updates the metadata and configuration of a specific Redis instance. Completed + * longrunning.Operation will contain the new instance object in the response field. The returned + * operation is automatically deleted after a few hours, so there is no need to call * DeleteOperation. * *

Sample code: - * - *


-   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
-   *   String pathsElement = "display_name";
-   *   String pathsElement2 = "memory_size_gb";
-   *   List<String> paths = Arrays.asList(pathsElement, pathsElement2);
-   *   FieldMask updateMask = FieldMask.newBuilder()
-   *     .addAllPaths(paths)
-   *     .build();
-   *   String displayName = "UpdatedDisplayName";
-   *   String name = "projects/<project-name>/locations/<location>/instances/<instance>";
-   *   int memorySizeGb = 4;
-   *   Instance instance = Instance.newBuilder()
-   *     .setDisplayName(displayName)
-   *     .setName(name)
-   *     .setMemorySizeGb(memorySizeGb)
-   *     .build();
-   *   UpdateInstanceRequest request = UpdateInstanceRequest.newBuilder()
-   *     .setUpdateMask(updateMask)
-   *     .setInstance(instance)
-   *     .build();
-   *   ApiFuture<Operation> future = cloudRedisClient.updateInstanceCallable().futureCall(request);
-   *   // Do something
-   *   Operation response = future.get();
-   * }
-   * 
*/ public final UnaryCallable updateInstanceCallable() { return stub.updateInstanceCallable(); } - // AUTO-GENERATED DOCUMENTATION AND METHOD + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** - * Import a Redis RDB snapshot file from Cloud Storage into a Redis instance. + * Upgrades Redis instance to the newer Redis version specified in the request. * - *

Redis may stop serving during this operation. Instance state will be IMPORTING for entire - * operation. When complete, the instance will contain only data from the imported file. + *

Sample code: * - *

The returned operation is automatically deleted after a few hours, so there is no need to - * call DeleteOperation. + * @param name Required. Redis instance resource name using the form: + * `projects/{project_id}/locations/{location_id}/instances/{instance_id}` where `location_id` + * refers to a GCP region. + * @param redis_version Required. Specifies the target version of Redis software to upgrade to. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final OperationFuture upgradeInstanceAsync( + InstanceName name, String redisVersion) { + UpgradeInstanceRequest request = + UpgradeInstanceRequest.newBuilder() + .setName(Objects.isNull(name) ? null : name.toString()) + .setRedisVersion(redisVersion) + .build(); + return upgradeInstanceAsync(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Upgrades Redis instance to the newer Redis version specified in the request. * *

Sample code: * - *


-   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
-   *   String name = "";
-   *   InputConfig inputConfig = InputConfig.newBuilder().build();
-   *   Instance response = cloudRedisClient.importInstanceAsync(name, inputConfig).get();
-   * }
-   * 
+ * @param name Required. Redis instance resource name using the form: + * `projects/{project_id}/locations/{location_id}/instances/{instance_id}` where `location_id` + * refers to a GCP region. + * @param redis_version Required. Specifies the target version of Redis software to upgrade to. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final OperationFuture upgradeInstanceAsync( + String name, String redisVersion) { + UpgradeInstanceRequest request = + UpgradeInstanceRequest.newBuilder().setName(name).setRedisVersion(redisVersion).build(); + return upgradeInstanceAsync(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Upgrades Redis instance to the newer Redis version specified in the request. + * + *

Sample code: + * + * @param request The request object containing all of the parameters for the API call. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final OperationFuture upgradeInstanceAsync( + UpgradeInstanceRequest request) { + return upgradeInstanceOperationCallable().futureCall(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Upgrades Redis instance to the newer Redis version specified in the request. + * + *

Sample code: + */ + public final OperationCallable + upgradeInstanceOperationCallable() { + return stub.upgradeInstanceOperationCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Upgrades Redis instance to the newer Redis version specified in the request. + * + *

Sample code: + */ + public final UnaryCallable upgradeInstanceCallable() { + return stub.upgradeInstanceCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Import a Redis RDB snapshot file from Cloud Storage into a Redis instance. Redis may stop + * serving during this operation. Instance state will be IMPORTING for entire operation. When + * complete, the instance will contain only data from the imported file. The returned operation is + * automatically deleted after a few hours, so there is no need to call DeleteOperation. + * + *

Sample code: * * @param name Required. Redis instance resource name using the form: * `projects/{project_id}/locations/{location_id}/instances/{instance_id}` where `location_id` * refers to a GCP region. - * @param inputConfig Required. Specify data to be imported. + * @param input_config Required. Specify data to be imported. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ - @BetaApi( - "The surface for long-running operations is not stable yet and may change in the future.") public final OperationFuture importInstanceAsync( String name, InputConfig inputConfig) { ImportInstanceRequest request = @@ -629,129 +576,64 @@ public final OperationFuture importInstanceAsync( return importInstanceAsync(request); } - // AUTO-GENERATED DOCUMENTATION AND METHOD + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** - * Import a Redis RDB snapshot file from Cloud Storage into a Redis instance. - * - *

Redis may stop serving during this operation. Instance state will be IMPORTING for entire - * operation. When complete, the instance will contain only data from the imported file. - * - *

The returned operation is automatically deleted after a few hours, so there is no need to - * call DeleteOperation. + * Import a Redis RDB snapshot file from Cloud Storage into a Redis instance. Redis may stop + * serving during this operation. Instance state will be IMPORTING for entire operation. When + * complete, the instance will contain only data from the imported file. The returned operation is + * automatically deleted after a few hours, so there is no need to call DeleteOperation. * *

Sample code: * - *


-   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
-   *   String name = "";
-   *   InputConfig inputConfig = InputConfig.newBuilder().build();
-   *   ImportInstanceRequest request = ImportInstanceRequest.newBuilder()
-   *     .setName(name)
-   *     .setInputConfig(inputConfig)
-   *     .build();
-   *   Instance response = cloudRedisClient.importInstanceAsync(request).get();
-   * }
-   * 
- * * @param request The request object containing all of the parameters for the API call. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ - @BetaApi( - "The surface for long-running operations is not stable yet and may change in the future.") public final OperationFuture importInstanceAsync( ImportInstanceRequest request) { return importInstanceOperationCallable().futureCall(request); } - // AUTO-GENERATED DOCUMENTATION AND METHOD + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** - * Import a Redis RDB snapshot file from Cloud Storage into a Redis instance. - * - *

Redis may stop serving during this operation. Instance state will be IMPORTING for entire - * operation. When complete, the instance will contain only data from the imported file. - * - *

The returned operation is automatically deleted after a few hours, so there is no need to - * call DeleteOperation. + * Import a Redis RDB snapshot file from Cloud Storage into a Redis instance. Redis may stop + * serving during this operation. Instance state will be IMPORTING for entire operation. When + * complete, the instance will contain only data from the imported file. The returned operation is + * automatically deleted after a few hours, so there is no need to call DeleteOperation. * *

Sample code: - * - *


-   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
-   *   String name = "";
-   *   InputConfig inputConfig = InputConfig.newBuilder().build();
-   *   ImportInstanceRequest request = ImportInstanceRequest.newBuilder()
-   *     .setName(name)
-   *     .setInputConfig(inputConfig)
-   *     .build();
-   *   OperationFuture<Instance, OperationMetadata> future = cloudRedisClient.importInstanceOperationCallable().futureCall(request);
-   *   // Do something
-   *   Instance response = future.get();
-   * }
-   * 
*/ - @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") public final OperationCallable importInstanceOperationCallable() { return stub.importInstanceOperationCallable(); } - // AUTO-GENERATED DOCUMENTATION AND METHOD + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** - * Import a Redis RDB snapshot file from Cloud Storage into a Redis instance. - * - *

Redis may stop serving during this operation. Instance state will be IMPORTING for entire - * operation. When complete, the instance will contain only data from the imported file. - * - *

The returned operation is automatically deleted after a few hours, so there is no need to - * call DeleteOperation. + * Import a Redis RDB snapshot file from Cloud Storage into a Redis instance. Redis may stop + * serving during this operation. Instance state will be IMPORTING for entire operation. When + * complete, the instance will contain only data from the imported file. The returned operation is + * automatically deleted after a few hours, so there is no need to call DeleteOperation. * *

Sample code: - * - *


-   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
-   *   String name = "";
-   *   InputConfig inputConfig = InputConfig.newBuilder().build();
-   *   ImportInstanceRequest request = ImportInstanceRequest.newBuilder()
-   *     .setName(name)
-   *     .setInputConfig(inputConfig)
-   *     .build();
-   *   ApiFuture<Operation> future = cloudRedisClient.importInstanceCallable().futureCall(request);
-   *   // Do something
-   *   Operation response = future.get();
-   * }
-   * 
*/ public final UnaryCallable importInstanceCallable() { return stub.importInstanceCallable(); } - // AUTO-GENERATED DOCUMENTATION AND METHOD + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** - * Export Redis instance data into a Redis RDB format file in Cloud Storage. - * - *

Redis will continue serving during this operation. - * - *

The returned operation is automatically deleted after a few hours, so there is no need to - * call DeleteOperation. + * Export Redis instance data into a Redis RDB format file in Cloud Storage. Redis will continue + * serving during this operation. The returned operation is automatically deleted after a few + * hours, so there is no need to call DeleteOperation. * *

Sample code: * - *


-   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
-   *   String name = "";
-   *   OutputConfig outputConfig = OutputConfig.newBuilder().build();
-   *   Instance response = cloudRedisClient.exportInstanceAsync(name, outputConfig).get();
-   * }
-   * 
- * * @param name Required. Redis instance resource name using the form: * `projects/{project_id}/locations/{location_id}/instances/{instance_id}` where `location_id` * refers to a GCP region. - * @param outputConfig Required. Specify data to be exported. + * @param output_config Required. Specify data to be exported. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ - @BetaApi( - "The surface for long-running operations is not stable yet and may change in the future.") public final OperationFuture exportInstanceAsync( String name, OutputConfig outputConfig) { ExportInstanceRequest request = @@ -759,157 +641,85 @@ public final OperationFuture exportInstanceAsync( return exportInstanceAsync(request); } - // AUTO-GENERATED DOCUMENTATION AND METHOD + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** - * Export Redis instance data into a Redis RDB format file in Cloud Storage. - * - *

Redis will continue serving during this operation. - * - *

The returned operation is automatically deleted after a few hours, so there is no need to - * call DeleteOperation. + * Export Redis instance data into a Redis RDB format file in Cloud Storage. Redis will continue + * serving during this operation. The returned operation is automatically deleted after a few + * hours, so there is no need to call DeleteOperation. * *

Sample code: * - *


-   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
-   *   String name = "";
-   *   OutputConfig outputConfig = OutputConfig.newBuilder().build();
-   *   ExportInstanceRequest request = ExportInstanceRequest.newBuilder()
-   *     .setName(name)
-   *     .setOutputConfig(outputConfig)
-   *     .build();
-   *   Instance response = cloudRedisClient.exportInstanceAsync(request).get();
-   * }
-   * 
- * * @param request The request object containing all of the parameters for the API call. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ - @BetaApi( - "The surface for long-running operations is not stable yet and may change in the future.") public final OperationFuture exportInstanceAsync( ExportInstanceRequest request) { return exportInstanceOperationCallable().futureCall(request); } - // AUTO-GENERATED DOCUMENTATION AND METHOD + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** - * Export Redis instance data into a Redis RDB format file in Cloud Storage. - * - *

Redis will continue serving during this operation. - * - *

The returned operation is automatically deleted after a few hours, so there is no need to - * call DeleteOperation. + * Export Redis instance data into a Redis RDB format file in Cloud Storage. Redis will continue + * serving during this operation. The returned operation is automatically deleted after a few + * hours, so there is no need to call DeleteOperation. * *

Sample code: - * - *


-   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
-   *   String name = "";
-   *   OutputConfig outputConfig = OutputConfig.newBuilder().build();
-   *   ExportInstanceRequest request = ExportInstanceRequest.newBuilder()
-   *     .setName(name)
-   *     .setOutputConfig(outputConfig)
-   *     .build();
-   *   OperationFuture<Instance, OperationMetadata> future = cloudRedisClient.exportInstanceOperationCallable().futureCall(request);
-   *   // Do something
-   *   Instance response = future.get();
-   * }
-   * 
*/ - @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") public final OperationCallable exportInstanceOperationCallable() { return stub.exportInstanceOperationCallable(); } - // AUTO-GENERATED DOCUMENTATION AND METHOD + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** - * Export Redis instance data into a Redis RDB format file in Cloud Storage. - * - *

Redis will continue serving during this operation. - * - *

The returned operation is automatically deleted after a few hours, so there is no need to - * call DeleteOperation. + * Export Redis instance data into a Redis RDB format file in Cloud Storage. Redis will continue + * serving during this operation. The returned operation is automatically deleted after a few + * hours, so there is no need to call DeleteOperation. * *

Sample code: - * - *


-   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
-   *   String name = "";
-   *   OutputConfig outputConfig = OutputConfig.newBuilder().build();
-   *   ExportInstanceRequest request = ExportInstanceRequest.newBuilder()
-   *     .setName(name)
-   *     .setOutputConfig(outputConfig)
-   *     .build();
-   *   ApiFuture<Operation> future = cloudRedisClient.exportInstanceCallable().futureCall(request);
-   *   // Do something
-   *   Operation response = future.get();
-   * }
-   * 
*/ public final UnaryCallable exportInstanceCallable() { return stub.exportInstanceCallable(); } - // AUTO-GENERATED DOCUMENTATION AND METHOD + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** * Initiates a failover of the master node to current replica node for a specific STANDARD tier * Cloud Memorystore for Redis instance. * *

Sample code: * - *


-   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
-   *   InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]");
-   *   FailoverInstanceRequest.DataProtectionMode dataProtectionMode = FailoverInstanceRequest.DataProtectionMode.DATA_PROTECTION_MODE_UNSPECIFIED;
-   *   Instance response = cloudRedisClient.failoverInstanceAsync(name, dataProtectionMode).get();
-   * }
-   * 
- * * @param name Required. Redis instance resource name using the form: * `projects/{project_id}/locations/{location_id}/instances/{instance_id}` where `location_id` * refers to a GCP region. - * @param dataProtectionMode Optional. Available data protection modes that the user can choose. + * @param data_protection_mode Optional. Available data protection modes that the user can choose. * If it's unspecified, data protection mode will be LIMITED_DATA_LOSS by default. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ - @BetaApi( - "The surface for long-running operations is not stable yet and may change in the future.") public final OperationFuture failoverInstanceAsync( InstanceName name, FailoverInstanceRequest.DataProtectionMode dataProtectionMode) { FailoverInstanceRequest request = FailoverInstanceRequest.newBuilder() - .setName(name == null ? null : name.toString()) + .setName(Objects.isNull(name) ? null : name.toString()) .setDataProtectionMode(dataProtectionMode) .build(); return failoverInstanceAsync(request); } - // AUTO-GENERATED DOCUMENTATION AND METHOD + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** * Initiates a failover of the master node to current replica node for a specific STANDARD tier * Cloud Memorystore for Redis instance. * *

Sample code: * - *


-   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
-   *   InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]");
-   *   FailoverInstanceRequest.DataProtectionMode dataProtectionMode = FailoverInstanceRequest.DataProtectionMode.DATA_PROTECTION_MODE_UNSPECIFIED;
-   *   Instance response = cloudRedisClient.failoverInstanceAsync(name.toString(), dataProtectionMode).get();
-   * }
-   * 
- * * @param name Required. Redis instance resource name using the form: * `projects/{project_id}/locations/{location_id}/instances/{instance_id}` where `location_id` * refers to a GCP region. - * @param dataProtectionMode Optional. Available data protection modes that the user can choose. + * @param data_protection_mode Optional. Available data protection modes that the user can choose. * If it's unspecified, data protection mode will be LIMITED_DATA_LOSS by default. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ - @BetaApi( - "The surface for long-running operations is not stable yet and may change in the future.") public final OperationFuture failoverInstanceAsync( String name, FailoverInstanceRequest.DataProtectionMode dataProtectionMode) { FailoverInstanceRequest request = @@ -920,607 +730,114 @@ public final OperationFuture failoverInstanceAsync( return failoverInstanceAsync(request); } - // AUTO-GENERATED DOCUMENTATION AND METHOD + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** * Initiates a failover of the master node to current replica node for a specific STANDARD tier * Cloud Memorystore for Redis instance. * *

Sample code: * - *


-   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
-   *   InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]");
-   *   FailoverInstanceRequest request = FailoverInstanceRequest.newBuilder()
-   *     .setName(name.toString())
-   *     .build();
-   *   Instance response = cloudRedisClient.failoverInstanceAsync(request).get();
-   * }
-   * 
- * * @param request The request object containing all of the parameters for the API call. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ - @BetaApi( - "The surface for long-running operations is not stable yet and may change in the future.") public final OperationFuture failoverInstanceAsync( FailoverInstanceRequest request) { return failoverInstanceOperationCallable().futureCall(request); } - // AUTO-GENERATED DOCUMENTATION AND METHOD + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** * Initiates a failover of the master node to current replica node for a specific STANDARD tier * Cloud Memorystore for Redis instance. * *

Sample code: - * - *


-   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
-   *   InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]");
-   *   FailoverInstanceRequest request = FailoverInstanceRequest.newBuilder()
-   *     .setName(name.toString())
-   *     .build();
-   *   OperationFuture<Instance, OperationMetadata> future = cloudRedisClient.failoverInstanceOperationCallable().futureCall(request);
-   *   // Do something
-   *   Instance response = future.get();
-   * }
-   * 
*/ - @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") public final OperationCallable failoverInstanceOperationCallable() { return stub.failoverInstanceOperationCallable(); } - // AUTO-GENERATED DOCUMENTATION AND METHOD + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** * Initiates a failover of the master node to current replica node for a specific STANDARD tier * Cloud Memorystore for Redis instance. * *

Sample code: - * - *


-   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
-   *   InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]");
-   *   FailoverInstanceRequest request = FailoverInstanceRequest.newBuilder()
-   *     .setName(name.toString())
-   *     .build();
-   *   ApiFuture<Operation> future = cloudRedisClient.failoverInstanceCallable().futureCall(request);
-   *   // Do something
-   *   Operation response = future.get();
-   * }
-   * 
*/ public final UnaryCallable failoverInstanceCallable() { return stub.failoverInstanceCallable(); } - // AUTO-GENERATED DOCUMENTATION AND METHOD + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** * Deletes a specific Redis instance. Instance stops serving and data is deleted. * *

Sample code: * - *


-   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
-   *   InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]");
-   *   cloudRedisClient.deleteInstanceAsync(name).get();
-   * }
-   * 
- * * @param name Required. Redis instance resource name using the form: * `projects/{project_id}/locations/{location_id}/instances/{instance_id}` where `location_id` * refers to a GCP region. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ - @BetaApi( - "The surface for long-running operations is not stable yet and may change in the future.") public final OperationFuture deleteInstanceAsync(InstanceName name) { DeleteInstanceRequest request = - DeleteInstanceRequest.newBuilder().setName(name == null ? null : name.toString()).build(); + DeleteInstanceRequest.newBuilder() + .setName(Objects.isNull(name) ? null : name.toString()) + .build(); return deleteInstanceAsync(request); } - // AUTO-GENERATED DOCUMENTATION AND METHOD + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** * Deletes a specific Redis instance. Instance stops serving and data is deleted. * *

Sample code: * - *


-   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
-   *   InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]");
-   *   cloudRedisClient.deleteInstanceAsync(name.toString()).get();
-   * }
-   * 
- * * @param name Required. Redis instance resource name using the form: * `projects/{project_id}/locations/{location_id}/instances/{instance_id}` where `location_id` * refers to a GCP region. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ - @BetaApi( - "The surface for long-running operations is not stable yet and may change in the future.") public final OperationFuture deleteInstanceAsync(String name) { DeleteInstanceRequest request = DeleteInstanceRequest.newBuilder().setName(name).build(); return deleteInstanceAsync(request); } - // AUTO-GENERATED DOCUMENTATION AND METHOD + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** * Deletes a specific Redis instance. Instance stops serving and data is deleted. * *

Sample code: * - *


-   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
-   *   InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]");
-   *   DeleteInstanceRequest request = DeleteInstanceRequest.newBuilder()
-   *     .setName(name.toString())
-   *     .build();
-   *   cloudRedisClient.deleteInstanceAsync(request).get();
-   * }
-   * 
- * * @param request The request object containing all of the parameters for the API call. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ - @BetaApi( - "The surface for long-running operations is not stable yet and may change in the future.") public final OperationFuture deleteInstanceAsync( DeleteInstanceRequest request) { return deleteInstanceOperationCallable().futureCall(request); } - // AUTO-GENERATED DOCUMENTATION AND METHOD + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** * Deletes a specific Redis instance. Instance stops serving and data is deleted. * *

Sample code: - * - *


-   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
-   *   InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]");
-   *   DeleteInstanceRequest request = DeleteInstanceRequest.newBuilder()
-   *     .setName(name.toString())
-   *     .build();
-   *   OperationFuture<Empty, OperationMetadata> future = cloudRedisClient.deleteInstanceOperationCallable().futureCall(request);
-   *   // Do something
-   *   future.get();
-   * }
-   * 
*/ - @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") public final OperationCallable deleteInstanceOperationCallable() { return stub.deleteInstanceOperationCallable(); } - // AUTO-GENERATED DOCUMENTATION AND METHOD + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** * Deletes a specific Redis instance. Instance stops serving and data is deleted. * *

Sample code: - * - *


-   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
-   *   InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]");
-   *   DeleteInstanceRequest request = DeleteInstanceRequest.newBuilder()
-   *     .setName(name.toString())
-   *     .build();
-   *   ApiFuture<Operation> future = cloudRedisClient.deleteInstanceCallable().futureCall(request);
-   *   // Do something
-   *   future.get();
-   * }
-   * 
*/ public final UnaryCallable deleteInstanceCallable() { return stub.deleteInstanceCallable(); } - // AUTO-GENERATED DOCUMENTATION AND METHOD - /** - * Lists all Redis instances owned by a project in either the specified location (region) or all - * locations. - * - *

The location should have the following format: - * - *

* `projects/{project_id}/locations/{location_id}` - * - *

If `location_id` is specified as `-` (wildcard), then all regions available to the project - * are queried, and the results are aggregated. - * - *

Sample code: - * - *


-   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
-   *   LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
-   *   for (Instance element : cloudRedisClient.listInstances(parent).iterateAll()) {
-   *     // doThingsWith(element);
-   *   }
-   * }
-   * 
- * - * @param parent Required. The resource name of the instance location using the form: - * `projects/{project_id}/locations/{location_id}` where `location_id` refers to a GCP region. - * @throws com.google.api.gax.rpc.ApiException if the remote call fails - */ - public final ListInstancesPagedResponse listInstances(LocationName parent) { - ListInstancesRequest request = - ListInstancesRequest.newBuilder() - .setParent(parent == null ? null : parent.toString()) - .build(); - return listInstances(request); - } - - // AUTO-GENERATED DOCUMENTATION AND METHOD - /** - * Lists all Redis instances owned by a project in either the specified location (region) or all - * locations. - * - *

The location should have the following format: - * - *

* `projects/{project_id}/locations/{location_id}` - * - *

If `location_id` is specified as `-` (wildcard), then all regions available to the project - * are queried, and the results are aggregated. - * - *

Sample code: - * - *


-   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
-   *   LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
-   *   for (Instance element : cloudRedisClient.listInstances(parent.toString()).iterateAll()) {
-   *     // doThingsWith(element);
-   *   }
-   * }
-   * 
- * - * @param parent Required. The resource name of the instance location using the form: - * `projects/{project_id}/locations/{location_id}` where `location_id` refers to a GCP region. - * @throws com.google.api.gax.rpc.ApiException if the remote call fails - */ - public final ListInstancesPagedResponse listInstances(String parent) { - ListInstancesRequest request = ListInstancesRequest.newBuilder().setParent(parent).build(); - return listInstances(request); - } - - // AUTO-GENERATED DOCUMENTATION AND METHOD - /** - * Lists all Redis instances owned by a project in either the specified location (region) or all - * locations. - * - *

The location should have the following format: - * - *

* `projects/{project_id}/locations/{location_id}` - * - *

If `location_id` is specified as `-` (wildcard), then all regions available to the project - * are queried, and the results are aggregated. - * - *

Sample code: - * - *


-   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
-   *   LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
-   *   ListInstancesRequest request = ListInstancesRequest.newBuilder()
-   *     .setParent(parent.toString())
-   *     .build();
-   *   for (Instance element : cloudRedisClient.listInstances(request).iterateAll()) {
-   *     // doThingsWith(element);
-   *   }
-   * }
-   * 
- * - * @param request The request object containing all of the parameters for the API call. - * @throws com.google.api.gax.rpc.ApiException if the remote call fails - */ - public final ListInstancesPagedResponse listInstances(ListInstancesRequest request) { - return listInstancesPagedCallable().call(request); - } - - // AUTO-GENERATED DOCUMENTATION AND METHOD - /** - * Lists all Redis instances owned by a project in either the specified location (region) or all - * locations. - * - *

The location should have the following format: - * - *

* `projects/{project_id}/locations/{location_id}` - * - *

If `location_id` is specified as `-` (wildcard), then all regions available to the project - * are queried, and the results are aggregated. - * - *

Sample code: - * - *


-   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
-   *   LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
-   *   ListInstancesRequest request = ListInstancesRequest.newBuilder()
-   *     .setParent(parent.toString())
-   *     .build();
-   *   ApiFuture<ListInstancesPagedResponse> future = cloudRedisClient.listInstancesPagedCallable().futureCall(request);
-   *   // Do something
-   *   for (Instance element : future.get().iterateAll()) {
-   *     // doThingsWith(element);
-   *   }
-   * }
-   * 
- */ - public final UnaryCallable - listInstancesPagedCallable() { - return stub.listInstancesPagedCallable(); - } - - // AUTO-GENERATED DOCUMENTATION AND METHOD - /** - * Lists all Redis instances owned by a project in either the specified location (region) or all - * locations. - * - *

The location should have the following format: - * - *

* `projects/{project_id}/locations/{location_id}` - * - *

If `location_id` is specified as `-` (wildcard), then all regions available to the project - * are queried, and the results are aggregated. - * - *

Sample code: - * - *


-   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
-   *   LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
-   *   ListInstancesRequest request = ListInstancesRequest.newBuilder()
-   *     .setParent(parent.toString())
-   *     .build();
-   *   while (true) {
-   *     ListInstancesResponse response = cloudRedisClient.listInstancesCallable().call(request);
-   *     for (Instance element : response.getInstancesList()) {
-   *       // doThingsWith(element);
-   *     }
-   *     String nextPageToken = response.getNextPageToken();
-   *     if (!Strings.isNullOrEmpty(nextPageToken)) {
-   *       request = request.toBuilder().setPageToken(nextPageToken).build();
-   *     } else {
-   *       break;
-   *     }
-   *   }
-   * }
-   * 
- */ - public final UnaryCallable listInstancesCallable() { - return stub.listInstancesCallable(); - } - - // AUTO-GENERATED DOCUMENTATION AND METHOD - /** - * Gets the details of a specific Redis instance. - * - *

Sample code: - * - *


-   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
-   *   InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]");
-   *   Instance response = cloudRedisClient.getInstance(name);
-   * }
-   * 
- * - * @param name Required. Redis instance resource name using the form: - * `projects/{project_id}/locations/{location_id}/instances/{instance_id}` where `location_id` - * refers to a GCP region. - * @throws com.google.api.gax.rpc.ApiException if the remote call fails - */ - public final Instance getInstance(InstanceName name) { - GetInstanceRequest request = - GetInstanceRequest.newBuilder().setName(name == null ? null : name.toString()).build(); - return getInstance(request); - } - - // AUTO-GENERATED DOCUMENTATION AND METHOD - /** - * Gets the details of a specific Redis instance. - * - *

Sample code: - * - *


-   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
-   *   InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]");
-   *   Instance response = cloudRedisClient.getInstance(name.toString());
-   * }
-   * 
- * - * @param name Required. Redis instance resource name using the form: - * `projects/{project_id}/locations/{location_id}/instances/{instance_id}` where `location_id` - * refers to a GCP region. - * @throws com.google.api.gax.rpc.ApiException if the remote call fails - */ - public final Instance getInstance(String name) { - GetInstanceRequest request = GetInstanceRequest.newBuilder().setName(name).build(); - return getInstance(request); - } - - // AUTO-GENERATED DOCUMENTATION AND METHOD - /** - * Gets the details of a specific Redis instance. - * - *

Sample code: - * - *


-   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
-   *   InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]");
-   *   GetInstanceRequest request = GetInstanceRequest.newBuilder()
-   *     .setName(name.toString())
-   *     .build();
-   *   Instance response = cloudRedisClient.getInstance(request);
-   * }
-   * 
- * - * @param request The request object containing all of the parameters for the API call. - * @throws com.google.api.gax.rpc.ApiException if the remote call fails - */ - public final Instance getInstance(GetInstanceRequest request) { - return getInstanceCallable().call(request); - } - - // AUTO-GENERATED DOCUMENTATION AND METHOD - /** - * Gets the details of a specific Redis instance. - * - *

Sample code: - * - *


-   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
-   *   InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]");
-   *   GetInstanceRequest request = GetInstanceRequest.newBuilder()
-   *     .setName(name.toString())
-   *     .build();
-   *   ApiFuture<Instance> future = cloudRedisClient.getInstanceCallable().futureCall(request);
-   *   // Do something
-   *   Instance response = future.get();
-   * }
-   * 
- */ - public final UnaryCallable getInstanceCallable() { - return stub.getInstanceCallable(); - } - - // AUTO-GENERATED DOCUMENTATION AND METHOD - /** - * Upgrades Redis instance to the newer Redis version specified in the request. - * - *

Sample code: - * - *


-   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
-   *   InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]");
-   *   String redisVersion = "";
-   *   Instance response = cloudRedisClient.upgradeInstanceAsync(name, redisVersion).get();
-   * }
-   * 
- * - * @param name Required. Redis instance resource name using the form: - * `projects/{project_id}/locations/{location_id}/instances/{instance_id}` where `location_id` - * refers to a GCP region. - * @param redisVersion Required. Specifies the target version of Redis software to upgrade to. - * @throws com.google.api.gax.rpc.ApiException if the remote call fails - */ - @BetaApi( - "The surface for long-running operations is not stable yet and may change in the future.") - public final OperationFuture upgradeInstanceAsync( - InstanceName name, String redisVersion) { - UpgradeInstanceRequest request = - UpgradeInstanceRequest.newBuilder() - .setName(name == null ? null : name.toString()) - .setRedisVersion(redisVersion) - .build(); - return upgradeInstanceAsync(request); - } - - // AUTO-GENERATED DOCUMENTATION AND METHOD - /** - * Upgrades Redis instance to the newer Redis version specified in the request. - * - *

Sample code: - * - *


-   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
-   *   InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]");
-   *   String redisVersion = "";
-   *   Instance response = cloudRedisClient.upgradeInstanceAsync(name.toString(), redisVersion).get();
-   * }
-   * 
- * - * @param name Required. Redis instance resource name using the form: - * `projects/{project_id}/locations/{location_id}/instances/{instance_id}` where `location_id` - * refers to a GCP region. - * @param redisVersion Required. Specifies the target version of Redis software to upgrade to. - * @throws com.google.api.gax.rpc.ApiException if the remote call fails - */ - @BetaApi( - "The surface for long-running operations is not stable yet and may change in the future.") - public final OperationFuture upgradeInstanceAsync( - String name, String redisVersion) { - UpgradeInstanceRequest request = - UpgradeInstanceRequest.newBuilder().setName(name).setRedisVersion(redisVersion).build(); - return upgradeInstanceAsync(request); - } - - // AUTO-GENERATED DOCUMENTATION AND METHOD - /** - * Upgrades Redis instance to the newer Redis version specified in the request. - * - *

Sample code: - * - *


-   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
-   *   InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]");
-   *   String redisVersion = "";
-   *   UpgradeInstanceRequest request = UpgradeInstanceRequest.newBuilder()
-   *     .setName(name.toString())
-   *     .setRedisVersion(redisVersion)
-   *     .build();
-   *   Instance response = cloudRedisClient.upgradeInstanceAsync(request).get();
-   * }
-   * 
- * - * @param request The request object containing all of the parameters for the API call. - * @throws com.google.api.gax.rpc.ApiException if the remote call fails - */ - @BetaApi( - "The surface for long-running operations is not stable yet and may change in the future.") - public final OperationFuture upgradeInstanceAsync( - UpgradeInstanceRequest request) { - return upgradeInstanceOperationCallable().futureCall(request); - } - - // AUTO-GENERATED DOCUMENTATION AND METHOD - /** - * Upgrades Redis instance to the newer Redis version specified in the request. - * - *

Sample code: - * - *


-   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
-   *   InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]");
-   *   String redisVersion = "";
-   *   UpgradeInstanceRequest request = UpgradeInstanceRequest.newBuilder()
-   *     .setName(name.toString())
-   *     .setRedisVersion(redisVersion)
-   *     .build();
-   *   OperationFuture<Instance, OperationMetadata> future = cloudRedisClient.upgradeInstanceOperationCallable().futureCall(request);
-   *   // Do something
-   *   Instance response = future.get();
-   * }
-   * 
- */ - @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") - public final OperationCallable - upgradeInstanceOperationCallable() { - return stub.upgradeInstanceOperationCallable(); - } - - // AUTO-GENERATED DOCUMENTATION AND METHOD - /** - * Upgrades Redis instance to the newer Redis version specified in the request. - * - *

Sample code: - * - *


-   * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
-   *   InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]");
-   *   String redisVersion = "";
-   *   UpgradeInstanceRequest request = UpgradeInstanceRequest.newBuilder()
-   *     .setName(name.toString())
-   *     .setRedisVersion(redisVersion)
-   *     .build();
-   *   ApiFuture<Operation> future = cloudRedisClient.upgradeInstanceCallable().futureCall(request);
-   *   // Do something
-   *   Operation response = future.get();
-   * }
-   * 
- */ - public final UnaryCallable upgradeInstanceCallable() { - return stub.upgradeInstanceCallable(); - } - @Override public final void close() { stub.close(); diff --git a/test/integration/goldens/redis/CloudRedisClientTest.java b/test/integration/goldens/redis/CloudRedisClientTest.java index a012313099..fcbd325315 100644 --- a/test/integration/goldens/redis/CloudRedisClientTest.java +++ b/test/integration/goldens/redis/CloudRedisClientTest.java @@ -5,7 +5,7 @@ * 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 + * 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, @@ -13,9 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.google.cloud.redis.v1; -import static com.google.cloud.redis.v1.CloudRedisClient.ListInstancesPagedResponse; +package com.google.cloud.redis.v1; import com.google.api.gax.core.NoCredentialsProvider; import com.google.api.gax.grpc.GaxGrpcProperties; @@ -31,13 +30,14 @@ import com.google.protobuf.Any; import com.google.protobuf.Empty; import com.google.protobuf.FieldMask; -import io.grpc.Status; import io.grpc.StatusRuntimeException; import java.io.IOException; import java.util.Arrays; +import java.util.HashMap; import java.util.List; import java.util.UUID; import java.util.concurrent.ExecutionException; +import javax.annotation.Generated; import org.junit.After; import org.junit.AfterClass; import org.junit.Assert; @@ -45,31 +45,31 @@ import org.junit.BeforeClass; import org.junit.Test; -@javax.annotation.Generated("by GAPIC") +@Generated("by gapic-generator-java") public class CloudRedisClientTest { private static MockCloudRedis mockCloudRedis; - private static MockServiceHelper serviceHelper; + private static MockServiceHelper mockServiceHelper; private CloudRedisClient client; private LocalChannelProvider channelProvider; @BeforeClass public static void startStaticServer() { mockCloudRedis = new MockCloudRedis(); - serviceHelper = + mockServiceHelper = new MockServiceHelper( UUID.randomUUID().toString(), Arrays.asList(mockCloudRedis)); - serviceHelper.start(); + mockServiceHelper.start(); } @AfterClass public static void stopServer() { - serviceHelper.stop(); + mockServiceHelper.stop(); } @Before public void setUp() throws IOException { - serviceHelper.reset(); - channelProvider = serviceHelper.createChannelProvider(); + mockServiceHelper.reset(); + channelProvider = mockServiceHelper.createChannelProvider(); CloudRedisSettings settings = CloudRedisSettings.newBuilder() .setTransportChannelProvider(channelProvider) @@ -84,36 +84,216 @@ public void tearDown() throws Exception { } @Test - @SuppressWarnings("all") - public void createInstanceTest() throws Exception { + public void listInstancesTest() { + Instance responsesElement = Instance.newBuilder().build(); + ListInstancesResponse expectedResponse = + ListInstancesResponse.newBuilder() + .setNextPageToken("") + .addAllResponses(Arrays.asList(responsesElement)) + .build(); + mockCloudRedis.addResponse(expectedResponse); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + + ListInstancesResponse pagedListResponse = client.listInstances(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getResponsesList().get(0), resources.get(0)); + + List actualRequests = mockCloudRedis.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + ListInstancesRequest actualRequest = ((ListInstancesRequest) actualRequests.get(0)); + + Assert.assertEquals(parent.toString(), actualRequest.getParent()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void listInstancesExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockCloudRedis.addException(exception); + + try { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + client.listInstances(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listInstancesTest2() { + Instance responsesElement = Instance.newBuilder().build(); + ListInstancesResponse expectedResponse = + ListInstancesResponse.newBuilder() + .setNextPageToken("") + .addAllResponses(Arrays.asList(responsesElement)) + .build(); + mockCloudRedis.addResponse(expectedResponse); + + String parent = "parent-995424086"; + + ListInstancesResponse pagedListResponse = client.listInstances(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getResponsesList().get(0), resources.get(0)); + + List actualRequests = mockCloudRedis.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + ListInstancesRequest actualRequest = ((ListInstancesRequest) actualRequests.get(0)); + + Assert.assertEquals(parent, actualRequest.getParent()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void listInstancesExceptionTest2() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockCloudRedis.addException(exception); + + try { + String parent = "parent-995424086"; + client.listInstances(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getInstanceTest() { + Instance expectedResponse = + Instance.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setDisplayName("display_name1615086568") + .putAllLabels(new HashMap<>()) + .setLocationId("location_id552319461") + .setAlternativeLocationId("alternative_location_id-718920621") + .setRedisVersion("redis_version-685310444") + .setReservedIpRange("reserved_ip_range-1082940580") + .setHost("host3208616") + .setPort(3446913) + .setCurrentLocationId("current_location_id1312712735") + .setStatusMessage("status_message-239442758") + .putAllRedisConfigs(new HashMap<>()) + .setMemorySizeGb(34199707) + .setAuthorizedNetwork("authorized_network-1733809270") + .setPersistenceIamIdentity("persistence_iam_identity1061944584") + .build(); + mockCloudRedis.addResponse(expectedResponse); + InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); - String displayName = "displayName1615086568"; - String locationId = "locationId552319461"; - String alternativeLocationId = "alternativeLocationId-718920621"; - String redisVersion = "redisVersion-685310444"; - String reservedIpRange = "reservedIpRange-1082940580"; - String host = "host3208616"; - int port = 3446913; - String currentLocationId = "currentLocationId1312712735"; - String statusMessage = "statusMessage-239442758"; - int memorySizeGb2 = 1493816946; - String authorizedNetwork = "authorizedNetwork-1733809270"; - String persistenceIamIdentity = "persistenceIamIdentity1061944584"; + + Instance actualResponse = client.getInstance(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockCloudRedis.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + GetInstanceRequest actualRequest = ((GetInstanceRequest) actualRequests.get(0)); + + Assert.assertEquals(name.toString(), actualRequest.getName()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void getInstanceExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockCloudRedis.addException(exception); + + try { + InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + client.getInstance(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getInstanceTest2() { + Instance expectedResponse = + Instance.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setDisplayName("display_name1615086568") + .putAllLabels(new HashMap<>()) + .setLocationId("location_id552319461") + .setAlternativeLocationId("alternative_location_id-718920621") + .setRedisVersion("redis_version-685310444") + .setReservedIpRange("reserved_ip_range-1082940580") + .setHost("host3208616") + .setPort(3446913) + .setCurrentLocationId("current_location_id1312712735") + .setStatusMessage("status_message-239442758") + .putAllRedisConfigs(new HashMap<>()) + .setMemorySizeGb(34199707) + .setAuthorizedNetwork("authorized_network-1733809270") + .setPersistenceIamIdentity("persistence_iam_identity1061944584") + .build(); + mockCloudRedis.addResponse(expectedResponse); + + String name = "name3373707"; + + Instance actualResponse = client.getInstance(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockCloudRedis.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + GetInstanceRequest actualRequest = ((GetInstanceRequest) actualRequests.get(0)); + + Assert.assertEquals(name, actualRequest.getName()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void getInstanceExceptionTest2() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockCloudRedis.addException(exception); + + try { + String name = "name3373707"; + client.getInstance(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createInstanceTest() { Instance expectedResponse = Instance.newBuilder() - .setName(name.toString()) - .setDisplayName(displayName) - .setLocationId(locationId) - .setAlternativeLocationId(alternativeLocationId) - .setRedisVersion(redisVersion) - .setReservedIpRange(reservedIpRange) - .setHost(host) - .setPort(port) - .setCurrentLocationId(currentLocationId) - .setStatusMessage(statusMessage) - .setMemorySizeGb(memorySizeGb2) - .setAuthorizedNetwork(authorizedNetwork) - .setPersistenceIamIdentity(persistenceIamIdentity) + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setDisplayName("display_name1615086568") + .putAllLabels(new HashMap<>()) + .setLocationId("location_id552319461") + .setAlternativeLocationId("alternative_location_id-718920621") + .setRedisVersion("redis_version-685310444") + .setReservedIpRange("reserved_ip_range-1082940580") + .setHost("host3208616") + .setPort(3446913) + .setCurrentLocationId("current_location_id1312712735") + .setStatusMessage("status_message-239442758") + .putAllRedisConfigs(new HashMap<>()) + .setMemorySizeGb(34199707) + .setAuthorizedNetwork("authorized_network-1733809270") + .setPersistenceIamIdentity("persistence_iam_identity1061944584") .build(); Operation resultOperation = Operation.newBuilder() @@ -124,19 +304,17 @@ public void createInstanceTest() throws Exception { mockCloudRedis.addResponse(resultOperation); LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); - String instanceId = "test_instance"; - Instance.Tier tier = Instance.Tier.BASIC; - int memorySizeGb = 1; - Instance instance = Instance.newBuilder().setTier(tier).setMemorySizeGb(memorySizeGb).build(); + String instanceId = "instance_id-2101995259"; + Instance instance = Instance.newBuilder().build(); Instance actualResponse = client.createInstanceAsync(parent, instanceId, instance).get(); Assert.assertEquals(expectedResponse, actualResponse); List actualRequests = mockCloudRedis.getRequests(); Assert.assertEquals(1, actualRequests.size()); - CreateInstanceRequest actualRequest = (CreateInstanceRequest) actualRequests.get(0); + CreateInstanceRequest actualRequest = ((CreateInstanceRequest) actualRequests.get(0)); - Assert.assertEquals(parent, LocationName.parse(actualRequest.getParent())); + Assert.assertEquals(parent.toString(), actualRequest.getParent()); Assert.assertEquals(instanceId, actualRequest.getInstanceId()); Assert.assertEquals(instance, actualRequest.getInstance()); Assert.assertTrue( @@ -146,87 +324,126 @@ public void createInstanceTest() throws Exception { } @Test - @SuppressWarnings("all") public void createInstanceExceptionTest() throws Exception { - StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); mockCloudRedis.addException(exception); try { LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); - String instanceId = "test_instance"; - Instance.Tier tier = Instance.Tier.BASIC; - int memorySizeGb = 1; - Instance instance = Instance.newBuilder().setTier(tier).setMemorySizeGb(memorySizeGb).build(); - + String instanceId = "instance_id-2101995259"; + Instance instance = Instance.newBuilder().build(); client.createInstanceAsync(parent, instanceId, instance).get(); Assert.fail("No exception raised"); } catch (ExecutionException e) { Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); - InvalidArgumentException apiException = (InvalidArgumentException) e.getCause(); + InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause()); Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); } } @Test - @SuppressWarnings("all") - public void updateInstanceTest() throws Exception { - InstanceName name2 = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); - String displayName2 = "displayName21615000987"; - String locationId = "locationId552319461"; - String alternativeLocationId = "alternativeLocationId-718920621"; - String redisVersion = "redisVersion-685310444"; - String reservedIpRange = "reservedIpRange-1082940580"; - String host = "host3208616"; - int port = 3446913; - String currentLocationId = "currentLocationId1312712735"; - String statusMessage = "statusMessage-239442758"; - int memorySizeGb2 = 1493816946; - String authorizedNetwork = "authorizedNetwork-1733809270"; - String persistenceIamIdentity = "persistenceIamIdentity1061944584"; + public void createInstanceTest2() { Instance expectedResponse = Instance.newBuilder() - .setName(name2.toString()) - .setDisplayName(displayName2) - .setLocationId(locationId) - .setAlternativeLocationId(alternativeLocationId) - .setRedisVersion(redisVersion) - .setReservedIpRange(reservedIpRange) - .setHost(host) - .setPort(port) - .setCurrentLocationId(currentLocationId) - .setStatusMessage(statusMessage) - .setMemorySizeGb(memorySizeGb2) - .setAuthorizedNetwork(authorizedNetwork) - .setPersistenceIamIdentity(persistenceIamIdentity) + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setDisplayName("display_name1615086568") + .putAllLabels(new HashMap<>()) + .setLocationId("location_id552319461") + .setAlternativeLocationId("alternative_location_id-718920621") + .setRedisVersion("redis_version-685310444") + .setReservedIpRange("reserved_ip_range-1082940580") + .setHost("host3208616") + .setPort(3446913) + .setCurrentLocationId("current_location_id1312712735") + .setStatusMessage("status_message-239442758") + .putAllRedisConfigs(new HashMap<>()) + .setMemorySizeGb(34199707) + .setAuthorizedNetwork("authorized_network-1733809270") + .setPersistenceIamIdentity("persistence_iam_identity1061944584") .build(); Operation resultOperation = Operation.newBuilder() - .setName("updateInstanceTest") + .setName("createInstanceTest") .setDone(true) .setResponse(Any.pack(expectedResponse)) .build(); mockCloudRedis.addResponse(resultOperation); - String pathsElement = "display_name"; - String pathsElement2 = "memory_size_gb"; - List paths = Arrays.asList(pathsElement, pathsElement2); - FieldMask updateMask = FieldMask.newBuilder().addAllPaths(paths).build(); - String displayName = "UpdatedDisplayName"; - String name = "projects//locations//instances/"; - int memorySizeGb = 4; - Instance instance = + String parent = "parent-995424086"; + String instanceId = "instance_id-2101995259"; + Instance instance = Instance.newBuilder().build(); + + Instance actualResponse = client.createInstanceAsync(parent, instanceId, instance).get(); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockCloudRedis.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + CreateInstanceRequest actualRequest = ((CreateInstanceRequest) actualRequests.get(0)); + + Assert.assertEquals(parent, actualRequest.getParent()); + Assert.assertEquals(instanceId, actualRequest.getInstanceId()); + Assert.assertEquals(instance, actualRequest.getInstance()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void createInstanceExceptionTest2() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockCloudRedis.addException(exception); + + try { + String parent = "parent-995424086"; + String instanceId = "instance_id-2101995259"; + Instance instance = Instance.newBuilder().build(); + client.createInstanceAsync(parent, instanceId, instance).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); + InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause()); + Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); + } + } + + @Test + public void updateInstanceTest() { + Instance expectedResponse = Instance.newBuilder() - .setDisplayName(displayName) - .setName(name) - .setMemorySizeGb(memorySizeGb) + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setDisplayName("display_name1615086568") + .putAllLabels(new HashMap<>()) + .setLocationId("location_id552319461") + .setAlternativeLocationId("alternative_location_id-718920621") + .setRedisVersion("redis_version-685310444") + .setReservedIpRange("reserved_ip_range-1082940580") + .setHost("host3208616") + .setPort(3446913) + .setCurrentLocationId("current_location_id1312712735") + .setStatusMessage("status_message-239442758") + .putAllRedisConfigs(new HashMap<>()) + .setMemorySizeGb(34199707) + .setAuthorizedNetwork("authorized_network-1733809270") + .setPersistenceIamIdentity("persistence_iam_identity1061944584") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("updateInstanceTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) .build(); + mockCloudRedis.addResponse(resultOperation); + + FieldMask updateMask = FieldMask.newBuilder().build(); + Instance instance = Instance.newBuilder().build(); Instance actualResponse = client.updateInstanceAsync(updateMask, instance).get(); Assert.assertEquals(expectedResponse, actualResponse); List actualRequests = mockCloudRedis.getRequests(); Assert.assertEquals(1, actualRequests.size()); - UpdateInstanceRequest actualRequest = (UpdateInstanceRequest) actualRequests.get(0); + UpdateInstanceRequest actualRequest = ((UpdateInstanceRequest) actualRequests.get(0)); Assert.assertEquals(updateMask, actualRequest.getUpdateMask()); Assert.assertEquals(instance, actualRequest.getInstance()); @@ -237,87 +454,125 @@ public void updateInstanceTest() throws Exception { } @Test - @SuppressWarnings("all") public void updateInstanceExceptionTest() throws Exception { - StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); mockCloudRedis.addException(exception); try { - String pathsElement = "display_name"; - String pathsElement2 = "memory_size_gb"; - List paths = Arrays.asList(pathsElement, pathsElement2); - FieldMask updateMask = FieldMask.newBuilder().addAllPaths(paths).build(); - String displayName = "UpdatedDisplayName"; - String name = "projects//locations//instances/"; - int memorySizeGb = 4; - Instance instance = - Instance.newBuilder() - .setDisplayName(displayName) - .setName(name) - .setMemorySizeGb(memorySizeGb) - .build(); - + FieldMask updateMask = FieldMask.newBuilder().build(); + Instance instance = Instance.newBuilder().build(); client.updateInstanceAsync(updateMask, instance).get(); Assert.fail("No exception raised"); } catch (ExecutionException e) { Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); - InvalidArgumentException apiException = (InvalidArgumentException) e.getCause(); + InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause()); Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); } } @Test - @SuppressWarnings("all") - public void importInstanceTest() throws Exception { - InstanceName name2 = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); - String displayName = "displayName1615086568"; - String locationId = "locationId552319461"; - String alternativeLocationId = "alternativeLocationId-718920621"; - String redisVersion = "redisVersion-685310444"; - String reservedIpRange = "reservedIpRange-1082940580"; - String host = "host3208616"; - int port = 3446913; - String currentLocationId = "currentLocationId1312712735"; - String statusMessage = "statusMessage-239442758"; - int memorySizeGb = 34199707; - String authorizedNetwork = "authorizedNetwork-1733809270"; - String persistenceIamIdentity = "persistenceIamIdentity1061944584"; + public void upgradeInstanceTest() { Instance expectedResponse = Instance.newBuilder() - .setName(name2.toString()) - .setDisplayName(displayName) - .setLocationId(locationId) - .setAlternativeLocationId(alternativeLocationId) - .setRedisVersion(redisVersion) - .setReservedIpRange(reservedIpRange) - .setHost(host) - .setPort(port) - .setCurrentLocationId(currentLocationId) - .setStatusMessage(statusMessage) - .setMemorySizeGb(memorySizeGb) - .setAuthorizedNetwork(authorizedNetwork) - .setPersistenceIamIdentity(persistenceIamIdentity) + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setDisplayName("display_name1615086568") + .putAllLabels(new HashMap<>()) + .setLocationId("location_id552319461") + .setAlternativeLocationId("alternative_location_id-718920621") + .setRedisVersion("redis_version-685310444") + .setReservedIpRange("reserved_ip_range-1082940580") + .setHost("host3208616") + .setPort(3446913) + .setCurrentLocationId("current_location_id1312712735") + .setStatusMessage("status_message-239442758") + .putAllRedisConfigs(new HashMap<>()) + .setMemorySizeGb(34199707) + .setAuthorizedNetwork("authorized_network-1733809270") + .setPersistenceIamIdentity("persistence_iam_identity1061944584") .build(); Operation resultOperation = Operation.newBuilder() - .setName("importInstanceTest") + .setName("upgradeInstanceTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockCloudRedis.addResponse(resultOperation); + + InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + String redisVersion = "redis_version-685310444"; + + Instance actualResponse = client.upgradeInstanceAsync(name, redisVersion).get(); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockCloudRedis.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + UpgradeInstanceRequest actualRequest = ((UpgradeInstanceRequest) actualRequests.get(0)); + + Assert.assertEquals(name.toString(), actualRequest.getName()); + Assert.assertEquals(redisVersion, actualRequest.getRedisVersion()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void upgradeInstanceExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockCloudRedis.addException(exception); + + try { + InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + String redisVersion = "redis_version-685310444"; + client.upgradeInstanceAsync(name, redisVersion).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); + InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause()); + Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); + } + } + + @Test + public void upgradeInstanceTest2() { + Instance expectedResponse = + Instance.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setDisplayName("display_name1615086568") + .putAllLabels(new HashMap<>()) + .setLocationId("location_id552319461") + .setAlternativeLocationId("alternative_location_id-718920621") + .setRedisVersion("redis_version-685310444") + .setReservedIpRange("reserved_ip_range-1082940580") + .setHost("host3208616") + .setPort(3446913) + .setCurrentLocationId("current_location_id1312712735") + .setStatusMessage("status_message-239442758") + .putAllRedisConfigs(new HashMap<>()) + .setMemorySizeGb(34199707) + .setAuthorizedNetwork("authorized_network-1733809270") + .setPersistenceIamIdentity("persistence_iam_identity1061944584") + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("upgradeInstanceTest") .setDone(true) .setResponse(Any.pack(expectedResponse)) .build(); mockCloudRedis.addResponse(resultOperation); String name = "name3373707"; - InputConfig inputConfig = InputConfig.newBuilder().build(); + String redisVersion = "redis_version-685310444"; - Instance actualResponse = client.importInstanceAsync(name, inputConfig).get(); + Instance actualResponse = client.upgradeInstanceAsync(name, redisVersion).get(); Assert.assertEquals(expectedResponse, actualResponse); List actualRequests = mockCloudRedis.getRequests(); Assert.assertEquals(1, actualRequests.size()); - ImportInstanceRequest actualRequest = (ImportInstanceRequest) actualRequests.get(0); + UpgradeInstanceRequest actualRequest = ((UpgradeInstanceRequest) actualRequests.get(0)); Assert.assertEquals(name, actualRequest.getName()); - Assert.assertEquals(inputConfig, actualRequest.getInputConfig()); + Assert.assertEquals(redisVersion, actualRequest.getRedisVersion()); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), @@ -325,76 +580,62 @@ public void importInstanceTest() throws Exception { } @Test - @SuppressWarnings("all") - public void importInstanceExceptionTest() throws Exception { - StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); + public void upgradeInstanceExceptionTest2() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); mockCloudRedis.addException(exception); try { String name = "name3373707"; - InputConfig inputConfig = InputConfig.newBuilder().build(); - - client.importInstanceAsync(name, inputConfig).get(); + String redisVersion = "redis_version-685310444"; + client.upgradeInstanceAsync(name, redisVersion).get(); Assert.fail("No exception raised"); } catch (ExecutionException e) { Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); - InvalidArgumentException apiException = (InvalidArgumentException) e.getCause(); + InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause()); Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); } } @Test - @SuppressWarnings("all") - public void exportInstanceTest() throws Exception { - InstanceName name2 = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); - String displayName = "displayName1615086568"; - String locationId = "locationId552319461"; - String alternativeLocationId = "alternativeLocationId-718920621"; - String redisVersion = "redisVersion-685310444"; - String reservedIpRange = "reservedIpRange-1082940580"; - String host = "host3208616"; - int port = 3446913; - String currentLocationId = "currentLocationId1312712735"; - String statusMessage = "statusMessage-239442758"; - int memorySizeGb = 34199707; - String authorizedNetwork = "authorizedNetwork-1733809270"; - String persistenceIamIdentity = "persistenceIamIdentity1061944584"; + public void importInstanceTest() { Instance expectedResponse = Instance.newBuilder() - .setName(name2.toString()) - .setDisplayName(displayName) - .setLocationId(locationId) - .setAlternativeLocationId(alternativeLocationId) - .setRedisVersion(redisVersion) - .setReservedIpRange(reservedIpRange) - .setHost(host) - .setPort(port) - .setCurrentLocationId(currentLocationId) - .setStatusMessage(statusMessage) - .setMemorySizeGb(memorySizeGb) - .setAuthorizedNetwork(authorizedNetwork) - .setPersistenceIamIdentity(persistenceIamIdentity) + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setDisplayName("display_name1615086568") + .putAllLabels(new HashMap<>()) + .setLocationId("location_id552319461") + .setAlternativeLocationId("alternative_location_id-718920621") + .setRedisVersion("redis_version-685310444") + .setReservedIpRange("reserved_ip_range-1082940580") + .setHost("host3208616") + .setPort(3446913) + .setCurrentLocationId("current_location_id1312712735") + .setStatusMessage("status_message-239442758") + .putAllRedisConfigs(new HashMap<>()) + .setMemorySizeGb(34199707) + .setAuthorizedNetwork("authorized_network-1733809270") + .setPersistenceIamIdentity("persistence_iam_identity1061944584") .build(); Operation resultOperation = Operation.newBuilder() - .setName("exportInstanceTest") + .setName("importInstanceTest") .setDone(true) .setResponse(Any.pack(expectedResponse)) .build(); mockCloudRedis.addResponse(resultOperation); String name = "name3373707"; - OutputConfig outputConfig = OutputConfig.newBuilder().build(); + InputConfig inputConfig = InputConfig.newBuilder().build(); - Instance actualResponse = client.exportInstanceAsync(name, outputConfig).get(); + Instance actualResponse = client.importInstanceAsync(name, inputConfig).get(); Assert.assertEquals(expectedResponse, actualResponse); List actualRequests = mockCloudRedis.getRequests(); Assert.assertEquals(1, actualRequests.size()); - ExportInstanceRequest actualRequest = (ExportInstanceRequest) actualRequests.get(0); + ImportInstanceRequest actualRequest = ((ImportInstanceRequest) actualRequests.get(0)); Assert.assertEquals(name, actualRequest.getName()); - Assert.assertEquals(outputConfig, actualRequest.getOutputConfig()); + Assert.assertEquals(inputConfig, actualRequest.getInputConfig()); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), @@ -402,77 +643,62 @@ public void exportInstanceTest() throws Exception { } @Test - @SuppressWarnings("all") - public void exportInstanceExceptionTest() throws Exception { - StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); + public void importInstanceExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); mockCloudRedis.addException(exception); try { String name = "name3373707"; - OutputConfig outputConfig = OutputConfig.newBuilder().build(); - - client.exportInstanceAsync(name, outputConfig).get(); + InputConfig inputConfig = InputConfig.newBuilder().build(); + client.importInstanceAsync(name, inputConfig).get(); Assert.fail("No exception raised"); } catch (ExecutionException e) { Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); - InvalidArgumentException apiException = (InvalidArgumentException) e.getCause(); + InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause()); Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); } } @Test - @SuppressWarnings("all") - public void failoverInstanceTest() throws Exception { - InstanceName name2 = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); - String displayName = "displayName1615086568"; - String locationId = "locationId552319461"; - String alternativeLocationId = "alternativeLocationId-718920621"; - String redisVersion = "redisVersion-685310444"; - String reservedIpRange = "reservedIpRange-1082940580"; - String host = "host3208616"; - int port = 3446913; - String currentLocationId = "currentLocationId1312712735"; - String statusMessage = "statusMessage-239442758"; - int memorySizeGb = 34199707; - String authorizedNetwork = "authorizedNetwork-1733809270"; - String persistenceIamIdentity = "persistenceIamIdentity1061944584"; + public void exportInstanceTest() { Instance expectedResponse = Instance.newBuilder() - .setName(name2.toString()) - .setDisplayName(displayName) - .setLocationId(locationId) - .setAlternativeLocationId(alternativeLocationId) - .setRedisVersion(redisVersion) - .setReservedIpRange(reservedIpRange) - .setHost(host) - .setPort(port) - .setCurrentLocationId(currentLocationId) - .setStatusMessage(statusMessage) - .setMemorySizeGb(memorySizeGb) - .setAuthorizedNetwork(authorizedNetwork) - .setPersistenceIamIdentity(persistenceIamIdentity) + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setDisplayName("display_name1615086568") + .putAllLabels(new HashMap<>()) + .setLocationId("location_id552319461") + .setAlternativeLocationId("alternative_location_id-718920621") + .setRedisVersion("redis_version-685310444") + .setReservedIpRange("reserved_ip_range-1082940580") + .setHost("host3208616") + .setPort(3446913) + .setCurrentLocationId("current_location_id1312712735") + .setStatusMessage("status_message-239442758") + .putAllRedisConfigs(new HashMap<>()) + .setMemorySizeGb(34199707) + .setAuthorizedNetwork("authorized_network-1733809270") + .setPersistenceIamIdentity("persistence_iam_identity1061944584") .build(); Operation resultOperation = Operation.newBuilder() - .setName("failoverInstanceTest") + .setName("exportInstanceTest") .setDone(true) .setResponse(Any.pack(expectedResponse)) .build(); mockCloudRedis.addResponse(resultOperation); - InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); - FailoverInstanceRequest.DataProtectionMode dataProtectionMode = - FailoverInstanceRequest.DataProtectionMode.DATA_PROTECTION_MODE_UNSPECIFIED; + String name = "name3373707"; + OutputConfig outputConfig = OutputConfig.newBuilder().build(); - Instance actualResponse = client.failoverInstanceAsync(name, dataProtectionMode).get(); + Instance actualResponse = client.exportInstanceAsync(name, outputConfig).get(); Assert.assertEquals(expectedResponse, actualResponse); List actualRequests = mockCloudRedis.getRequests(); Assert.assertEquals(1, actualRequests.size()); - FailoverInstanceRequest actualRequest = (FailoverInstanceRequest) actualRequests.get(0); + ExportInstanceRequest actualRequest = ((ExportInstanceRequest) actualRequests.get(0)); - Assert.assertEquals(name, InstanceName.parse(actualRequest.getName())); - Assert.assertEquals(dataProtectionMode, actualRequest.getDataProtectionMode()); + Assert.assertEquals(name, actualRequest.getName()); + Assert.assertEquals(outputConfig, actualRequest.getOutputConfig()); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), @@ -480,47 +706,63 @@ public void failoverInstanceTest() throws Exception { } @Test - @SuppressWarnings("all") - public void failoverInstanceExceptionTest() throws Exception { - StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); + public void exportInstanceExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); mockCloudRedis.addException(exception); try { - InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); - FailoverInstanceRequest.DataProtectionMode dataProtectionMode = - FailoverInstanceRequest.DataProtectionMode.DATA_PROTECTION_MODE_UNSPECIFIED; - - client.failoverInstanceAsync(name, dataProtectionMode).get(); + String name = "name3373707"; + OutputConfig outputConfig = OutputConfig.newBuilder().build(); + client.exportInstanceAsync(name, outputConfig).get(); Assert.fail("No exception raised"); } catch (ExecutionException e) { Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); - InvalidArgumentException apiException = (InvalidArgumentException) e.getCause(); + InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause()); Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); } } @Test - @SuppressWarnings("all") - public void deleteInstanceTest() throws Exception { - Empty expectedResponse = Empty.newBuilder().build(); + public void failoverInstanceTest() { + Instance expectedResponse = + Instance.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setDisplayName("display_name1615086568") + .putAllLabels(new HashMap<>()) + .setLocationId("location_id552319461") + .setAlternativeLocationId("alternative_location_id-718920621") + .setRedisVersion("redis_version-685310444") + .setReservedIpRange("reserved_ip_range-1082940580") + .setHost("host3208616") + .setPort(3446913) + .setCurrentLocationId("current_location_id1312712735") + .setStatusMessage("status_message-239442758") + .putAllRedisConfigs(new HashMap<>()) + .setMemorySizeGb(34199707) + .setAuthorizedNetwork("authorized_network-1733809270") + .setPersistenceIamIdentity("persistence_iam_identity1061944584") + .build(); Operation resultOperation = Operation.newBuilder() - .setName("deleteInstanceTest") + .setName("failoverInstanceTest") .setDone(true) .setResponse(Any.pack(expectedResponse)) .build(); mockCloudRedis.addResponse(resultOperation); InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); + FailoverInstanceRequest.DataProtectionMode dataProtectionMode = + FailoverInstanceRequest.DataProtectionMode.forNumber(0); - Empty actualResponse = client.deleteInstanceAsync(name).get(); + Instance actualResponse = client.failoverInstanceAsync(name, dataProtectionMode).get(); Assert.assertEquals(expectedResponse, actualResponse); List actualRequests = mockCloudRedis.getRequests(); Assert.assertEquals(1, actualRequests.size()); - DeleteInstanceRequest actualRequest = (DeleteInstanceRequest) actualRequests.get(0); + FailoverInstanceRequest actualRequest = ((FailoverInstanceRequest) actualRequests.get(0)); - Assert.assertEquals(name, InstanceName.parse(actualRequest.getName())); + Assert.assertEquals(name.toString(), actualRequest.getName()); + Assert.assertEquals(dataProtectionMode, actualRequest.getDataProtectionMode()); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), @@ -528,49 +770,64 @@ public void deleteInstanceTest() throws Exception { } @Test - @SuppressWarnings("all") - public void deleteInstanceExceptionTest() throws Exception { - StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); + public void failoverInstanceExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); mockCloudRedis.addException(exception); try { InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); - - client.deleteInstanceAsync(name).get(); + FailoverInstanceRequest.DataProtectionMode dataProtectionMode = + FailoverInstanceRequest.DataProtectionMode.forNumber(0); + client.failoverInstanceAsync(name, dataProtectionMode).get(); Assert.fail("No exception raised"); } catch (ExecutionException e) { Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); - InvalidArgumentException apiException = (InvalidArgumentException) e.getCause(); + InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause()); Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); } } @Test - @SuppressWarnings("all") - public void listInstancesTest() { - String nextPageToken = ""; - Instance instancesElement = Instance.newBuilder().build(); - List instances = Arrays.asList(instancesElement); - ListInstancesResponse expectedResponse = - ListInstancesResponse.newBuilder() - .setNextPageToken(nextPageToken) - .addAllInstances(instances) + public void failoverInstanceTest2() { + Instance expectedResponse = + Instance.newBuilder() + .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) + .setDisplayName("display_name1615086568") + .putAllLabels(new HashMap<>()) + .setLocationId("location_id552319461") + .setAlternativeLocationId("alternative_location_id-718920621") + .setRedisVersion("redis_version-685310444") + .setReservedIpRange("reserved_ip_range-1082940580") + .setHost("host3208616") + .setPort(3446913) + .setCurrentLocationId("current_location_id1312712735") + .setStatusMessage("status_message-239442758") + .putAllRedisConfigs(new HashMap<>()) + .setMemorySizeGb(34199707) + .setAuthorizedNetwork("authorized_network-1733809270") + .setPersistenceIamIdentity("persistence_iam_identity1061944584") .build(); - mockCloudRedis.addResponse(expectedResponse); - - LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + Operation resultOperation = + Operation.newBuilder() + .setName("failoverInstanceTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockCloudRedis.addResponse(resultOperation); - ListInstancesPagedResponse pagedListResponse = client.listInstances(parent); + String name = "name3373707"; + FailoverInstanceRequest.DataProtectionMode dataProtectionMode = + FailoverInstanceRequest.DataProtectionMode.forNumber(0); - List resources = Lists.newArrayList(pagedListResponse.iterateAll()); - Assert.assertEquals(1, resources.size()); - Assert.assertEquals(expectedResponse.getInstancesList().get(0), resources.get(0)); + Instance actualResponse = client.failoverInstanceAsync(name, dataProtectionMode).get(); + Assert.assertEquals(expectedResponse, actualResponse); List actualRequests = mockCloudRedis.getRequests(); Assert.assertEquals(1, actualRequests.size()); - ListInstancesRequest actualRequest = (ListInstancesRequest) actualRequests.get(0); + FailoverInstanceRequest actualRequest = ((FailoverInstanceRequest) actualRequests.get(0)); - Assert.assertEquals(parent, LocationName.parse(actualRequest.getParent())); + Assert.assertEquals(name, actualRequest.getName()); + Assert.assertEquals(dataProtectionMode, actualRequest.getDataProtectionMode()); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), @@ -578,65 +835,44 @@ public void listInstancesTest() { } @Test - @SuppressWarnings("all") - public void listInstancesExceptionTest() throws Exception { - StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); + public void failoverInstanceExceptionTest2() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); mockCloudRedis.addException(exception); try { - LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); - - client.listInstances(parent); + String name = "name3373707"; + FailoverInstanceRequest.DataProtectionMode dataProtectionMode = + FailoverInstanceRequest.DataProtectionMode.forNumber(0); + client.failoverInstanceAsync(name, dataProtectionMode).get(); Assert.fail("No exception raised"); - } catch (InvalidArgumentException e) { - // Expected exception + } catch (ExecutionException e) { + Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); + InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause()); + Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); } } @Test - @SuppressWarnings("all") - public void getInstanceTest() { - InstanceName name2 = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); - String displayName = "displayName1615086568"; - String locationId = "locationId552319461"; - String alternativeLocationId = "alternativeLocationId-718920621"; - String redisVersion = "redisVersion-685310444"; - String reservedIpRange = "reservedIpRange-1082940580"; - String host = "host3208616"; - int port = 3446913; - String currentLocationId = "currentLocationId1312712735"; - String statusMessage = "statusMessage-239442758"; - int memorySizeGb = 34199707; - String authorizedNetwork = "authorizedNetwork-1733809270"; - String persistenceIamIdentity = "persistenceIamIdentity1061944584"; - Instance expectedResponse = - Instance.newBuilder() - .setName(name2.toString()) - .setDisplayName(displayName) - .setLocationId(locationId) - .setAlternativeLocationId(alternativeLocationId) - .setRedisVersion(redisVersion) - .setReservedIpRange(reservedIpRange) - .setHost(host) - .setPort(port) - .setCurrentLocationId(currentLocationId) - .setStatusMessage(statusMessage) - .setMemorySizeGb(memorySizeGb) - .setAuthorizedNetwork(authorizedNetwork) - .setPersistenceIamIdentity(persistenceIamIdentity) + public void deleteInstanceTest() { + Empty expectedResponse = Empty.newBuilder().build(); + Operation resultOperation = + Operation.newBuilder() + .setName("deleteInstanceTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) .build(); - mockCloudRedis.addResponse(expectedResponse); + mockCloudRedis.addResponse(resultOperation); InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); - Instance actualResponse = client.getInstance(name); + Empty actualResponse = client.deleteInstanceAsync(name).get(); Assert.assertEquals(expectedResponse, actualResponse); List actualRequests = mockCloudRedis.getRequests(); Assert.assertEquals(1, actualRequests.size()); - GetInstanceRequest actualRequest = (GetInstanceRequest) actualRequests.get(0); + DeleteInstanceRequest actualRequest = ((DeleteInstanceRequest) actualRequests.get(0)); - Assert.assertEquals(name, InstanceName.parse(actualRequest.getName())); + Assert.assertEquals(name.toString(), actualRequest.getName()); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), @@ -644,73 +880,42 @@ public void getInstanceTest() { } @Test - @SuppressWarnings("all") - public void getInstanceExceptionTest() throws Exception { - StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); + public void deleteInstanceExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); mockCloudRedis.addException(exception); try { InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); - - client.getInstance(name); + client.deleteInstanceAsync(name).get(); Assert.fail("No exception raised"); - } catch (InvalidArgumentException e) { - // Expected exception + } catch (ExecutionException e) { + Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); + InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause()); + Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); } } @Test - @SuppressWarnings("all") - public void upgradeInstanceTest() throws Exception { - InstanceName name2 = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); - String displayName = "displayName1615086568"; - String locationId = "locationId552319461"; - String alternativeLocationId = "alternativeLocationId-718920621"; - String redisVersion2 = "redisVersion2-1453337401"; - String reservedIpRange = "reservedIpRange-1082940580"; - String host = "host3208616"; - int port = 3446913; - String currentLocationId = "currentLocationId1312712735"; - String statusMessage = "statusMessage-239442758"; - int memorySizeGb = 34199707; - String authorizedNetwork = "authorizedNetwork-1733809270"; - String persistenceIamIdentity = "persistenceIamIdentity1061944584"; - Instance expectedResponse = - Instance.newBuilder() - .setName(name2.toString()) - .setDisplayName(displayName) - .setLocationId(locationId) - .setAlternativeLocationId(alternativeLocationId) - .setRedisVersion(redisVersion2) - .setReservedIpRange(reservedIpRange) - .setHost(host) - .setPort(port) - .setCurrentLocationId(currentLocationId) - .setStatusMessage(statusMessage) - .setMemorySizeGb(memorySizeGb) - .setAuthorizedNetwork(authorizedNetwork) - .setPersistenceIamIdentity(persistenceIamIdentity) - .build(); + public void deleteInstanceTest2() { + Empty expectedResponse = Empty.newBuilder().build(); Operation resultOperation = Operation.newBuilder() - .setName("upgradeInstanceTest") + .setName("deleteInstanceTest") .setDone(true) .setResponse(Any.pack(expectedResponse)) .build(); mockCloudRedis.addResponse(resultOperation); - InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); - String redisVersion = "redisVersion-685310444"; + String name = "name3373707"; - Instance actualResponse = client.upgradeInstanceAsync(name, redisVersion).get(); + Empty actualResponse = client.deleteInstanceAsync(name).get(); Assert.assertEquals(expectedResponse, actualResponse); List actualRequests = mockCloudRedis.getRequests(); Assert.assertEquals(1, actualRequests.size()); - UpgradeInstanceRequest actualRequest = (UpgradeInstanceRequest) actualRequests.get(0); + DeleteInstanceRequest actualRequest = ((DeleteInstanceRequest) actualRequests.get(0)); - Assert.assertEquals(name, InstanceName.parse(actualRequest.getName())); - Assert.assertEquals(redisVersion, actualRequest.getRedisVersion()); + Assert.assertEquals(name, actualRequest.getName()); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), @@ -718,20 +923,17 @@ public void upgradeInstanceTest() throws Exception { } @Test - @SuppressWarnings("all") - public void upgradeInstanceExceptionTest() throws Exception { - StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); + public void deleteInstanceExceptionTest2() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); mockCloudRedis.addException(exception); try { - InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); - String redisVersion = "redisVersion-685310444"; - - client.upgradeInstanceAsync(name, redisVersion).get(); + String name = "name3373707"; + client.deleteInstanceAsync(name).get(); Assert.fail("No exception raised"); } catch (ExecutionException e) { Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); - InvalidArgumentException apiException = (InvalidArgumentException) e.getCause(); + InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause()); Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); } } diff --git a/test/integration/goldens/redis/CloudRedisSettings.java b/test/integration/goldens/redis/CloudRedisSettings.java index b54865d04f..4a33403427 100644 --- a/test/integration/goldens/redis/CloudRedisSettings.java +++ b/test/integration/goldens/redis/CloudRedisSettings.java @@ -5,7 +5,7 @@ * 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 + * 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, @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.google.cloud.redis.v1; import static com.google.cloud.redis.v1.CloudRedisClient.ListInstancesPagedResponse; @@ -27,6 +28,7 @@ import com.google.api.gax.rpc.ClientSettings; import com.google.api.gax.rpc.OperationCallSettings; import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.StubSettings; import com.google.api.gax.rpc.TransportChannelProvider; import com.google.api.gax.rpc.UnaryCallSettings; import com.google.cloud.redis.v1.stub.CloudRedisStubSettings; @@ -36,7 +38,7 @@ import java.util.List; import javax.annotation.Generated; -// AUTO-GENERATED DOCUMENTATION AND CLASS +// AUTO-GENERATED DOCUMENTATION AND CLASS. /** * Settings class to configure an instance of {@link CloudRedisClient}. * @@ -51,33 +53,28 @@ *

The builder of this class is recursive, so contained classes are themselves builders. When * build() is called, the tree of builders is called to create the complete settings object. * - *

For example, to set the total timeout of getInstance to 30 seconds: - * - *

- * 
- * CloudRedisSettings.Builder cloudRedisSettingsBuilder =
- *     CloudRedisSettings.newBuilder();
- * cloudRedisSettingsBuilder
- *     .getInstanceSettings()
- *     .setRetrySettings(
- *         cloudRedisSettingsBuilder.getInstanceSettings().getRetrySettings().toBuilder()
- *             .setTotalTimeout(Duration.ofSeconds(30))
- *             .build());
- * CloudRedisSettings cloudRedisSettings = cloudRedisSettingsBuilder.build();
- * 
- * 
+ *

For example, to set the total timeout of listInstances to 30 seconds: */ -@Generated("by gapic-generator") -@BetaApi +@Generated("by gapic-generator-java") public class CloudRedisSettings extends ClientSettings { + + /** Returns the object with the settings used for calls to listInstances. */ + public PagedCallSettings + listInstancesSettings() { + return ((CloudRedisStubSettings) getStubSettings()).listInstancesSettings(); + } + + /** Returns the object with the settings used for calls to getInstance. */ + public UnaryCallSettings getInstanceSettings() { + return ((CloudRedisStubSettings) getStubSettings()).getInstanceSettings(); + } + /** Returns the object with the settings used for calls to createInstance. */ public UnaryCallSettings createInstanceSettings() { return ((CloudRedisStubSettings) getStubSettings()).createInstanceSettings(); } /** Returns the object with the settings used for calls to createInstance. */ - @BetaApi( - "The surface for long-running operations is not stable yet and may change in the future.") public OperationCallSettings createInstanceOperationSettings() { return ((CloudRedisStubSettings) getStubSettings()).createInstanceOperationSettings(); @@ -89,21 +86,28 @@ public UnaryCallSettings updateInstanceSetting } /** Returns the object with the settings used for calls to updateInstance. */ - @BetaApi( - "The surface for long-running operations is not stable yet and may change in the future.") public OperationCallSettings updateInstanceOperationSettings() { return ((CloudRedisStubSettings) getStubSettings()).updateInstanceOperationSettings(); } + /** Returns the object with the settings used for calls to upgradeInstance. */ + public UnaryCallSettings upgradeInstanceSettings() { + return ((CloudRedisStubSettings) getStubSettings()).upgradeInstanceSettings(); + } + + /** Returns the object with the settings used for calls to upgradeInstance. */ + public OperationCallSettings + upgradeInstanceOperationSettings() { + return ((CloudRedisStubSettings) getStubSettings()).upgradeInstanceOperationSettings(); + } + /** Returns the object with the settings used for calls to importInstance. */ public UnaryCallSettings importInstanceSettings() { return ((CloudRedisStubSettings) getStubSettings()).importInstanceSettings(); } /** Returns the object with the settings used for calls to importInstance. */ - @BetaApi( - "The surface for long-running operations is not stable yet and may change in the future.") public OperationCallSettings importInstanceOperationSettings() { return ((CloudRedisStubSettings) getStubSettings()).importInstanceOperationSettings(); @@ -115,8 +119,6 @@ public UnaryCallSettings exportInstanceSetting } /** Returns the object with the settings used for calls to exportInstance. */ - @BetaApi( - "The surface for long-running operations is not stable yet and may change in the future.") public OperationCallSettings exportInstanceOperationSettings() { return ((CloudRedisStubSettings) getStubSettings()).exportInstanceOperationSettings(); @@ -128,8 +130,6 @@ public UnaryCallSettings failoverInstanceSet } /** Returns the object with the settings used for calls to failoverInstance. */ - @BetaApi( - "The surface for long-running operations is not stable yet and may change in the future.") public OperationCallSettings failoverInstanceOperationSettings() { return ((CloudRedisStubSettings) getStubSettings()).failoverInstanceOperationSettings(); @@ -141,37 +141,11 @@ public UnaryCallSettings deleteInstanceSetting } /** Returns the object with the settings used for calls to deleteInstance. */ - @BetaApi( - "The surface for long-running operations is not stable yet and may change in the future.") public OperationCallSettings deleteInstanceOperationSettings() { return ((CloudRedisStubSettings) getStubSettings()).deleteInstanceOperationSettings(); } - /** Returns the object with the settings used for calls to listInstances. */ - public PagedCallSettings - listInstancesSettings() { - return ((CloudRedisStubSettings) getStubSettings()).listInstancesSettings(); - } - - /** Returns the object with the settings used for calls to getInstance. */ - public UnaryCallSettings getInstanceSettings() { - return ((CloudRedisStubSettings) getStubSettings()).getInstanceSettings(); - } - - /** Returns the object with the settings used for calls to upgradeInstance. */ - public UnaryCallSettings upgradeInstanceSettings() { - return ((CloudRedisStubSettings) getStubSettings()).upgradeInstanceSettings(); - } - - /** Returns the object with the settings used for calls to upgradeInstance. */ - @BetaApi( - "The surface for long-running operations is not stable yet and may change in the future.") - public OperationCallSettings - upgradeInstanceOperationSettings() { - return ((CloudRedisStubSettings) getStubSettings()).upgradeInstanceOperationSettings(); - } - public static final CloudRedisSettings create(CloudRedisStubSettings stub) throws IOException { return new CloudRedisSettings.Builder(stub.toBuilder()).build(); } @@ -231,18 +205,15 @@ protected CloudRedisSettings(Builder settingsBuilder) throws IOException { /** Builder for CloudRedisSettings. */ public static class Builder extends ClientSettings.Builder { + protected Builder() throws IOException { - this((ClientContext) null); + this(((ClientContext) null)); } protected Builder(ClientContext clientContext) { super(CloudRedisStubSettings.newBuilder(clientContext)); } - private static Builder createDefault() { - return new Builder(CloudRedisStubSettings.newBuilder()); - } - protected Builder(CloudRedisSettings settings) { super(settings.getStubSettings().toBuilder()); } @@ -251,11 +222,15 @@ protected Builder(CloudRedisStubSettings.Builder stubSettings) { super(stubSettings); } + private static Builder createDefault() { + return new Builder(CloudRedisStubSettings.newBuilder()); + } + public CloudRedisStubSettings.Builder getStubSettingsBuilder() { return ((CloudRedisStubSettings.Builder) getStubSettings()); } - // NEXT_MAJOR_VER: remove 'throws Exception' + // NEXT_MAJOR_VER: remove 'throws Exception'. /** * Applies the given settings updater function to all of the unary API methods in this service. * @@ -268,14 +243,24 @@ public Builder applyToAllUnaryMethods( return this; } + /** Returns the builder for the settings used for calls to listInstances. */ + public PagedCallSettings.Builder< + ListInstancesRequest, ListInstancesResponse, ListInstancesPagedResponse> + listInstancesSettings() { + return getStubSettingsBuilder().listInstancesSettings(); + } + + /** Returns the builder for the settings used for calls to getInstance. */ + public UnaryCallSettings.Builder getInstanceSettings() { + return getStubSettingsBuilder().getInstanceSettings(); + } + /** Returns the builder for the settings used for calls to createInstance. */ public UnaryCallSettings.Builder createInstanceSettings() { return getStubSettingsBuilder().createInstanceSettings(); } /** Returns the builder for the settings used for calls to createInstance. */ - @BetaApi( - "The surface for long-running operations is not stable yet and may change in the future.") public OperationCallSettings.Builder createInstanceOperationSettings() { return getStubSettingsBuilder().createInstanceOperationSettings(); @@ -287,21 +272,28 @@ public UnaryCallSettings.Builder updateInstanc } /** Returns the builder for the settings used for calls to updateInstance. */ - @BetaApi( - "The surface for long-running operations is not stable yet and may change in the future.") public OperationCallSettings.Builder updateInstanceOperationSettings() { return getStubSettingsBuilder().updateInstanceOperationSettings(); } + /** Returns the builder for the settings used for calls to upgradeInstance. */ + public UnaryCallSettings.Builder upgradeInstanceSettings() { + return getStubSettingsBuilder().upgradeInstanceSettings(); + } + + /** Returns the builder for the settings used for calls to upgradeInstance. */ + public OperationCallSettings.Builder + upgradeInstanceOperationSettings() { + return getStubSettingsBuilder().upgradeInstanceOperationSettings(); + } + /** Returns the builder for the settings used for calls to importInstance. */ public UnaryCallSettings.Builder importInstanceSettings() { return getStubSettingsBuilder().importInstanceSettings(); } /** Returns the builder for the settings used for calls to importInstance. */ - @BetaApi( - "The surface for long-running operations is not stable yet and may change in the future.") public OperationCallSettings.Builder importInstanceOperationSettings() { return getStubSettingsBuilder().importInstanceOperationSettings(); @@ -313,8 +305,6 @@ public UnaryCallSettings.Builder exportInstanc } /** Returns the builder for the settings used for calls to exportInstance. */ - @BetaApi( - "The surface for long-running operations is not stable yet and may change in the future.") public OperationCallSettings.Builder exportInstanceOperationSettings() { return getStubSettingsBuilder().exportInstanceOperationSettings(); @@ -327,8 +317,6 @@ public UnaryCallSettings.Builder exportInstanc } /** Returns the builder for the settings used for calls to failoverInstance. */ - @BetaApi( - "The surface for long-running operations is not stable yet and may change in the future.") public OperationCallSettings.Builder failoverInstanceOperationSettings() { return getStubSettingsBuilder().failoverInstanceOperationSettings(); @@ -340,38 +328,11 @@ public UnaryCallSettings.Builder deleteInstanc } /** Returns the builder for the settings used for calls to deleteInstance. */ - @BetaApi( - "The surface for long-running operations is not stable yet and may change in the future.") public OperationCallSettings.Builder deleteInstanceOperationSettings() { return getStubSettingsBuilder().deleteInstanceOperationSettings(); } - /** Returns the builder for the settings used for calls to listInstances. */ - public PagedCallSettings.Builder< - ListInstancesRequest, ListInstancesResponse, ListInstancesPagedResponse> - listInstancesSettings() { - return getStubSettingsBuilder().listInstancesSettings(); - } - - /** Returns the builder for the settings used for calls to getInstance. */ - public UnaryCallSettings.Builder getInstanceSettings() { - return getStubSettingsBuilder().getInstanceSettings(); - } - - /** Returns the builder for the settings used for calls to upgradeInstance. */ - public UnaryCallSettings.Builder upgradeInstanceSettings() { - return getStubSettingsBuilder().upgradeInstanceSettings(); - } - - /** Returns the builder for the settings used for calls to upgradeInstance. */ - @BetaApi( - "The surface for long-running operations is not stable yet and may change in the future.") - public OperationCallSettings.Builder - upgradeInstanceOperationSettings() { - return getStubSettingsBuilder().upgradeInstanceOperationSettings(); - } - @Override public CloudRedisSettings build() throws IOException { return new CloudRedisSettings(this); diff --git a/test/integration/goldens/redis/CloudRedisStub.java b/test/integration/goldens/redis/CloudRedisStub.java index 68cfb9523f..cb83fee1eb 100644 --- a/test/integration/goldens/redis/CloudRedisStub.java +++ b/test/integration/goldens/redis/CloudRedisStub.java @@ -5,7 +5,7 @@ * 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 + * 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, @@ -13,11 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.google.cloud.redis.v1.stub; import static com.google.cloud.redis.v1.CloudRedisClient.ListInstancesPagedResponse; -import com.google.api.core.BetaApi; import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.rpc.OperationCallable; import com.google.api.gax.rpc.UnaryCallable; @@ -38,22 +38,32 @@ import com.google.protobuf.Empty; import javax.annotation.Generated; -// AUTO-GENERATED DOCUMENTATION AND CLASS +// AUTO-GENERATED DOCUMENTATION AND CLASS. /** - * Base stub class for Google Cloud Memorystore for Redis API. + * Base stub class for the CloudRedis service API. * *

This class is for advanced usage and reflects the underlying API directly. */ @Generated("by gapic-generator") -@BetaApi("A restructuring of stub classes is planned, so this may break in the future") public abstract class CloudRedisStub implements BackgroundResource { - @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") public OperationsStub getOperationsStub() { throw new UnsupportedOperationException("Not implemented: getOperationsStub()"); } - @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") + public UnaryCallable + listInstancesPagedCallable() { + throw new UnsupportedOperationException("Not implemented: listInstancesPagedCallable()"); + } + + public UnaryCallable listInstancesCallable() { + throw new UnsupportedOperationException("Not implemented: listInstancesCallable()"); + } + + public UnaryCallable getInstanceCallable() { + throw new UnsupportedOperationException("Not implemented: getInstanceCallable()"); + } + public OperationCallable createInstanceOperationCallable() { throw new UnsupportedOperationException("Not implemented: createInstanceOperationCallable()"); @@ -63,7 +73,6 @@ public UnaryCallable createInstanceCallable() throw new UnsupportedOperationException("Not implemented: createInstanceCallable()"); } - @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") public OperationCallable updateInstanceOperationCallable() { throw new UnsupportedOperationException("Not implemented: updateInstanceOperationCallable()"); @@ -73,7 +82,15 @@ public UnaryCallable updateInstanceCallable() throw new UnsupportedOperationException("Not implemented: updateInstanceCallable()"); } - @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") + public OperationCallable + upgradeInstanceOperationCallable() { + throw new UnsupportedOperationException("Not implemented: upgradeInstanceOperationCallable()"); + } + + public UnaryCallable upgradeInstanceCallable() { + throw new UnsupportedOperationException("Not implemented: upgradeInstanceCallable()"); + } + public OperationCallable importInstanceOperationCallable() { throw new UnsupportedOperationException("Not implemented: importInstanceOperationCallable()"); @@ -83,7 +100,6 @@ public UnaryCallable importInstanceCallable() throw new UnsupportedOperationException("Not implemented: importInstanceCallable()"); } - @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") public OperationCallable exportInstanceOperationCallable() { throw new UnsupportedOperationException("Not implemented: exportInstanceOperationCallable()"); @@ -93,7 +109,6 @@ public UnaryCallable exportInstanceCallable() throw new UnsupportedOperationException("Not implemented: exportInstanceCallable()"); } - @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") public OperationCallable failoverInstanceOperationCallable() { throw new UnsupportedOperationException("Not implemented: failoverInstanceOperationCallable()"); @@ -103,7 +118,6 @@ public UnaryCallable failoverInstanceCallabl throw new UnsupportedOperationException("Not implemented: failoverInstanceCallable()"); } - @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") public OperationCallable deleteInstanceOperationCallable() { throw new UnsupportedOperationException("Not implemented: deleteInstanceOperationCallable()"); @@ -113,29 +127,6 @@ public UnaryCallable deleteInstanceCallable() throw new UnsupportedOperationException("Not implemented: deleteInstanceCallable()"); } - public UnaryCallable - listInstancesPagedCallable() { - throw new UnsupportedOperationException("Not implemented: listInstancesPagedCallable()"); - } - - public UnaryCallable listInstancesCallable() { - throw new UnsupportedOperationException("Not implemented: listInstancesCallable()"); - } - - public UnaryCallable getInstanceCallable() { - throw new UnsupportedOperationException("Not implemented: getInstanceCallable()"); - } - - @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") - public OperationCallable - upgradeInstanceOperationCallable() { - throw new UnsupportedOperationException("Not implemented: upgradeInstanceOperationCallable()"); - } - - public UnaryCallable upgradeInstanceCallable() { - throw new UnsupportedOperationException("Not implemented: upgradeInstanceCallable()"); - } - @Override public abstract void close(); } diff --git a/test/integration/goldens/redis/CloudRedisStubSettings.java b/test/integration/goldens/redis/CloudRedisStubSettings.java index c31ed11904..823b99f3a4 100644 --- a/test/integration/goldens/redis/CloudRedisStubSettings.java +++ b/test/integration/goldens/redis/CloudRedisStubSettings.java @@ -5,7 +5,7 @@ * 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 + * 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, @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.google.cloud.redis.v1.stub; import static com.google.cloud.redis.v1.CloudRedisClient.ListInstancesPagedResponse; @@ -63,10 +64,11 @@ import com.google.protobuf.Empty; import java.io.IOException; import java.util.List; +import java.util.Objects; import javax.annotation.Generated; import org.threeten.bp.Duration; -// AUTO-GENERATED DOCUMENTATION AND CLASS +// AUTO-GENERATED DOCUMENTATION AND CLASS. /** * Settings class to configure an instance of {@link CloudRedisStub}. * @@ -81,35 +83,28 @@ *

The builder of this class is recursive, so contained classes are themselves builders. When * build() is called, the tree of builders is called to create the complete settings object. * - *

For example, to set the total timeout of getInstance to 30 seconds: - * - *

- * 
- * CloudRedisStubSettings.Builder cloudRedisSettingsBuilder =
- *     CloudRedisStubSettings.newBuilder();
- * cloudRedisSettingsBuilder
- *     .getInstanceSettings()
- *     .setRetrySettings(
- *         cloudRedisSettingsBuilder.getInstanceSettings().getRetrySettings().toBuilder()
- *             .setTotalTimeout(Duration.ofSeconds(30))
- *             .build());
- * CloudRedisStubSettings cloudRedisSettings = cloudRedisSettingsBuilder.build();
- * 
- * 
+ *

For example, to set the total timeout of listInstances to 30 seconds: */ -@Generated("by gapic-generator") @BetaApi +@Generated("by gapic-generator-java") public class CloudRedisStubSettings extends StubSettings { /** The default scopes of the service. */ private static final ImmutableList DEFAULT_SERVICE_SCOPES = ImmutableList.builder().add("https://www.googleapis.com/auth/cloud-platform").build(); + private final PagedCallSettings< + ListInstancesRequest, ListInstancesResponse, ListInstancesPagedResponse> + listInstancesSettings; + private final UnaryCallSettings getInstanceSettings; private final UnaryCallSettings createInstanceSettings; private final OperationCallSettings createInstanceOperationSettings; private final UnaryCallSettings updateInstanceSettings; private final OperationCallSettings updateInstanceOperationSettings; + private final UnaryCallSettings upgradeInstanceSettings; + private final OperationCallSettings + upgradeInstanceOperationSettings; private final UnaryCallSettings importInstanceSettings; private final OperationCallSettings importInstanceOperationSettings; @@ -122,13 +117,70 @@ public class CloudRedisStubSettings extends StubSettings private final UnaryCallSettings deleteInstanceSettings; private final OperationCallSettings deleteInstanceOperationSettings; - private final PagedCallSettings< + + private static final PagedListDescriptor + LIST_INSTANCES_PAGE_STR_DESC = + new PagedListDescriptor() { + @Override + public String emptyToken() { + return ""; + } + + @Override + public ListInstancesRequest injectToken(ListInstancesRequest payload, String token) { + return ListInstancesRequest.newBuilder(payload).setPageToken(token).build(); + } + + @Override + public ListInstancesRequest injectPageSize(ListInstancesRequest payload, int pageSize) { + return ListInstancesRequest.newBuilder(payload).setPageSize(pageSize).build(); + } + + @Override + public Integer extractPageSize(ListInstancesRequest payload) { + return payload.getPageSize(); + } + + @Override + public String extractNextToken(ListInstancesResponse payload) { + return payload.getNextPageToken(); + } + + @Override + public Iterable extractResources(ListInstancesResponse payload) { + return Objects.isNull(payload.getInstancesList()) + ? ImmutableList.of() + : payload.getInstancesList(); + } + }; + + private static final PagedListResponseFactory< ListInstancesRequest, ListInstancesResponse, ListInstancesPagedResponse> - listInstancesSettings; - private final UnaryCallSettings getInstanceSettings; - private final UnaryCallSettings upgradeInstanceSettings; - private final OperationCallSettings - upgradeInstanceOperationSettings; + LIST_INSTANCES_PAGE_STR_FACT = + new PagedListResponseFactory< + ListInstancesRequest, ListInstancesResponse, ListInstancesPagedResponse>() { + @Override + public ApiFuture getFuturePagedResponse( + UnaryCallable callable, + ListInstancesRequest request, + ApiCallContext context, + ApiFuture futureResponse) { + PageContext pageContext = + PageContext.create(callable, LIST_INSTANCES_PAGE_STR_DESC, request, context); + return ListInstancesPagedResponse.createAsync(pageContext, futureResponse); + } + }; + + /** Returns the object with the settings used for calls to listInstances. */ + public PagedCallSettings + listInstancesSettings() { + return listInstancesSettings; + } + + /** Returns the object with the settings used for calls to getInstance. */ + public UnaryCallSettings getInstanceSettings() { + return getInstanceSettings; + } /** Returns the object with the settings used for calls to createInstance. */ public UnaryCallSettings createInstanceSettings() { @@ -136,7 +188,6 @@ public UnaryCallSettings createInstanceSetting } /** Returns the object with the settings used for calls to createInstance. */ - @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") public OperationCallSettings createInstanceOperationSettings() { return createInstanceOperationSettings; @@ -148,19 +199,28 @@ public UnaryCallSettings updateInstanceSetting } /** Returns the object with the settings used for calls to updateInstance. */ - @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") public OperationCallSettings updateInstanceOperationSettings() { return updateInstanceOperationSettings; } + /** Returns the object with the settings used for calls to upgradeInstance. */ + public UnaryCallSettings upgradeInstanceSettings() { + return upgradeInstanceSettings; + } + + /** Returns the object with the settings used for calls to upgradeInstance. */ + public OperationCallSettings + upgradeInstanceOperationSettings() { + return upgradeInstanceOperationSettings; + } + /** Returns the object with the settings used for calls to importInstance. */ public UnaryCallSettings importInstanceSettings() { return importInstanceSettings; } /** Returns the object with the settings used for calls to importInstance. */ - @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") public OperationCallSettings importInstanceOperationSettings() { return importInstanceOperationSettings; @@ -172,7 +232,6 @@ public UnaryCallSettings exportInstanceSetting } /** Returns the object with the settings used for calls to exportInstance. */ - @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") public OperationCallSettings exportInstanceOperationSettings() { return exportInstanceOperationSettings; @@ -184,7 +243,6 @@ public UnaryCallSettings failoverInstanceSet } /** Returns the object with the settings used for calls to failoverInstance. */ - @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") public OperationCallSettings failoverInstanceOperationSettings() { return failoverInstanceOperationSettings; @@ -196,45 +254,21 @@ public UnaryCallSettings deleteInstanceSetting } /** Returns the object with the settings used for calls to deleteInstance. */ - @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") public OperationCallSettings deleteInstanceOperationSettings() { return deleteInstanceOperationSettings; } - /** Returns the object with the settings used for calls to listInstances. */ - public PagedCallSettings - listInstancesSettings() { - return listInstancesSettings; - } - - /** Returns the object with the settings used for calls to getInstance. */ - public UnaryCallSettings getInstanceSettings() { - return getInstanceSettings; - } - - /** Returns the object with the settings used for calls to upgradeInstance. */ - public UnaryCallSettings upgradeInstanceSettings() { - return upgradeInstanceSettings; - } - - /** Returns the object with the settings used for calls to upgradeInstance. */ - @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") - public OperationCallSettings - upgradeInstanceOperationSettings() { - return upgradeInstanceOperationSettings; - } - @BetaApi("A restructuring of stub classes is planned, so this may break in the future") public CloudRedisStub createStub() throws IOException { if (getTransportChannelProvider() .getTransportName() .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcCloudRedisStub.create(this); - } else { - throw new UnsupportedOperationException( - "Transport not supported: " + getTransportChannelProvider().getTransportName()); } + throw new UnsupportedOperationException( + String.format( + "Transport not supported: %s", getTransportChannelProvider().getTransportName())); } /** Returns a builder for the default ExecutorProvider for this service. */ @@ -294,10 +328,14 @@ public Builder toBuilder() { protected CloudRedisStubSettings(Builder settingsBuilder) throws IOException { super(settingsBuilder); + listInstancesSettings = settingsBuilder.listInstancesSettings().build(); + getInstanceSettings = settingsBuilder.getInstanceSettings().build(); createInstanceSettings = settingsBuilder.createInstanceSettings().build(); createInstanceOperationSettings = settingsBuilder.createInstanceOperationSettings().build(); updateInstanceSettings = settingsBuilder.updateInstanceSettings().build(); updateInstanceOperationSettings = settingsBuilder.updateInstanceOperationSettings().build(); + upgradeInstanceSettings = settingsBuilder.upgradeInstanceSettings().build(); + upgradeInstanceOperationSettings = settingsBuilder.upgradeInstanceOperationSettings().build(); importInstanceSettings = settingsBuilder.importInstanceSettings().build(); importInstanceOperationSettings = settingsBuilder.importInstanceOperationSettings().build(); exportInstanceSettings = settingsBuilder.exportInstanceSettings().build(); @@ -306,69 +344,15 @@ protected CloudRedisStubSettings(Builder settingsBuilder) throws IOException { failoverInstanceOperationSettings = settingsBuilder.failoverInstanceOperationSettings().build(); deleteInstanceSettings = settingsBuilder.deleteInstanceSettings().build(); deleteInstanceOperationSettings = settingsBuilder.deleteInstanceOperationSettings().build(); - listInstancesSettings = settingsBuilder.listInstancesSettings().build(); - getInstanceSettings = settingsBuilder.getInstanceSettings().build(); - upgradeInstanceSettings = settingsBuilder.upgradeInstanceSettings().build(); - upgradeInstanceOperationSettings = settingsBuilder.upgradeInstanceOperationSettings().build(); } - private static final PagedListDescriptor - LIST_INSTANCES_PAGE_STR_DESC = - new PagedListDescriptor() { - @Override - public String emptyToken() { - return ""; - } - - @Override - public ListInstancesRequest injectToken(ListInstancesRequest payload, String token) { - return ListInstancesRequest.newBuilder(payload).setPageToken(token).build(); - } - - @Override - public ListInstancesRequest injectPageSize(ListInstancesRequest payload, int pageSize) { - return ListInstancesRequest.newBuilder(payload).setPageSize(pageSize).build(); - } - - @Override - public Integer extractPageSize(ListInstancesRequest payload) { - return payload.getPageSize(); - } - - @Override - public String extractNextToken(ListInstancesResponse payload) { - return payload.getNextPageToken(); - } - - @Override - public Iterable extractResources(ListInstancesResponse payload) { - return payload.getInstancesList() != null - ? payload.getInstancesList() - : ImmutableList.of(); - } - }; - - private static final PagedListResponseFactory< - ListInstancesRequest, ListInstancesResponse, ListInstancesPagedResponse> - LIST_INSTANCES_PAGE_STR_FACT = - new PagedListResponseFactory< - ListInstancesRequest, ListInstancesResponse, ListInstancesPagedResponse>() { - @Override - public ApiFuture getFuturePagedResponse( - UnaryCallable callable, - ListInstancesRequest request, - ApiCallContext context, - ApiFuture futureResponse) { - PageContext pageContext = - PageContext.create(callable, LIST_INSTANCES_PAGE_STR_DESC, request, context); - return ListInstancesPagedResponse.createAsync(pageContext, futureResponse); - } - }; - /** Builder for CloudRedisStubSettings. */ public static class Builder extends StubSettings.Builder { private final ImmutableList> unaryMethodSettingsBuilders; - + private final PagedCallSettings.Builder< + ListInstancesRequest, ListInstancesResponse, ListInstancesPagedResponse> + listInstancesSettings; + private final UnaryCallSettings.Builder getInstanceSettings; private final UnaryCallSettings.Builder createInstanceSettings; private final OperationCallSettings.Builder @@ -377,6 +361,10 @@ public static class Builder extends StubSettings.Builder updateInstanceOperationSettings; + private final UnaryCallSettings.Builder + upgradeInstanceSettings; + private final OperationCallSettings.Builder + upgradeInstanceOperationSettings; private final UnaryCallSettings.Builder importInstanceSettings; private final OperationCallSettings.Builder @@ -394,24 +382,14 @@ public static class Builder extends StubSettings.Builder deleteInstanceOperationSettings; - private final PagedCallSettings.Builder< - ListInstancesRequest, ListInstancesResponse, ListInstancesPagedResponse> - listInstancesSettings; - private final UnaryCallSettings.Builder getInstanceSettings; - private final UnaryCallSettings.Builder - upgradeInstanceSettings; - private final OperationCallSettings.Builder - upgradeInstanceOperationSettings; - private static final ImmutableMap> RETRYABLE_CODE_DEFINITIONS; static { ImmutableMap.Builder> definitions = ImmutableMap.builder(); - definitions.put("no_retry_codes", ImmutableSet.copyOf(Lists.newArrayList())); definitions.put( - "no_retry_1_codes", ImmutableSet.copyOf(Lists.newArrayList())); + "no_retry_0_codes", ImmutableSet.copyOf(Lists.newArrayList())); RETRYABLE_CODE_DEFINITIONS = definitions.build(); } @@ -420,8 +398,6 @@ public static class Builder extends StubSettings.Builder definitions = ImmutableMap.builder(); RetrySettings settings = null; - settings = RetrySettings.newBuilder().setRpcTimeoutMultiplier(1.0).build(); - definitions.put("no_retry_params", settings); settings = RetrySettings.newBuilder() .setInitialRpcTimeout(Duration.ofMillis(600000L)) @@ -429,126 +405,145 @@ public static class Builder extends StubSettings.Builder>of( + listInstancesSettings, + getInstanceSettings, + createInstanceSettings, + updateInstanceSettings, + upgradeInstanceSettings, + importInstanceSettings, + exportInstanceSettings, + failoverInstanceSettings, + deleteInstanceSettings); + initDefaults(this); + } - upgradeInstanceSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + protected Builder(CloudRedisStubSettings settings) { + super(settings); - upgradeInstanceOperationSettings = OperationCallSettings.newBuilder(); + listInstancesSettings = settings.listInstancesSettings.toBuilder(); + getInstanceSettings = settings.getInstanceSettings.toBuilder(); + createInstanceSettings = settings.createInstanceSettings.toBuilder(); + createInstanceOperationSettings = settings.createInstanceOperationSettings.toBuilder(); + updateInstanceSettings = settings.updateInstanceSettings.toBuilder(); + updateInstanceOperationSettings = settings.updateInstanceOperationSettings.toBuilder(); + upgradeInstanceSettings = settings.upgradeInstanceSettings.toBuilder(); + upgradeInstanceOperationSettings = settings.upgradeInstanceOperationSettings.toBuilder(); + importInstanceSettings = settings.importInstanceSettings.toBuilder(); + importInstanceOperationSettings = settings.importInstanceOperationSettings.toBuilder(); + exportInstanceSettings = settings.exportInstanceSettings.toBuilder(); + exportInstanceOperationSettings = settings.exportInstanceOperationSettings.toBuilder(); + failoverInstanceSettings = settings.failoverInstanceSettings.toBuilder(); + failoverInstanceOperationSettings = settings.failoverInstanceOperationSettings.toBuilder(); + deleteInstanceSettings = settings.deleteInstanceSettings.toBuilder(); + deleteInstanceOperationSettings = settings.deleteInstanceOperationSettings.toBuilder(); unaryMethodSettingsBuilders = ImmutableList.>of( + listInstancesSettings, + getInstanceSettings, createInstanceSettings, updateInstanceSettings, + upgradeInstanceSettings, importInstanceSettings, exportInstanceSettings, failoverInstanceSettings, - deleteInstanceSettings, - listInstancesSettings, - getInstanceSettings, - upgradeInstanceSettings); - - initDefaults(this); + deleteInstanceSettings); } private static Builder createDefault() { - Builder builder = new Builder((ClientContext) null); + Builder builder = new Builder(((ClientContext) null)); + builder.setTransportChannelProvider(defaultTransportChannelProvider()); builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build()); builder.setInternalHeaderProvider(defaultApiClientHeaderProviderBuilder().build()); builder.setEndpoint(getDefaultEndpoint()); + return initDefaults(builder); } private static Builder initDefaults(Builder builder) { + builder + .listInstancesSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params")); + + builder + .getInstanceSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params")); builder .createInstanceSettings() - .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_1_codes")) - .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_1_params")); + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params")); builder .updateInstanceSettings() - .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_1_codes")) - .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_1_params")); + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params")); + + builder + .upgradeInstanceSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params")); builder .importInstanceSettings() - .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_1_codes")) - .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_1_params")); + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params")); builder .exportInstanceSettings() - .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_1_codes")) - .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_1_params")); + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params")); builder .failoverInstanceSettings() - .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_1_codes")) - .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_1_params")); + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params")); builder .deleteInstanceSettings() - .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_1_codes")) - .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_1_params")); - - builder - .listInstancesSettings() - .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_1_codes")) - .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_1_params")); - - builder - .getInstanceSettings() - .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_1_codes")) - .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_1_params")); + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params")); - builder - .upgradeInstanceSettings() - .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_1_codes")) - .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_1_params")); builder .createInstanceOperationSettings() .setInitialCallSettings( UnaryCallSettings .newUnaryCallSettingsBuilder() - .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_1_codes")) - .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_1_params")) + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params")) .build()) .setResponseTransformer( ProtoOperationTransformers.ResponseTransformer.create(Instance.class)) @@ -557,21 +552,22 @@ private static Builder initDefaults(Builder builder) { .setPollingAlgorithm( OperationTimedPollAlgorithm.create( RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.ofMillis(60000L)) + .setInitialRetryDelay(Duration.ofMillis(500L)) .setRetryDelayMultiplier(1.5) - .setMaxRetryDelay(Duration.ofMillis(360000L)) - .setInitialRpcTimeout(Duration.ZERO) // ignored - .setRpcTimeoutMultiplier(1.0) // ignored - .setMaxRpcTimeout(Duration.ZERO) // ignored - .setTotalTimeout(Duration.ofMillis(7200000L)) + .setMaxRetryDelay(Duration.ofMillis(5000L)) + .setInitialRpcTimeout(Duration.ZERO) + .setRpcTimeoutMultiplier(1.0) + .setMaxRpcTimeout(Duration.ZERO) + .setTotalTimeout(Duration.ofMillis(300000L)) .build())); + builder .updateInstanceOperationSettings() .setInitialCallSettings( UnaryCallSettings .newUnaryCallSettingsBuilder() - .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_1_codes")) - .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_1_params")) + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params")) .build()) .setResponseTransformer( ProtoOperationTransformers.ResponseTransformer.create(Instance.class)) @@ -580,21 +576,22 @@ private static Builder initDefaults(Builder builder) { .setPollingAlgorithm( OperationTimedPollAlgorithm.create( RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.ofMillis(60000L)) + .setInitialRetryDelay(Duration.ofMillis(500L)) .setRetryDelayMultiplier(1.5) - .setMaxRetryDelay(Duration.ofMillis(360000L)) - .setInitialRpcTimeout(Duration.ZERO) // ignored - .setRpcTimeoutMultiplier(1.0) // ignored - .setMaxRpcTimeout(Duration.ZERO) // ignored - .setTotalTimeout(Duration.ofMillis(7200000L)) + .setMaxRetryDelay(Duration.ofMillis(5000L)) + .setInitialRpcTimeout(Duration.ZERO) + .setRpcTimeoutMultiplier(1.0) + .setMaxRpcTimeout(Duration.ZERO) + .setTotalTimeout(Duration.ofMillis(300000L)) .build())); + builder - .importInstanceOperationSettings() + .upgradeInstanceOperationSettings() .setInitialCallSettings( UnaryCallSettings - .newUnaryCallSettingsBuilder() - .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_1_codes")) - .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_1_params")) + .newUnaryCallSettingsBuilder() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params")) .build()) .setResponseTransformer( ProtoOperationTransformers.ResponseTransformer.create(Instance.class)) @@ -603,21 +600,22 @@ private static Builder initDefaults(Builder builder) { .setPollingAlgorithm( OperationTimedPollAlgorithm.create( RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.ofMillis(60000L)) + .setInitialRetryDelay(Duration.ofMillis(500L)) .setRetryDelayMultiplier(1.5) - .setMaxRetryDelay(Duration.ofMillis(360000L)) - .setInitialRpcTimeout(Duration.ZERO) // ignored - .setRpcTimeoutMultiplier(1.0) // ignored - .setMaxRpcTimeout(Duration.ZERO) // ignored - .setTotalTimeout(Duration.ofMillis(18000000L)) + .setMaxRetryDelay(Duration.ofMillis(5000L)) + .setInitialRpcTimeout(Duration.ZERO) + .setRpcTimeoutMultiplier(1.0) + .setMaxRpcTimeout(Duration.ZERO) + .setTotalTimeout(Duration.ofMillis(300000L)) .build())); + builder - .exportInstanceOperationSettings() + .importInstanceOperationSettings() .setInitialCallSettings( UnaryCallSettings - .newUnaryCallSettingsBuilder() - .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_1_codes")) - .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_1_params")) + .newUnaryCallSettingsBuilder() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params")) .build()) .setResponseTransformer( ProtoOperationTransformers.ResponseTransformer.create(Instance.class)) @@ -626,21 +624,22 @@ private static Builder initDefaults(Builder builder) { .setPollingAlgorithm( OperationTimedPollAlgorithm.create( RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.ofMillis(60000L)) + .setInitialRetryDelay(Duration.ofMillis(500L)) .setRetryDelayMultiplier(1.5) - .setMaxRetryDelay(Duration.ofMillis(360000L)) - .setInitialRpcTimeout(Duration.ZERO) // ignored - .setRpcTimeoutMultiplier(1.0) // ignored - .setMaxRpcTimeout(Duration.ZERO) // ignored - .setTotalTimeout(Duration.ofMillis(18000000L)) + .setMaxRetryDelay(Duration.ofMillis(5000L)) + .setInitialRpcTimeout(Duration.ZERO) + .setRpcTimeoutMultiplier(1.0) + .setMaxRpcTimeout(Duration.ZERO) + .setTotalTimeout(Duration.ofMillis(300000L)) .build())); + builder - .failoverInstanceOperationSettings() + .exportInstanceOperationSettings() .setInitialCallSettings( UnaryCallSettings - .newUnaryCallSettingsBuilder() - .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_1_codes")) - .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_1_params")) + .newUnaryCallSettingsBuilder() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params")) .build()) .setResponseTransformer( ProtoOperationTransformers.ResponseTransformer.create(Instance.class)) @@ -649,47 +648,49 @@ private static Builder initDefaults(Builder builder) { .setPollingAlgorithm( OperationTimedPollAlgorithm.create( RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.ofMillis(60000L)) + .setInitialRetryDelay(Duration.ofMillis(500L)) .setRetryDelayMultiplier(1.5) - .setMaxRetryDelay(Duration.ofMillis(360000L)) - .setInitialRpcTimeout(Duration.ZERO) // ignored - .setRpcTimeoutMultiplier(1.0) // ignored - .setMaxRpcTimeout(Duration.ZERO) // ignored - .setTotalTimeout(Duration.ofMillis(1200000L)) + .setMaxRetryDelay(Duration.ofMillis(5000L)) + .setInitialRpcTimeout(Duration.ZERO) + .setRpcTimeoutMultiplier(1.0) + .setMaxRpcTimeout(Duration.ZERO) + .setTotalTimeout(Duration.ofMillis(300000L)) .build())); + builder - .deleteInstanceOperationSettings() + .failoverInstanceOperationSettings() .setInitialCallSettings( UnaryCallSettings - .newUnaryCallSettingsBuilder() - .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_1_codes")) - .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_1_params")) + .newUnaryCallSettingsBuilder() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params")) .build()) .setResponseTransformer( - ProtoOperationTransformers.ResponseTransformer.create(Empty.class)) + ProtoOperationTransformers.ResponseTransformer.create(Instance.class)) .setMetadataTransformer( ProtoOperationTransformers.MetadataTransformer.create(OperationMetadata.class)) .setPollingAlgorithm( OperationTimedPollAlgorithm.create( RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.ofMillis(60000L)) + .setInitialRetryDelay(Duration.ofMillis(500L)) .setRetryDelayMultiplier(1.5) - .setMaxRetryDelay(Duration.ofMillis(360000L)) - .setInitialRpcTimeout(Duration.ZERO) // ignored - .setRpcTimeoutMultiplier(1.0) // ignored - .setMaxRpcTimeout(Duration.ZERO) // ignored - .setTotalTimeout(Duration.ofMillis(1200000L)) + .setMaxRetryDelay(Duration.ofMillis(5000L)) + .setInitialRpcTimeout(Duration.ZERO) + .setRpcTimeoutMultiplier(1.0) + .setMaxRpcTimeout(Duration.ZERO) + .setTotalTimeout(Duration.ofMillis(300000L)) .build())); + builder - .upgradeInstanceOperationSettings() + .deleteInstanceOperationSettings() .setInitialCallSettings( UnaryCallSettings - .newUnaryCallSettingsBuilder() - .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_1_codes")) - .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_1_params")) + .newUnaryCallSettingsBuilder() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params")) .build()) .setResponseTransformer( - ProtoOperationTransformers.ResponseTransformer.create(Instance.class)) + ProtoOperationTransformers.ResponseTransformer.create(Empty.class)) .setMetadataTransformer( ProtoOperationTransformers.MetadataTransformer.create(OperationMetadata.class)) .setPollingAlgorithm( @@ -698,49 +699,16 @@ private static Builder initDefaults(Builder builder) { .setInitialRetryDelay(Duration.ofMillis(500L)) .setRetryDelayMultiplier(1.5) .setMaxRetryDelay(Duration.ofMillis(5000L)) - .setInitialRpcTimeout(Duration.ZERO) // ignored - .setRpcTimeoutMultiplier(1.0) // ignored - .setMaxRpcTimeout(Duration.ZERO) // ignored + .setInitialRpcTimeout(Duration.ZERO) + .setRpcTimeoutMultiplier(1.0) + .setMaxRpcTimeout(Duration.ZERO) .setTotalTimeout(Duration.ofMillis(300000L)) .build())); return builder; } - protected Builder(CloudRedisStubSettings settings) { - super(settings); - - createInstanceSettings = settings.createInstanceSettings.toBuilder(); - createInstanceOperationSettings = settings.createInstanceOperationSettings.toBuilder(); - updateInstanceSettings = settings.updateInstanceSettings.toBuilder(); - updateInstanceOperationSettings = settings.updateInstanceOperationSettings.toBuilder(); - importInstanceSettings = settings.importInstanceSettings.toBuilder(); - importInstanceOperationSettings = settings.importInstanceOperationSettings.toBuilder(); - exportInstanceSettings = settings.exportInstanceSettings.toBuilder(); - exportInstanceOperationSettings = settings.exportInstanceOperationSettings.toBuilder(); - failoverInstanceSettings = settings.failoverInstanceSettings.toBuilder(); - failoverInstanceOperationSettings = settings.failoverInstanceOperationSettings.toBuilder(); - deleteInstanceSettings = settings.deleteInstanceSettings.toBuilder(); - deleteInstanceOperationSettings = settings.deleteInstanceOperationSettings.toBuilder(); - listInstancesSettings = settings.listInstancesSettings.toBuilder(); - getInstanceSettings = settings.getInstanceSettings.toBuilder(); - upgradeInstanceSettings = settings.upgradeInstanceSettings.toBuilder(); - upgradeInstanceOperationSettings = settings.upgradeInstanceOperationSettings.toBuilder(); - - unaryMethodSettingsBuilders = - ImmutableList.>of( - createInstanceSettings, - updateInstanceSettings, - importInstanceSettings, - exportInstanceSettings, - failoverInstanceSettings, - deleteInstanceSettings, - listInstancesSettings, - getInstanceSettings, - upgradeInstanceSettings); - } - - // NEXT_MAJOR_VER: remove 'throws Exception' + // NEXT_MAJOR_VER: remove 'throws Exception'. /** * Applies the given settings updater function to all of the unary API methods in this service. * @@ -756,6 +724,18 @@ public Builder applyToAllUnaryMethods( return unaryMethodSettingsBuilders; } + /** Returns the builder for the settings used for calls to listInstances. */ + public PagedCallSettings.Builder< + ListInstancesRequest, ListInstancesResponse, ListInstancesPagedResponse> + listInstancesSettings() { + return listInstancesSettings; + } + + /** Returns the builder for the settings used for calls to getInstance. */ + public UnaryCallSettings.Builder getInstanceSettings() { + return getInstanceSettings; + } + /** Returns the builder for the settings used for calls to createInstance. */ public UnaryCallSettings.Builder createInstanceSettings() { return createInstanceSettings; @@ -782,6 +762,19 @@ public UnaryCallSettings.Builder updateInstanc return updateInstanceOperationSettings; } + /** Returns the builder for the settings used for calls to upgradeInstance. */ + public UnaryCallSettings.Builder upgradeInstanceSettings() { + return upgradeInstanceSettings; + } + + /** Returns the builder for the settings used for calls to upgradeInstance. */ + @BetaApi( + "The surface for use by generated code is not stable yet and may change in the future.") + public OperationCallSettings.Builder + upgradeInstanceOperationSettings() { + return upgradeInstanceOperationSettings; + } + /** Returns the builder for the settings used for calls to importInstance. */ public UnaryCallSettings.Builder importInstanceSettings() { return importInstanceSettings; @@ -835,31 +828,6 @@ public UnaryCallSettings.Builder deleteInstanc return deleteInstanceOperationSettings; } - /** Returns the builder for the settings used for calls to listInstances. */ - public PagedCallSettings.Builder< - ListInstancesRequest, ListInstancesResponse, ListInstancesPagedResponse> - listInstancesSettings() { - return listInstancesSettings; - } - - /** Returns the builder for the settings used for calls to getInstance. */ - public UnaryCallSettings.Builder getInstanceSettings() { - return getInstanceSettings; - } - - /** Returns the builder for the settings used for calls to upgradeInstance. */ - public UnaryCallSettings.Builder upgradeInstanceSettings() { - return upgradeInstanceSettings; - } - - /** Returns the builder for the settings used for calls to upgradeInstance. */ - @BetaApi( - "The surface for use by generated code is not stable yet and may change in the future.") - public OperationCallSettings.Builder - upgradeInstanceOperationSettings() { - return upgradeInstanceOperationSettings; - } - @Override public CloudRedisStubSettings build() throws IOException { return new CloudRedisStubSettings(this); diff --git a/test/integration/goldens/redis/GrpcCloudRedisCallableFactory.java b/test/integration/goldens/redis/GrpcCloudRedisCallableFactory.java index 49a6cf4b7f..7631c208ea 100644 --- a/test/integration/goldens/redis/GrpcCloudRedisCallableFactory.java +++ b/test/integration/goldens/redis/GrpcCloudRedisCallableFactory.java @@ -5,7 +5,7 @@ * 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 + * 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, @@ -13,9 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.google.cloud.redis.v1.stub; -import com.google.api.core.BetaApi; import com.google.api.gax.grpc.GrpcCallSettings; import com.google.api.gax.grpc.GrpcCallableFactory; import com.google.api.gax.grpc.GrpcStubCallableFactory; @@ -31,18 +31,19 @@ import com.google.api.gax.rpc.StreamingCallSettings; import com.google.api.gax.rpc.UnaryCallSettings; import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; import com.google.longrunning.stub.OperationsStub; import javax.annotation.Generated; -// AUTO-GENERATED DOCUMENTATION AND CLASS +// AUTO-GENERATED DOCUMENTATION AND CLASS. /** - * gRPC callable factory implementation for Google Cloud Memorystore for Redis API. + * gRPC callable factory implementation for the CloudRedis service API. * *

This class is for advanced usage. */ @Generated("by gapic-generator") -@BetaApi("The surface for use by generated code is not stable yet and may change in the future.") public class GrpcCloudRedisCallableFactory implements GrpcStubCallableFactory { + @Override public UnaryCallable createUnaryCallable( GrpcCallSettings grpcCallSettings, @@ -55,61 +56,58 @@ public UnaryCallable createUnaryCalla public UnaryCallable createPagedCallable( GrpcCallSettings grpcCallSettings, - PagedCallSettings pagedCallSettings, + PagedCallSettings callSettings, ClientContext clientContext) { - return GrpcCallableFactory.createPagedCallable( - grpcCallSettings, pagedCallSettings, clientContext); + return GrpcCallableFactory.createPagedCallable(grpcCallSettings, callSettings, clientContext); } @Override public UnaryCallable createBatchingCallable( GrpcCallSettings grpcCallSettings, - BatchingCallSettings batchingCallSettings, + BatchingCallSettings callSettings, ClientContext clientContext) { return GrpcCallableFactory.createBatchingCallable( - grpcCallSettings, batchingCallSettings, clientContext); + grpcCallSettings, callSettings, clientContext); } - @BetaApi( - "The surface for long-running operations is not stable yet and may change in the future.") @Override public OperationCallable createOperationCallable( - GrpcCallSettings grpcCallSettings, - OperationCallSettings operationCallSettings, + GrpcCallSettings grpcCallSettings, + OperationCallSettings callSettings, ClientContext clientContext, OperationsStub operationsStub) { return GrpcCallableFactory.createOperationCallable( - grpcCallSettings, operationCallSettings, clientContext, operationsStub); + grpcCallSettings, callSettings, clientContext, operationsStub); } @Override public BidiStreamingCallable createBidiStreamingCallable( GrpcCallSettings grpcCallSettings, - StreamingCallSettings streamingCallSettings, + StreamingCallSettings callSettings, ClientContext clientContext) { return GrpcCallableFactory.createBidiStreamingCallable( - grpcCallSettings, streamingCallSettings, clientContext); + grpcCallSettings, callSettings, clientContext); } @Override public ServerStreamingCallable createServerStreamingCallable( GrpcCallSettings grpcCallSettings, - ServerStreamingCallSettings streamingCallSettings, + ServerStreamingCallSettings callSettings, ClientContext clientContext) { return GrpcCallableFactory.createServerStreamingCallable( - grpcCallSettings, streamingCallSettings, clientContext); + grpcCallSettings, callSettings, clientContext); } @Override public ClientStreamingCallable createClientStreamingCallable( GrpcCallSettings grpcCallSettings, - StreamingCallSettings streamingCallSettings, + StreamingCallSettings callSettings, ClientContext clientContext) { return GrpcCallableFactory.createClientStreamingCallable( - grpcCallSettings, streamingCallSettings, clientContext); + grpcCallSettings, callSettings, clientContext); } } diff --git a/test/integration/goldens/redis/GrpcCloudRedisStub.java b/test/integration/goldens/redis/GrpcCloudRedisStub.java index ceb42c9a1b..64ffc5d17c 100644 --- a/test/integration/goldens/redis/GrpcCloudRedisStub.java +++ b/test/integration/goldens/redis/GrpcCloudRedisStub.java @@ -5,7 +5,7 @@ * 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 + * 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, @@ -13,18 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.google.cloud.redis.v1.stub; import static com.google.cloud.redis.v1.CloudRedisClient.ListInstancesPagedResponse; -import com.google.api.core.BetaApi; import com.google.api.gax.core.BackgroundResource; import com.google.api.gax.core.BackgroundResourceAggregation; import com.google.api.gax.grpc.GrpcCallSettings; 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; @@ -38,26 +37,41 @@ 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; -// AUTO-GENERATED DOCUMENTATION AND CLASS +// AUTO-GENERATED DOCUMENTATION AND CLASS. /** - * gRPC stub implementation for Google Cloud Memorystore for Redis API. + * gRPC stub implementation for the CloudRedis service API. * *

This class is for advanced usage and reflects the underlying API directly. */ -@Generated("by gapic-generator") -@BetaApi("A restructuring of stub classes is planned, so this may break in the future") +@Generated("by gapic-generator-java") public class GrpcCloudRedisStub extends CloudRedisStub { + private static final MethodDescriptor + listInstancesMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.cloud.redis.v1.CloudRedis/ListInstances") + .setRequestMarshaller( + ProtoUtils.marshaller(ListInstancesRequest.getDefaultInstance())) + .setResponseMarshaller( + ProtoUtils.marshaller(ListInstancesResponse.getDefaultInstance())) + .build(); + + private static final MethodDescriptor getInstanceMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.cloud.redis.v1.CloudRedis/GetInstance") + .setRequestMarshaller(ProtoUtils.marshaller(GetInstanceRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Instance.getDefaultInstance())) + .build(); private static final MethodDescriptor createInstanceMethodDescriptor = @@ -68,6 +82,7 @@ public class GrpcCloudRedisStub extends CloudRedisStub { ProtoUtils.marshaller(CreateInstanceRequest.getDefaultInstance())) .setResponseMarshaller(ProtoUtils.marshaller(Operation.getDefaultInstance())) .build(); + private static final MethodDescriptor updateInstanceMethodDescriptor = MethodDescriptor.newBuilder() @@ -77,6 +92,17 @@ public class GrpcCloudRedisStub extends CloudRedisStub { ProtoUtils.marshaller(UpdateInstanceRequest.getDefaultInstance())) .setResponseMarshaller(ProtoUtils.marshaller(Operation.getDefaultInstance())) .build(); + + private static final MethodDescriptor + upgradeInstanceMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.cloud.redis.v1.CloudRedis/UpgradeInstance") + .setRequestMarshaller( + ProtoUtils.marshaller(UpgradeInstanceRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Operation.getDefaultInstance())) + .build(); + private static final MethodDescriptor importInstanceMethodDescriptor = MethodDescriptor.newBuilder() @@ -86,6 +112,7 @@ public class GrpcCloudRedisStub extends CloudRedisStub { ProtoUtils.marshaller(ImportInstanceRequest.getDefaultInstance())) .setResponseMarshaller(ProtoUtils.marshaller(Operation.getDefaultInstance())) .build(); + private static final MethodDescriptor exportInstanceMethodDescriptor = MethodDescriptor.newBuilder() @@ -95,6 +122,7 @@ public class GrpcCloudRedisStub extends CloudRedisStub { ProtoUtils.marshaller(ExportInstanceRequest.getDefaultInstance())) .setResponseMarshaller(ProtoUtils.marshaller(Operation.getDefaultInstance())) .build(); + private static final MethodDescriptor failoverInstanceMethodDescriptor = MethodDescriptor.newBuilder() @@ -104,6 +132,7 @@ public class GrpcCloudRedisStub extends CloudRedisStub { ProtoUtils.marshaller(FailoverInstanceRequest.getDefaultInstance())) .setResponseMarshaller(ProtoUtils.marshaller(Operation.getDefaultInstance())) .build(); + private static final MethodDescriptor deleteInstanceMethodDescriptor = MethodDescriptor.newBuilder() @@ -113,42 +142,20 @@ public class GrpcCloudRedisStub extends CloudRedisStub { ProtoUtils.marshaller(DeleteInstanceRequest.getDefaultInstance())) .setResponseMarshaller(ProtoUtils.marshaller(Operation.getDefaultInstance())) .build(); - private static final MethodDescriptor - listInstancesMethodDescriptor = - MethodDescriptor.newBuilder() - .setType(MethodDescriptor.MethodType.UNARY) - .setFullMethodName("google.cloud.redis.v1.CloudRedis/ListInstances") - .setRequestMarshaller( - ProtoUtils.marshaller(ListInstancesRequest.getDefaultInstance())) - .setResponseMarshaller( - ProtoUtils.marshaller(ListInstancesResponse.getDefaultInstance())) - .build(); - private static final MethodDescriptor getInstanceMethodDescriptor = - MethodDescriptor.newBuilder() - .setType(MethodDescriptor.MethodType.UNARY) - .setFullMethodName("google.cloud.redis.v1.CloudRedis/GetInstance") - .setRequestMarshaller(ProtoUtils.marshaller(GetInstanceRequest.getDefaultInstance())) - .setResponseMarshaller(ProtoUtils.marshaller(Instance.getDefaultInstance())) - .build(); - private static final MethodDescriptor - upgradeInstanceMethodDescriptor = - MethodDescriptor.newBuilder() - .setType(MethodDescriptor.MethodType.UNARY) - .setFullMethodName("google.cloud.redis.v1.CloudRedis/UpgradeInstance") - .setRequestMarshaller( - ProtoUtils.marshaller(UpgradeInstanceRequest.getDefaultInstance())) - .setResponseMarshaller(ProtoUtils.marshaller(Operation.getDefaultInstance())) - .build(); - - private final BackgroundResource backgroundResources; - private final GrpcOperationsStub operationsStub; + private final UnaryCallable listInstancesCallable; + private final UnaryCallable + listInstancesPagedCallable; + private final UnaryCallable getInstanceCallable; private final UnaryCallable createInstanceCallable; private final OperationCallable createInstanceOperationCallable; private final UnaryCallable updateInstanceCallable; private final OperationCallable updateInstanceOperationCallable; + private final UnaryCallable upgradeInstanceCallable; + private final OperationCallable + upgradeInstanceOperationCallable; private final UnaryCallable importInstanceCallable; private final OperationCallable importInstanceOperationCallable; @@ -161,14 +168,9 @@ public class GrpcCloudRedisStub extends CloudRedisStub { private final UnaryCallable deleteInstanceCallable; private final OperationCallable deleteInstanceOperationCallable; - private final UnaryCallable listInstancesCallable; - private final UnaryCallable - listInstancesPagedCallable; - private final UnaryCallable getInstanceCallable; - private final UnaryCallable upgradeInstanceCallable; - private final OperationCallable - upgradeInstanceOperationCallable; + private final BackgroundResource backgroundResources; + private final GrpcOperationsStub operationsStub; private final GrpcStubCallableFactory callableFactory; public static final GrpcCloudRedisStub create(CloudRedisStubSettings settings) @@ -186,21 +188,11 @@ public static final GrpcCloudRedisStub create( CloudRedisStubSettings.newBuilder().build(), clientContext, callableFactory); } - /** - * Constructs an instance of GrpcCloudRedisStub, using the given settings. This is protected so - * that it is easy to make a subclass, but otherwise, the static factory methods should be - * preferred. - */ protected GrpcCloudRedisStub(CloudRedisStubSettings settings, ClientContext clientContext) throws IOException { this(settings, clientContext, new GrpcCloudRedisCallableFactory()); } - /** - * Constructs an instance of GrpcCloudRedisStub, using the given settings. This is protected so - * that it is easy to make a subclass, but otherwise, the static factory methods should be - * preferred. - */ protected GrpcCloudRedisStub( CloudRedisStubSettings settings, ClientContext clientContext, @@ -209,124 +201,52 @@ protected GrpcCloudRedisStub( this.callableFactory = callableFactory; this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory); + GrpcCallSettings listInstancesTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(listInstancesMethodDescriptor) + .build(); + GrpcCallSettings getInstanceTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(getInstanceMethodDescriptor) + .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) .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(); - 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 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(); + this.listInstancesCallable = + callableFactory.createUnaryCallable( + listInstancesTransportSettings, settings.listInstancesSettings(), clientContext); + this.listInstancesPagedCallable = + callableFactory.createPagedCallable( + listInstancesTransportSettings, settings.listInstancesSettings(), clientContext); + this.getInstanceCallable = + callableFactory.createUnaryCallable( + getInstanceTransportSettings, settings.getInstanceSettings(), clientContext); this.createInstanceCallable = callableFactory.createUnaryCallable( createInstanceTransportSettings, settings.createInstanceSettings(), clientContext); @@ -335,7 +255,7 @@ public Map extract(UpgradeInstanceRequest request) { createInstanceTransportSettings, settings.createInstanceOperationSettings(), clientContext, - this.operationsStub); + operationsStub); this.updateInstanceCallable = callableFactory.createUnaryCallable( updateInstanceTransportSettings, settings.updateInstanceSettings(), clientContext); @@ -344,7 +264,16 @@ public Map extract(UpgradeInstanceRequest request) { updateInstanceTransportSettings, settings.updateInstanceOperationSettings(), clientContext, - this.operationsStub); + operationsStub); + this.upgradeInstanceCallable = + callableFactory.createUnaryCallable( + upgradeInstanceTransportSettings, settings.upgradeInstanceSettings(), clientContext); + this.upgradeInstanceOperationCallable = + callableFactory.createOperationCallable( + upgradeInstanceTransportSettings, + settings.upgradeInstanceOperationSettings(), + clientContext, + operationsStub); this.importInstanceCallable = callableFactory.createUnaryCallable( importInstanceTransportSettings, settings.importInstanceSettings(), clientContext); @@ -353,7 +282,7 @@ public Map extract(UpgradeInstanceRequest request) { importInstanceTransportSettings, settings.importInstanceOperationSettings(), clientContext, - this.operationsStub); + operationsStub); this.exportInstanceCallable = callableFactory.createUnaryCallable( exportInstanceTransportSettings, settings.exportInstanceSettings(), clientContext); @@ -362,7 +291,7 @@ public Map extract(UpgradeInstanceRequest request) { exportInstanceTransportSettings, settings.exportInstanceOperationSettings(), clientContext, - this.operationsStub); + operationsStub); this.failoverInstanceCallable = callableFactory.createUnaryCallable( failoverInstanceTransportSettings, settings.failoverInstanceSettings(), clientContext); @@ -371,7 +300,7 @@ public Map extract(UpgradeInstanceRequest request) { failoverInstanceTransportSettings, settings.failoverInstanceOperationSettings(), clientContext, - this.operationsStub); + operationsStub); this.deleteInstanceCallable = callableFactory.createUnaryCallable( deleteInstanceTransportSettings, settings.deleteInstanceSettings(), clientContext); @@ -380,115 +309,90 @@ public Map extract(UpgradeInstanceRequest request) { deleteInstanceTransportSettings, settings.deleteInstanceOperationSettings(), clientContext, - this.operationsStub); - this.listInstancesCallable = - callableFactory.createUnaryCallable( - listInstancesTransportSettings, settings.listInstancesSettings(), clientContext); - this.listInstancesPagedCallable = - callableFactory.createPagedCallable( - listInstancesTransportSettings, settings.listInstancesSettings(), clientContext); - this.getInstanceCallable = - callableFactory.createUnaryCallable( - getInstanceTransportSettings, settings.getInstanceSettings(), clientContext); - this.upgradeInstanceCallable = - callableFactory.createUnaryCallable( - upgradeInstanceTransportSettings, settings.upgradeInstanceSettings(), clientContext); - this.upgradeInstanceOperationCallable = - callableFactory.createOperationCallable( - upgradeInstanceTransportSettings, - settings.upgradeInstanceOperationSettings(), - clientContext, - this.operationsStub); + operationsStub); - backgroundResources = new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); } - @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") public GrpcOperationsStub getOperationsStub() { return operationsStub; } - @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") + public UnaryCallable listInstancesCallable() { + return listInstancesCallable; + } + + public UnaryCallable + listInstancesPagedCallable() { + return listInstancesPagedCallable; + } + + public UnaryCallable getInstanceCallable() { + return getInstanceCallable; + } + + public UnaryCallable createInstanceCallable() { + return createInstanceCallable; + } + public OperationCallable createInstanceOperationCallable() { return createInstanceOperationCallable; } - public UnaryCallable createInstanceCallable() { - return createInstanceCallable; + public UnaryCallable updateInstanceCallable() { + return updateInstanceCallable; } - @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") public OperationCallable updateInstanceOperationCallable() { return updateInstanceOperationCallable; } - public UnaryCallable updateInstanceCallable() { - return updateInstanceCallable; + public UnaryCallable upgradeInstanceCallable() { + return upgradeInstanceCallable; } - @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") - public OperationCallable - importInstanceOperationCallable() { - return importInstanceOperationCallable; + public OperationCallable + upgradeInstanceOperationCallable() { + return upgradeInstanceOperationCallable; } public UnaryCallable importInstanceCallable() { return importInstanceCallable; } - @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") - public OperationCallable - exportInstanceOperationCallable() { - return exportInstanceOperationCallable; + public OperationCallable + importInstanceOperationCallable() { + return importInstanceOperationCallable; } public UnaryCallable exportInstanceCallable() { return exportInstanceCallable; } - @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") - public OperationCallable - failoverInstanceOperationCallable() { - return failoverInstanceOperationCallable; + public OperationCallable + exportInstanceOperationCallable() { + return exportInstanceOperationCallable; } public UnaryCallable failoverInstanceCallable() { return failoverInstanceCallable; } - @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") - public OperationCallable - deleteInstanceOperationCallable() { - return deleteInstanceOperationCallable; + public OperationCallable + failoverInstanceOperationCallable() { + return failoverInstanceOperationCallable; } public UnaryCallable deleteInstanceCallable() { return deleteInstanceCallable; } - public UnaryCallable - listInstancesPagedCallable() { - return listInstancesPagedCallable; - } - - public UnaryCallable listInstancesCallable() { - return listInstancesCallable; - } - - public UnaryCallable getInstanceCallable() { - return getInstanceCallable; - } - - @BetaApi("The surface for use by generated code is not stable yet and may change in the future.") - public OperationCallable - upgradeInstanceOperationCallable() { - return upgradeInstanceOperationCallable; - } - - public UnaryCallable upgradeInstanceCallable() { - return upgradeInstanceCallable; + public OperationCallable + deleteInstanceOperationCallable() { + return deleteInstanceOperationCallable; } @Override diff --git a/test/integration/goldens/redis/InstanceName.java b/test/integration/goldens/redis/InstanceName.java index 7653fd9799..f2fb7dfe5a 100644 --- a/test/integration/goldens/redis/InstanceName.java +++ b/test/integration/goldens/redis/InstanceName.java @@ -1,42 +1,48 @@ /* - * Copyright 2018 Google LLC + * 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 + * 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 * - * http://www.apache.org/licenses/LICENSE-2.0 + * 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. + * 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. */ package com.google.cloud.redis.v1; -import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableMap; import com.google.api.pathtemplate.PathTemplate; import com.google.api.resourcenames.ResourceName; -import java.util.Map; +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableMap; import java.util.ArrayList; import java.util.List; +import java.util.Map; +import java.util.Objects; +import javax.annotation.Generated; -/** - * AUTO-GENERATED DOCUMENTATION AND CLASS - */ -@javax.annotation.Generated("by GAPIC protoc plugin") +// AUTO-GENERATED DOCUMENTATION AND CLASS. +@Generated("by gapic-generator-java") public class InstanceName implements ResourceName { - - private static final PathTemplate PATH_TEMPLATE = - PathTemplate.createWithoutUrlEncoding("projects/{project}/locations/{location}/instances/{instance}"); - + private static final PathTemplate PROJECT_LOCATION_INSTANCE = + PathTemplate.createWithoutUrlEncoding( + "projects/{project}/locations/{location}/instances/{instance}"); private volatile Map fieldValuesMap; - private final String project; private final String location; private final String instance; + private InstanceName(Builder builder) { + project = Preconditions.checkNotNull(builder.getProject()); + location = Preconditions.checkNotNull(builder.getLocation()); + instance = Preconditions.checkNotNull(builder.getInstance()); + } + public String getProject() { return project; } @@ -57,27 +63,17 @@ public Builder toBuilder() { return new Builder(this); } - private InstanceName(Builder builder) { - project = Preconditions.checkNotNull(builder.getProject()); - location = Preconditions.checkNotNull(builder.getLocation()); - instance = Preconditions.checkNotNull(builder.getInstance()); - } - public static InstanceName of(String project, String location, String instance) { - return newBuilder() - .setProject(project) - .setLocation(location) - .setInstance(instance) - .build(); + return newBuilder().setProject(project).setLocation(location).setInstance(instance).build(); } public static String format(String project, String location, String instance) { return newBuilder() - .setProject(project) - .setLocation(location) - .setInstance(instance) - .build() - .toString(); + .setProject(project) + .setLocation(location) + .setInstance(instance) + .build() + .toString(); } public static InstanceName parse(String formattedString) { @@ -85,7 +81,8 @@ public static InstanceName parse(String formattedString) { return null; } Map matchMap = - PATH_TEMPLATE.validatedMatch(formattedString, "InstanceName.parse: formattedString not in valid format"); + PROJECT_LOCATION_INSTANCE.validatedMatch( + formattedString, "InstanceName.parse: formattedString not in valid format"); return of(matchMap.get("project"), matchMap.get("location"), matchMap.get("instance")); } @@ -98,9 +95,9 @@ public static List parseList(List formattedStrings) { } public static List toStringList(List values) { - List list = new ArrayList(values.size()); + List list = new ArrayList<>(values.size()); for (InstanceName value : values) { - if (value == null) { + if (Objects.isNull(value)) { list.add(""); } else { list.add(value.toString()); @@ -110,17 +107,24 @@ public static List toStringList(List values) { } public static boolean isParsableFrom(String formattedString) { - return PATH_TEMPLATE.matches(formattedString); + return PROJECT_LOCATION_INSTANCE.matches(formattedString); } + @Override public Map getFieldValuesMap() { - if (fieldValuesMap == null) { + if (Objects.isNull(fieldValuesMap)) { synchronized (this) { - if (fieldValuesMap == null) { + if (Objects.isNull(fieldValuesMap)) { ImmutableMap.Builder fieldMapBuilder = ImmutableMap.builder(); - fieldMapBuilder.put("project", project); - fieldMapBuilder.put("location", location); - fieldMapBuilder.put("instance", instance); + if (!Objects.isNull(project)) { + fieldMapBuilder.put("project", project); + } + if (!Objects.isNull(location)) { + fieldMapBuilder.put("location", location); + } + if (!Objects.isNull(instance)) { + fieldMapBuilder.put("instance", instance); + } fieldValuesMap = fieldMapBuilder.build(); } } @@ -134,16 +138,43 @@ public String getFieldValue(String fieldName) { @Override public String toString() { - return PATH_TEMPLATE.instantiate("project", project, "location", location, "instance", instance); + return PROJECT_LOCATION_INSTANCE.instantiate("project", project); } - /** Builder for InstanceName. */ - public static class Builder { + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (o != null || getClass() == o.getClass()) { + InstanceName that = ((InstanceName) o); + return Objects.equals(this.project, that.project) + && Objects.equals(this.location, that.location) + && Objects.equals(this.instance, that.instance); + } + return false; + } + @Override + public int hashCode() { + int h = 1; + h *= 1000003; + h ^= Objects.hashCode(project); + h *= 1000003; + h ^= Objects.hashCode(location); + h *= 1000003; + h ^= Objects.hashCode(instance); + return h; + } + + /** Builder for projects/{project}/locations/{location}/instances/{instance}. */ + public static class Builder { private String project; private String location; private String instance; + private Builder() {} + public String getProject() { return project; } @@ -171,9 +202,6 @@ public Builder setInstance(String instance) { return this; } - private Builder() { - } - private Builder(InstanceName instanceName) { project = instanceName.project; location = instanceName.location; @@ -184,31 +212,4 @@ public InstanceName build() { return new InstanceName(this); } } - - @Override - public boolean equals(Object o) { - if (o == this) { - return true; - } - if (o instanceof InstanceName) { - InstanceName that = (InstanceName) o; - return (this.project.equals(that.project)) - && (this.location.equals(that.location)) - && (this.instance.equals(that.instance)); - } - return false; - } - - @Override - public int hashCode() { - int h = 1; - h *= 1000003; - h ^= project.hashCode(); - h *= 1000003; - h ^= location.hashCode(); - h *= 1000003; - h ^= instance.hashCode(); - return h; - } } - diff --git a/test/integration/goldens/redis/LocationName.java b/test/integration/goldens/redis/LocationName.java index 54b551b3f1..d781b0b94b 100644 --- a/test/integration/goldens/redis/LocationName.java +++ b/test/integration/goldens/redis/LocationName.java @@ -1,41 +1,45 @@ /* - * Copyright 2018 Google LLC + * 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 + * 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 * - * http://www.apache.org/licenses/LICENSE-2.0 + * 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. + * 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. */ package com.google.cloud.redis.v1; -import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableMap; import com.google.api.pathtemplate.PathTemplate; import com.google.api.resourcenames.ResourceName; -import java.util.Map; +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableMap; import java.util.ArrayList; import java.util.List; +import java.util.Map; +import java.util.Objects; +import javax.annotation.Generated; -/** - * AUTO-GENERATED DOCUMENTATION AND CLASS - */ -@javax.annotation.Generated("by GAPIC protoc plugin") +// AUTO-GENERATED DOCUMENTATION AND CLASS. +@Generated("by gapic-generator-java") public class LocationName implements ResourceName { - - private static final PathTemplate PATH_TEMPLATE = + private static final PathTemplate PROJECT_LOCATION = PathTemplate.createWithoutUrlEncoding("projects/{project}/locations/{location}"); - private volatile Map fieldValuesMap; - private final String project; private final String location; + private LocationName(Builder builder) { + project = Preconditions.checkNotNull(builder.getProject()); + location = Preconditions.checkNotNull(builder.getLocation()); + } + public String getProject() { return project; } @@ -52,24 +56,12 @@ public Builder toBuilder() { return new Builder(this); } - private LocationName(Builder builder) { - project = Preconditions.checkNotNull(builder.getProject()); - location = Preconditions.checkNotNull(builder.getLocation()); - } - public static LocationName of(String project, String location) { - return newBuilder() - .setProject(project) - .setLocation(location) - .build(); + return newBuilder().setProject(project).setLocation(location).build(); } public static String format(String project, String location) { - return newBuilder() - .setProject(project) - .setLocation(location) - .build() - .toString(); + return newBuilder().setProject(project).setLocation(location).build().toString(); } public static LocationName parse(String formattedString) { @@ -77,7 +69,8 @@ public static LocationName parse(String formattedString) { return null; } Map matchMap = - PATH_TEMPLATE.validatedMatch(formattedString, "LocationName.parse: formattedString not in valid format"); + PROJECT_LOCATION.validatedMatch( + formattedString, "LocationName.parse: formattedString not in valid format"); return of(matchMap.get("project"), matchMap.get("location")); } @@ -90,9 +83,9 @@ public static List parseList(List formattedStrings) { } public static List toStringList(List values) { - List list = new ArrayList(values.size()); + List list = new ArrayList<>(values.size()); for (LocationName value : values) { - if (value == null) { + if (Objects.isNull(value)) { list.add(""); } else { list.add(value.toString()); @@ -102,16 +95,21 @@ public static List toStringList(List values) { } public static boolean isParsableFrom(String formattedString) { - return PATH_TEMPLATE.matches(formattedString); + return PROJECT_LOCATION.matches(formattedString); } + @Override public Map getFieldValuesMap() { - if (fieldValuesMap == null) { + if (Objects.isNull(fieldValuesMap)) { synchronized (this) { - if (fieldValuesMap == null) { + if (Objects.isNull(fieldValuesMap)) { ImmutableMap.Builder fieldMapBuilder = ImmutableMap.builder(); - fieldMapBuilder.put("project", project); - fieldMapBuilder.put("location", location); + if (!Objects.isNull(project)) { + fieldMapBuilder.put("project", project); + } + if (!Objects.isNull(location)) { + fieldMapBuilder.put("location", location); + } fieldValuesMap = fieldMapBuilder.build(); } } @@ -125,15 +123,39 @@ public String getFieldValue(String fieldName) { @Override public String toString() { - return PATH_TEMPLATE.instantiate("project", project, "location", location); + return PROJECT_LOCATION.instantiate("project", project); } - /** Builder for LocationName. */ - public static class Builder { + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (o != null || getClass() == o.getClass()) { + LocationName that = ((LocationName) o); + return Objects.equals(this.project, that.project) + && Objects.equals(this.location, that.location); + } + return false; + } + @Override + public int hashCode() { + int h = 1; + h *= 1000003; + h ^= Objects.hashCode(project); + h *= 1000003; + h ^= Objects.hashCode(location); + return h; + } + + /** Builder for projects/{project}/locations/{location}. */ + public static class Builder { private String project; private String location; + private Builder() {} + public String getProject() { return project; } @@ -152,9 +174,6 @@ public Builder setLocation(String location) { return this; } - private Builder() { - } - private Builder(LocationName locationName) { project = locationName.project; location = locationName.location; @@ -164,28 +183,4 @@ public LocationName build() { return new LocationName(this); } } - - @Override - public boolean equals(Object o) { - if (o == this) { - return true; - } - if (o instanceof LocationName) { - LocationName that = (LocationName) o; - return (this.project.equals(that.project)) - && (this.location.equals(that.location)); - } - return false; - } - - @Override - public int hashCode() { - int h = 1; - h *= 1000003; - h ^= project.hashCode(); - h *= 1000003; - h ^= location.hashCode(); - return h; - } } - diff --git a/test/integration/goldens/redis/MockCloudRedis.java b/test/integration/goldens/redis/MockCloudRedis.java index 9145045390..acbf9c33d0 100644 --- a/test/integration/goldens/redis/MockCloudRedis.java +++ b/test/integration/goldens/redis/MockCloudRedis.java @@ -5,7 +5,7 @@ * 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 + * 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, @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.google.cloud.redis.v1; import com.google.api.core.BetaApi; @@ -20,9 +21,10 @@ import com.google.protobuf.AbstractMessage; import io.grpc.ServerServiceDefinition; import java.util.List; +import javax.annotation.Generated; -@javax.annotation.Generated("by GAPIC") @BetaApi +@Generated("by gapic-generator-java") public class MockCloudRedis implements MockGrpcService { private final MockCloudRedisImpl serviceImpl; diff --git a/test/integration/goldens/redis/MockCloudRedisImpl.java b/test/integration/goldens/redis/MockCloudRedisImpl.java index c81719e881..434f9d3f57 100644 --- a/test/integration/goldens/redis/MockCloudRedisImpl.java +++ b/test/integration/goldens/redis/MockCloudRedisImpl.java @@ -5,7 +5,7 @@ * 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 + * 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, @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.google.cloud.redis.v1; import com.google.api.core.BetaApi; @@ -24,9 +25,10 @@ import java.util.LinkedList; import java.util.List; import java.util.Queue; +import javax.annotation.Generated; -@javax.annotation.Generated("by GAPIC") @BetaApi +@Generated("by gapic-generator-java") public class MockCloudRedisImpl extends CloudRedisImplBase { private List requests; private Queue responses; @@ -63,10 +65,10 @@ public void listInstances( Object response = responses.remove(); if (response instanceof ListInstancesResponse) { requests.add(request); - responseObserver.onNext((ListInstancesResponse) response); + responseObserver.onNext(((ListInstancesResponse) response)); responseObserver.onCompleted(); } else if (response instanceof Exception) { - responseObserver.onError((Exception) response); + responseObserver.onError(((Exception) response)); } else { responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); } @@ -77,10 +79,10 @@ public void getInstance(GetInstanceRequest request, StreamObserver res Object response = responses.remove(); if (response instanceof Instance) { requests.add(request); - responseObserver.onNext((Instance) response); + responseObserver.onNext(((Instance) response)); responseObserver.onCompleted(); } else if (response instanceof Exception) { - responseObserver.onError((Exception) response); + responseObserver.onError(((Exception) response)); } else { responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); } @@ -92,10 +94,10 @@ public void createInstance( Object response = responses.remove(); if (response instanceof Operation) { requests.add(request); - responseObserver.onNext((Operation) response); + responseObserver.onNext(((Operation) response)); responseObserver.onCompleted(); } else if (response instanceof Exception) { - responseObserver.onError((Exception) response); + responseObserver.onError(((Exception) response)); } else { responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); } @@ -107,10 +109,10 @@ public void updateInstance( Object response = responses.remove(); if (response instanceof Operation) { requests.add(request); - responseObserver.onNext((Operation) response); + responseObserver.onNext(((Operation) response)); responseObserver.onCompleted(); } else if (response instanceof Exception) { - responseObserver.onError((Exception) response); + responseObserver.onError(((Exception) response)); } else { responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); } @@ -122,10 +124,10 @@ public void upgradeInstance( Object response = responses.remove(); if (response instanceof Operation) { requests.add(request); - responseObserver.onNext((Operation) response); + responseObserver.onNext(((Operation) response)); responseObserver.onCompleted(); } else if (response instanceof Exception) { - responseObserver.onError((Exception) response); + responseObserver.onError(((Exception) response)); } else { responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); } @@ -137,10 +139,10 @@ public void importInstance( Object response = responses.remove(); if (response instanceof Operation) { requests.add(request); - responseObserver.onNext((Operation) response); + responseObserver.onNext(((Operation) response)); responseObserver.onCompleted(); } else if (response instanceof Exception) { - responseObserver.onError((Exception) response); + responseObserver.onError(((Exception) response)); } else { responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); } @@ -152,10 +154,10 @@ public void exportInstance( Object response = responses.remove(); if (response instanceof Operation) { requests.add(request); - responseObserver.onNext((Operation) response); + responseObserver.onNext(((Operation) response)); responseObserver.onCompleted(); } else if (response instanceof Exception) { - responseObserver.onError((Exception) response); + responseObserver.onError(((Exception) response)); } else { responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); } @@ -167,10 +169,10 @@ public void failoverInstance( Object response = responses.remove(); if (response instanceof Operation) { requests.add(request); - responseObserver.onNext((Operation) response); + responseObserver.onNext(((Operation) response)); responseObserver.onCompleted(); } else if (response instanceof Exception) { - responseObserver.onError((Exception) response); + responseObserver.onError(((Exception) response)); } else { responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); } @@ -182,10 +184,10 @@ public void deleteInstance( Object response = responses.remove(); if (response instanceof Operation) { requests.add(request); - responseObserver.onNext((Operation) response); + responseObserver.onNext(((Operation) response)); responseObserver.onCompleted(); } else if (response instanceof Exception) { - responseObserver.onError((Exception) response); + responseObserver.onError(((Exception) response)); } else { responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); } From b38559a59543255427503343a86532329c107d7b Mon Sep 17 00:00:00 2001 From: Xiaozhen Liu Date: Mon, 12 Oct 2020 16:48:08 +0000 Subject: [PATCH 07/17] add bazel rules --- rules_bazel/java/java_integration_test.bzl | 69 ++++++++++++++++++++++ test/integration/BUILD.bazel | 11 ++++ 2 files changed, 80 insertions(+) create mode 100644 rules_bazel/java/java_integration_test.bzl diff --git a/rules_bazel/java/java_integration_test.bzl b/rules_bazel/java/java_integration_test.bzl new file mode 100644 index 0000000000..832e577e91 --- /dev/null +++ b/rules_bazel/java/java_integration_test.bzl @@ -0,0 +1,69 @@ +def _compare_with_goldens_impl(ctx): + codegen_srcjar = ctx.outputs.codegen_srcjar + codegen_comparison_script = ctx.outputs.codegen_comparison_script + input = ctx.attr.api_target + srcs = ctx.files.srcs + script_content = """ + # remove unneeded non-java files, like MANIFEST + 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 + zip -r ../{codegen_srcjar} . + echo ../{codegen_srcjar} + """.format( + codegen_srcjar = codegen_srcjar.path, + input = input[0][JavaInfo].source_jars[0].path, + input_resource_name = input[1][JavaInfo].source_jars[0].path, + input_test = input[2][JavaInfo].source_jars[0].path, + ) + ctx.actions.run_shell( + inputs = [input[0][JavaInfo].source_jars[0], input[1][JavaInfo].source_jars[0], input[2][JavaInfo].source_jars[0]], + outputs = [codegen_srcjar], + command = script_content, + ) + + compare_with_golden_script_content = """ + #!/bin/bash + cd ${{BUILD_WORKSPACE_DIRECTORY}} + mkdir test/integration/goldens/.source_code_tmp + echo 'I am here, dir created!' + unzip {codegen_srcjar} -d test/integration/goldens/.source_code_tmp + cd test/integration/goldens/ + diff redis .source_code_tmp + """.format( + codegen_srcjar = codegen_srcjar.path, + ) + ctx.actions.write( + output = codegen_comparison_script, + content = compare_with_golden_script_content, + is_executable = True, + ) + return [DefaultInfo(executable = codegen_comparison_script)] + + +compare_with_goldens = rule( + attrs = { + "api_target": attr.label_list(), + "srcs": attr.label_list( + allow_files = True, + mandatory = True, + ), + }, + outputs = { + "codegen_srcjar": "%{name}_codegen.srcjar", + "codegen_comparison_script": "codegen_comparison_script.sh", + }, + executable = True, + implementation = _compare_with_goldens_impl, + test = True, +) + + +def integration_test(name, path, deps): + compare_with_goldens( + name = name, + api_target = [path, "%s_resource_name" % path, "%s_test" % path], + srcs = deps, + ) diff --git a/test/integration/BUILD.bazel b/test/integration/BUILD.bazel index 8c771fdac7..3bfe16a410 100644 --- a/test/integration/BUILD.bazel +++ b/test/integration/BUILD.bazel @@ -4,6 +4,11 @@ load( java_gapic_library = "java_gapic_library2", ) +load( + "//:rules_bazel/java/java_integration_test.bzl", + "integration_test", +) + package(default_visibility = ["//visibility:public"]) #################################################### @@ -50,3 +55,9 @@ java_gapic_library( "@com_google_googleapis//google/cloud/redis/v1:redis_java_proto", ], ) + +integration_test( + name = "redis_test_integration", + path = ":redis_java_gapic", + deps = [] +) From 62bdbc984ed64d1a3cf44e986b05dd59def5a678 Mon Sep 17 00:00:00 2001 From: Xiaozhen Liu Date: Mon, 12 Oct 2020 17:35:03 +0000 Subject: [PATCH 08/17] remove package-info --- .../goldens/redis/package-info.java | 52 ------------------- 1 file changed, 52 deletions(-) delete mode 100644 test/integration/goldens/redis/package-info.java diff --git a/test/integration/goldens/redis/package-info.java b/test/integration/goldens/redis/package-info.java deleted file mode 100644 index 7299e26c8d..0000000000 --- a/test/integration/goldens/redis/package-info.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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: - * - *

- * 
- * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
- *   InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]");
- *   Instance response = cloudRedisClient.getInstance(name);
- * }
- * 
- * 
- */ -@Generated("by gapic-generator") -package com.google.cloud.redis.v1; - -import javax.annotation.Generated; From bc430267d25565a8ac1fa7d997a49e5484d04ec1 Mon Sep 17 00:00:00 2001 From: Xiaozhen Liu Date: Tue, 13 Oct 2020 05:36:35 +0000 Subject: [PATCH 09/17] add bazel rules for integration test --- rules_bazel/java/java_integration_test.bzl | 73 +++++++++++++--------- test/integration/BUILD.bazel | 6 +- test/integration/goldens/redis/BUILD.bazel | 2 +- 3 files changed, 46 insertions(+), 35 deletions(-) diff --git a/rules_bazel/java/java_integration_test.bzl b/rules_bazel/java/java_integration_test.bzl index 832e577e91..ee5e3756ca 100644 --- a/rules_bazel/java/java_integration_test.bzl +++ b/rules_bazel/java/java_integration_test.bzl @@ -1,49 +1,57 @@ -def _compare_with_goldens_impl(ctx): - codegen_srcjar = ctx.outputs.codegen_srcjar - codegen_comparison_script = ctx.outputs.codegen_comparison_script +def _compare_with_goldens_test_impl(ctx): + diff_output = ctx.outputs.diff_output + check_diff_script = ctx.outputs.check_diff_script input = ctx.attr.api_target srcs = ctx.files.srcs - script_content = """ - # remove unneeded non-java files, like MANIFEST + + 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 - zip -r ../{codegen_srcjar} . - echo ../{codegen_srcjar} + # Remove unneeded non-Java files, like MANIFEST + rm -rf $(find . -type f ! -name "*.java") + cd .. + diff codegen_tmp test/integration/goldens/redis/ > {diff_output} """.format( - codegen_srcjar = codegen_srcjar.path, + diff_output = diff_output.path, input = input[0][JavaInfo].source_jars[0].path, input_resource_name = input[1][JavaInfo].source_jars[0].path, input_test = input[2][JavaInfo].source_jars[0].path, ) ctx.actions.run_shell( - inputs = [input[0][JavaInfo].source_jars[0], input[1][JavaInfo].source_jars[0], input[2][JavaInfo].source_jars[0]], - outputs = [codegen_srcjar], - command = script_content, + inputs = srcs + [ + input[0][JavaInfo].source_jars[0], + input[1][JavaInfo].source_jars[0], + input[2][JavaInfo].source_jars[0], + ], + outputs = [diff_output], + command = script, ) - compare_with_golden_script_content = """ - #!/bin/bash + + check_diff_script_content = """ cd ${{BUILD_WORKSPACE_DIRECTORY}} - mkdir test/integration/goldens/.source_code_tmp - echo 'I am here, dir created!' - unzip {codegen_srcjar} -d test/integration/goldens/.source_code_tmp - cd test/integration/goldens/ - diff redis .source_code_tmp + if [ -s {diff_output} ] + then + cat {diff_output} + exit 1 + else + exit 0 + fi """.format( - codegen_srcjar = codegen_srcjar.path, + diff_output = diff_output.path, ) ctx.actions.write( - output = codegen_comparison_script, - content = compare_with_golden_script_content, + output = check_diff_script, + content = check_diff_script_content, is_executable = True, ) - return [DefaultInfo(executable = codegen_comparison_script)] + return [DefaultInfo(executable = check_diff_script)] -compare_with_goldens = rule( +compare_with_goldens_test = rule( attrs = { "api_target": attr.label_list(), "srcs": attr.label_list( @@ -52,18 +60,21 @@ compare_with_goldens = rule( ), }, outputs = { - "codegen_srcjar": "%{name}_codegen.srcjar", - "codegen_comparison_script": "codegen_comparison_script.sh", + "diff_output": "%{name}_diff.txt", + "check_diff_script": "check_diff_script.sh", }, - executable = True, - implementation = _compare_with_goldens_impl, + implementation = _compare_with_goldens_test_impl, test = True, ) -def integration_test(name, path, deps): - compare_with_goldens( +def integration_test(name, target, data): + compare_with_goldens_test( name = name, - api_target = [path, "%s_resource_name" % path, "%s_test" % path], - srcs = deps, + api_target = [ + target, + "%s_resource_name" % target, + "%s_test" % target + ], + srcs = data, ) diff --git a/test/integration/BUILD.bazel b/test/integration/BUILD.bazel index 3bfe16a410..1b56fd3f1d 100644 --- a/test/integration/BUILD.bazel +++ b/test/integration/BUILD.bazel @@ -57,7 +57,7 @@ java_gapic_library( ) integration_test( - name = "redis_test_integration", - path = ":redis_java_gapic", - deps = [] + name = "redis_integration_test", + target = ":redis_java_gapic", + data = ["//test/integration/goldens/redis:goldens_files"], ) diff --git a/test/integration/goldens/redis/BUILD.bazel b/test/integration/goldens/redis/BUILD.bazel index 132766c072..0b74aed56b 100644 --- a/test/integration/goldens/redis/BUILD.bazel +++ b/test/integration/goldens/redis/BUILD.bazel @@ -1,6 +1,6 @@ package(default_visibility = ["//visibility:public"]) filegroup( - name = "redis_goldens_files", + name = "goldens_files", srcs = glob(["*.java"]), ) From 4ae798dbefbc630f8b83406ac6efe666cf81663d Mon Sep 17 00:00:00 2001 From: Xiaozhen Liu Date: Tue, 13 Oct 2020 05:47:08 +0000 Subject: [PATCH 10/17] take api name as arg --- rules_bazel/java/java_integration_test.bzl | 4 +++- test/integration/BUILD.bazel | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/rules_bazel/java/java_integration_test.bzl b/rules_bazel/java/java_integration_test.bzl index ee5e3756ca..3cc4f99f60 100644 --- a/rules_bazel/java/java_integration_test.bzl +++ b/rules_bazel/java/java_integration_test.bzl @@ -3,6 +3,7 @@ def _compare_with_goldens_test_impl(ctx): check_diff_script = ctx.outputs.check_diff_script input = ctx.attr.api_target srcs = ctx.files.srcs + api_name = ctx.attr.name script = """ mkdir codegen_tmp @@ -13,12 +14,13 @@ def _compare_with_goldens_test_impl(ctx): # Remove unneeded non-Java files, like MANIFEST rm -rf $(find . -type f ! -name "*.java") cd .. - diff codegen_tmp test/integration/goldens/redis/ > {diff_output} + diff codegen_tmp test/integration/goldens/{api_name}/ > {diff_output} """.format( diff_output = diff_output.path, input = input[0][JavaInfo].source_jars[0].path, input_resource_name = input[1][JavaInfo].source_jars[0].path, input_test = input[2][JavaInfo].source_jars[0].path, + api_name = api_name ) ctx.actions.run_shell( inputs = srcs + [ diff --git a/test/integration/BUILD.bazel b/test/integration/BUILD.bazel index 1b56fd3f1d..04352bd7f9 100644 --- a/test/integration/BUILD.bazel +++ b/test/integration/BUILD.bazel @@ -57,7 +57,7 @@ java_gapic_library( ) integration_test( - name = "redis_integration_test", + name = "redis", target = ":redis_java_gapic", data = ["//test/integration/goldens/redis:goldens_files"], ) From 5e65c2d50b00b31e7271eeb1f32347e634dbe7ef Mon Sep 17 00:00:00 2001 From: Xiaozhen Liu Date: Tue, 13 Oct 2020 15:41:57 +0000 Subject: [PATCH 11/17] feedback --- rules_bazel/java/java_integration_test.bzl | 28 ++++++++++++---------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/rules_bazel/java/java_integration_test.bzl b/rules_bazel/java/java_integration_test.bzl index 3cc4f99f60..fce97cb45d 100644 --- a/rules_bazel/java/java_integration_test.bzl +++ b/rules_bazel/java/java_integration_test.bzl @@ -1,7 +1,9 @@ def _compare_with_goldens_test_impl(ctx): diff_output = ctx.outputs.diff_output check_diff_script = ctx.outputs.check_diff_script - input = ctx.attr.api_target + gapic_library = ctx.attr.gapic_library + resource_name_library = ctx.attr.resource_name_library + test_library = ctx.attr.test_library srcs = ctx.files.srcs api_name = ctx.attr.name @@ -17,16 +19,16 @@ def _compare_with_goldens_test_impl(ctx): diff codegen_tmp test/integration/goldens/{api_name}/ > {diff_output} """.format( diff_output = diff_output.path, - input = input[0][JavaInfo].source_jars[0].path, - input_resource_name = input[1][JavaInfo].source_jars[0].path, - input_test = input[2][JavaInfo].source_jars[0].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, api_name = api_name ) ctx.actions.run_shell( inputs = srcs + [ - input[0][JavaInfo].source_jars[0], - input[1][JavaInfo].source_jars[0], - input[2][JavaInfo].source_jars[0], + gapic_library[JavaInfo].source_jars[0], + resource_name_library[JavaInfo].source_jars[0], + test_library[JavaInfo].source_jars[0], ], outputs = [diff_output], command = script, @@ -55,7 +57,9 @@ def _compare_with_goldens_test_impl(ctx): compare_with_goldens_test = rule( attrs = { - "api_target": attr.label_list(), + "gapic_library": attr.label(), + "resource_name_library": attr.label(), + "test_library": attr.label(), "srcs": attr.label_list( allow_files = True, mandatory = True, @@ -73,10 +77,8 @@ compare_with_goldens_test = rule( def integration_test(name, target, data): compare_with_goldens_test( name = name, - api_target = [ - target, - "%s_resource_name" % target, - "%s_test" % target - ], + gapic_library = target, + resource_name_library = "%s_resource_name" % target, + test_library = "%s_test" % target, srcs = data, ) From 658f4b708e5ffa4bdc46a255f0788ab7f0556a88 Mon Sep 17 00:00:00 2001 From: Xiaozhen Liu Date: Wed, 14 Oct 2020 17:41:03 +0000 Subject: [PATCH 12/17] work --- rules_bazel/java/java_integration_test.bzl | 29 ++++++---------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/rules_bazel/java/java_integration_test.bzl b/rules_bazel/java/java_integration_test.bzl index fce97cb45d..568eab6230 100644 --- a/rules_bazel/java/java_integration_test.bzl +++ b/rules_bazel/java/java_integration_test.bzl @@ -17,7 +17,13 @@ def _compare_with_goldens_test_impl(ctx): rm -rf $(find . -type f ! -name "*.java") cd .. diff codegen_tmp test/integration/goldens/{api_name}/ > {diff_output} + touch {check_diff_script} + if [ -s {diff_output} ] + then + echo 'exit 1' >> {check_diff_script} + fi """.format( + check_diff_script = check_diff_script.path, diff_output = diff_output.path, input = gapic_library[JavaInfo].source_jars[0].path, input_resource_name = resource_name_library[JavaInfo].source_jars[0].path, @@ -30,28 +36,9 @@ def _compare_with_goldens_test_impl(ctx): resource_name_library[JavaInfo].source_jars[0], test_library[JavaInfo].source_jars[0], ], - outputs = [diff_output], + outputs = [diff_output, check_diff_script], command = script, ) - - - check_diff_script_content = """ - cd ${{BUILD_WORKSPACE_DIRECTORY}} - if [ -s {diff_output} ] - then - cat {diff_output} - exit 1 - else - exit 0 - fi - """.format( - diff_output = diff_output.path, - ) - ctx.actions.write( - output = check_diff_script, - content = check_diff_script_content, - is_executable = True, - ) return [DefaultInfo(executable = check_diff_script)] @@ -66,7 +53,7 @@ compare_with_goldens_test = rule( ), }, outputs = { - "diff_output": "%{name}_diff.txt", + "diff_output": "diff_output.txt", "check_diff_script": "check_diff_script.sh", }, implementation = _compare_with_goldens_test_impl, From cfde217adb4886e23ff77ec51c1d684b2db2b34f Mon Sep 17 00:00:00 2001 From: Xiaozhen Liu Date: Tue, 20 Oct 2020 17:30:15 +0000 Subject: [PATCH 13/17] emit diff to test.log --- rules_bazel/java/java_integration_test.bzl | 26 +++++++++++++++------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/rules_bazel/java/java_integration_test.bzl b/rules_bazel/java/java_integration_test.bzl index 568eab6230..b968bd1b15 100644 --- a/rules_bazel/java/java_integration_test.bzl +++ b/rules_bazel/java/java_integration_test.bzl @@ -17,13 +17,7 @@ def _compare_with_goldens_test_impl(ctx): rm -rf $(find . -type f ! -name "*.java") cd .. diff codegen_tmp test/integration/goldens/{api_name}/ > {diff_output} - touch {check_diff_script} - if [ -s {diff_output} ] - then - echo 'exit 1' >> {check_diff_script} - fi """.format( - check_diff_script = check_diff_script.path, diff_output = diff_output.path, input = gapic_library[JavaInfo].source_jars[0].path, input_resource_name = resource_name_library[JavaInfo].source_jars[0].path, @@ -36,10 +30,26 @@ def _compare_with_goldens_test_impl(ctx): resource_name_library[JavaInfo].source_jars[0], test_library[JavaInfo].source_jars[0], ], - outputs = [diff_output, check_diff_script], + outputs = [diff_output], command = script, ) - return [DefaultInfo(executable = check_diff_script)] + check_diff_script_content = """ + cat $PWD/test/integration/diff_output.txt + if [ -s $PWD/test/integration/diff_output.txt ] + then + cp $PWD/test/integration/diff_output.txt $XML_OUTPUT_FILE + exit 1 + else + echo 'Test success!' + fi + """ + + ctx.actions.write( + output = check_diff_script, + content = check_diff_script_content, + ) + runfiles = ctx.runfiles(files = [ctx.outputs.diff_output]) + return [DefaultInfo(executable = check_diff_script, runfiles = runfiles)] compare_with_goldens_test = rule( From 23154f19f02ccd60647e22934d51ac86e390a5f9 Mon Sep 17 00:00:00 2001 From: Xiaozhen Liu Date: Tue, 20 Oct 2020 19:25:21 +0000 Subject: [PATCH 14/17] fix diff command --- rules_bazel/java/java_integration_test.bzl | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/rules_bazel/java/java_integration_test.bzl b/rules_bazel/java/java_integration_test.bzl index b968bd1b15..38bc4c1a70 100644 --- a/rules_bazel/java/java_integration_test.bzl +++ b/rules_bazel/java/java_integration_test.bzl @@ -1,4 +1,9 @@ def _compare_with_goldens_test_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`. + # Compare the `codegen_tmp` with the goldens folder e.g `test/integration/goldens/redis` + # and save the differences in output file `diff_output.txt`. + diff_output = ctx.outputs.diff_output check_diff_script = ctx.outputs.check_diff_script gapic_library = ctx.attr.gapic_library @@ -17,6 +22,9 @@ def _compare_with_goldens_test_impl(ctx): rm -rf $(find . -type f ! -name "*.java") cd .. diff codegen_tmp test/integration/goldens/{api_name}/ > {diff_output} + # Bash `diff` command will return exit code 1 when there are differences between the two + # folders. So we explicitly `exit 0` after the diff command to avoid build failure. + exit 0 """.format( diff_output = diff_output.path, input = gapic_library[JavaInfo].source_jars[0].path, @@ -33,14 +41,20 @@ def _compare_with_goldens_test_impl(ctx): outputs = [diff_output], command = script, ) + + # Check the generated diff_output file, if it is empty, that means there is no difference + # between generated source code and goldens files, test should pass. If it is not empty, then + # test will fail by exiting 1. + check_diff_script_content = """ + # This will not print diff_output to the console unless `--test_output=all` option + # is enabled, it only emits the comparison results to the test.log. + # We could not copy the diff_output.txt to the test.log ($XML_OUTPUT_FILE) because that + # file is not existing at the moment. It is generated once test is finished. cat $PWD/test/integration/diff_output.txt if [ -s $PWD/test/integration/diff_output.txt ] then - cp $PWD/test/integration/diff_output.txt $XML_OUTPUT_FILE exit 1 - else - echo 'Test success!' fi """ @@ -72,6 +86,8 @@ compare_with_goldens_test = rule( def integration_test(name, target, data): + # Bazel target `java_gapic_library` will generate 3 source jars including the + # the source Java code of the gapic_library, resource_name_library and test_library. compare_with_goldens_test( name = name, gapic_library = target, From 9cf077eb5641f8a5040c5531f80332545ea49cc0 Mon Sep 17 00:00:00 2001 From: Xiaozhen Liu Date: Tue, 20 Oct 2020 19:27:43 +0000 Subject: [PATCH 15/17] rename --- .../{java_integration_test.bzl => integration_test.bzl} | 8 ++++---- test/integration/BUILD.bazel | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) rename rules_bazel/java/{java_integration_test.bzl => integration_test.bzl} (95%) diff --git a/rules_bazel/java/java_integration_test.bzl b/rules_bazel/java/integration_test.bzl similarity index 95% rename from rules_bazel/java/java_integration_test.bzl rename to rules_bazel/java/integration_test.bzl index 38bc4c1a70..8a7acc9de2 100644 --- a/rules_bazel/java/java_integration_test.bzl +++ b/rules_bazel/java/integration_test.bzl @@ -1,4 +1,4 @@ -def _compare_with_goldens_test_impl(ctx): +def _diff_integration_goldens_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`. # Compare the `codegen_tmp` with the goldens folder e.g `test/integration/goldens/redis` @@ -66,7 +66,7 @@ def _compare_with_goldens_test_impl(ctx): return [DefaultInfo(executable = check_diff_script, runfiles = runfiles)] -compare_with_goldens_test = rule( +diff_integration_goldens_test = rule( attrs = { "gapic_library": attr.label(), "resource_name_library": attr.label(), @@ -80,7 +80,7 @@ compare_with_goldens_test = rule( "diff_output": "diff_output.txt", "check_diff_script": "check_diff_script.sh", }, - implementation = _compare_with_goldens_test_impl, + implementation = _diff_integration_goldens_impl, test = True, ) @@ -88,7 +88,7 @@ compare_with_goldens_test = rule( def integration_test(name, target, data): # Bazel target `java_gapic_library` will generate 3 source jars including the # the source Java code of the gapic_library, resource_name_library and test_library. - compare_with_goldens_test( + diff_integration_goldens_test( name = name, gapic_library = target, resource_name_library = "%s_resource_name" % target, diff --git a/test/integration/BUILD.bazel b/test/integration/BUILD.bazel index 04352bd7f9..11f96c0dbe 100644 --- a/test/integration/BUILD.bazel +++ b/test/integration/BUILD.bazel @@ -5,7 +5,7 @@ load( ) load( - "//:rules_bazel/java/java_integration_test.bzl", + "//:rules_bazel/java/integration_test.bzl", "integration_test", ) From edf06903ccafff43346291c5e6c3a7c423f553e1 Mon Sep 17 00:00:00 2001 From: Xiaozhen Liu Date: Tue, 20 Oct 2020 19:57:04 +0000 Subject: [PATCH 16/17] add bazel rules --- rules_bazel/java/integration_test.bzl | 12 +++++++----- test/integration/BUILD.bazel | 7 +++++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/rules_bazel/java/integration_test.bzl b/rules_bazel/java/integration_test.bzl index 8a7acc9de2..fddaa7e02c 100644 --- a/rules_bazel/java/integration_test.bzl +++ b/rules_bazel/java/integration_test.bzl @@ -51,12 +51,14 @@ def _diff_integration_goldens_impl(ctx): # is enabled, it only emits the comparison results to the test.log. # We could not copy the diff_output.txt to the test.log ($XML_OUTPUT_FILE) because that # file is not existing at the moment. It is generated once test is finished. - cat $PWD/test/integration/diff_output.txt - if [ -s $PWD/test/integration/diff_output.txt ] + cat $PWD/test/integration/{api_name}_diff_output.txt + if [ -s $PWD/test/integration/{api_name}_diff_output.txt ] then exit 1 fi - """ + """.format( + api_name = api_name + ) ctx.actions.write( output = check_diff_script, @@ -77,8 +79,8 @@ diff_integration_goldens_test = rule( ), }, outputs = { - "diff_output": "diff_output.txt", - "check_diff_script": "check_diff_script.sh", + "diff_output": "%{name}_diff_output.txt", + "check_diff_script": "%{name}_check_diff_script.sh", }, implementation = _diff_integration_goldens_impl, test = True, diff --git a/test/integration/BUILD.bazel b/test/integration/BUILD.bazel index 11f96c0dbe..71a95ab66e 100644 --- a/test/integration/BUILD.bazel +++ b/test/integration/BUILD.bazel @@ -61,3 +61,10 @@ integration_test( target = ":redis_java_gapic", data = ["//test/integration/goldens/redis:goldens_files"], ) + +integration_test( + name = "asset", + target = ":asset_java_gapic", + data = ["//test/integration/goldens/asset:goldens_files"], +) + From ef12859b3f7fdf47972a69da611c695b22fad831 Mon Sep 17 00:00:00 2001 From: Xiaozhen Liu Date: Tue, 20 Oct 2020 22:50:01 +0000 Subject: [PATCH 17/17] update asset client lib goldens --- .../goldens/asset/AssetServiceClientTest.java | 71 +++++++++++++++++-- .../asset/AssetServiceStubSettings.java | 21 ++++++ .../goldens/asset/GrpcAssetServiceStub.java | 13 ++++ 3 files changed, 99 insertions(+), 6 deletions(-) diff --git a/test/integration/goldens/asset/AssetServiceClientTest.java b/test/integration/goldens/asset/AssetServiceClientTest.java index e01605c702..4587e17e1c 100644 --- a/test/integration/goldens/asset/AssetServiceClientTest.java +++ b/test/integration/goldens/asset/AssetServiceClientTest.java @@ -46,10 +46,10 @@ @Generated("by gapic-generator-java") public class AssetServiceClientTest { - public static MockServiceHelper mockServiceHelper; - public AssetServiceClient client; - public LocalChannelProvider channelProvider; - public static MockAssetService mockAssetService; + private static MockServiceHelper mockServiceHelper; + private AssetServiceClient client; + private LocalChannelProvider channelProvider; + private static MockAssetService mockAssetService; @BeforeClass public static void startStaticServer() { @@ -96,17 +96,21 @@ public void exportAssetsTest() { .setResponse(Any.pack(expectedResponse)) .build(); mockAssetService.addResponse(resultOperation); + ExportAssetsRequest request = ExportAssetsRequest.newBuilder() .setParent(ProjectName.of("[PROJECT]").toString()) .addAllAssetTypes(new ArrayList<>()) .setOutputConfig(OutputConfig.newBuilder().build()) .build(); + ExportAssetsResponse actualResponse = client.exportAssetsAsync(request).get(); Assert.assertEquals(expectedResponse, actualResponse); + List actualRequests = mockAssetService.getRequests(); Assert.assertEquals(1, actualRequests.size()); ExportAssetsRequest actualRequest = ((ExportAssetsRequest) actualRequests.get(0)); + Assert.assertEquals(request.getParent(), actualRequest.getParent()); Assert.assertEquals(request.getReadTime(), actualRequest.getReadTime()); Assert.assertEquals(request.getAssetTypesList(), actualRequest.getAssetTypesList()); @@ -122,6 +126,7 @@ public void exportAssetsTest() { public void exportAssetsExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); mockAssetService.addException(exception); + try { ExportAssetsRequest request = ExportAssetsRequest.newBuilder() @@ -143,18 +148,22 @@ public void batchGetAssetsHistoryTest() { BatchGetAssetsHistoryResponse expectedResponse = BatchGetAssetsHistoryResponse.newBuilder().addAllAssets(new ArrayList<>()).build(); mockAssetService.addResponse(expectedResponse); + BatchGetAssetsHistoryRequest request = BatchGetAssetsHistoryRequest.newBuilder() .setParent(ProjectName.of("[PROJECT]").toString()) .addAllAssetNames(new ArrayList<>()) .setReadTimeWindow(TimeWindow.newBuilder().build()) .build(); + BatchGetAssetsHistoryResponse actualResponse = client.batchGetAssetsHistory(request); Assert.assertEquals(expectedResponse, actualResponse); + List actualRequests = mockAssetService.getRequests(); Assert.assertEquals(1, actualRequests.size()); BatchGetAssetsHistoryRequest actualRequest = ((BatchGetAssetsHistoryRequest) actualRequests.get(0)); + Assert.assertEquals(request.getParent(), actualRequest.getParent()); Assert.assertEquals(request.getAssetNamesList(), actualRequest.getAssetNamesList()); Assert.assertEquals(request.getContentType(), actualRequest.getContentType()); @@ -169,6 +178,7 @@ public void batchGetAssetsHistoryTest() { public void batchGetAssetsHistoryExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); mockAssetService.addException(exception); + try { BatchGetAssetsHistoryRequest request = BatchGetAssetsHistoryRequest.newBuilder() @@ -193,12 +203,16 @@ public void createFeedTest() { .setFeedOutputConfig(FeedOutputConfig.newBuilder().build()) .build(); mockAssetService.addResponse(expectedResponse); + String parent = "parent-995424086"; + Feed actualResponse = client.createFeed(parent); Assert.assertEquals(expectedResponse, actualResponse); + List actualRequests = mockAssetService.getRequests(); Assert.assertEquals(1, actualRequests.size()); CreateFeedRequest actualRequest = ((CreateFeedRequest) actualRequests.get(0)); + Assert.assertEquals(parent, actualRequest.getParent()); Assert.assertTrue( channelProvider.isHeaderSent( @@ -210,6 +224,7 @@ public void createFeedTest() { public void createFeedExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); mockAssetService.addException(exception); + try { String parent = "parent-995424086"; client.createFeed(parent); @@ -229,12 +244,16 @@ public void getFeedTest() { .setFeedOutputConfig(FeedOutputConfig.newBuilder().build()) .build(); mockAssetService.addResponse(expectedResponse); + FeedName name = FeedName.ofProjectFeedName("[PROJECT]", "[FEED]"); + Feed actualResponse = client.getFeed(name); Assert.assertEquals(expectedResponse, actualResponse); + List actualRequests = mockAssetService.getRequests(); Assert.assertEquals(1, actualRequests.size()); GetFeedRequest actualRequest = ((GetFeedRequest) actualRequests.get(0)); + Assert.assertEquals(name.toString(), actualRequest.getName()); Assert.assertTrue( channelProvider.isHeaderSent( @@ -246,6 +265,7 @@ public void getFeedTest() { public void getFeedExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); mockAssetService.addException(exception); + try { FeedName name = FeedName.ofProjectFeedName("[PROJECT]", "[FEED]"); client.getFeed(name); @@ -265,12 +285,16 @@ public void getFeedTest2() { .setFeedOutputConfig(FeedOutputConfig.newBuilder().build()) .build(); mockAssetService.addResponse(expectedResponse); + String name = "name3373707"; + Feed actualResponse = client.getFeed(name); Assert.assertEquals(expectedResponse, actualResponse); + List actualRequests = mockAssetService.getRequests(); Assert.assertEquals(1, actualRequests.size()); GetFeedRequest actualRequest = ((GetFeedRequest) actualRequests.get(0)); + Assert.assertEquals(name, actualRequest.getName()); Assert.assertTrue( channelProvider.isHeaderSent( @@ -282,6 +306,7 @@ public void getFeedTest2() { public void getFeedExceptionTest2() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); mockAssetService.addException(exception); + try { String name = "name3373707"; client.getFeed(name); @@ -296,12 +321,16 @@ public void listFeedsTest() { ListFeedsResponse expectedResponse = ListFeedsResponse.newBuilder().addAllFeeds(new ArrayList<>()).build(); mockAssetService.addResponse(expectedResponse); + String parent = "parent-995424086"; + ListFeedsResponse actualResponse = client.listFeeds(parent); Assert.assertEquals(expectedResponse, actualResponse); + List actualRequests = mockAssetService.getRequests(); Assert.assertEquals(1, actualRequests.size()); ListFeedsRequest actualRequest = ((ListFeedsRequest) actualRequests.get(0)); + Assert.assertEquals(parent, actualRequest.getParent()); Assert.assertTrue( channelProvider.isHeaderSent( @@ -313,6 +342,7 @@ public void listFeedsTest() { public void listFeedsExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); mockAssetService.addException(exception); + try { String parent = "parent-995424086"; client.listFeeds(parent); @@ -332,12 +362,16 @@ public void updateFeedTest() { .setFeedOutputConfig(FeedOutputConfig.newBuilder().build()) .build(); mockAssetService.addResponse(expectedResponse); + Feed feed = Feed.newBuilder().build(); + Feed actualResponse = client.updateFeed(feed); Assert.assertEquals(expectedResponse, actualResponse); + List actualRequests = mockAssetService.getRequests(); Assert.assertEquals(1, actualRequests.size()); UpdateFeedRequest actualRequest = ((UpdateFeedRequest) actualRequests.get(0)); + Assert.assertEquals(feed, actualRequest.getFeed()); Assert.assertTrue( channelProvider.isHeaderSent( @@ -349,6 +383,7 @@ public void updateFeedTest() { public void updateFeedExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); mockAssetService.addException(exception); + try { Feed feed = Feed.newBuilder().build(); client.updateFeed(feed); @@ -362,12 +397,16 @@ public void updateFeedExceptionTest() throws Exception { public void deleteFeedTest() { Empty expectedResponse = Empty.newBuilder().build(); mockAssetService.addResponse(expectedResponse); + FeedName name = FeedName.ofProjectFeedName("[PROJECT]", "[FEED]"); + Empty actualResponse = client.deleteFeed(name); Assert.assertEquals(expectedResponse, actualResponse); + List actualRequests = mockAssetService.getRequests(); Assert.assertEquals(1, actualRequests.size()); DeleteFeedRequest actualRequest = ((DeleteFeedRequest) actualRequests.get(0)); + Assert.assertEquals(name.toString(), actualRequest.getName()); Assert.assertTrue( channelProvider.isHeaderSent( @@ -379,6 +418,7 @@ public void deleteFeedTest() { public void deleteFeedExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); mockAssetService.addException(exception); + try { FeedName name = FeedName.ofProjectFeedName("[PROJECT]", "[FEED]"); client.deleteFeed(name); @@ -392,12 +432,16 @@ public void deleteFeedExceptionTest() throws Exception { public void deleteFeedTest2() { Empty expectedResponse = Empty.newBuilder().build(); mockAssetService.addResponse(expectedResponse); + String name = "name3373707"; + Empty actualResponse = client.deleteFeed(name); Assert.assertEquals(expectedResponse, actualResponse); + List actualRequests = mockAssetService.getRequests(); Assert.assertEquals(1, actualRequests.size()); DeleteFeedRequest actualRequest = ((DeleteFeedRequest) actualRequests.get(0)); + Assert.assertEquals(name, actualRequest.getName()); Assert.assertTrue( channelProvider.isHeaderSent( @@ -409,6 +453,7 @@ public void deleteFeedTest2() { public void deleteFeedExceptionTest2() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); mockAssetService.addException(exception); + try { String name = "name3373707"; client.deleteFeed(name); @@ -427,17 +472,23 @@ public void searchAllResourcesTest() { .addAllResponses(Arrays.asList(responsesElement)) .build(); mockAssetService.addResponse(expectedResponse); + String scope = "scope109264468"; String query = "query107944136"; List assetTypes = new ArrayList<>(); + SearchAllResourcesResponse pagedListResponse = client.searchAllResources(scope, query, assetTypes); - resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + Assert.assertEquals(1, resources.size()); Assert.assertEquals(expectedResponse.getResponsesList().get(0), resources.get(0)); + List actualRequests = mockAssetService.getRequests(); Assert.assertEquals(1, actualRequests.size()); SearchAllResourcesRequest actualRequest = ((SearchAllResourcesRequest) actualRequests.get(0)); + Assert.assertEquals(scope, actualRequest.getScope()); Assert.assertEquals(query, actualRequest.getQuery()); Assert.assertEquals(assetTypes, actualRequest.getAssetTypesList()); @@ -451,6 +502,7 @@ public void searchAllResourcesTest() { public void searchAllResourcesExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); mockAssetService.addException(exception); + try { String scope = "scope109264468"; String query = "query107944136"; @@ -471,16 +523,22 @@ public void searchAllIamPoliciesTest() { .addAllResponses(Arrays.asList(responsesElement)) .build(); mockAssetService.addResponse(expectedResponse); + String scope = "scope109264468"; String query = "query107944136"; + SearchAllIamPoliciesResponse pagedListResponse = client.searchAllIamPolicies(scope, query); - resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + Assert.assertEquals(1, resources.size()); Assert.assertEquals(expectedResponse.getResponsesList().get(0), resources.get(0)); + List actualRequests = mockAssetService.getRequests(); Assert.assertEquals(1, actualRequests.size()); SearchAllIamPoliciesRequest actualRequest = ((SearchAllIamPoliciesRequest) actualRequests.get(0)); + Assert.assertEquals(scope, actualRequest.getScope()); Assert.assertEquals(query, actualRequest.getQuery()); Assert.assertTrue( @@ -493,6 +551,7 @@ public void searchAllIamPoliciesTest() { public void searchAllIamPoliciesExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); mockAssetService.addException(exception); + try { String scope = "scope109264468"; String query = "query107944136"; diff --git a/test/integration/goldens/asset/AssetServiceStubSettings.java b/test/integration/goldens/asset/AssetServiceStubSettings.java index 4229f34554..ba92bb4860 100644 --- a/test/integration/goldens/asset/AssetServiceStubSettings.java +++ b/test/integration/goldens/asset/AssetServiceStubSettings.java @@ -117,6 +117,7 @@ public class AssetServiceStubSettings extends StubSettings searchAllIamPoliciesSettings; + private static final PagedListDescriptor< SearchAllResourcesRequest, SearchAllResourcesResponse, ResourceSearchResult> SEARCH_ALL_RESOURCES_PAGE_STR_DESC = @@ -157,6 +158,7 @@ public Iterable extractResources( : payload.getResultsList(); } }; + private static final PagedListDescriptor< SearchAllIamPoliciesRequest, SearchAllIamPoliciesResponse, IamPolicySearchResult> SEARCH_ALL_IAM_POLICIES_PAGE_STR_DESC = @@ -197,6 +199,7 @@ public Iterable extractResources( : payload.getResultsList(); } }; + private static final PagedListResponseFactory< SearchAllResourcesRequest, SearchAllResourcesResponse, SearchAllResourcesPagedResponse> SEARCH_ALL_RESOURCES_PAGE_STR_FACT = @@ -218,6 +221,7 @@ public ApiFuture getFuturePagedResponse( return SearchAllResourcesPagedResponse.createAsync(pageContext, futureResponse); } }; + private static final PagedListResponseFactory< SearchAllIamPoliciesRequest, SearchAllIamPoliciesResponse, @@ -370,6 +374,7 @@ public Builder toBuilder() { protected AssetServiceStubSettings(Builder settingsBuilder) throws IOException { super(settingsBuilder); + exportAssetsSettings = settingsBuilder.exportAssetsSettings().build(); exportAssetsOperationSettings = settingsBuilder.exportAssetsOperationSettings().build(); batchGetAssetsHistorySettings = settingsBuilder.batchGetAssetsHistorySettings().build(); @@ -470,6 +475,7 @@ protected Builder() { protected Builder(ClientContext clientContext) { super(clientContext); + exportAssetsSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); exportAssetsOperationSettings = OperationCallSettings.newBuilder(); batchGetAssetsHistorySettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); @@ -481,6 +487,7 @@ protected Builder(ClientContext clientContext) { searchAllResourcesSettings = PagedCallSettings.newBuilder(SEARCH_ALL_RESOURCES_PAGE_STR_FACT); searchAllIamPoliciesSettings = PagedCallSettings.newBuilder(SEARCH_ALL_IAM_POLICIES_PAGE_STR_FACT); + unaryMethodSettingsBuilders = ImmutableList.>of( exportAssetsSettings, @@ -497,6 +504,7 @@ protected Builder(ClientContext clientContext) { protected Builder(AssetServiceStubSettings settings) { super(settings); + exportAssetsSettings = settings.exportAssetsSettings.toBuilder(); exportAssetsOperationSettings = settings.exportAssetsOperationSettings.toBuilder(); batchGetAssetsHistorySettings = settings.batchGetAssetsHistorySettings.toBuilder(); @@ -507,6 +515,7 @@ protected Builder(AssetServiceStubSettings settings) { deleteFeedSettings = settings.deleteFeedSettings.toBuilder(); searchAllResourcesSettings = settings.searchAllResourcesSettings.toBuilder(); searchAllIamPoliciesSettings = settings.searchAllIamPoliciesSettings.toBuilder(); + unaryMethodSettingsBuilders = ImmutableList.>of( exportAssetsSettings, @@ -522,10 +531,12 @@ protected Builder(AssetServiceStubSettings settings) { private static Builder createDefault() { Builder builder = new Builder(((ClientContext) null)); + builder.setTransportChannelProvider(defaultTransportChannelProvider()); builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build()); builder.setInternalHeaderProvider(defaultApiClientHeaderProviderBuilder().build()); builder.setEndpoint(getDefaultEndpoint()); + return initDefaults(builder); } @@ -534,38 +545,47 @@ private static Builder initDefaults(Builder builder) { .exportAssetsSettings() .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes")) .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params")); + builder .batchGetAssetsHistorySettings() .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_1_codes")) .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_1_params")); + builder .createFeedSettings() .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes")) .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params")); + builder .getFeedSettings() .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_1_codes")) .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_1_params")); + builder .listFeedsSettings() .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_1_codes")) .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_1_params")); + builder .updateFeedSettings() .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes")) .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params")); + builder .deleteFeedSettings() .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_1_codes")) .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_1_params")); + builder .searchAllResourcesSettings() .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_2_codes")) .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_2_params")); + builder .searchAllIamPoliciesSettings() .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_2_codes")) .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_2_params")); + builder .exportAssetsOperationSettings() .setInitialCallSettings( @@ -589,6 +609,7 @@ private static Builder initDefaults(Builder builder) { .setMaxRpcTimeout(Duration.ZERO) .setTotalTimeout(Duration.ofMillis(300000L)) .build())); + return builder; } diff --git a/test/integration/goldens/asset/GrpcAssetServiceStub.java b/test/integration/goldens/asset/GrpcAssetServiceStub.java index f29c88957f..7b4daba7a0 100644 --- a/test/integration/goldens/asset/GrpcAssetServiceStub.java +++ b/test/integration/goldens/asset/GrpcAssetServiceStub.java @@ -66,6 +66,7 @@ public class GrpcAssetServiceStub extends AssetServiceStub { .setRequestMarshaller(ProtoUtils.marshaller(ExportAssetsRequest.getDefaultInstance())) .setResponseMarshaller(ProtoUtils.marshaller(Operation.getDefaultInstance())) .build(); + private static final MethodDescriptor batchGetAssetsHistoryMethodDescriptor = MethodDescriptor.newBuilder() @@ -76,6 +77,7 @@ public class GrpcAssetServiceStub extends AssetServiceStub { .setResponseMarshaller( ProtoUtils.marshaller(BatchGetAssetsHistoryResponse.getDefaultInstance())) .build(); + private static final MethodDescriptor createFeedMethodDescriptor = MethodDescriptor.newBuilder() .setType(MethodDescriptor.MethodType.UNARY) @@ -83,6 +85,7 @@ public class GrpcAssetServiceStub extends AssetServiceStub { .setRequestMarshaller(ProtoUtils.marshaller(CreateFeedRequest.getDefaultInstance())) .setResponseMarshaller(ProtoUtils.marshaller(Feed.getDefaultInstance())) .build(); + private static final MethodDescriptor getFeedMethodDescriptor = MethodDescriptor.newBuilder() .setType(MethodDescriptor.MethodType.UNARY) @@ -90,6 +93,7 @@ public class GrpcAssetServiceStub extends AssetServiceStub { .setRequestMarshaller(ProtoUtils.marshaller(GetFeedRequest.getDefaultInstance())) .setResponseMarshaller(ProtoUtils.marshaller(Feed.getDefaultInstance())) .build(); + private static final MethodDescriptor listFeedsMethodDescriptor = MethodDescriptor.newBuilder() @@ -98,6 +102,7 @@ public class GrpcAssetServiceStub extends AssetServiceStub { .setRequestMarshaller(ProtoUtils.marshaller(ListFeedsRequest.getDefaultInstance())) .setResponseMarshaller(ProtoUtils.marshaller(ListFeedsResponse.getDefaultInstance())) .build(); + private static final MethodDescriptor updateFeedMethodDescriptor = MethodDescriptor.newBuilder() .setType(MethodDescriptor.MethodType.UNARY) @@ -105,6 +110,7 @@ public class GrpcAssetServiceStub extends AssetServiceStub { .setRequestMarshaller(ProtoUtils.marshaller(UpdateFeedRequest.getDefaultInstance())) .setResponseMarshaller(ProtoUtils.marshaller(Feed.getDefaultInstance())) .build(); + private static final MethodDescriptor deleteFeedMethodDescriptor = MethodDescriptor.newBuilder() .setType(MethodDescriptor.MethodType.UNARY) @@ -112,6 +118,7 @@ public class GrpcAssetServiceStub extends AssetServiceStub { .setRequestMarshaller(ProtoUtils.marshaller(DeleteFeedRequest.getDefaultInstance())) .setResponseMarshaller(ProtoUtils.marshaller(Empty.getDefaultInstance())) .build(); + private static final MethodDescriptor searchAllResourcesMethodDescriptor = MethodDescriptor.newBuilder() @@ -122,6 +129,7 @@ public class GrpcAssetServiceStub extends AssetServiceStub { .setResponseMarshaller( ProtoUtils.marshaller(SearchAllResourcesResponse.getDefaultInstance())) .build(); + private static final MethodDescriptor searchAllIamPoliciesMethodDescriptor = MethodDescriptor.newBuilder() @@ -132,6 +140,7 @@ public class GrpcAssetServiceStub extends AssetServiceStub { .setResponseMarshaller( ProtoUtils.marshaller(SearchAllIamPoliciesResponse.getDefaultInstance())) .build(); + private final UnaryCallable exportAssetsCallable; private final OperationCallable exportAssetsOperationCallable; @@ -150,6 +159,7 @@ public class GrpcAssetServiceStub extends AssetServiceStub { searchAllIamPoliciesCallable; private final UnaryCallable searchAllIamPoliciesPagedCallable; + private final BackgroundResource backgroundResources; private final GrpcOperationsStub operationsStub; private final GrpcStubCallableFactory callableFactory; @@ -181,6 +191,7 @@ protected GrpcAssetServiceStub( throws IOException { this.callableFactory = callableFactory; this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory); + GrpcCallSettings exportAssetsTransportSettings = GrpcCallSettings.newBuilder() .setMethodDescriptor(exportAssetsMethodDescriptor) @@ -221,6 +232,7 @@ protected GrpcAssetServiceStub( GrpcCallSettings.newBuilder() .setMethodDescriptor(searchAllIamPoliciesMethodDescriptor) .build(); + this.exportAssetsCallable = callableFactory.createUnaryCallable( exportAssetsTransportSettings, settings.exportAssetsSettings(), clientContext); @@ -270,6 +282,7 @@ protected GrpcAssetServiceStub( searchAllIamPoliciesTransportSettings, settings.searchAllIamPoliciesSettings(), clientContext); + this.backgroundResources = new BackgroundResourceAggregation(clientContext.getBackgroundResources()); }