diff --git a/rules_php_gapic/php_gapic.bzl b/rules_php_gapic/php_gapic.bzl index 3cc82ff2..393e1e72 100644 --- a/rules_php_gapic/php_gapic.bzl +++ b/rules_php_gapic/php_gapic.bzl @@ -55,7 +55,7 @@ def php_gapic_srcjar( rest_numeric_enums = False, generate_snippets = True, # Supported values validated and specified in src/Utils/MigrationMode.php. - migration_mode = "PRE_MIGRATION_SURFACE_ONLY", + migration_mode = "PRE_MIGRATION_SURFACE_ONLY", generator_binary = Label("//rules_php_gapic:php_gapic_generator_binary"), **kwargs): plugin_file_args = {} @@ -71,6 +71,8 @@ def php_gapic_srcjar( transport = "grpc+rest" if transport != "grpc+rest" and transport != "rest" and transport != "grpc": fail("Error: Only 'grpc+rest', 'rest' or `grpc` transports are supported") + if transport == "grpc" and migration_mode != "NEW_SURFACE_ONLY": + fail("Error: 'grpc' transport is only supported with 'NEW_SURFACE_ONLY' migration mode") # Set plugin arguments. plugin_args = ["metadata"] # Generate the gapic_metadata.json file. diff --git a/src/Generation/GapicClientGenerator.php b/src/Generation/GapicClientGenerator.php index 73fe764b..60e22200 100644 --- a/src/Generation/GapicClientGenerator.php +++ b/src/Generation/GapicClientGenerator.php @@ -443,7 +443,7 @@ private function getClientDefaults(): PhpClassMember // TODO: Consolidate setting all the known array values together. // We do this here to maintain the existing sensible ordering. - if ($this->serviceDetails->transportType !== Transport::REST) { + if ($this->serviceDetails->transportType === Transport::GRPC_REST) { $clientDefaultValues['gcpApiConfigPath'] = AST::concat(AST::__DIR__, "/../resources/{$this->serviceDetails->grpcConfigFilename}"); } diff --git a/src/Generation/GapicClientV2Generator.php b/src/Generation/GapicClientV2Generator.php index e1a273b3..dcb57770 100644 --- a/src/Generation/GapicClientV2Generator.php +++ b/src/Generation/GapicClientV2Generator.php @@ -431,7 +431,7 @@ private function getClientDefaults(): PhpClassMember // TODO: Consolidate setting all the known array values together. // We do this here to maintain the existing sensible ordering. - if ($this->serviceDetails->transportType === Transport::GRPC_REST) { + if ($this->serviceDetails->transportType !== Transport::REST) { $clientDefaultValues['gcpApiConfigPath'] = AST::concat(AST::__DIR__, "/../resources/{$this->serviceDetails->grpcConfigFilename}"); } @@ -548,7 +548,7 @@ private function construct(): PhpClassMember AST::call( $ctx->type( Type::fromName( - Transport::isRestOnly($transportType) ? + Transport::isRestOnly($transportType) ? RestTransport::class : GrpcTransport::class ), @@ -556,8 +556,8 @@ private function construct(): PhpClassMember ), AST::method('build') )(), - Transport::isGRPCRest($transportType) ? 'and' : '', - Transport::isGRPCRest($transportType) ? + Transport::isGrpcRest($transportType) ? 'and' : '', + Transport::isGrpcRest($transportType) ? AST::call( $ctx->type( Type::fromName(RestTransport::class), @@ -566,7 +566,7 @@ private function construct(): PhpClassMember AST::method('build') )() : '', - Transport::isGRPCRest($transportType) ? 'methods ' : 'method ', + Transport::isGrpcRest($transportType) ? 'methods ' : 'method ', 'for the supported options.' ); return AST::method('__construct') diff --git a/src/Utils/Transport.php b/src/Utils/Transport.php index fe0d8aa7..01e27bf6 100644 --- a/src/Utils/Transport.php +++ b/src/Utils/Transport.php @@ -55,7 +55,7 @@ public static function isGrpcOnly(int $transport): bool return Transport::compareTransports(Transport::GRPC, $transport); } - public static function isGRPCRest(int $transport): bool + public static function isGrpcRest(int $transport): bool { return Transport::compareTransports(Transport::GRPC_REST, $transport); } diff --git a/tests/Integration/BUILD.bazel b/tests/Integration/BUILD.bazel index 7824b144..5b79918e 100644 --- a/tests/Integration/BUILD.bazel +++ b/tests/Integration/BUILD.bazel @@ -353,7 +353,7 @@ php_gapic_library( gapic_yaml = "apis/redis/v1/redis_gapic.yaml", grpc_service_config = "@com_google_googleapis//google/cloud/redis/v1:redis_grpc_service_config.json", service_yaml = "@com_google_googleapis//google/cloud/redis/v1:redis_v1.yaml", - migration_mode = "MIGRATION_MODE_UNSPECIFIED", + migration_mode = "NEW_SURFACE_ONLY", transport = "grpc", deps = [ ":redis_php_grpc", diff --git a/tests/Integration/goldens/redis/samples/V1/CloudRedisClient/create_instance.php b/tests/Integration/goldens/redis/samples/V1/CloudRedisClient/create_instance.php index 37d30c15..3f0b2760 100644 --- a/tests/Integration/goldens/redis/samples/V1/CloudRedisClient/create_instance.php +++ b/tests/Integration/goldens/redis/samples/V1/CloudRedisClient/create_instance.php @@ -25,7 +25,8 @@ // [START redis_v1_generated_CloudRedis_CreateInstance_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\Redis\V1\CloudRedisClient; +use Google\Cloud\Redis\V1\Client\CloudRedisClient; +use Google\Cloud\Redis\V1\CreateInstanceRequest; use Google\Cloud\Redis\V1\Instance; use Google\Cloud\Redis\V1\Instance\Tier; use Google\Rpc\Status; @@ -80,16 +81,20 @@ function create_instance_sample( // Create a client. $cloudRedisClient = new CloudRedisClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $instance = (new Instance()) ->setName($instanceName) ->setTier($instanceTier) ->setMemorySizeGb($instanceMemorySizeGb); + $request = (new CreateInstanceRequest()) + ->setParent($formattedParent) + ->setInstanceId($instanceId) + ->setInstance($instance); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $cloudRedisClient->createInstance($formattedParent, $instanceId, $instance); + $response = $cloudRedisClient->createInstance($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/tests/Integration/goldens/redis/samples/V1/CloudRedisClient/delete_instance.php b/tests/Integration/goldens/redis/samples/V1/CloudRedisClient/delete_instance.php index 2cf7a62a..353af566 100644 --- a/tests/Integration/goldens/redis/samples/V1/CloudRedisClient/delete_instance.php +++ b/tests/Integration/goldens/redis/samples/V1/CloudRedisClient/delete_instance.php @@ -25,7 +25,8 @@ // [START redis_v1_generated_CloudRedis_DeleteInstance_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\Redis\V1\CloudRedisClient; +use Google\Cloud\Redis\V1\Client\CloudRedisClient; +use Google\Cloud\Redis\V1\DeleteInstanceRequest; use Google\Rpc\Status; /** @@ -42,10 +43,14 @@ function delete_instance_sample(string $formattedName): void // Create a client. $cloudRedisClient = new CloudRedisClient(); + // Prepare the request message. + $request = (new DeleteInstanceRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $cloudRedisClient->deleteInstance($formattedName); + $response = $cloudRedisClient->deleteInstance($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/tests/Integration/goldens/redis/samples/V1/CloudRedisClient/export_instance.php b/tests/Integration/goldens/redis/samples/V1/CloudRedisClient/export_instance.php index b094acd5..9d69ccd1 100644 --- a/tests/Integration/goldens/redis/samples/V1/CloudRedisClient/export_instance.php +++ b/tests/Integration/goldens/redis/samples/V1/CloudRedisClient/export_instance.php @@ -25,7 +25,8 @@ // [START redis_v1_generated_CloudRedis_ExportInstance_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\Redis\V1\CloudRedisClient; +use Google\Cloud\Redis\V1\Client\CloudRedisClient; +use Google\Cloud\Redis\V1\ExportInstanceRequest; use Google\Cloud\Redis\V1\Instance; use Google\Cloud\Redis\V1\OutputConfig; use Google\Rpc\Status; @@ -47,13 +48,16 @@ function export_instance_sample(string $name): void // Create a client. $cloudRedisClient = new CloudRedisClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $outputConfig = new OutputConfig(); + $request = (new ExportInstanceRequest()) + ->setName($name) + ->setOutputConfig($outputConfig); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $cloudRedisClient->exportInstance($name, $outputConfig); + $response = $cloudRedisClient->exportInstance($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/tests/Integration/goldens/redis/samples/V1/CloudRedisClient/failover_instance.php b/tests/Integration/goldens/redis/samples/V1/CloudRedisClient/failover_instance.php index 130d5541..b963dfeb 100644 --- a/tests/Integration/goldens/redis/samples/V1/CloudRedisClient/failover_instance.php +++ b/tests/Integration/goldens/redis/samples/V1/CloudRedisClient/failover_instance.php @@ -25,7 +25,8 @@ // [START redis_v1_generated_CloudRedis_FailoverInstance_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\Redis\V1\CloudRedisClient; +use Google\Cloud\Redis\V1\Client\CloudRedisClient; +use Google\Cloud\Redis\V1\FailoverInstanceRequest; use Google\Cloud\Redis\V1\Instance; use Google\Rpc\Status; @@ -43,10 +44,14 @@ function failover_instance_sample(string $formattedName): void // Create a client. $cloudRedisClient = new CloudRedisClient(); + // Prepare the request message. + $request = (new FailoverInstanceRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $cloudRedisClient->failoverInstance($formattedName); + $response = $cloudRedisClient->failoverInstance($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/tests/Integration/goldens/redis/samples/V1/CloudRedisClient/get_instance.php b/tests/Integration/goldens/redis/samples/V1/CloudRedisClient/get_instance.php index d5401bd5..5d8663d4 100644 --- a/tests/Integration/goldens/redis/samples/V1/CloudRedisClient/get_instance.php +++ b/tests/Integration/goldens/redis/samples/V1/CloudRedisClient/get_instance.php @@ -24,7 +24,8 @@ // [START redis_v1_generated_CloudRedis_GetInstance_sync] use Google\ApiCore\ApiException; -use Google\Cloud\Redis\V1\CloudRedisClient; +use Google\Cloud\Redis\V1\Client\CloudRedisClient; +use Google\Cloud\Redis\V1\GetInstanceRequest; use Google\Cloud\Redis\V1\Instance; /** @@ -40,10 +41,14 @@ function get_instance_sample(string $formattedName): void // Create a client. $cloudRedisClient = new CloudRedisClient(); + // Prepare the request message. + $request = (new GetInstanceRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var Instance $response */ - $response = $cloudRedisClient->getInstance($formattedName); + $response = $cloudRedisClient->getInstance($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/tests/Integration/goldens/redis/samples/V1/CloudRedisClient/get_instance_auth_string.php b/tests/Integration/goldens/redis/samples/V1/CloudRedisClient/get_instance_auth_string.php index 0eb11328..7f765809 100644 --- a/tests/Integration/goldens/redis/samples/V1/CloudRedisClient/get_instance_auth_string.php +++ b/tests/Integration/goldens/redis/samples/V1/CloudRedisClient/get_instance_auth_string.php @@ -24,7 +24,8 @@ // [START redis_v1_generated_CloudRedis_GetInstanceAuthString_sync] use Google\ApiCore\ApiException; -use Google\Cloud\Redis\V1\CloudRedisClient; +use Google\Cloud\Redis\V1\Client\CloudRedisClient; +use Google\Cloud\Redis\V1\GetInstanceAuthStringRequest; use Google\Cloud\Redis\V1\InstanceAuthString; /** @@ -42,10 +43,14 @@ function get_instance_auth_string_sample(string $formattedName): void // Create a client. $cloudRedisClient = new CloudRedisClient(); + // Prepare the request message. + $request = (new GetInstanceAuthStringRequest()) + ->setName($formattedName); + // Call the API and handle any network failures. try { /** @var InstanceAuthString $response */ - $response = $cloudRedisClient->getInstanceAuthString($formattedName); + $response = $cloudRedisClient->getInstanceAuthString($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/tests/Integration/goldens/redis/samples/V1/CloudRedisClient/get_location.php b/tests/Integration/goldens/redis/samples/V1/CloudRedisClient/get_location.php index 6f8be4a2..0152cf8a 100644 --- a/tests/Integration/goldens/redis/samples/V1/CloudRedisClient/get_location.php +++ b/tests/Integration/goldens/redis/samples/V1/CloudRedisClient/get_location.php @@ -24,8 +24,9 @@ // [START redis_v1_generated_CloudRedis_GetLocation_sync] use Google\ApiCore\ApiException; +use Google\Cloud\Location\GetLocationRequest; use Google\Cloud\Location\Location; -use Google\Cloud\Redis\V1\CloudRedisClient; +use Google\Cloud\Redis\V1\Client\CloudRedisClient; /** * Gets information about a location. @@ -41,10 +42,13 @@ function get_location_sample(): void // Create a client. $cloudRedisClient = new CloudRedisClient(); + // Prepare the request message. + $request = new GetLocationRequest(); + // Call the API and handle any network failures. try { /** @var Location $response */ - $response = $cloudRedisClient->getLocation(); + $response = $cloudRedisClient->getLocation($request); printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); diff --git a/tests/Integration/goldens/redis/samples/V1/CloudRedisClient/import_instance.php b/tests/Integration/goldens/redis/samples/V1/CloudRedisClient/import_instance.php index 1d695746..9b070b04 100644 --- a/tests/Integration/goldens/redis/samples/V1/CloudRedisClient/import_instance.php +++ b/tests/Integration/goldens/redis/samples/V1/CloudRedisClient/import_instance.php @@ -25,7 +25,8 @@ // [START redis_v1_generated_CloudRedis_ImportInstance_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\Redis\V1\CloudRedisClient; +use Google\Cloud\Redis\V1\Client\CloudRedisClient; +use Google\Cloud\Redis\V1\ImportInstanceRequest; use Google\Cloud\Redis\V1\InputConfig; use Google\Cloud\Redis\V1\Instance; use Google\Rpc\Status; @@ -49,13 +50,16 @@ function import_instance_sample(string $name): void // Create a client. $cloudRedisClient = new CloudRedisClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $inputConfig = new InputConfig(); + $request = (new ImportInstanceRequest()) + ->setName($name) + ->setInputConfig($inputConfig); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $cloudRedisClient->importInstance($name, $inputConfig); + $response = $cloudRedisClient->importInstance($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/tests/Integration/goldens/redis/samples/V1/CloudRedisClient/list_instances.php b/tests/Integration/goldens/redis/samples/V1/CloudRedisClient/list_instances.php index d0106dbf..b460ce81 100644 --- a/tests/Integration/goldens/redis/samples/V1/CloudRedisClient/list_instances.php +++ b/tests/Integration/goldens/redis/samples/V1/CloudRedisClient/list_instances.php @@ -25,8 +25,9 @@ // [START redis_v1_generated_CloudRedis_ListInstances_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; -use Google\Cloud\Redis\V1\CloudRedisClient; +use Google\Cloud\Redis\V1\Client\CloudRedisClient; use Google\Cloud\Redis\V1\Instance; +use Google\Cloud\Redis\V1\ListInstancesRequest; /** * Lists all Redis instances owned by a project in either the specified @@ -49,10 +50,14 @@ function list_instances_sample(string $formattedParent): void // Create a client. $cloudRedisClient = new CloudRedisClient(); + // Prepare the request message. + $request = (new ListInstancesRequest()) + ->setParent($formattedParent); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $cloudRedisClient->listInstances($formattedParent); + $response = $cloudRedisClient->listInstances($request); /** @var Instance $element */ foreach ($response as $element) { diff --git a/tests/Integration/goldens/redis/samples/V1/CloudRedisClient/list_locations.php b/tests/Integration/goldens/redis/samples/V1/CloudRedisClient/list_locations.php index 40ea7856..d477ab8f 100644 --- a/tests/Integration/goldens/redis/samples/V1/CloudRedisClient/list_locations.php +++ b/tests/Integration/goldens/redis/samples/V1/CloudRedisClient/list_locations.php @@ -25,8 +25,9 @@ // [START redis_v1_generated_CloudRedis_ListLocations_sync] use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; +use Google\Cloud\Location\ListLocationsRequest; use Google\Cloud\Location\Location; -use Google\Cloud\Redis\V1\CloudRedisClient; +use Google\Cloud\Redis\V1\Client\CloudRedisClient; /** * Lists information about the supported locations for this service. @@ -42,10 +43,13 @@ function list_locations_sample(): void // Create a client. $cloudRedisClient = new CloudRedisClient(); + // Prepare the request message. + $request = new ListLocationsRequest(); + // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ - $response = $cloudRedisClient->listLocations(); + $response = $cloudRedisClient->listLocations($request); /** @var Location $element */ foreach ($response as $element) { diff --git a/tests/Integration/goldens/redis/samples/V1/CloudRedisClient/reschedule_maintenance.php b/tests/Integration/goldens/redis/samples/V1/CloudRedisClient/reschedule_maintenance.php index 23c0df35..412a8b3a 100644 --- a/tests/Integration/goldens/redis/samples/V1/CloudRedisClient/reschedule_maintenance.php +++ b/tests/Integration/goldens/redis/samples/V1/CloudRedisClient/reschedule_maintenance.php @@ -25,8 +25,9 @@ // [START redis_v1_generated_CloudRedis_RescheduleMaintenance_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\Redis\V1\CloudRedisClient; +use Google\Cloud\Redis\V1\Client\CloudRedisClient; use Google\Cloud\Redis\V1\Instance; +use Google\Cloud\Redis\V1\RescheduleMaintenanceRequest; use Google\Cloud\Redis\V1\RescheduleMaintenanceRequest\RescheduleType; use Google\Rpc\Status; @@ -46,10 +47,15 @@ function reschedule_maintenance_sample(string $formattedName, int $rescheduleTyp // Create a client. $cloudRedisClient = new CloudRedisClient(); + // Prepare the request message. + $request = (new RescheduleMaintenanceRequest()) + ->setName($formattedName) + ->setRescheduleType($rescheduleType); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $cloudRedisClient->rescheduleMaintenance($formattedName, $rescheduleType); + $response = $cloudRedisClient->rescheduleMaintenance($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/tests/Integration/goldens/redis/samples/V1/CloudRedisClient/update_instance.php b/tests/Integration/goldens/redis/samples/V1/CloudRedisClient/update_instance.php index 97ea7f2b..835331e0 100644 --- a/tests/Integration/goldens/redis/samples/V1/CloudRedisClient/update_instance.php +++ b/tests/Integration/goldens/redis/samples/V1/CloudRedisClient/update_instance.php @@ -25,9 +25,10 @@ // [START redis_v1_generated_CloudRedis_UpdateInstance_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\Redis\V1\CloudRedisClient; +use Google\Cloud\Redis\V1\Client\CloudRedisClient; use Google\Cloud\Redis\V1\Instance; use Google\Cloud\Redis\V1\Instance\Tier; +use Google\Cloud\Redis\V1\UpdateInstanceRequest; use Google\Protobuf\FieldMask; use Google\Rpc\Status; @@ -60,17 +61,20 @@ function update_instance_sample( // Create a client. $cloudRedisClient = new CloudRedisClient(); - // Prepare any non-scalar elements to be passed along with the request. + // Prepare the request message. $updateMask = new FieldMask(); $instance = (new Instance()) ->setName($instanceName) ->setTier($instanceTier) ->setMemorySizeGb($instanceMemorySizeGb); + $request = (new UpdateInstanceRequest()) + ->setUpdateMask($updateMask) + ->setInstance($instance); // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $cloudRedisClient->updateInstance($updateMask, $instance); + $response = $cloudRedisClient->updateInstance($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/tests/Integration/goldens/redis/samples/V1/CloudRedisClient/upgrade_instance.php b/tests/Integration/goldens/redis/samples/V1/CloudRedisClient/upgrade_instance.php index 7db09c01..e99f0ce1 100644 --- a/tests/Integration/goldens/redis/samples/V1/CloudRedisClient/upgrade_instance.php +++ b/tests/Integration/goldens/redis/samples/V1/CloudRedisClient/upgrade_instance.php @@ -25,8 +25,9 @@ // [START redis_v1_generated_CloudRedis_UpgradeInstance_sync] use Google\ApiCore\ApiException; use Google\ApiCore\OperationResponse; -use Google\Cloud\Redis\V1\CloudRedisClient; +use Google\Cloud\Redis\V1\Client\CloudRedisClient; use Google\Cloud\Redis\V1\Instance; +use Google\Cloud\Redis\V1\UpgradeInstanceRequest; use Google\Rpc\Status; /** @@ -44,10 +45,15 @@ function upgrade_instance_sample(string $formattedName, string $redisVersion): v // Create a client. $cloudRedisClient = new CloudRedisClient(); + // Prepare the request message. + $request = (new UpgradeInstanceRequest()) + ->setName($formattedName) + ->setRedisVersion($redisVersion); + // Call the API and handle any network failures. try { /** @var OperationResponse $response */ - $response = $cloudRedisClient->upgradeInstance($formattedName, $redisVersion); + $response = $cloudRedisClient->upgradeInstance($request); $response->pollUntilComplete(); if ($response->operationSucceeded()) { diff --git a/tests/Integration/goldens/redis/src/V1/Client/CloudRedisClient.php b/tests/Integration/goldens/redis/src/V1/Client/CloudRedisClient.php index 67468112..05136c7c 100644 --- a/tests/Integration/goldens/redis/src/V1/Client/CloudRedisClient.php +++ b/tests/Integration/goldens/redis/src/V1/Client/CloudRedisClient.php @@ -131,6 +131,7 @@ private static function getClientDefaults() 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, 'clientConfig' => __DIR__ . '/../resources/cloud_redis_client_config.json', 'descriptorsConfigPath' => __DIR__ . '/../resources/cloud_redis_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../resources/cloud_redis_grpc_config.json', 'credentialsConfig' => [ 'defaultScopes' => self::$serviceScopes, ], @@ -326,6 +327,8 @@ public function __call($method, $args) * * The async variant is {@see CloudRedisClient::createInstanceAsync()} . * + * @example samples/V1/CloudRedisClient/create_instance.php + * * @param CreateInstanceRequest $request A request to house fields associated with the call. * @param array $callOptions { * Optional. @@ -351,6 +354,8 @@ public function createInstance(CreateInstanceRequest $request, array $callOption * * The async variant is {@see CloudRedisClient::deleteInstanceAsync()} . * + * @example samples/V1/CloudRedisClient/delete_instance.php + * * @param DeleteInstanceRequest $request A request to house fields associated with the call. * @param array $callOptions { * Optional. @@ -380,6 +385,8 @@ public function deleteInstance(DeleteInstanceRequest $request, array $callOption * * The async variant is {@see CloudRedisClient::exportInstanceAsync()} . * + * @example samples/V1/CloudRedisClient/export_instance.php + * * @param ExportInstanceRequest $request A request to house fields associated with the call. * @param array $callOptions { * Optional. @@ -405,6 +412,8 @@ public function exportInstance(ExportInstanceRequest $request, array $callOption * * The async variant is {@see CloudRedisClient::failoverInstanceAsync()} . * + * @example samples/V1/CloudRedisClient/failover_instance.php + * * @param FailoverInstanceRequest $request A request to house fields associated with the call. * @param array $callOptions { * Optional. @@ -429,6 +438,8 @@ public function failoverInstance(FailoverInstanceRequest $request, array $callOp * * The async variant is {@see CloudRedisClient::getInstanceAsync()} . * + * @example samples/V1/CloudRedisClient/get_instance.php + * * @param GetInstanceRequest $request A request to house fields associated with the call. * @param array $callOptions { * Optional. @@ -455,6 +466,8 @@ public function getInstance(GetInstanceRequest $request, array $callOptions = [] * * The async variant is {@see CloudRedisClient::getInstanceAuthStringAsync()} . * + * @example samples/V1/CloudRedisClient/get_instance_auth_string.php + * * @param GetInstanceAuthStringRequest $request A request to house fields associated with the call. * @param array $callOptions { * Optional. @@ -486,6 +499,8 @@ public function getInstanceAuthString(GetInstanceAuthStringRequest $request, arr * * The async variant is {@see CloudRedisClient::importInstanceAsync()} . * + * @example samples/V1/CloudRedisClient/import_instance.php + * * @param ImportInstanceRequest $request A request to house fields associated with the call. * @param array $callOptions { * Optional. @@ -518,6 +533,8 @@ public function importInstance(ImportInstanceRequest $request, array $callOption * * The async variant is {@see CloudRedisClient::listInstancesAsync()} . * + * @example samples/V1/CloudRedisClient/list_instances.php + * * @param ListInstancesRequest $request A request to house fields associated with the call. * @param array $callOptions { * Optional. @@ -543,6 +560,8 @@ public function listInstances(ListInstancesRequest $request, array $callOptions * * The async variant is {@see CloudRedisClient::rescheduleMaintenanceAsync()} . * + * @example samples/V1/CloudRedisClient/reschedule_maintenance.php + * * @param RescheduleMaintenanceRequest $request A request to house fields associated with the call. * @param array $callOptions { * Optional. @@ -571,6 +590,8 @@ public function rescheduleMaintenance(RescheduleMaintenanceRequest $request, arr * * The async variant is {@see CloudRedisClient::updateInstanceAsync()} . * + * @example samples/V1/CloudRedisClient/update_instance.php + * * @param UpdateInstanceRequest $request A request to house fields associated with the call. * @param array $callOptions { * Optional. @@ -596,6 +617,8 @@ public function updateInstance(UpdateInstanceRequest $request, array $callOption * * The async variant is {@see CloudRedisClient::upgradeInstanceAsync()} . * + * @example samples/V1/CloudRedisClient/upgrade_instance.php + * * @param UpgradeInstanceRequest $request A request to house fields associated with the call. * @param array $callOptions { * Optional. @@ -620,6 +643,8 @@ public function upgradeInstance(UpgradeInstanceRequest $request, array $callOpti * * The async variant is {@see CloudRedisClient::getLocationAsync()} . * + * @example samples/V1/CloudRedisClient/get_location.php + * * @param GetLocationRequest $request A request to house fields associated with the call. * @param array $callOptions { * Optional. @@ -644,6 +669,8 @@ public function getLocation(GetLocationRequest $request, array $callOptions = [] * * The async variant is {@see CloudRedisClient::listLocationsAsync()} . * + * @example samples/V1/CloudRedisClient/list_locations.php + * * @param ListLocationsRequest $request A request to house fields associated with the call. * @param array $callOptions { * Optional. diff --git a/tests/Integration/goldens/redis/src/V1/CloudRedisClient.php b/tests/Integration/goldens/redis/src/V1/CloudRedisClient.php deleted file mode 100644 index eb4be3b1..00000000 --- a/tests/Integration/goldens/redis/src/V1/CloudRedisClient.php +++ /dev/null @@ -1,34 +0,0 @@ -locationName('[PROJECT]', '[LOCATION]'); - * $instanceId = 'instance_id'; - * $instance = new Instance(); - * $operationResponse = $cloudRedisClient->createInstance($formattedParent, $instanceId, $instance); - * $operationResponse->pollUntilComplete(); - * if ($operationResponse->operationSucceeded()) { - * $result = $operationResponse->getResult(); - * // doSomethingWith($result) - * } else { - * $error = $operationResponse->getError(); - * // handleError($error) - * } - * // Alternatively: - * // start the operation, keep the operation name, and resume later - * $operationResponse = $cloudRedisClient->createInstance($formattedParent, $instanceId, $instance); - * $operationName = $operationResponse->getName(); - * // ... do other work - * $newOperationResponse = $cloudRedisClient->resumeOperation($operationName, 'createInstance'); - * while (!$newOperationResponse->isDone()) { - * // ... do other work - * $newOperationResponse->reload(); - * } - * if ($newOperationResponse->operationSucceeded()) { - * $result = $newOperationResponse->getResult(); - * // doSomethingWith($result) - * } else { - * $error = $newOperationResponse->getError(); - * // handleError($error) - * } - * } finally { - * $cloudRedisClient->close(); - * } - * ``` - * - * 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 parseName method to extract the individual identifiers - * contained within formatted names that are returned by the API. - * - * @deprecated Please use the new service client {@see \Google\Cloud\Redis\V1\Client\CloudRedisClient}. - */ -class CloudRedisGapicClient -{ - use GapicClientTrait; - - /** The name of the service. */ - const SERVICE_NAME = 'google.cloud.redis.v1.CloudRedis'; - - /** - * The default address of the service. - * - * @deprecated SERVICE_ADDRESS_TEMPLATE should be used instead. - */ - const SERVICE_ADDRESS = 'redis.googleapis.com'; - - /** The address template of the service. */ - private const SERVICE_ADDRESS_TEMPLATE = 'redis.UNIVERSE_DOMAIN'; - - /** The default port of the service. */ - const DEFAULT_SERVICE_PORT = 443; - - /** The name of the code generator, to be included in the agent header. */ - const CODEGEN_NAME = 'gapic'; - - /** The default scopes required by the service. */ - public static $serviceScopes = [ - 'https://www.googleapis.com/auth/cloud-platform', - ]; - - private static $instanceNameTemplate; - - private static $locationNameTemplate; - - private static $pathTemplateMap; - - private $operationsClient; - - private static function getClientDefaults() - { - return [ - 'serviceName' => self::SERVICE_NAME, - 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, - 'clientConfig' => __DIR__ . '/../resources/cloud_redis_client_config.json', - 'descriptorsConfigPath' => __DIR__ . '/../resources/cloud_redis_descriptor_config.php', - 'gcpApiConfigPath' => __DIR__ . '/../resources/cloud_redis_grpc_config.json', - 'credentialsConfig' => [ - 'defaultScopes' => self::$serviceScopes, - ], - 'transportConfig' => [ - 'rest' => [ - 'restClientConfigPath' => __DIR__ . '/../resources/cloud_redis_rest_client_config.php', - ], - ], - ]; - } - - private static function getInstanceNameTemplate() - { - if (self::$instanceNameTemplate == null) { - self::$instanceNameTemplate = new PathTemplate('projects/{project}/locations/{location}/instances/{instance}'); - } - - return self::$instanceNameTemplate; - } - - private static function getLocationNameTemplate() - { - if (self::$locationNameTemplate == null) { - self::$locationNameTemplate = new PathTemplate('projects/{project}/locations/{location}'); - } - - return self::$locationNameTemplate; - } - - private static function getPathTemplateMap() - { - if (self::$pathTemplateMap == null) { - self::$pathTemplateMap = [ - 'instance' => self::getInstanceNameTemplate(), - 'location' => self::getLocationNameTemplate(), - ]; - } - - return self::$pathTemplateMap; - } - - /** - * Formats a string containing the fully-qualified path to represent a instance - * resource. - * - * @param string $project - * @param string $location - * @param string $instance - * - * @return string The formatted instance resource. - */ - public static function instanceName($project, $location, $instance) - { - return self::getInstanceNameTemplate()->render([ - 'project' => $project, - 'location' => $location, - 'instance' => $instance, - ]); - } - - /** - * Formats a string containing the fully-qualified path to represent a location - * resource. - * - * @param string $project - * @param string $location - * - * @return string The formatted location resource. - */ - public static function locationName($project, $location) - { - return self::getLocationNameTemplate()->render([ - 'project' => $project, - 'location' => $location, - ]); - } - - /** - * Parses a formatted name string and returns an associative array of the components in the name. - * The following name formats are supported: - * Template: Pattern - * - instance: projects/{project}/locations/{location}/instances/{instance} - * - location: projects/{project}/locations/{location} - * - * The optional $template argument can be supplied to specify a particular pattern, - * and must match one of the templates listed above. If no $template argument is - * provided, or if the $template argument does not match one of the templates - * listed, then parseName will check each of the supported templates, and return - * the first match. - * - * @param string $formattedName The formatted name string - * @param string $template Optional name of template to match - * - * @return array An associative array from name component IDs to component values. - * - * @throws ValidationException If $formattedName could not be matched. - */ - public static function parseName($formattedName, $template = null) - { - $templateMap = self::getPathTemplateMap(); - if ($template) { - if (!isset($templateMap[$template])) { - throw new ValidationException("Template name $template does not exist"); - } - - return $templateMap[$template]->match($formattedName); - } - - foreach ($templateMap as $templateName => $pathTemplate) { - try { - return $pathTemplate->match($formattedName); - } catch (ValidationException $ex) { - // Swallow the exception to continue trying other path templates - } - } - - throw new ValidationException("Input did not match any known format. Input: $formattedName"); - } - - /** - * Return an OperationsClient object with the same endpoint as $this. - * - * @return OperationsClient - */ - public function getOperationsClient() - { - return $this->operationsClient; - } - - /** - * Resume an existing long running operation that was previously started by a long - * running API method. If $methodName is not provided, or does not match a long - * running API method, then the operation can still be resumed, but the - * OperationResponse object will not deserialize the final response. - * - * @param string $operationName The name of the long running operation - * @param string $methodName The name of the method used to start the operation - * - * @return OperationResponse - */ - public function resumeOperation($operationName, $methodName = null) - { - $options = isset($this->descriptors[$methodName]['longRunning']) ? $this->descriptors[$methodName]['longRunning'] : []; - $operation = new OperationResponse($operationName, $this->getOperationsClient(), $options); - $operation->reload(); - return $operation; - } - - /** - * Constructor. - * - * @param array $options { - * Optional. Options for configuring the service API wrapper. - * - * @type string $apiEndpoint - * The address of the API remote host. May optionally include the port, formatted - * as ":". Default 'redis.googleapis.com:443'. - * @type string|array|FetchAuthTokenInterface|CredentialsWrapper $credentials - * The credentials to be used by the client to authorize API calls. This option - * accepts either a path to a credentials file, or a decoded credentials file as a - * PHP array. - * *Advanced usage*: In addition, this option can also accept a pre-constructed - * {@see \Google\Auth\FetchAuthTokenInterface} object or - * {@see \Google\ApiCore\CredentialsWrapper} object. Note that when one of these - * objects are provided, any settings in $credentialsConfig will be ignored. - * @type array $credentialsConfig - * Options used to configure credentials, including auth token caching, for the - * client. For a full list of supporting configuration options, see - * {@see \Google\ApiCore\CredentialsWrapper::build()} . - * @type bool $disableRetries - * Determines whether or not retries defined by the client configuration should be - * disabled. Defaults to `false`. - * @type string|array $clientConfig - * Client method configuration, including retry settings. This option can be either - * a path to a JSON file, or a PHP array containing the decoded JSON data. By - * default this settings points to the default client config file, which is - * provided in the resources folder. - * @type string|TransportInterface $transport - * The transport used for executing network requests. At the moment, supports only - * `rest`. *Advanced usage*: Additionally, it is possible to pass in an already - * instantiated {@see \Google\ApiCore\Transport\TransportInterface} object. Note - * that when this object is provided, any settings in $transportConfig, and any - * $apiEndpoint setting, will be ignored. - * @type array $transportConfig - * Configuration options that will be used to construct the transport. Options for - * each supported transport type should be passed in a key for that transport. For - * example: - * $transportConfig = [ - * 'rest' => [...], - * ]; - * See the {@see \Google\ApiCore\Transport\RestTransport::build()} method for the - * supported options. - * @type callable $clientCertSource - * A callable which returns the client cert as a string. This can be used to - * provide a certificate and private key to the transport layer for mTLS. - * } - * - * @throws ValidationException - */ - public function __construct(array $options = []) - { - $clientOptions = $this->buildClientOptions($options); - $this->setClientOptions($clientOptions); - $this->operationsClient = $this->createOperationsClient($clientOptions); - } - - /** - * 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: - * ``` - * $cloudRedisClient = new CloudRedisClient(); - * try { - * $formattedParent = $cloudRedisClient->locationName('[PROJECT]', '[LOCATION]'); - * $instanceId = 'instance_id'; - * $instance = new Instance(); - * $operationResponse = $cloudRedisClient->createInstance($formattedParent, $instanceId, $instance); - * $operationResponse->pollUntilComplete(); - * if ($operationResponse->operationSucceeded()) { - * $result = $operationResponse->getResult(); - * // doSomethingWith($result) - * } else { - * $error = $operationResponse->getError(); - * // handleError($error) - * } - * // Alternatively: - * // start the operation, keep the operation name, and resume later - * $operationResponse = $cloudRedisClient->createInstance($formattedParent, $instanceId, $instance); - * $operationName = $operationResponse->getName(); - * // ... do other work - * $newOperationResponse = $cloudRedisClient->resumeOperation($operationName, 'createInstance'); - * while (!$newOperationResponse->isDone()) { - * // ... do other work - * $newOperationResponse->reload(); - * } - * if ($newOperationResponse->operationSucceeded()) { - * $result = $newOperationResponse->getResult(); - * // doSomethingWith($result) - * } else { - * $error = $newOperationResponse->getError(); - * // handleError($error) - * } - * } finally { - * $cloudRedisClient->close(); - * } - * ``` - * - * @param string $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 string $instanceId Required. The logical name of the Redis instance in the customer project - * with the following restrictions: - * - * * Must contain only lowercase letters, numbers, and hyphens. - * * Must start with a letter. - * * Must be between 1-40 characters. - * * Must end with a number or a letter. - * * Must be unique within the customer project / location - * @param Instance $instance Required. A Redis [Instance] resource - * @param array $optionalArgs { - * Optional. - * - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an - * associative array of retry settings parameters. See the documentation on - * {@see RetrySettings} for example usage. - * } - * - * @return \Google\ApiCore\OperationResponse - * - * @throws ApiException if the remote call fails - */ - public function createInstance($parent, $instanceId, $instance, array $optionalArgs = []) - { - $request = new CreateInstanceRequest(); - $requestParamHeaders = []; - $request->setParent($parent); - $request->setInstanceId($instanceId); - $request->setInstance($instance); - $requestParamHeaders['parent'] = $parent; - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->startOperationsCall('CreateInstance', $optionalArgs, $request, $this->getOperationsClient())->wait(); - } - - /** - * Deletes a specific Redis instance. Instance stops serving and data is - * deleted. - * - * Sample code: - * ``` - * $cloudRedisClient = new CloudRedisClient(); - * try { - * $formattedName = $cloudRedisClient->instanceName('[PROJECT]', '[LOCATION]', '[INSTANCE]'); - * $operationResponse = $cloudRedisClient->deleteInstance($formattedName); - * $operationResponse->pollUntilComplete(); - * if ($operationResponse->operationSucceeded()) { - * // operation succeeded and returns no value - * } else { - * $error = $operationResponse->getError(); - * // handleError($error) - * } - * // Alternatively: - * // start the operation, keep the operation name, and resume later - * $operationResponse = $cloudRedisClient->deleteInstance($formattedName); - * $operationName = $operationResponse->getName(); - * // ... do other work - * $newOperationResponse = $cloudRedisClient->resumeOperation($operationName, 'deleteInstance'); - * while (!$newOperationResponse->isDone()) { - * // ... do other work - * $newOperationResponse->reload(); - * } - * if ($newOperationResponse->operationSucceeded()) { - * // operation succeeded and returns no value - * } else { - * $error = $newOperationResponse->getError(); - * // handleError($error) - * } - * } finally { - * $cloudRedisClient->close(); - * } - * ``` - * - * @param string $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 array $optionalArgs { - * Optional. - * - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an - * associative array of retry settings parameters. See the documentation on - * {@see RetrySettings} for example usage. - * } - * - * @return \Google\ApiCore\OperationResponse - * - * @throws ApiException if the remote call fails - */ - public function deleteInstance($name, array $optionalArgs = []) - { - $request = new DeleteInstanceRequest(); - $requestParamHeaders = []; - $request->setName($name); - $requestParamHeaders['name'] = $name; - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->startOperationsCall('DeleteInstance', $optionalArgs, $request, $this->getOperationsClient())->wait(); - } - - /** - * 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: - * ``` - * $cloudRedisClient = new CloudRedisClient(); - * try { - * $name = 'name'; - * $outputConfig = new OutputConfig(); - * $operationResponse = $cloudRedisClient->exportInstance($name, $outputConfig); - * $operationResponse->pollUntilComplete(); - * if ($operationResponse->operationSucceeded()) { - * $result = $operationResponse->getResult(); - * // doSomethingWith($result) - * } else { - * $error = $operationResponse->getError(); - * // handleError($error) - * } - * // Alternatively: - * // start the operation, keep the operation name, and resume later - * $operationResponse = $cloudRedisClient->exportInstance($name, $outputConfig); - * $operationName = $operationResponse->getName(); - * // ... do other work - * $newOperationResponse = $cloudRedisClient->resumeOperation($operationName, 'exportInstance'); - * while (!$newOperationResponse->isDone()) { - * // ... do other work - * $newOperationResponse->reload(); - * } - * if ($newOperationResponse->operationSucceeded()) { - * $result = $newOperationResponse->getResult(); - * // doSomethingWith($result) - * } else { - * $error = $newOperationResponse->getError(); - * // handleError($error) - * } - * } finally { - * $cloudRedisClient->close(); - * } - * ``` - * - * @param string $name Required. Redis instance resource name using the form: - * `projects/{project_id}/locations/{location_id}/instances/{instance_id}` - * where `location_id` refers to a GCP region. - * @param OutputConfig $outputConfig Required. Specify data to be exported. - * @param array $optionalArgs { - * Optional. - * - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an - * associative array of retry settings parameters. See the documentation on - * {@see RetrySettings} for example usage. - * } - * - * @return \Google\ApiCore\OperationResponse - * - * @throws ApiException if the remote call fails - */ - public function exportInstance($name, $outputConfig, array $optionalArgs = []) - { - $request = new ExportInstanceRequest(); - $requestParamHeaders = []; - $request->setName($name); - $request->setOutputConfig($outputConfig); - $requestParamHeaders['name'] = $name; - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->startOperationsCall('ExportInstance', $optionalArgs, $request, $this->getOperationsClient())->wait(); - } - - /** - * Initiates a failover of the primary node to current replica node for a - * specific STANDARD tier Cloud Memorystore for Redis instance. - * - * Sample code: - * ``` - * $cloudRedisClient = new CloudRedisClient(); - * try { - * $formattedName = $cloudRedisClient->instanceName('[PROJECT]', '[LOCATION]', '[INSTANCE]'); - * $operationResponse = $cloudRedisClient->failoverInstance($formattedName); - * $operationResponse->pollUntilComplete(); - * if ($operationResponse->operationSucceeded()) { - * $result = $operationResponse->getResult(); - * // doSomethingWith($result) - * } else { - * $error = $operationResponse->getError(); - * // handleError($error) - * } - * // Alternatively: - * // start the operation, keep the operation name, and resume later - * $operationResponse = $cloudRedisClient->failoverInstance($formattedName); - * $operationName = $operationResponse->getName(); - * // ... do other work - * $newOperationResponse = $cloudRedisClient->resumeOperation($operationName, 'failoverInstance'); - * while (!$newOperationResponse->isDone()) { - * // ... do other work - * $newOperationResponse->reload(); - * } - * if ($newOperationResponse->operationSucceeded()) { - * $result = $newOperationResponse->getResult(); - * // doSomethingWith($result) - * } else { - * $error = $newOperationResponse->getError(); - * // handleError($error) - * } - * } finally { - * $cloudRedisClient->close(); - * } - * ``` - * - * @param string $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 array $optionalArgs { - * Optional. - * - * @type int $dataProtectionMode - * Optional. Available data protection modes that the user can choose. If it's - * unspecified, data protection mode will be LIMITED_DATA_LOSS by default. - * For allowed values, use constants defined on {@see \Google\Cloud\Redis\V1\FailoverInstanceRequest\DataProtectionMode} - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an - * associative array of retry settings parameters. See the documentation on - * {@see RetrySettings} for example usage. - * } - * - * @return \Google\ApiCore\OperationResponse - * - * @throws ApiException if the remote call fails - */ - public function failoverInstance($name, array $optionalArgs = []) - { - $request = new FailoverInstanceRequest(); - $requestParamHeaders = []; - $request->setName($name); - $requestParamHeaders['name'] = $name; - if (isset($optionalArgs['dataProtectionMode'])) { - $request->setDataProtectionMode($optionalArgs['dataProtectionMode']); - } - - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->startOperationsCall('FailoverInstance', $optionalArgs, $request, $this->getOperationsClient())->wait(); - } - - /** - * Gets the details of a specific Redis instance. - * - * Sample code: - * ``` - * $cloudRedisClient = new CloudRedisClient(); - * try { - * $formattedName = $cloudRedisClient->instanceName('[PROJECT]', '[LOCATION]', '[INSTANCE]'); - * $response = $cloudRedisClient->getInstance($formattedName); - * } finally { - * $cloudRedisClient->close(); - * } - * ``` - * - * @param string $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 array $optionalArgs { - * Optional. - * - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an - * associative array of retry settings parameters. See the documentation on - * {@see RetrySettings} for example usage. - * } - * - * @return \Google\Cloud\Redis\V1\Instance - * - * @throws ApiException if the remote call fails - */ - public function getInstance($name, array $optionalArgs = []) - { - $request = new GetInstanceRequest(); - $requestParamHeaders = []; - $request->setName($name); - $requestParamHeaders['name'] = $name; - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->startCall('GetInstance', Instance::class, $optionalArgs, $request)->wait(); - } - - /** - * Gets the AUTH string for a Redis instance. If AUTH is not enabled for the - * instance the response will be empty. This information is not included in - * the details returned to GetInstance. - * - * Sample code: - * ``` - * $cloudRedisClient = new CloudRedisClient(); - * try { - * $formattedName = $cloudRedisClient->instanceName('[PROJECT]', '[LOCATION]', '[INSTANCE]'); - * $response = $cloudRedisClient->getInstanceAuthString($formattedName); - * } finally { - * $cloudRedisClient->close(); - * } - * ``` - * - * @param string $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 array $optionalArgs { - * Optional. - * - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an - * associative array of retry settings parameters. See the documentation on - * {@see RetrySettings} for example usage. - * } - * - * @return \Google\Cloud\Redis\V1\InstanceAuthString - * - * @throws ApiException if the remote call fails - */ - public function getInstanceAuthString($name, array $optionalArgs = []) - { - $request = new GetInstanceAuthStringRequest(); - $requestParamHeaders = []; - $request->setName($name); - $requestParamHeaders['name'] = $name; - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->startCall('GetInstanceAuthString', InstanceAuthString::class, $optionalArgs, $request)->wait(); - } - - /** - * 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: - * ``` - * $cloudRedisClient = new CloudRedisClient(); - * try { - * $name = 'name'; - * $inputConfig = new InputConfig(); - * $operationResponse = $cloudRedisClient->importInstance($name, $inputConfig); - * $operationResponse->pollUntilComplete(); - * if ($operationResponse->operationSucceeded()) { - * $result = $operationResponse->getResult(); - * // doSomethingWith($result) - * } else { - * $error = $operationResponse->getError(); - * // handleError($error) - * } - * // Alternatively: - * // start the operation, keep the operation name, and resume later - * $operationResponse = $cloudRedisClient->importInstance($name, $inputConfig); - * $operationName = $operationResponse->getName(); - * // ... do other work - * $newOperationResponse = $cloudRedisClient->resumeOperation($operationName, 'importInstance'); - * while (!$newOperationResponse->isDone()) { - * // ... do other work - * $newOperationResponse->reload(); - * } - * if ($newOperationResponse->operationSucceeded()) { - * $result = $newOperationResponse->getResult(); - * // doSomethingWith($result) - * } else { - * $error = $newOperationResponse->getError(); - * // handleError($error) - * } - * } finally { - * $cloudRedisClient->close(); - * } - * ``` - * - * @param string $name Required. Redis instance resource name using the form: - * `projects/{project_id}/locations/{location_id}/instances/{instance_id}` - * where `location_id` refers to a GCP region. - * @param InputConfig $inputConfig Required. Specify data to be imported. - * @param array $optionalArgs { - * Optional. - * - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an - * associative array of retry settings parameters. See the documentation on - * {@see RetrySettings} for example usage. - * } - * - * @return \Google\ApiCore\OperationResponse - * - * @throws ApiException if the remote call fails - */ - public function importInstance($name, $inputConfig, array $optionalArgs = []) - { - $request = new ImportInstanceRequest(); - $requestParamHeaders = []; - $request->setName($name); - $request->setInputConfig($inputConfig); - $requestParamHeaders['name'] = $name; - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->startOperationsCall('ImportInstance', $optionalArgs, $request, $this->getOperationsClient())->wait(); - } - - /** - * 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: - * ``` - * $cloudRedisClient = new CloudRedisClient(); - * try { - * $formattedParent = $cloudRedisClient->locationName('[PROJECT]', '[LOCATION]'); - * // Iterate over pages of elements - * $pagedResponse = $cloudRedisClient->listInstances($formattedParent); - * foreach ($pagedResponse->iteratePages() as $page) { - * foreach ($page as $element) { - * // doSomethingWith($element); - * } - * } - * // Alternatively: - * // Iterate through all elements - * $pagedResponse = $cloudRedisClient->listInstances($formattedParent); - * foreach ($pagedResponse->iterateAllElements() as $element) { - * // doSomethingWith($element); - * } - * } finally { - * $cloudRedisClient->close(); - * } - * ``` - * - * @param string $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 array $optionalArgs { - * Optional. - * - * @type int $pageSize - * The maximum number of resources contained in the underlying API - * response. The API may return fewer values in a page, even if - * there are additional values to be retrieved. - * @type string $pageToken - * A page token is used to specify a page of values to be returned. - * If no page token is specified (the default), the first page - * of values will be returned. Any page token used here must have - * been generated by a previous call to the API. - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an - * associative array of retry settings parameters. See the documentation on - * {@see RetrySettings} for example usage. - * } - * - * @return \Google\ApiCore\PagedListResponse - * - * @throws ApiException if the remote call fails - */ - public function listInstances($parent, array $optionalArgs = []) - { - $request = new ListInstancesRequest(); - $requestParamHeaders = []; - $request->setParent($parent); - $requestParamHeaders['parent'] = $parent; - if (isset($optionalArgs['pageSize'])) { - $request->setPageSize($optionalArgs['pageSize']); - } - - if (isset($optionalArgs['pageToken'])) { - $request->setPageToken($optionalArgs['pageToken']); - } - - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->getPagedListResponse('ListInstances', $optionalArgs, ListInstancesResponse::class, $request); - } - - /** - * Reschedule maintenance for a given instance in a given project and - * location. - * - * Sample code: - * ``` - * $cloudRedisClient = new CloudRedisClient(); - * try { - * $formattedName = $cloudRedisClient->instanceName('[PROJECT]', '[LOCATION]', '[INSTANCE]'); - * $rescheduleType = RescheduleType::RESCHEDULE_TYPE_UNSPECIFIED; - * $operationResponse = $cloudRedisClient->rescheduleMaintenance($formattedName, $rescheduleType); - * $operationResponse->pollUntilComplete(); - * if ($operationResponse->operationSucceeded()) { - * $result = $operationResponse->getResult(); - * // doSomethingWith($result) - * } else { - * $error = $operationResponse->getError(); - * // handleError($error) - * } - * // Alternatively: - * // start the operation, keep the operation name, and resume later - * $operationResponse = $cloudRedisClient->rescheduleMaintenance($formattedName, $rescheduleType); - * $operationName = $operationResponse->getName(); - * // ... do other work - * $newOperationResponse = $cloudRedisClient->resumeOperation($operationName, 'rescheduleMaintenance'); - * while (!$newOperationResponse->isDone()) { - * // ... do other work - * $newOperationResponse->reload(); - * } - * if ($newOperationResponse->operationSucceeded()) { - * $result = $newOperationResponse->getResult(); - * // doSomethingWith($result) - * } else { - * $error = $newOperationResponse->getError(); - * // handleError($error) - * } - * } finally { - * $cloudRedisClient->close(); - * } - * ``` - * - * @param string $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 int $rescheduleType Required. If reschedule type is SPECIFIC_TIME, must set up schedule_time as - * well. - * For allowed values, use constants defined on {@see \Google\Cloud\Redis\V1\RescheduleMaintenanceRequest\RescheduleType} - * @param array $optionalArgs { - * Optional. - * - * @type Timestamp $scheduleTime - * Optional. Timestamp when the maintenance shall be rescheduled to if - * reschedule_type=SPECIFIC_TIME, in RFC 3339 format, for - * example `2012-11-15T16:19:00.094Z`. - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an - * associative array of retry settings parameters. See the documentation on - * {@see RetrySettings} for example usage. - * } - * - * @return \Google\ApiCore\OperationResponse - * - * @throws ApiException if the remote call fails - */ - public function rescheduleMaintenance($name, $rescheduleType, array $optionalArgs = []) - { - $request = new RescheduleMaintenanceRequest(); - $requestParamHeaders = []; - $request->setName($name); - $request->setRescheduleType($rescheduleType); - $requestParamHeaders['name'] = $name; - if (isset($optionalArgs['scheduleTime'])) { - $request->setScheduleTime($optionalArgs['scheduleTime']); - } - - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->startOperationsCall('RescheduleMaintenance', $optionalArgs, $request, $this->getOperationsClient())->wait(); - } - - /** - * 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: - * ``` - * $cloudRedisClient = new CloudRedisClient(); - * try { - * $updateMask = new FieldMask(); - * $instance = new Instance(); - * $operationResponse = $cloudRedisClient->updateInstance($updateMask, $instance); - * $operationResponse->pollUntilComplete(); - * if ($operationResponse->operationSucceeded()) { - * $result = $operationResponse->getResult(); - * // doSomethingWith($result) - * } else { - * $error = $operationResponse->getError(); - * // handleError($error) - * } - * // Alternatively: - * // start the operation, keep the operation name, and resume later - * $operationResponse = $cloudRedisClient->updateInstance($updateMask, $instance); - * $operationName = $operationResponse->getName(); - * // ... do other work - * $newOperationResponse = $cloudRedisClient->resumeOperation($operationName, 'updateInstance'); - * while (!$newOperationResponse->isDone()) { - * // ... do other work - * $newOperationResponse->reload(); - * } - * if ($newOperationResponse->operationSucceeded()) { - * $result = $newOperationResponse->getResult(); - * // doSomethingWith($result) - * } else { - * $error = $newOperationResponse->getError(); - * // handleError($error) - * } - * } finally { - * $cloudRedisClient->close(); - * } - * ``` - * - * @param FieldMask $updateMask Required. Mask of fields to update. At least one path must be supplied in - * this field. The elements of the repeated paths field may only include these - * fields from [Instance][google.cloud.redis.v1.Instance]: - * - * * `displayName` - * * `labels` - * * `memorySizeGb` - * * `redisConfig` - * * `replica_count` - * @param Instance $instance Required. Update description. - * Only fields specified in update_mask are updated. - * @param array $optionalArgs { - * Optional. - * - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an - * associative array of retry settings parameters. See the documentation on - * {@see RetrySettings} for example usage. - * } - * - * @return \Google\ApiCore\OperationResponse - * - * @throws ApiException if the remote call fails - */ - public function updateInstance($updateMask, $instance, array $optionalArgs = []) - { - $request = new UpdateInstanceRequest(); - $requestParamHeaders = []; - $request->setUpdateMask($updateMask); - $request->setInstance($instance); - $requestParamHeaders['instance.name'] = $instance->getName(); - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->startOperationsCall('UpdateInstance', $optionalArgs, $request, $this->getOperationsClient())->wait(); - } - - /** - * Upgrades Redis instance to the newer Redis version specified in the - * request. - * - * Sample code: - * ``` - * $cloudRedisClient = new CloudRedisClient(); - * try { - * $formattedName = $cloudRedisClient->instanceName('[PROJECT]', '[LOCATION]', '[INSTANCE]'); - * $redisVersion = 'redis_version'; - * $operationResponse = $cloudRedisClient->upgradeInstance($formattedName, $redisVersion); - * $operationResponse->pollUntilComplete(); - * if ($operationResponse->operationSucceeded()) { - * $result = $operationResponse->getResult(); - * // doSomethingWith($result) - * } else { - * $error = $operationResponse->getError(); - * // handleError($error) - * } - * // Alternatively: - * // start the operation, keep the operation name, and resume later - * $operationResponse = $cloudRedisClient->upgradeInstance($formattedName, $redisVersion); - * $operationName = $operationResponse->getName(); - * // ... do other work - * $newOperationResponse = $cloudRedisClient->resumeOperation($operationName, 'upgradeInstance'); - * while (!$newOperationResponse->isDone()) { - * // ... do other work - * $newOperationResponse->reload(); - * } - * if ($newOperationResponse->operationSucceeded()) { - * $result = $newOperationResponse->getResult(); - * // doSomethingWith($result) - * } else { - * $error = $newOperationResponse->getError(); - * // handleError($error) - * } - * } finally { - * $cloudRedisClient->close(); - * } - * ``` - * - * @param string $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 string $redisVersion Required. Specifies the target version of Redis software to upgrade to. - * @param array $optionalArgs { - * Optional. - * - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an - * associative array of retry settings parameters. See the documentation on - * {@see RetrySettings} for example usage. - * } - * - * @return \Google\ApiCore\OperationResponse - * - * @throws ApiException if the remote call fails - */ - public function upgradeInstance($name, $redisVersion, array $optionalArgs = []) - { - $request = new UpgradeInstanceRequest(); - $requestParamHeaders = []; - $request->setName($name); - $request->setRedisVersion($redisVersion); - $requestParamHeaders['name'] = $name; - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->startOperationsCall('UpgradeInstance', $optionalArgs, $request, $this->getOperationsClient())->wait(); - } - - /** - * Gets information about a location. - * - * Sample code: - * ``` - * $cloudRedisClient = new CloudRedisClient(); - * try { - * $response = $cloudRedisClient->getLocation(); - * } finally { - * $cloudRedisClient->close(); - * } - * ``` - * - * @param array $optionalArgs { - * Optional. - * - * @type string $name - * Resource name for the location. - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an - * associative array of retry settings parameters. See the documentation on - * {@see RetrySettings} for example usage. - * } - * - * @return \Google\Cloud\Location\Location - * - * @throws ApiException if the remote call fails - */ - public function getLocation(array $optionalArgs = []) - { - $request = new GetLocationRequest(); - $requestParamHeaders = []; - if (isset($optionalArgs['name'])) { - $request->setName($optionalArgs['name']); - $requestParamHeaders['name'] = $optionalArgs['name']; - } - - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->startCall('GetLocation', Location::class, $optionalArgs, $request, Call::UNARY_CALL, 'google.cloud.location.Locations')->wait(); - } - - /** - * Lists information about the supported locations for this service. - * - * Sample code: - * ``` - * $cloudRedisClient = new CloudRedisClient(); - * try { - * // Iterate over pages of elements - * $pagedResponse = $cloudRedisClient->listLocations(); - * foreach ($pagedResponse->iteratePages() as $page) { - * foreach ($page as $element) { - * // doSomethingWith($element); - * } - * } - * // Alternatively: - * // Iterate through all elements - * $pagedResponse = $cloudRedisClient->listLocations(); - * foreach ($pagedResponse->iterateAllElements() as $element) { - * // doSomethingWith($element); - * } - * } finally { - * $cloudRedisClient->close(); - * } - * ``` - * - * @param array $optionalArgs { - * Optional. - * - * @type string $name - * The resource that owns the locations collection, if applicable. - * @type string $filter - * The standard list filter. - * @type int $pageSize - * The maximum number of resources contained in the underlying API - * response. The API may return fewer values in a page, even if - * there are additional values to be retrieved. - * @type string $pageToken - * A page token is used to specify a page of values to be returned. - * If no page token is specified (the default), the first page - * of values will be returned. Any page token used here must have - * been generated by a previous call to the API. - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an - * associative array of retry settings parameters. See the documentation on - * {@see RetrySettings} for example usage. - * } - * - * @return \Google\ApiCore\PagedListResponse - * - * @throws ApiException if the remote call fails - */ - public function listLocations(array $optionalArgs = []) - { - $request = new ListLocationsRequest(); - $requestParamHeaders = []; - if (isset($optionalArgs['name'])) { - $request->setName($optionalArgs['name']); - $requestParamHeaders['name'] = $optionalArgs['name']; - } - - if (isset($optionalArgs['filter'])) { - $request->setFilter($optionalArgs['filter']); - } - - if (isset($optionalArgs['pageSize'])) { - $request->setPageSize($optionalArgs['pageSize']); - } - - if (isset($optionalArgs['pageToken'])) { - $request->setPageToken($optionalArgs['pageToken']); - } - - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->getPagedListResponse('ListLocations', $optionalArgs, ListLocationsResponse::class, $request, 'google.cloud.location.Locations'); - } -} diff --git a/tests/Integration/goldens/redis/tests/Unit/V1/CloudRedisClientTest.php b/tests/Integration/goldens/redis/tests/Unit/V1/CloudRedisClientTest.php deleted file mode 100644 index d80c3b35..00000000 --- a/tests/Integration/goldens/redis/tests/Unit/V1/CloudRedisClientTest.php +++ /dev/null @@ -1,1689 +0,0 @@ -getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); - } - - /** @return CloudRedisClient */ - private function createClient(array $options = []) - { - $options += [ - 'credentials' => $this->createCredentials(), - ]; - return new CloudRedisClient($options); - } - - /** @test */ - public function createInstanceTest() - { - $operationsTransport = $this->createTransport(); - $operationsClient = new OperationsClient([ - 'apiEndpoint' => '', - 'transport' => $operationsTransport, - 'credentials' => $this->createCredentials(), - ]); - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - 'operationsClient' => $operationsClient, - ]); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - // Mock response - $incompleteOperation = new Operation(); - $incompleteOperation->setName('operations/createInstanceTest'); - $incompleteOperation->setDone(false); - $transport->addResponse($incompleteOperation); - $name = 'name3373707'; - $displayName = 'displayName1615086568'; - $locationId = 'locationId552319461'; - $alternativeLocationId = 'alternativeLocationId-718920621'; - $redisVersion = 'redisVersion-685310444'; - $reservedIpRange = 'reservedIpRange-1082940580'; - $secondaryIpRange = 'secondaryIpRange-1484975472'; - $host = 'host3208616'; - $port = 3446913; - $currentLocationId = 'currentLocationId1312712735'; - $statusMessage = 'statusMessage-239442758'; - $memorySizeGb = 34199707; - $authorizedNetwork = 'authorizedNetwork-1733809270'; - $persistenceIamIdentity = 'persistenceIamIdentity1061944584'; - $authEnabled = true; - $replicaCount = 564075208; - $readEndpoint = 'readEndpoint-2081202658'; - $readEndpointPort = 1676143102; - $customerManagedKey = 'customerManagedKey-1392642338'; - $maintenanceVersion = 'maintenanceVersion-588975188'; - $expectedResponse = new Instance(); - $expectedResponse->setName($name); - $expectedResponse->setDisplayName($displayName); - $expectedResponse->setLocationId($locationId); - $expectedResponse->setAlternativeLocationId($alternativeLocationId); - $expectedResponse->setRedisVersion($redisVersion); - $expectedResponse->setReservedIpRange($reservedIpRange); - $expectedResponse->setSecondaryIpRange($secondaryIpRange); - $expectedResponse->setHost($host); - $expectedResponse->setPort($port); - $expectedResponse->setCurrentLocationId($currentLocationId); - $expectedResponse->setStatusMessage($statusMessage); - $expectedResponse->setMemorySizeGb($memorySizeGb); - $expectedResponse->setAuthorizedNetwork($authorizedNetwork); - $expectedResponse->setPersistenceIamIdentity($persistenceIamIdentity); - $expectedResponse->setAuthEnabled($authEnabled); - $expectedResponse->setReplicaCount($replicaCount); - $expectedResponse->setReadEndpoint($readEndpoint); - $expectedResponse->setReadEndpointPort($readEndpointPort); - $expectedResponse->setCustomerManagedKey($customerManagedKey); - $expectedResponse->setMaintenanceVersion($maintenanceVersion); - $anyResponse = new Any(); - $anyResponse->setValue($expectedResponse->serializeToString()); - $completeOperation = new Operation(); - $completeOperation->setName('operations/createInstanceTest'); - $completeOperation->setDone(true); - $completeOperation->setResponse($anyResponse); - $operationsTransport->addResponse($completeOperation); - // Mock request - $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); - $instanceId = 'instanceId-2101995259'; - $instance = new Instance(); - $instanceName = 'instanceName-737857344'; - $instance->setName($instanceName); - $instanceTier = Tier::TIER_UNSPECIFIED; - $instance->setTier($instanceTier); - $instanceMemorySizeGb = 193936814; - $instance->setMemorySizeGb($instanceMemorySizeGb); - $response = $gapicClient->createInstance($formattedParent, $instanceId, $instance); - $this->assertFalse($response->isDone()); - $this->assertNull($response->getResult()); - $apiRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($apiRequests)); - $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); - $this->assertSame(0, count($operationsRequestsEmpty)); - $actualApiFuncCall = $apiRequests[0]->getFuncCall(); - $actualApiRequestObject = $apiRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.redis.v1.CloudRedis/CreateInstance', $actualApiFuncCall); - $actualValue = $actualApiRequestObject->getParent(); - $this->assertProtobufEquals($formattedParent, $actualValue); - $actualValue = $actualApiRequestObject->getInstanceId(); - $this->assertProtobufEquals($instanceId, $actualValue); - $actualValue = $actualApiRequestObject->getInstance(); - $this->assertProtobufEquals($instance, $actualValue); - $expectedOperationsRequestObject = new GetOperationRequest(); - $expectedOperationsRequestObject->setName('operations/createInstanceTest'); - $response->pollUntilComplete([ - 'initialPollDelayMillis' => 1, - ]); - $this->assertTrue($response->isDone()); - $this->assertEquals($expectedResponse, $response->getResult()); - $apiRequestsEmpty = $transport->popReceivedCalls(); - $this->assertSame(0, count($apiRequestsEmpty)); - $operationsRequests = $operationsTransport->popReceivedCalls(); - $this->assertSame(1, count($operationsRequests)); - $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); - $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); - $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); - $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - } - - /** @test */ - public function createInstanceExceptionTest() - { - $operationsTransport = $this->createTransport(); - $operationsClient = new OperationsClient([ - 'apiEndpoint' => '', - 'transport' => $operationsTransport, - 'credentials' => $this->createCredentials(), - ]); - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - 'operationsClient' => $operationsClient, - ]); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - // Mock response - $incompleteOperation = new Operation(); - $incompleteOperation->setName('operations/createInstanceTest'); - $incompleteOperation->setDone(false); - $transport->addResponse($incompleteOperation); - $status = new stdClass(); - $status->code = Code::DATA_LOSS; - $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); - $operationsTransport->addResponse(null, $status); - // Mock request - $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); - $instanceId = 'instanceId-2101995259'; - $instance = new Instance(); - $instanceName = 'instanceName-737857344'; - $instance->setName($instanceName); - $instanceTier = Tier::TIER_UNSPECIFIED; - $instance->setTier($instanceTier); - $instanceMemorySizeGb = 193936814; - $instance->setMemorySizeGb($instanceMemorySizeGb); - $response = $gapicClient->createInstance($formattedParent, $instanceId, $instance); - $this->assertFalse($response->isDone()); - $this->assertNull($response->getResult()); - $expectedOperationsRequestObject = new GetOperationRequest(); - $expectedOperationsRequestObject->setName('operations/createInstanceTest'); - try { - $response->pollUntilComplete([ - 'initialPollDelayMillis' => 1, - ]); - // If the pollUntilComplete() method call did not throw, fail the test - $this->fail('Expected an ApiException, but no exception was thrown.'); - } catch (ApiException $ex) { - $this->assertEquals($status->code, $ex->getCode()); - $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); - } - // Call popReceivedCalls to ensure the stubs are exhausted - $transport->popReceivedCalls(); - $operationsTransport->popReceivedCalls(); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - } - - /** @test */ - public function deleteInstanceTest() - { - $operationsTransport = $this->createTransport(); - $operationsClient = new OperationsClient([ - 'apiEndpoint' => '', - 'transport' => $operationsTransport, - 'credentials' => $this->createCredentials(), - ]); - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - 'operationsClient' => $operationsClient, - ]); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - // Mock response - $incompleteOperation = new Operation(); - $incompleteOperation->setName('operations/deleteInstanceTest'); - $incompleteOperation->setDone(false); - $transport->addResponse($incompleteOperation); - $expectedResponse = new GPBEmpty(); - $anyResponse = new Any(); - $anyResponse->setValue($expectedResponse->serializeToString()); - $completeOperation = new Operation(); - $completeOperation->setName('operations/deleteInstanceTest'); - $completeOperation->setDone(true); - $completeOperation->setResponse($anyResponse); - $operationsTransport->addResponse($completeOperation); - // Mock request - $formattedName = $gapicClient->instanceName('[PROJECT]', '[LOCATION]', '[INSTANCE]'); - $response = $gapicClient->deleteInstance($formattedName); - $this->assertFalse($response->isDone()); - $this->assertNull($response->getResult()); - $apiRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($apiRequests)); - $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); - $this->assertSame(0, count($operationsRequestsEmpty)); - $actualApiFuncCall = $apiRequests[0]->getFuncCall(); - $actualApiRequestObject = $apiRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.redis.v1.CloudRedis/DeleteInstance', $actualApiFuncCall); - $actualValue = $actualApiRequestObject->getName(); - $this->assertProtobufEquals($formattedName, $actualValue); - $expectedOperationsRequestObject = new GetOperationRequest(); - $expectedOperationsRequestObject->setName('operations/deleteInstanceTest'); - $response->pollUntilComplete([ - 'initialPollDelayMillis' => 1, - ]); - $this->assertTrue($response->isDone()); - $this->assertEquals($expectedResponse, $response->getResult()); - $apiRequestsEmpty = $transport->popReceivedCalls(); - $this->assertSame(0, count($apiRequestsEmpty)); - $operationsRequests = $operationsTransport->popReceivedCalls(); - $this->assertSame(1, count($operationsRequests)); - $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); - $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); - $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); - $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - } - - /** @test */ - public function deleteInstanceExceptionTest() - { - $operationsTransport = $this->createTransport(); - $operationsClient = new OperationsClient([ - 'apiEndpoint' => '', - 'transport' => $operationsTransport, - 'credentials' => $this->createCredentials(), - ]); - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - 'operationsClient' => $operationsClient, - ]); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - // Mock response - $incompleteOperation = new Operation(); - $incompleteOperation->setName('operations/deleteInstanceTest'); - $incompleteOperation->setDone(false); - $transport->addResponse($incompleteOperation); - $status = new stdClass(); - $status->code = Code::DATA_LOSS; - $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); - $operationsTransport->addResponse(null, $status); - // Mock request - $formattedName = $gapicClient->instanceName('[PROJECT]', '[LOCATION]', '[INSTANCE]'); - $response = $gapicClient->deleteInstance($formattedName); - $this->assertFalse($response->isDone()); - $this->assertNull($response->getResult()); - $expectedOperationsRequestObject = new GetOperationRequest(); - $expectedOperationsRequestObject->setName('operations/deleteInstanceTest'); - try { - $response->pollUntilComplete([ - 'initialPollDelayMillis' => 1, - ]); - // If the pollUntilComplete() method call did not throw, fail the test - $this->fail('Expected an ApiException, but no exception was thrown.'); - } catch (ApiException $ex) { - $this->assertEquals($status->code, $ex->getCode()); - $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); - } - // Call popReceivedCalls to ensure the stubs are exhausted - $transport->popReceivedCalls(); - $operationsTransport->popReceivedCalls(); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - } - - /** @test */ - public function exportInstanceTest() - { - $operationsTransport = $this->createTransport(); - $operationsClient = new OperationsClient([ - 'apiEndpoint' => '', - 'transport' => $operationsTransport, - 'credentials' => $this->createCredentials(), - ]); - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - 'operationsClient' => $operationsClient, - ]); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - // Mock response - $incompleteOperation = new Operation(); - $incompleteOperation->setName('operations/exportInstanceTest'); - $incompleteOperation->setDone(false); - $transport->addResponse($incompleteOperation); - $name2 = 'name2-1052831874'; - $displayName = 'displayName1615086568'; - $locationId = 'locationId552319461'; - $alternativeLocationId = 'alternativeLocationId-718920621'; - $redisVersion = 'redisVersion-685310444'; - $reservedIpRange = 'reservedIpRange-1082940580'; - $secondaryIpRange = 'secondaryIpRange-1484975472'; - $host = 'host3208616'; - $port = 3446913; - $currentLocationId = 'currentLocationId1312712735'; - $statusMessage = 'statusMessage-239442758'; - $memorySizeGb = 34199707; - $authorizedNetwork = 'authorizedNetwork-1733809270'; - $persistenceIamIdentity = 'persistenceIamIdentity1061944584'; - $authEnabled = true; - $replicaCount = 564075208; - $readEndpoint = 'readEndpoint-2081202658'; - $readEndpointPort = 1676143102; - $customerManagedKey = 'customerManagedKey-1392642338'; - $maintenanceVersion = 'maintenanceVersion-588975188'; - $expectedResponse = new Instance(); - $expectedResponse->setName($name2); - $expectedResponse->setDisplayName($displayName); - $expectedResponse->setLocationId($locationId); - $expectedResponse->setAlternativeLocationId($alternativeLocationId); - $expectedResponse->setRedisVersion($redisVersion); - $expectedResponse->setReservedIpRange($reservedIpRange); - $expectedResponse->setSecondaryIpRange($secondaryIpRange); - $expectedResponse->setHost($host); - $expectedResponse->setPort($port); - $expectedResponse->setCurrentLocationId($currentLocationId); - $expectedResponse->setStatusMessage($statusMessage); - $expectedResponse->setMemorySizeGb($memorySizeGb); - $expectedResponse->setAuthorizedNetwork($authorizedNetwork); - $expectedResponse->setPersistenceIamIdentity($persistenceIamIdentity); - $expectedResponse->setAuthEnabled($authEnabled); - $expectedResponse->setReplicaCount($replicaCount); - $expectedResponse->setReadEndpoint($readEndpoint); - $expectedResponse->setReadEndpointPort($readEndpointPort); - $expectedResponse->setCustomerManagedKey($customerManagedKey); - $expectedResponse->setMaintenanceVersion($maintenanceVersion); - $anyResponse = new Any(); - $anyResponse->setValue($expectedResponse->serializeToString()); - $completeOperation = new Operation(); - $completeOperation->setName('operations/exportInstanceTest'); - $completeOperation->setDone(true); - $completeOperation->setResponse($anyResponse); - $operationsTransport->addResponse($completeOperation); - // Mock request - $name = 'name3373707'; - $outputConfig = new OutputConfig(); - $response = $gapicClient->exportInstance($name, $outputConfig); - $this->assertFalse($response->isDone()); - $this->assertNull($response->getResult()); - $apiRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($apiRequests)); - $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); - $this->assertSame(0, count($operationsRequestsEmpty)); - $actualApiFuncCall = $apiRequests[0]->getFuncCall(); - $actualApiRequestObject = $apiRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.redis.v1.CloudRedis/ExportInstance', $actualApiFuncCall); - $actualValue = $actualApiRequestObject->getName(); - $this->assertProtobufEquals($name, $actualValue); - $actualValue = $actualApiRequestObject->getOutputConfig(); - $this->assertProtobufEquals($outputConfig, $actualValue); - $expectedOperationsRequestObject = new GetOperationRequest(); - $expectedOperationsRequestObject->setName('operations/exportInstanceTest'); - $response->pollUntilComplete([ - 'initialPollDelayMillis' => 1, - ]); - $this->assertTrue($response->isDone()); - $this->assertEquals($expectedResponse, $response->getResult()); - $apiRequestsEmpty = $transport->popReceivedCalls(); - $this->assertSame(0, count($apiRequestsEmpty)); - $operationsRequests = $operationsTransport->popReceivedCalls(); - $this->assertSame(1, count($operationsRequests)); - $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); - $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); - $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); - $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - } - - /** @test */ - public function exportInstanceExceptionTest() - { - $operationsTransport = $this->createTransport(); - $operationsClient = new OperationsClient([ - 'apiEndpoint' => '', - 'transport' => $operationsTransport, - 'credentials' => $this->createCredentials(), - ]); - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - 'operationsClient' => $operationsClient, - ]); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - // Mock response - $incompleteOperation = new Operation(); - $incompleteOperation->setName('operations/exportInstanceTest'); - $incompleteOperation->setDone(false); - $transport->addResponse($incompleteOperation); - $status = new stdClass(); - $status->code = Code::DATA_LOSS; - $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); - $operationsTransport->addResponse(null, $status); - // Mock request - $name = 'name3373707'; - $outputConfig = new OutputConfig(); - $response = $gapicClient->exportInstance($name, $outputConfig); - $this->assertFalse($response->isDone()); - $this->assertNull($response->getResult()); - $expectedOperationsRequestObject = new GetOperationRequest(); - $expectedOperationsRequestObject->setName('operations/exportInstanceTest'); - try { - $response->pollUntilComplete([ - 'initialPollDelayMillis' => 1, - ]); - // If the pollUntilComplete() method call did not throw, fail the test - $this->fail('Expected an ApiException, but no exception was thrown.'); - } catch (ApiException $ex) { - $this->assertEquals($status->code, $ex->getCode()); - $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); - } - // Call popReceivedCalls to ensure the stubs are exhausted - $transport->popReceivedCalls(); - $operationsTransport->popReceivedCalls(); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - } - - /** @test */ - public function failoverInstanceTest() - { - $operationsTransport = $this->createTransport(); - $operationsClient = new OperationsClient([ - 'apiEndpoint' => '', - 'transport' => $operationsTransport, - 'credentials' => $this->createCredentials(), - ]); - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - 'operationsClient' => $operationsClient, - ]); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - // Mock response - $incompleteOperation = new Operation(); - $incompleteOperation->setName('operations/failoverInstanceTest'); - $incompleteOperation->setDone(false); - $transport->addResponse($incompleteOperation); - $name2 = 'name2-1052831874'; - $displayName = 'displayName1615086568'; - $locationId = 'locationId552319461'; - $alternativeLocationId = 'alternativeLocationId-718920621'; - $redisVersion = 'redisVersion-685310444'; - $reservedIpRange = 'reservedIpRange-1082940580'; - $secondaryIpRange = 'secondaryIpRange-1484975472'; - $host = 'host3208616'; - $port = 3446913; - $currentLocationId = 'currentLocationId1312712735'; - $statusMessage = 'statusMessage-239442758'; - $memorySizeGb = 34199707; - $authorizedNetwork = 'authorizedNetwork-1733809270'; - $persistenceIamIdentity = 'persistenceIamIdentity1061944584'; - $authEnabled = true; - $replicaCount = 564075208; - $readEndpoint = 'readEndpoint-2081202658'; - $readEndpointPort = 1676143102; - $customerManagedKey = 'customerManagedKey-1392642338'; - $maintenanceVersion = 'maintenanceVersion-588975188'; - $expectedResponse = new Instance(); - $expectedResponse->setName($name2); - $expectedResponse->setDisplayName($displayName); - $expectedResponse->setLocationId($locationId); - $expectedResponse->setAlternativeLocationId($alternativeLocationId); - $expectedResponse->setRedisVersion($redisVersion); - $expectedResponse->setReservedIpRange($reservedIpRange); - $expectedResponse->setSecondaryIpRange($secondaryIpRange); - $expectedResponse->setHost($host); - $expectedResponse->setPort($port); - $expectedResponse->setCurrentLocationId($currentLocationId); - $expectedResponse->setStatusMessage($statusMessage); - $expectedResponse->setMemorySizeGb($memorySizeGb); - $expectedResponse->setAuthorizedNetwork($authorizedNetwork); - $expectedResponse->setPersistenceIamIdentity($persistenceIamIdentity); - $expectedResponse->setAuthEnabled($authEnabled); - $expectedResponse->setReplicaCount($replicaCount); - $expectedResponse->setReadEndpoint($readEndpoint); - $expectedResponse->setReadEndpointPort($readEndpointPort); - $expectedResponse->setCustomerManagedKey($customerManagedKey); - $expectedResponse->setMaintenanceVersion($maintenanceVersion); - $anyResponse = new Any(); - $anyResponse->setValue($expectedResponse->serializeToString()); - $completeOperation = new Operation(); - $completeOperation->setName('operations/failoverInstanceTest'); - $completeOperation->setDone(true); - $completeOperation->setResponse($anyResponse); - $operationsTransport->addResponse($completeOperation); - // Mock request - $formattedName = $gapicClient->instanceName('[PROJECT]', '[LOCATION]', '[INSTANCE]'); - $response = $gapicClient->failoverInstance($formattedName); - $this->assertFalse($response->isDone()); - $this->assertNull($response->getResult()); - $apiRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($apiRequests)); - $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); - $this->assertSame(0, count($operationsRequestsEmpty)); - $actualApiFuncCall = $apiRequests[0]->getFuncCall(); - $actualApiRequestObject = $apiRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.redis.v1.CloudRedis/FailoverInstance', $actualApiFuncCall); - $actualValue = $actualApiRequestObject->getName(); - $this->assertProtobufEquals($formattedName, $actualValue); - $expectedOperationsRequestObject = new GetOperationRequest(); - $expectedOperationsRequestObject->setName('operations/failoverInstanceTest'); - $response->pollUntilComplete([ - 'initialPollDelayMillis' => 1, - ]); - $this->assertTrue($response->isDone()); - $this->assertEquals($expectedResponse, $response->getResult()); - $apiRequestsEmpty = $transport->popReceivedCalls(); - $this->assertSame(0, count($apiRequestsEmpty)); - $operationsRequests = $operationsTransport->popReceivedCalls(); - $this->assertSame(1, count($operationsRequests)); - $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); - $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); - $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); - $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - } - - /** @test */ - public function failoverInstanceExceptionTest() - { - $operationsTransport = $this->createTransport(); - $operationsClient = new OperationsClient([ - 'apiEndpoint' => '', - 'transport' => $operationsTransport, - 'credentials' => $this->createCredentials(), - ]); - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - 'operationsClient' => $operationsClient, - ]); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - // Mock response - $incompleteOperation = new Operation(); - $incompleteOperation->setName('operations/failoverInstanceTest'); - $incompleteOperation->setDone(false); - $transport->addResponse($incompleteOperation); - $status = new stdClass(); - $status->code = Code::DATA_LOSS; - $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); - $operationsTransport->addResponse(null, $status); - // Mock request - $formattedName = $gapicClient->instanceName('[PROJECT]', '[LOCATION]', '[INSTANCE]'); - $response = $gapicClient->failoverInstance($formattedName); - $this->assertFalse($response->isDone()); - $this->assertNull($response->getResult()); - $expectedOperationsRequestObject = new GetOperationRequest(); - $expectedOperationsRequestObject->setName('operations/failoverInstanceTest'); - try { - $response->pollUntilComplete([ - 'initialPollDelayMillis' => 1, - ]); - // If the pollUntilComplete() method call did not throw, fail the test - $this->fail('Expected an ApiException, but no exception was thrown.'); - } catch (ApiException $ex) { - $this->assertEquals($status->code, $ex->getCode()); - $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); - } - // Call popReceivedCalls to ensure the stubs are exhausted - $transport->popReceivedCalls(); - $operationsTransport->popReceivedCalls(); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - } - - /** @test */ - public function getInstanceTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $name2 = 'name2-1052831874'; - $displayName = 'displayName1615086568'; - $locationId = 'locationId552319461'; - $alternativeLocationId = 'alternativeLocationId-718920621'; - $redisVersion = 'redisVersion-685310444'; - $reservedIpRange = 'reservedIpRange-1082940580'; - $secondaryIpRange = 'secondaryIpRange-1484975472'; - $host = 'host3208616'; - $port = 3446913; - $currentLocationId = 'currentLocationId1312712735'; - $statusMessage = 'statusMessage-239442758'; - $memorySizeGb = 34199707; - $authorizedNetwork = 'authorizedNetwork-1733809270'; - $persistenceIamIdentity = 'persistenceIamIdentity1061944584'; - $authEnabled = true; - $replicaCount = 564075208; - $readEndpoint = 'readEndpoint-2081202658'; - $readEndpointPort = 1676143102; - $customerManagedKey = 'customerManagedKey-1392642338'; - $maintenanceVersion = 'maintenanceVersion-588975188'; - $expectedResponse = new Instance(); - $expectedResponse->setName($name2); - $expectedResponse->setDisplayName($displayName); - $expectedResponse->setLocationId($locationId); - $expectedResponse->setAlternativeLocationId($alternativeLocationId); - $expectedResponse->setRedisVersion($redisVersion); - $expectedResponse->setReservedIpRange($reservedIpRange); - $expectedResponse->setSecondaryIpRange($secondaryIpRange); - $expectedResponse->setHost($host); - $expectedResponse->setPort($port); - $expectedResponse->setCurrentLocationId($currentLocationId); - $expectedResponse->setStatusMessage($statusMessage); - $expectedResponse->setMemorySizeGb($memorySizeGb); - $expectedResponse->setAuthorizedNetwork($authorizedNetwork); - $expectedResponse->setPersistenceIamIdentity($persistenceIamIdentity); - $expectedResponse->setAuthEnabled($authEnabled); - $expectedResponse->setReplicaCount($replicaCount); - $expectedResponse->setReadEndpoint($readEndpoint); - $expectedResponse->setReadEndpointPort($readEndpointPort); - $expectedResponse->setCustomerManagedKey($customerManagedKey); - $expectedResponse->setMaintenanceVersion($maintenanceVersion); - $transport->addResponse($expectedResponse); - // Mock request - $formattedName = $gapicClient->instanceName('[PROJECT]', '[LOCATION]', '[INSTANCE]'); - $response = $gapicClient->getInstance($formattedName); - $this->assertEquals($expectedResponse, $response); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.redis.v1.CloudRedis/GetInstance', $actualFuncCall); - $actualValue = $actualRequestObject->getName(); - $this->assertProtobufEquals($formattedName, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function getInstanceExceptionTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); - $status->code = Code::DATA_LOSS; - $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); - $transport->addResponse(null, $status); - // Mock request - $formattedName = $gapicClient->instanceName('[PROJECT]', '[LOCATION]', '[INSTANCE]'); - try { - $gapicClient->getInstance($formattedName); - // If the $gapicClient method call did not throw, fail the test - $this->fail('Expected an ApiException, but no exception was thrown.'); - } catch (ApiException $ex) { - $this->assertEquals($status->code, $ex->getCode()); - $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); - } - // Call popReceivedCalls to ensure the stub is exhausted - $transport->popReceivedCalls(); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function getInstanceAuthStringTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $authString = 'authString-554020216'; - $expectedResponse = new InstanceAuthString(); - $expectedResponse->setAuthString($authString); - $transport->addResponse($expectedResponse); - // Mock request - $formattedName = $gapicClient->instanceName('[PROJECT]', '[LOCATION]', '[INSTANCE]'); - $response = $gapicClient->getInstanceAuthString($formattedName); - $this->assertEquals($expectedResponse, $response); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.redis.v1.CloudRedis/GetInstanceAuthString', $actualFuncCall); - $actualValue = $actualRequestObject->getName(); - $this->assertProtobufEquals($formattedName, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function getInstanceAuthStringExceptionTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); - $status->code = Code::DATA_LOSS; - $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); - $transport->addResponse(null, $status); - // Mock request - $formattedName = $gapicClient->instanceName('[PROJECT]', '[LOCATION]', '[INSTANCE]'); - try { - $gapicClient->getInstanceAuthString($formattedName); - // If the $gapicClient method call did not throw, fail the test - $this->fail('Expected an ApiException, but no exception was thrown.'); - } catch (ApiException $ex) { - $this->assertEquals($status->code, $ex->getCode()); - $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); - } - // Call popReceivedCalls to ensure the stub is exhausted - $transport->popReceivedCalls(); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function importInstanceTest() - { - $operationsTransport = $this->createTransport(); - $operationsClient = new OperationsClient([ - 'apiEndpoint' => '', - 'transport' => $operationsTransport, - 'credentials' => $this->createCredentials(), - ]); - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - 'operationsClient' => $operationsClient, - ]); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - // Mock response - $incompleteOperation = new Operation(); - $incompleteOperation->setName('operations/importInstanceTest'); - $incompleteOperation->setDone(false); - $transport->addResponse($incompleteOperation); - $name2 = 'name2-1052831874'; - $displayName = 'displayName1615086568'; - $locationId = 'locationId552319461'; - $alternativeLocationId = 'alternativeLocationId-718920621'; - $redisVersion = 'redisVersion-685310444'; - $reservedIpRange = 'reservedIpRange-1082940580'; - $secondaryIpRange = 'secondaryIpRange-1484975472'; - $host = 'host3208616'; - $port = 3446913; - $currentLocationId = 'currentLocationId1312712735'; - $statusMessage = 'statusMessage-239442758'; - $memorySizeGb = 34199707; - $authorizedNetwork = 'authorizedNetwork-1733809270'; - $persistenceIamIdentity = 'persistenceIamIdentity1061944584'; - $authEnabled = true; - $replicaCount = 564075208; - $readEndpoint = 'readEndpoint-2081202658'; - $readEndpointPort = 1676143102; - $customerManagedKey = 'customerManagedKey-1392642338'; - $maintenanceVersion = 'maintenanceVersion-588975188'; - $expectedResponse = new Instance(); - $expectedResponse->setName($name2); - $expectedResponse->setDisplayName($displayName); - $expectedResponse->setLocationId($locationId); - $expectedResponse->setAlternativeLocationId($alternativeLocationId); - $expectedResponse->setRedisVersion($redisVersion); - $expectedResponse->setReservedIpRange($reservedIpRange); - $expectedResponse->setSecondaryIpRange($secondaryIpRange); - $expectedResponse->setHost($host); - $expectedResponse->setPort($port); - $expectedResponse->setCurrentLocationId($currentLocationId); - $expectedResponse->setStatusMessage($statusMessage); - $expectedResponse->setMemorySizeGb($memorySizeGb); - $expectedResponse->setAuthorizedNetwork($authorizedNetwork); - $expectedResponse->setPersistenceIamIdentity($persistenceIamIdentity); - $expectedResponse->setAuthEnabled($authEnabled); - $expectedResponse->setReplicaCount($replicaCount); - $expectedResponse->setReadEndpoint($readEndpoint); - $expectedResponse->setReadEndpointPort($readEndpointPort); - $expectedResponse->setCustomerManagedKey($customerManagedKey); - $expectedResponse->setMaintenanceVersion($maintenanceVersion); - $anyResponse = new Any(); - $anyResponse->setValue($expectedResponse->serializeToString()); - $completeOperation = new Operation(); - $completeOperation->setName('operations/importInstanceTest'); - $completeOperation->setDone(true); - $completeOperation->setResponse($anyResponse); - $operationsTransport->addResponse($completeOperation); - // Mock request - $name = 'name3373707'; - $inputConfig = new InputConfig(); - $response = $gapicClient->importInstance($name, $inputConfig); - $this->assertFalse($response->isDone()); - $this->assertNull($response->getResult()); - $apiRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($apiRequests)); - $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); - $this->assertSame(0, count($operationsRequestsEmpty)); - $actualApiFuncCall = $apiRequests[0]->getFuncCall(); - $actualApiRequestObject = $apiRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.redis.v1.CloudRedis/ImportInstance', $actualApiFuncCall); - $actualValue = $actualApiRequestObject->getName(); - $this->assertProtobufEquals($name, $actualValue); - $actualValue = $actualApiRequestObject->getInputConfig(); - $this->assertProtobufEquals($inputConfig, $actualValue); - $expectedOperationsRequestObject = new GetOperationRequest(); - $expectedOperationsRequestObject->setName('operations/importInstanceTest'); - $response->pollUntilComplete([ - 'initialPollDelayMillis' => 1, - ]); - $this->assertTrue($response->isDone()); - $this->assertEquals($expectedResponse, $response->getResult()); - $apiRequestsEmpty = $transport->popReceivedCalls(); - $this->assertSame(0, count($apiRequestsEmpty)); - $operationsRequests = $operationsTransport->popReceivedCalls(); - $this->assertSame(1, count($operationsRequests)); - $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); - $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); - $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); - $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - } - - /** @test */ - public function importInstanceExceptionTest() - { - $operationsTransport = $this->createTransport(); - $operationsClient = new OperationsClient([ - 'apiEndpoint' => '', - 'transport' => $operationsTransport, - 'credentials' => $this->createCredentials(), - ]); - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - 'operationsClient' => $operationsClient, - ]); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - // Mock response - $incompleteOperation = new Operation(); - $incompleteOperation->setName('operations/importInstanceTest'); - $incompleteOperation->setDone(false); - $transport->addResponse($incompleteOperation); - $status = new stdClass(); - $status->code = Code::DATA_LOSS; - $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); - $operationsTransport->addResponse(null, $status); - // Mock request - $name = 'name3373707'; - $inputConfig = new InputConfig(); - $response = $gapicClient->importInstance($name, $inputConfig); - $this->assertFalse($response->isDone()); - $this->assertNull($response->getResult()); - $expectedOperationsRequestObject = new GetOperationRequest(); - $expectedOperationsRequestObject->setName('operations/importInstanceTest'); - try { - $response->pollUntilComplete([ - 'initialPollDelayMillis' => 1, - ]); - // If the pollUntilComplete() method call did not throw, fail the test - $this->fail('Expected an ApiException, but no exception was thrown.'); - } catch (ApiException $ex) { - $this->assertEquals($status->code, $ex->getCode()); - $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); - } - // Call popReceivedCalls to ensure the stubs are exhausted - $transport->popReceivedCalls(); - $operationsTransport->popReceivedCalls(); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - } - - /** @test */ - public function listInstancesTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $nextPageToken = ''; - $instancesElement = new Instance(); - $instances = [ - $instancesElement, - ]; - $expectedResponse = new ListInstancesResponse(); - $expectedResponse->setNextPageToken($nextPageToken); - $expectedResponse->setInstances($instances); - $transport->addResponse($expectedResponse); - // Mock request - $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); - $response = $gapicClient->listInstances($formattedParent); - $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); - $resources = iterator_to_array($response->iterateAllElements()); - $this->assertSame(1, count($resources)); - $this->assertEquals($expectedResponse->getInstances()[0], $resources[0]); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.redis.v1.CloudRedis/ListInstances', $actualFuncCall); - $actualValue = $actualRequestObject->getParent(); - $this->assertProtobufEquals($formattedParent, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function listInstancesExceptionTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); - $status->code = Code::DATA_LOSS; - $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); - $transport->addResponse(null, $status); - // Mock request - $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); - try { - $gapicClient->listInstances($formattedParent); - // If the $gapicClient method call did not throw, fail the test - $this->fail('Expected an ApiException, but no exception was thrown.'); - } catch (ApiException $ex) { - $this->assertEquals($status->code, $ex->getCode()); - $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); - } - // Call popReceivedCalls to ensure the stub is exhausted - $transport->popReceivedCalls(); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function rescheduleMaintenanceTest() - { - $operationsTransport = $this->createTransport(); - $operationsClient = new OperationsClient([ - 'apiEndpoint' => '', - 'transport' => $operationsTransport, - 'credentials' => $this->createCredentials(), - ]); - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - 'operationsClient' => $operationsClient, - ]); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - // Mock response - $incompleteOperation = new Operation(); - $incompleteOperation->setName('operations/rescheduleMaintenanceTest'); - $incompleteOperation->setDone(false); - $transport->addResponse($incompleteOperation); - $name2 = 'name2-1052831874'; - $displayName = 'displayName1615086568'; - $locationId = 'locationId552319461'; - $alternativeLocationId = 'alternativeLocationId-718920621'; - $redisVersion = 'redisVersion-685310444'; - $reservedIpRange = 'reservedIpRange-1082940580'; - $secondaryIpRange = 'secondaryIpRange-1484975472'; - $host = 'host3208616'; - $port = 3446913; - $currentLocationId = 'currentLocationId1312712735'; - $statusMessage = 'statusMessage-239442758'; - $memorySizeGb = 34199707; - $authorizedNetwork = 'authorizedNetwork-1733809270'; - $persistenceIamIdentity = 'persistenceIamIdentity1061944584'; - $authEnabled = true; - $replicaCount = 564075208; - $readEndpoint = 'readEndpoint-2081202658'; - $readEndpointPort = 1676143102; - $customerManagedKey = 'customerManagedKey-1392642338'; - $maintenanceVersion = 'maintenanceVersion-588975188'; - $expectedResponse = new Instance(); - $expectedResponse->setName($name2); - $expectedResponse->setDisplayName($displayName); - $expectedResponse->setLocationId($locationId); - $expectedResponse->setAlternativeLocationId($alternativeLocationId); - $expectedResponse->setRedisVersion($redisVersion); - $expectedResponse->setReservedIpRange($reservedIpRange); - $expectedResponse->setSecondaryIpRange($secondaryIpRange); - $expectedResponse->setHost($host); - $expectedResponse->setPort($port); - $expectedResponse->setCurrentLocationId($currentLocationId); - $expectedResponse->setStatusMessage($statusMessage); - $expectedResponse->setMemorySizeGb($memorySizeGb); - $expectedResponse->setAuthorizedNetwork($authorizedNetwork); - $expectedResponse->setPersistenceIamIdentity($persistenceIamIdentity); - $expectedResponse->setAuthEnabled($authEnabled); - $expectedResponse->setReplicaCount($replicaCount); - $expectedResponse->setReadEndpoint($readEndpoint); - $expectedResponse->setReadEndpointPort($readEndpointPort); - $expectedResponse->setCustomerManagedKey($customerManagedKey); - $expectedResponse->setMaintenanceVersion($maintenanceVersion); - $anyResponse = new Any(); - $anyResponse->setValue($expectedResponse->serializeToString()); - $completeOperation = new Operation(); - $completeOperation->setName('operations/rescheduleMaintenanceTest'); - $completeOperation->setDone(true); - $completeOperation->setResponse($anyResponse); - $operationsTransport->addResponse($completeOperation); - // Mock request - $formattedName = $gapicClient->instanceName('[PROJECT]', '[LOCATION]', '[INSTANCE]'); - $rescheduleType = RescheduleType::RESCHEDULE_TYPE_UNSPECIFIED; - $response = $gapicClient->rescheduleMaintenance($formattedName, $rescheduleType); - $this->assertFalse($response->isDone()); - $this->assertNull($response->getResult()); - $apiRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($apiRequests)); - $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); - $this->assertSame(0, count($operationsRequestsEmpty)); - $actualApiFuncCall = $apiRequests[0]->getFuncCall(); - $actualApiRequestObject = $apiRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.redis.v1.CloudRedis/RescheduleMaintenance', $actualApiFuncCall); - $actualValue = $actualApiRequestObject->getName(); - $this->assertProtobufEquals($formattedName, $actualValue); - $actualValue = $actualApiRequestObject->getRescheduleType(); - $this->assertProtobufEquals($rescheduleType, $actualValue); - $expectedOperationsRequestObject = new GetOperationRequest(); - $expectedOperationsRequestObject->setName('operations/rescheduleMaintenanceTest'); - $response->pollUntilComplete([ - 'initialPollDelayMillis' => 1, - ]); - $this->assertTrue($response->isDone()); - $this->assertEquals($expectedResponse, $response->getResult()); - $apiRequestsEmpty = $transport->popReceivedCalls(); - $this->assertSame(0, count($apiRequestsEmpty)); - $operationsRequests = $operationsTransport->popReceivedCalls(); - $this->assertSame(1, count($operationsRequests)); - $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); - $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); - $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); - $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - } - - /** @test */ - public function rescheduleMaintenanceExceptionTest() - { - $operationsTransport = $this->createTransport(); - $operationsClient = new OperationsClient([ - 'apiEndpoint' => '', - 'transport' => $operationsTransport, - 'credentials' => $this->createCredentials(), - ]); - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - 'operationsClient' => $operationsClient, - ]); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - // Mock response - $incompleteOperation = new Operation(); - $incompleteOperation->setName('operations/rescheduleMaintenanceTest'); - $incompleteOperation->setDone(false); - $transport->addResponse($incompleteOperation); - $status = new stdClass(); - $status->code = Code::DATA_LOSS; - $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); - $operationsTransport->addResponse(null, $status); - // Mock request - $formattedName = $gapicClient->instanceName('[PROJECT]', '[LOCATION]', '[INSTANCE]'); - $rescheduleType = RescheduleType::RESCHEDULE_TYPE_UNSPECIFIED; - $response = $gapicClient->rescheduleMaintenance($formattedName, $rescheduleType); - $this->assertFalse($response->isDone()); - $this->assertNull($response->getResult()); - $expectedOperationsRequestObject = new GetOperationRequest(); - $expectedOperationsRequestObject->setName('operations/rescheduleMaintenanceTest'); - try { - $response->pollUntilComplete([ - 'initialPollDelayMillis' => 1, - ]); - // If the pollUntilComplete() method call did not throw, fail the test - $this->fail('Expected an ApiException, but no exception was thrown.'); - } catch (ApiException $ex) { - $this->assertEquals($status->code, $ex->getCode()); - $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); - } - // Call popReceivedCalls to ensure the stubs are exhausted - $transport->popReceivedCalls(); - $operationsTransport->popReceivedCalls(); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - } - - /** @test */ - public function updateInstanceTest() - { - $operationsTransport = $this->createTransport(); - $operationsClient = new OperationsClient([ - 'apiEndpoint' => '', - 'transport' => $operationsTransport, - 'credentials' => $this->createCredentials(), - ]); - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - 'operationsClient' => $operationsClient, - ]); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - // Mock response - $incompleteOperation = new Operation(); - $incompleteOperation->setName('operations/updateInstanceTest'); - $incompleteOperation->setDone(false); - $transport->addResponse($incompleteOperation); - $name = 'name3373707'; - $displayName = 'displayName1615086568'; - $locationId = 'locationId552319461'; - $alternativeLocationId = 'alternativeLocationId-718920621'; - $redisVersion = 'redisVersion-685310444'; - $reservedIpRange = 'reservedIpRange-1082940580'; - $secondaryIpRange = 'secondaryIpRange-1484975472'; - $host = 'host3208616'; - $port = 3446913; - $currentLocationId = 'currentLocationId1312712735'; - $statusMessage = 'statusMessage-239442758'; - $memorySizeGb = 34199707; - $authorizedNetwork = 'authorizedNetwork-1733809270'; - $persistenceIamIdentity = 'persistenceIamIdentity1061944584'; - $authEnabled = true; - $replicaCount = 564075208; - $readEndpoint = 'readEndpoint-2081202658'; - $readEndpointPort = 1676143102; - $customerManagedKey = 'customerManagedKey-1392642338'; - $maintenanceVersion = 'maintenanceVersion-588975188'; - $expectedResponse = new Instance(); - $expectedResponse->setName($name); - $expectedResponse->setDisplayName($displayName); - $expectedResponse->setLocationId($locationId); - $expectedResponse->setAlternativeLocationId($alternativeLocationId); - $expectedResponse->setRedisVersion($redisVersion); - $expectedResponse->setReservedIpRange($reservedIpRange); - $expectedResponse->setSecondaryIpRange($secondaryIpRange); - $expectedResponse->setHost($host); - $expectedResponse->setPort($port); - $expectedResponse->setCurrentLocationId($currentLocationId); - $expectedResponse->setStatusMessage($statusMessage); - $expectedResponse->setMemorySizeGb($memorySizeGb); - $expectedResponse->setAuthorizedNetwork($authorizedNetwork); - $expectedResponse->setPersistenceIamIdentity($persistenceIamIdentity); - $expectedResponse->setAuthEnabled($authEnabled); - $expectedResponse->setReplicaCount($replicaCount); - $expectedResponse->setReadEndpoint($readEndpoint); - $expectedResponse->setReadEndpointPort($readEndpointPort); - $expectedResponse->setCustomerManagedKey($customerManagedKey); - $expectedResponse->setMaintenanceVersion($maintenanceVersion); - $anyResponse = new Any(); - $anyResponse->setValue($expectedResponse->serializeToString()); - $completeOperation = new Operation(); - $completeOperation->setName('operations/updateInstanceTest'); - $completeOperation->setDone(true); - $completeOperation->setResponse($anyResponse); - $operationsTransport->addResponse($completeOperation); - // Mock request - $updateMask = new FieldMask(); - $instance = new Instance(); - $instanceName = 'instanceName-737857344'; - $instance->setName($instanceName); - $instanceTier = Tier::TIER_UNSPECIFIED; - $instance->setTier($instanceTier); - $instanceMemorySizeGb = 193936814; - $instance->setMemorySizeGb($instanceMemorySizeGb); - $response = $gapicClient->updateInstance($updateMask, $instance); - $this->assertFalse($response->isDone()); - $this->assertNull($response->getResult()); - $apiRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($apiRequests)); - $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); - $this->assertSame(0, count($operationsRequestsEmpty)); - $actualApiFuncCall = $apiRequests[0]->getFuncCall(); - $actualApiRequestObject = $apiRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.redis.v1.CloudRedis/UpdateInstance', $actualApiFuncCall); - $actualValue = $actualApiRequestObject->getUpdateMask(); - $this->assertProtobufEquals($updateMask, $actualValue); - $actualValue = $actualApiRequestObject->getInstance(); - $this->assertProtobufEquals($instance, $actualValue); - $expectedOperationsRequestObject = new GetOperationRequest(); - $expectedOperationsRequestObject->setName('operations/updateInstanceTest'); - $response->pollUntilComplete([ - 'initialPollDelayMillis' => 1, - ]); - $this->assertTrue($response->isDone()); - $this->assertEquals($expectedResponse, $response->getResult()); - $apiRequestsEmpty = $transport->popReceivedCalls(); - $this->assertSame(0, count($apiRequestsEmpty)); - $operationsRequests = $operationsTransport->popReceivedCalls(); - $this->assertSame(1, count($operationsRequests)); - $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); - $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); - $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); - $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - } - - /** @test */ - public function updateInstanceExceptionTest() - { - $operationsTransport = $this->createTransport(); - $operationsClient = new OperationsClient([ - 'apiEndpoint' => '', - 'transport' => $operationsTransport, - 'credentials' => $this->createCredentials(), - ]); - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - 'operationsClient' => $operationsClient, - ]); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - // Mock response - $incompleteOperation = new Operation(); - $incompleteOperation->setName('operations/updateInstanceTest'); - $incompleteOperation->setDone(false); - $transport->addResponse($incompleteOperation); - $status = new stdClass(); - $status->code = Code::DATA_LOSS; - $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); - $operationsTransport->addResponse(null, $status); - // Mock request - $updateMask = new FieldMask(); - $instance = new Instance(); - $instanceName = 'instanceName-737857344'; - $instance->setName($instanceName); - $instanceTier = Tier::TIER_UNSPECIFIED; - $instance->setTier($instanceTier); - $instanceMemorySizeGb = 193936814; - $instance->setMemorySizeGb($instanceMemorySizeGb); - $response = $gapicClient->updateInstance($updateMask, $instance); - $this->assertFalse($response->isDone()); - $this->assertNull($response->getResult()); - $expectedOperationsRequestObject = new GetOperationRequest(); - $expectedOperationsRequestObject->setName('operations/updateInstanceTest'); - try { - $response->pollUntilComplete([ - 'initialPollDelayMillis' => 1, - ]); - // If the pollUntilComplete() method call did not throw, fail the test - $this->fail('Expected an ApiException, but no exception was thrown.'); - } catch (ApiException $ex) { - $this->assertEquals($status->code, $ex->getCode()); - $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); - } - // Call popReceivedCalls to ensure the stubs are exhausted - $transport->popReceivedCalls(); - $operationsTransport->popReceivedCalls(); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - } - - /** @test */ - public function upgradeInstanceTest() - { - $operationsTransport = $this->createTransport(); - $operationsClient = new OperationsClient([ - 'apiEndpoint' => '', - 'transport' => $operationsTransport, - 'credentials' => $this->createCredentials(), - ]); - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - 'operationsClient' => $operationsClient, - ]); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - // Mock response - $incompleteOperation = new Operation(); - $incompleteOperation->setName('operations/upgradeInstanceTest'); - $incompleteOperation->setDone(false); - $transport->addResponse($incompleteOperation); - $name2 = 'name2-1052831874'; - $displayName = 'displayName1615086568'; - $locationId = 'locationId552319461'; - $alternativeLocationId = 'alternativeLocationId-718920621'; - $redisVersion2 = 'redisVersion2-1453337401'; - $reservedIpRange = 'reservedIpRange-1082940580'; - $secondaryIpRange = 'secondaryIpRange-1484975472'; - $host = 'host3208616'; - $port = 3446913; - $currentLocationId = 'currentLocationId1312712735'; - $statusMessage = 'statusMessage-239442758'; - $memorySizeGb = 34199707; - $authorizedNetwork = 'authorizedNetwork-1733809270'; - $persistenceIamIdentity = 'persistenceIamIdentity1061944584'; - $authEnabled = true; - $replicaCount = 564075208; - $readEndpoint = 'readEndpoint-2081202658'; - $readEndpointPort = 1676143102; - $customerManagedKey = 'customerManagedKey-1392642338'; - $maintenanceVersion = 'maintenanceVersion-588975188'; - $expectedResponse = new Instance(); - $expectedResponse->setName($name2); - $expectedResponse->setDisplayName($displayName); - $expectedResponse->setLocationId($locationId); - $expectedResponse->setAlternativeLocationId($alternativeLocationId); - $expectedResponse->setRedisVersion($redisVersion2); - $expectedResponse->setReservedIpRange($reservedIpRange); - $expectedResponse->setSecondaryIpRange($secondaryIpRange); - $expectedResponse->setHost($host); - $expectedResponse->setPort($port); - $expectedResponse->setCurrentLocationId($currentLocationId); - $expectedResponse->setStatusMessage($statusMessage); - $expectedResponse->setMemorySizeGb($memorySizeGb); - $expectedResponse->setAuthorizedNetwork($authorizedNetwork); - $expectedResponse->setPersistenceIamIdentity($persistenceIamIdentity); - $expectedResponse->setAuthEnabled($authEnabled); - $expectedResponse->setReplicaCount($replicaCount); - $expectedResponse->setReadEndpoint($readEndpoint); - $expectedResponse->setReadEndpointPort($readEndpointPort); - $expectedResponse->setCustomerManagedKey($customerManagedKey); - $expectedResponse->setMaintenanceVersion($maintenanceVersion); - $anyResponse = new Any(); - $anyResponse->setValue($expectedResponse->serializeToString()); - $completeOperation = new Operation(); - $completeOperation->setName('operations/upgradeInstanceTest'); - $completeOperation->setDone(true); - $completeOperation->setResponse($anyResponse); - $operationsTransport->addResponse($completeOperation); - // Mock request - $formattedName = $gapicClient->instanceName('[PROJECT]', '[LOCATION]', '[INSTANCE]'); - $redisVersion = 'redisVersion-685310444'; - $response = $gapicClient->upgradeInstance($formattedName, $redisVersion); - $this->assertFalse($response->isDone()); - $this->assertNull($response->getResult()); - $apiRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($apiRequests)); - $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); - $this->assertSame(0, count($operationsRequestsEmpty)); - $actualApiFuncCall = $apiRequests[0]->getFuncCall(); - $actualApiRequestObject = $apiRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.redis.v1.CloudRedis/UpgradeInstance', $actualApiFuncCall); - $actualValue = $actualApiRequestObject->getName(); - $this->assertProtobufEquals($formattedName, $actualValue); - $actualValue = $actualApiRequestObject->getRedisVersion(); - $this->assertProtobufEquals($redisVersion, $actualValue); - $expectedOperationsRequestObject = new GetOperationRequest(); - $expectedOperationsRequestObject->setName('operations/upgradeInstanceTest'); - $response->pollUntilComplete([ - 'initialPollDelayMillis' => 1, - ]); - $this->assertTrue($response->isDone()); - $this->assertEquals($expectedResponse, $response->getResult()); - $apiRequestsEmpty = $transport->popReceivedCalls(); - $this->assertSame(0, count($apiRequestsEmpty)); - $operationsRequests = $operationsTransport->popReceivedCalls(); - $this->assertSame(1, count($operationsRequests)); - $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); - $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); - $this->assertSame('/google.longrunning.Operations/GetOperation', $actualOperationsFuncCall); - $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - } - - /** @test */ - public function upgradeInstanceExceptionTest() - { - $operationsTransport = $this->createTransport(); - $operationsClient = new OperationsClient([ - 'apiEndpoint' => '', - 'transport' => $operationsTransport, - 'credentials' => $this->createCredentials(), - ]); - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - 'operationsClient' => $operationsClient, - ]); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - // Mock response - $incompleteOperation = new Operation(); - $incompleteOperation->setName('operations/upgradeInstanceTest'); - $incompleteOperation->setDone(false); - $transport->addResponse($incompleteOperation); - $status = new stdClass(); - $status->code = Code::DATA_LOSS; - $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); - $operationsTransport->addResponse(null, $status); - // Mock request - $formattedName = $gapicClient->instanceName('[PROJECT]', '[LOCATION]', '[INSTANCE]'); - $redisVersion = 'redisVersion-685310444'; - $response = $gapicClient->upgradeInstance($formattedName, $redisVersion); - $this->assertFalse($response->isDone()); - $this->assertNull($response->getResult()); - $expectedOperationsRequestObject = new GetOperationRequest(); - $expectedOperationsRequestObject->setName('operations/upgradeInstanceTest'); - try { - $response->pollUntilComplete([ - 'initialPollDelayMillis' => 1, - ]); - // If the pollUntilComplete() method call did not throw, fail the test - $this->fail('Expected an ApiException, but no exception was thrown.'); - } catch (ApiException $ex) { - $this->assertEquals($status->code, $ex->getCode()); - $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); - } - // Call popReceivedCalls to ensure the stubs are exhausted - $transport->popReceivedCalls(); - $operationsTransport->popReceivedCalls(); - $this->assertTrue($transport->isExhausted()); - $this->assertTrue($operationsTransport->isExhausted()); - } - - /** @test */ - public function getLocationTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $name2 = 'name2-1052831874'; - $locationId = 'locationId552319461'; - $displayName = 'displayName1615086568'; - $expectedResponse = new Location(); - $expectedResponse->setName($name2); - $expectedResponse->setLocationId($locationId); - $expectedResponse->setDisplayName($displayName); - $transport->addResponse($expectedResponse); - $response = $gapicClient->getLocation(); - $this->assertEquals($expectedResponse, $response); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.location.Locations/GetLocation', $actualFuncCall); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function getLocationExceptionTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); - $status->code = Code::DATA_LOSS; - $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); - $transport->addResponse(null, $status); - try { - $gapicClient->getLocation(); - // If the $gapicClient method call did not throw, fail the test - $this->fail('Expected an ApiException, but no exception was thrown.'); - } catch (ApiException $ex) { - $this->assertEquals($status->code, $ex->getCode()); - $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); - } - // Call popReceivedCalls to ensure the stub is exhausted - $transport->popReceivedCalls(); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function listLocationsTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $nextPageToken = ''; - $locationsElement = new Location(); - $locations = [ - $locationsElement, - ]; - $expectedResponse = new ListLocationsResponse(); - $expectedResponse->setNextPageToken($nextPageToken); - $expectedResponse->setLocations($locations); - $transport->addResponse($expectedResponse); - $response = $gapicClient->listLocations(); - $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); - $resources = iterator_to_array($response->iterateAllElements()); - $this->assertSame(1, count($resources)); - $this->assertEquals($expectedResponse->getLocations()[0], $resources[0]); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.location.Locations/ListLocations', $actualFuncCall); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function listLocationsExceptionTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); - $status->code = Code::DATA_LOSS; - $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); - $transport->addResponse(null, $status); - try { - $gapicClient->listLocations(); - // If the $gapicClient method call did not throw, fail the test - $this->fail('Expected an ApiException, but no exception was thrown.'); - } catch (ApiException $ex) { - $this->assertEquals($status->code, $ex->getCode()); - $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); - } - // Call popReceivedCalls to ensure the stub is exhausted - $transport->popReceivedCalls(); - $this->assertTrue($transport->isExhausted()); - } -} diff --git a/tests/Unit/ProtoTests/BasicGrpcOnly/out/src/Client/BasicGrpcOnlyClient.php b/tests/Unit/ProtoTests/BasicGrpcOnly/out/src/Client/BasicGrpcOnlyClient.php index c5636f1d..b79ec059 100644 --- a/tests/Unit/ProtoTests/BasicGrpcOnly/out/src/Client/BasicGrpcOnlyClient.php +++ b/tests/Unit/ProtoTests/BasicGrpcOnly/out/src/Client/BasicGrpcOnlyClient.php @@ -62,6 +62,7 @@ private static function getClientDefaults() 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, 'clientConfig' => __DIR__ . '/../resources/basic_grpc_only_client_config.json', 'descriptorsConfigPath' => __DIR__ . '/../resources/basic_grpc_only_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../resources/basic_grpc_only_grpc_config.json', 'credentialsConfig' => [ 'defaultScopes' => self::$serviceScopes, ],