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 +``` diff --git a/test/integration/goldens/redis/BUILD.bazel b/test/integration/goldens/redis/BUILD.bazel new file mode 100644 index 0000000000..0b74aed56b --- /dev/null +++ b/test/integration/goldens/redis/BUILD.bazel @@ -0,0 +1,6 @@ +package(default_visibility = ["//visibility:public"]) + +filegroup( + name = "goldens_files", + srcs = glob(["*.java"]), +) diff --git a/test/integration/goldens/redis/CloudRedisClient.java b/test/integration/goldens/redis/CloudRedisClient.java new file mode 100644 index 0000000000..83a43c2b11 --- /dev/null +++ b/test/integration/goldens/redis/CloudRedisClient.java @@ -0,0 +1,951 @@ +/* + * 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.Objects; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// 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: * + * `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: + * + *

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 + * 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: + * + *

To customize the endpoint: + */ +@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 EchoClient with default settings. */ + public static final CloudRedisClient create() throws IOException { + return create(CloudRedisSettings.newBuilder().build()); + } + + /** + * 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 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) { + return new CloudRedisClient(stub); + } + + /** + * 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; + 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. + */ + public final OperationsClient getOperationsClient() { + return operationsClient; + } + + // 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 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. + * + *

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. + * + *

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 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 + */ + public final OperationFuture createInstanceAsync( + LocationName parent, String instanceId, Instance instance) { + CreateInstanceRequest request = + CreateInstanceRequest.newBuilder() + .setParent(Objects.isNull(parent) ? 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: + * + * @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 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 + */ + 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: + * + * @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 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: + */ + 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: + */ + 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: + * + * @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` + * @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 + */ + 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: + * + * @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 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: + */ + 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: + */ + public final UnaryCallable updateInstanceCallable() { + return stub.updateInstanceCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Upgrades Redis instance to the newer Redis version specified in the request. + * + *

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 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: + * + * @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 input_config Required. Specify data to be imported. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + 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: + * + * @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 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: + */ + 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: + */ + 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: + * + * @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 output_config Required. Specify data to be exported. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + 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: + * + * @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 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: + */ + 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: + */ + 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: + * + * @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 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 + */ + public final OperationFuture failoverInstanceAsync( + InstanceName name, FailoverInstanceRequest.DataProtectionMode dataProtectionMode) { + FailoverInstanceRequest request = + FailoverInstanceRequest.newBuilder() + .setName(Objects.isNull(name) ? 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: + * + * @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 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 + */ + 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: + * + * @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 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: + */ + 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: + */ + 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: + * + * @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 OperationFuture deleteInstanceAsync(InstanceName name) { + DeleteInstanceRequest request = + DeleteInstanceRequest.newBuilder() + .setName(Objects.isNull(name) ? 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: + * + * @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 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: + * + * @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 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: + */ + 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: + */ + public final UnaryCallable deleteInstanceCallable() { + return stub.deleteInstanceCallable(); + } + + @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..fcbd325315 --- /dev/null +++ b/test/integration/goldens/redis/CloudRedisClientTest.java @@ -0,0 +1,940 @@ +/* + * 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.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.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; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +@Generated("by gapic-generator-java") +public class CloudRedisClientTest { + private static MockCloudRedis mockCloudRedis; + private static MockServiceHelper mockServiceHelper; + private CloudRedisClient client; + private LocalChannelProvider channelProvider; + + @BeforeClass + public static void startStaticServer() { + mockCloudRedis = new MockCloudRedis(); + mockServiceHelper = + new MockServiceHelper( + UUID.randomUUID().toString(), Arrays.asList(mockCloudRedis)); + mockServiceHelper.start(); + } + + @AfterClass + public static void stopServer() { + mockServiceHelper.stop(); + } + + @Before + public void setUp() throws IOException { + mockServiceHelper.reset(); + channelProvider = mockServiceHelper.createChannelProvider(); + CloudRedisSettings settings = + CloudRedisSettings.newBuilder() + .setTransportChannelProvider(channelProvider) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = CloudRedisClient.create(settings); + } + + @After + public void tearDown() throws Exception { + client.close(); + } + + @Test + 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]"); + + 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(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("createInstanceTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockCloudRedis.addResponse(resultOperation); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + 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.toString(), actualRequest.getParent()); + Assert.assertEquals(instanceId, actualRequest.getInstanceId()); + Assert.assertEquals(instance, actualRequest.getInstance()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void createInstanceExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockCloudRedis.addException(exception); + + try { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + 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 createInstanceTest2() { + 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("createInstanceTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockCloudRedis.addResponse(resultOperation); + + 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() + .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)); + + Assert.assertEquals(updateMask, actualRequest.getUpdateMask()); + Assert.assertEquals(instance, actualRequest.getInstance()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void updateInstanceExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockCloudRedis.addException(exception); + + try { + 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()); + Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); + } + } + + @Test + public void upgradeInstanceTest() { + 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); + + 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"; + 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, actualRequest.getName()); + Assert.assertEquals(redisVersion, actualRequest.getRedisVersion()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void upgradeInstanceExceptionTest2() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockCloudRedis.addException(exception); + + try { + String name = "name3373707"; + 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 importInstanceTest() { + 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("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 + public void importInstanceExceptionTest() 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(); + 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 exportInstanceTest() { + 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("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 + public void exportInstanceExceptionTest() 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(); + 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 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("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); + + 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.toString(), actualRequest.getName()); + Assert.assertEquals(dataProtectionMode, actualRequest.getDataProtectionMode()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + 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]"); + 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()); + Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); + } + } + + @Test + 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(); + Operation resultOperation = + Operation.newBuilder() + .setName("failoverInstanceTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockCloudRedis.addResponse(resultOperation); + + String name = "name3373707"; + FailoverInstanceRequest.DataProtectionMode dataProtectionMode = + FailoverInstanceRequest.DataProtectionMode.forNumber(0); + + 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, actualRequest.getName()); + Assert.assertEquals(dataProtectionMode, actualRequest.getDataProtectionMode()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void failoverInstanceExceptionTest2() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockCloudRedis.addException(exception); + + try { + String name = "name3373707"; + 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()); + Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); + } + } + + @Test + public void deleteInstanceTest() { + 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.toString(), actualRequest.getName()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + 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.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 + public void deleteInstanceTest2() { + Empty expectedResponse = Empty.newBuilder().build(); + Operation resultOperation = + Operation.newBuilder() + .setName("deleteInstanceTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockCloudRedis.addResponse(resultOperation); + + String name = "name3373707"; + + 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, actualRequest.getName()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void deleteInstanceExceptionTest2() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockCloudRedis.addException(exception); + + try { + 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()); + 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..4a33403427 --- /dev/null +++ b/test/integration/goldens/redis/CloudRedisSettings.java @@ -0,0 +1,341 @@ +/* + * 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.StubSettings; +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 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 listInstances to 30 seconds: + */ +@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. */ + 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. */ + 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. */ + 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. */ + 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. */ + 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. */ + public OperationCallSettings + deleteInstanceOperationSettings() { + return ((CloudRedisStubSettings) getStubSettings()).deleteInstanceOperationSettings(); + } + + 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)); + } + + protected Builder(CloudRedisSettings settings) { + super(settings.getStubSettings().toBuilder()); + } + + 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'. + /** + * 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 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. */ + 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. */ + 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. */ + 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. */ + 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. */ + 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. */ + public OperationCallSettings.Builder + deleteInstanceOperationSettings() { + return getStubSettingsBuilder().deleteInstanceOperationSettings(); + } + + @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..cb83fee1eb --- /dev/null +++ b/test/integration/goldens/redis/CloudRedisStub.java @@ -0,0 +1,132 @@ +/* + * 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.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 the CloudRedis service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@Generated("by gapic-generator") +public abstract class CloudRedisStub implements BackgroundResource { + + public OperationsStub getOperationsStub() { + throw new UnsupportedOperationException("Not implemented: getOperationsStub()"); + } + + 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()"); + } + + public UnaryCallable createInstanceCallable() { + throw new UnsupportedOperationException("Not implemented: createInstanceCallable()"); + } + + public OperationCallable + updateInstanceOperationCallable() { + throw new UnsupportedOperationException("Not implemented: updateInstanceOperationCallable()"); + } + + public UnaryCallable updateInstanceCallable() { + throw new UnsupportedOperationException("Not implemented: updateInstanceCallable()"); + } + + 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()"); + } + + public UnaryCallable importInstanceCallable() { + throw new UnsupportedOperationException("Not implemented: importInstanceCallable()"); + } + + public OperationCallable + exportInstanceOperationCallable() { + throw new UnsupportedOperationException("Not implemented: exportInstanceOperationCallable()"); + } + + public UnaryCallable exportInstanceCallable() { + throw new UnsupportedOperationException("Not implemented: exportInstanceCallable()"); + } + + public OperationCallable + failoverInstanceOperationCallable() { + throw new UnsupportedOperationException("Not implemented: failoverInstanceOperationCallable()"); + } + + public UnaryCallable failoverInstanceCallable() { + throw new UnsupportedOperationException("Not implemented: failoverInstanceCallable()"); + } + + public OperationCallable + deleteInstanceOperationCallable() { + throw new UnsupportedOperationException("Not implemented: deleteInstanceOperationCallable()"); + } + + public UnaryCallable deleteInstanceCallable() { + throw new UnsupportedOperationException("Not implemented: deleteInstanceCallable()"); + } + + @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..823b99f3a4 --- /dev/null +++ b/test/integration/goldens/redis/CloudRedisStubSettings.java @@ -0,0 +1,836 @@ +/* + * 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 java.util.Objects; +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 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 listInstances to 30 seconds: + */ +@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; + 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 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> + 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() { + return createInstanceSettings; + } + + /** Returns the object with the settings used for calls to createInstance. */ + 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. */ + 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. */ + 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. */ + 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. */ + 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. */ + public OperationCallSettings + deleteInstanceOperationSettings() { + return deleteInstanceOperationSettings; + } + + @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); + } + throw new UnsupportedOperationException( + String.format( + "Transport not supported: %s", 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); + + 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(); + exportInstanceOperationSettings = settingsBuilder.exportInstanceOperationSettings().build(); + failoverInstanceSettings = settingsBuilder.failoverInstanceSettings().build(); + failoverInstanceOperationSettings = settingsBuilder.failoverInstanceOperationSettings().build(); + deleteInstanceSettings = settingsBuilder.deleteInstanceSettings().build(); + deleteInstanceOperationSettings = settingsBuilder.deleteInstanceOperationSettings().build(); + } + + /** 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 + createInstanceOperationSettings; + private final UnaryCallSettings.Builder + updateInstanceSettings; + private final OperationCallSettings.Builder + updateInstanceOperationSettings; + private final UnaryCallSettings.Builder + upgradeInstanceSettings; + private final OperationCallSettings.Builder + upgradeInstanceOperationSettings; + 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 static final ImmutableMap> + RETRYABLE_CODE_DEFINITIONS; + + static { + ImmutableMap.Builder> definitions = + ImmutableMap.builder(); + definitions.put( + "no_retry_0_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() + .setInitialRpcTimeout(Duration.ofMillis(600000L)) + .setRpcTimeoutMultiplier(1.0) + .setMaxRpcTimeout(Duration.ofMillis(600000L)) + .setTotalTimeout(Duration.ofMillis(600000L)) + .build(); + definitions.put("no_retry_0_params", settings); + RETRY_PARAM_DEFINITIONS = definitions.build(); + } + + protected Builder() { + this(((ClientContext) null)); + } + + protected Builder(ClientContext clientContext) { + super(clientContext); + + listInstancesSettings = PagedCallSettings.newBuilder(LIST_INSTANCES_PAGE_STR_FACT); + getInstanceSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + createInstanceSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + createInstanceOperationSettings = OperationCallSettings.newBuilder(); + updateInstanceSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + updateInstanceOperationSettings = OperationCallSettings.newBuilder(); + upgradeInstanceSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + upgradeInstanceOperationSettings = 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(); + + unaryMethodSettingsBuilders = + ImmutableList.>of( + listInstancesSettings, + getInstanceSettings, + createInstanceSettings, + updateInstanceSettings, + upgradeInstanceSettings, + importInstanceSettings, + exportInstanceSettings, + failoverInstanceSettings, + deleteInstanceSettings); + initDefaults(this); + } + + protected Builder(CloudRedisStubSettings settings) { + super(settings); + + 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); + } + + 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 + .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_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params")); + + builder + .updateInstanceSettings() + .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_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params")); + + builder + .exportInstanceSettings() + .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_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params")); + + builder + .deleteInstanceSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params")); + + builder + .createInstanceOperationSettings() + .setInitialCallSettings( + UnaryCallSettings + .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)) + .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) + .setRpcTimeoutMultiplier(1.0) + .setMaxRpcTimeout(Duration.ZERO) + .setTotalTimeout(Duration.ofMillis(300000L)) + .build())); + + builder + .updateInstanceOperationSettings() + .setInitialCallSettings( + UnaryCallSettings + .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)) + .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) + .setRpcTimeoutMultiplier(1.0) + .setMaxRpcTimeout(Duration.ZERO) + .setTotalTimeout(Duration.ofMillis(300000L)) + .build())); + + builder + .upgradeInstanceOperationSettings() + .setInitialCallSettings( + UnaryCallSettings + .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)) + .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) + .setRpcTimeoutMultiplier(1.0) + .setMaxRpcTimeout(Duration.ZERO) + .setTotalTimeout(Duration.ofMillis(300000L)) + .build())); + + builder + .importInstanceOperationSettings() + .setInitialCallSettings( + UnaryCallSettings + .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)) + .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) + .setRpcTimeoutMultiplier(1.0) + .setMaxRpcTimeout(Duration.ZERO) + .setTotalTimeout(Duration.ofMillis(300000L)) + .build())); + + builder + .exportInstanceOperationSettings() + .setInitialCallSettings( + UnaryCallSettings + .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)) + .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) + .setRpcTimeoutMultiplier(1.0) + .setMaxRpcTimeout(Duration.ZERO) + .setTotalTimeout(Duration.ofMillis(300000L)) + .build())); + + builder + .failoverInstanceOperationSettings() + .setInitialCallSettings( + UnaryCallSettings + .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)) + .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) + .setRpcTimeoutMultiplier(1.0) + .setMaxRpcTimeout(Duration.ZERO) + .setTotalTimeout(Duration.ofMillis(300000L)) + .build())); + + builder + .deleteInstanceOperationSettings() + .setInitialCallSettings( + UnaryCallSettings + .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)) + .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) + .setRpcTimeoutMultiplier(1.0) + .setMaxRpcTimeout(Duration.ZERO) + .setTotalTimeout(Duration.ofMillis(300000L)) + .build())); + + return builder; + } + + // 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 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; + } + + /** 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 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; + } + + /** 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; + } + + @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..7631c208ea --- /dev/null +++ b/test/integration/goldens/redis/GrpcCloudRedisCallableFactory.java @@ -0,0 +1,113 @@ +/* + * 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.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.Operation; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * gRPC callable factory implementation for the CloudRedis service API. + * + *

This class is for advanced usage. + */ +@Generated("by gapic-generator") +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 callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createPagedCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + GrpcCallSettings grpcCallSettings, + BatchingCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBatchingCallable( + grpcCallSettings, callSettings, clientContext); + } + + @Override + public + OperationCallable createOperationCallable( + GrpcCallSettings grpcCallSettings, + OperationCallSettings callSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + return GrpcCallableFactory.createOperationCallable( + grpcCallSettings, callSettings, clientContext, operationsStub); + } + + @Override + public + BidiStreamingCallable createBidiStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBidiStreamingCallable( + grpcCallSettings, callSettings, clientContext); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + GrpcCallSettings grpcCallSettings, + ServerStreamingCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createServerStreamingCallable( + grpcCallSettings, callSettings, clientContext); + } + + @Override + public + ClientStreamingCallable createClientStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createClientStreamingCallable( + grpcCallSettings, callSettings, clientContext); + } +} diff --git a/test/integration/goldens/redis/GrpcCloudRedisStub.java b/test/integration/goldens/redis/GrpcCloudRedisStub.java new file mode 100644 index 0000000000..64ffc5d17c --- /dev/null +++ b/test/integration/goldens/redis/GrpcCloudRedisStub.java @@ -0,0 +1,427 @@ +/* + * 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.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.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.GrpcOperationsStub; +import com.google.protobuf.Empty; +import io.grpc.MethodDescriptor; +import io.grpc.protobuf.ProtoUtils; +import java.io.IOException; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * gRPC stub implementation for the CloudRedis service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@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 = + 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 + 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() + .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 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; + 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 BackgroundResource backgroundResources; + private final GrpcOperationsStub operationsStub; + 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); + } + + protected GrpcCloudRedisStub(CloudRedisStubSettings settings, ClientContext clientContext) + throws IOException { + this(settings, clientContext, new GrpcCloudRedisCallableFactory()); + } + + protected GrpcCloudRedisStub( + CloudRedisStubSettings settings, + ClientContext clientContext, + GrpcStubCallableFactory callableFactory) + throws IOException { + 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) + .build(); + GrpcCallSettings updateInstanceTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(updateInstanceMethodDescriptor) + .build(); + GrpcCallSettings upgradeInstanceTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(upgradeInstanceMethodDescriptor) + .build(); + GrpcCallSettings importInstanceTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(importInstanceMethodDescriptor) + .build(); + GrpcCallSettings exportInstanceTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(exportInstanceMethodDescriptor) + .build(); + GrpcCallSettings failoverInstanceTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(failoverInstanceMethodDescriptor) + .build(); + GrpcCallSettings deleteInstanceTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(deleteInstanceMethodDescriptor) + .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); + this.createInstanceOperationCallable = + callableFactory.createOperationCallable( + createInstanceTransportSettings, + settings.createInstanceOperationSettings(), + clientContext, + operationsStub); + this.updateInstanceCallable = + callableFactory.createUnaryCallable( + updateInstanceTransportSettings, settings.updateInstanceSettings(), clientContext); + this.updateInstanceOperationCallable = + callableFactory.createOperationCallable( + updateInstanceTransportSettings, + settings.updateInstanceOperationSettings(), + clientContext, + 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); + this.importInstanceOperationCallable = + callableFactory.createOperationCallable( + importInstanceTransportSettings, + settings.importInstanceOperationSettings(), + clientContext, + operationsStub); + this.exportInstanceCallable = + callableFactory.createUnaryCallable( + exportInstanceTransportSettings, settings.exportInstanceSettings(), clientContext); + this.exportInstanceOperationCallable = + callableFactory.createOperationCallable( + exportInstanceTransportSettings, + settings.exportInstanceOperationSettings(), + clientContext, + operationsStub); + this.failoverInstanceCallable = + callableFactory.createUnaryCallable( + failoverInstanceTransportSettings, settings.failoverInstanceSettings(), clientContext); + this.failoverInstanceOperationCallable = + callableFactory.createOperationCallable( + failoverInstanceTransportSettings, + settings.failoverInstanceOperationSettings(), + clientContext, + operationsStub); + this.deleteInstanceCallable = + callableFactory.createUnaryCallable( + deleteInstanceTransportSettings, settings.deleteInstanceSettings(), clientContext); + this.deleteInstanceOperationCallable = + callableFactory.createOperationCallable( + deleteInstanceTransportSettings, + settings.deleteInstanceOperationSettings(), + clientContext, + operationsStub); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + public GrpcOperationsStub getOperationsStub() { + return operationsStub; + } + + 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 updateInstanceCallable() { + return updateInstanceCallable; + } + + public OperationCallable + updateInstanceOperationCallable() { + return updateInstanceOperationCallable; + } + + public UnaryCallable upgradeInstanceCallable() { + return upgradeInstanceCallable; + } + + public OperationCallable + upgradeInstanceOperationCallable() { + return upgradeInstanceOperationCallable; + } + + public UnaryCallable importInstanceCallable() { + return importInstanceCallable; + } + + public OperationCallable + importInstanceOperationCallable() { + return importInstanceOperationCallable; + } + + public UnaryCallable exportInstanceCallable() { + return exportInstanceCallable; + } + + public OperationCallable + exportInstanceOperationCallable() { + return exportInstanceOperationCallable; + } + + public UnaryCallable failoverInstanceCallable() { + return failoverInstanceCallable; + } + + public OperationCallable + failoverInstanceOperationCallable() { + return failoverInstanceOperationCallable; + } + + public UnaryCallable deleteInstanceCallable() { + return deleteInstanceCallable; + } + + public OperationCallable + deleteInstanceOperationCallable() { + return deleteInstanceOperationCallable; + } + + @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..f2fb7dfe5a --- /dev/null +++ b/test/integration/goldens/redis/InstanceName.java @@ -0,0 +1,215 @@ +/* + * 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.pathtemplate.PathTemplate; +import com.google.api.resourcenames.ResourceName; +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. +@Generated("by gapic-generator-java") +public class InstanceName implements ResourceName { + 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; + } + + public String getLocation() { + return location; + } + + public String getInstance() { + return instance; + } + + public static Builder newBuilder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder(this); + } + + 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 = + PROJECT_LOCATION_INSTANCE.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 (Objects.isNull(value)) { + list.add(""); + } else { + list.add(value.toString()); + } + } + return list; + } + + public static boolean isParsableFrom(String formattedString) { + return PROJECT_LOCATION_INSTANCE.matches(formattedString); + } + + @Override + public Map getFieldValuesMap() { + if (Objects.isNull(fieldValuesMap)) { + synchronized (this) { + if (Objects.isNull(fieldValuesMap)) { + ImmutableMap.Builder fieldMapBuilder = ImmutableMap.builder(); + 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(); + } + } + } + return fieldValuesMap; + } + + public String getFieldValue(String fieldName) { + return getFieldValuesMap().get(fieldName); + } + + @Override + public String toString() { + return PROJECT_LOCATION_INSTANCE.instantiate("project", project); + } + + @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; + } + + 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(InstanceName instanceName) { + project = instanceName.project; + location = instanceName.location; + instance = instanceName.instance; + } + + public InstanceName build() { + return new InstanceName(this); + } + } +} diff --git a/test/integration/goldens/redis/LocationName.java b/test/integration/goldens/redis/LocationName.java new file mode 100644 index 0000000000..d781b0b94b --- /dev/null +++ b/test/integration/goldens/redis/LocationName.java @@ -0,0 +1,186 @@ +/* + * 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.pathtemplate.PathTemplate; +import com.google.api.resourcenames.ResourceName; +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. +@Generated("by gapic-generator-java") +public class LocationName implements ResourceName { + 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; + } + + public String getLocation() { + return location; + } + + public static Builder newBuilder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder(this); + } + + 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 = + PROJECT_LOCATION.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 (Objects.isNull(value)) { + list.add(""); + } else { + list.add(value.toString()); + } + } + return list; + } + + public static boolean isParsableFrom(String formattedString) { + return PROJECT_LOCATION.matches(formattedString); + } + + @Override + public Map getFieldValuesMap() { + if (Objects.isNull(fieldValuesMap)) { + synchronized (this) { + if (Objects.isNull(fieldValuesMap)) { + ImmutableMap.Builder fieldMapBuilder = ImmutableMap.builder(); + if (!Objects.isNull(project)) { + fieldMapBuilder.put("project", project); + } + if (!Objects.isNull(location)) { + fieldMapBuilder.put("location", location); + } + fieldValuesMap = fieldMapBuilder.build(); + } + } + } + return fieldValuesMap; + } + + public String getFieldValue(String fieldName) { + return getFieldValuesMap().get(fieldName); + } + + @Override + public String toString() { + return PROJECT_LOCATION.instantiate("project", project); + } + + @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; + } + + 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(LocationName locationName) { + project = locationName.project; + location = locationName.location; + } + + public LocationName build() { + return new LocationName(this); + } + } +} diff --git a/test/integration/goldens/redis/MockCloudRedis.java b/test/integration/goldens/redis/MockCloudRedis.java new file mode 100644 index 0000000000..acbf9c33d0 --- /dev/null +++ b/test/integration/goldens/redis/MockCloudRedis.java @@ -0,0 +1,59 @@ +/* + * 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; +import javax.annotation.Generated; + +@BetaApi +@Generated("by gapic-generator-java") +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..434f9d3f57 --- /dev/null +++ b/test/integration/goldens/redis/MockCloudRedisImpl.java @@ -0,0 +1,195 @@ +/* + * 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; +import javax.annotation.Generated; + +@BetaApi +@Generated("by gapic-generator-java") +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")); + } + } +}