public static InstanceName parse(String formattedString) { if (formattedString.isEmpty()) { return null; } Map<String, String> matchMap = PATH_TEMPLATE.validatedMatch( formattedString, "InstanceName.parse: formattedString not in valid format"); return of(matchMap.get("project"), matchMap.get("location"), matchMap.get("instance")); }
public static List<InstanceName> parseList(List<String> formattedStrings) { List<InstanceName> list = new ArrayList<>(formattedStrings.size()); for (String formattedString : formattedStrings) { list.add(parse(formattedString)); } return list; }
public static String format(String project, String location, String instance) { return newBuilder() .setProject(project) .setLocation(location) .setInstance(instance) .build() .toString(); }
@Test @SuppressWarnings("all") public void deleteInstanceTest() throws Exception { Empty expectedResponse = Empty.newBuilder().build(); Operation resultOperation = Operation.newBuilder() .setName("deleteInstanceTest") .setDone(true) .setResponse(Any.pack(expectedResponse)) .build(); mockCloudRedis.addResponse(resultOperation); InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); Empty actualResponse = client.deleteInstanceAsync(name).get(); Assert.assertEquals(expectedResponse, actualResponse); List<GeneratedMessageV3> actualRequests = mockCloudRedis.getRequests(); Assert.assertEquals(1, actualRequests.size()); DeleteInstanceRequest actualRequest = (DeleteInstanceRequest) actualRequests.get(0); Assert.assertEquals(name, InstanceName.parse(actualRequest.getName())); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern())); }
public static List<String> toStringList(List<InstanceName> values) { List<String> list = new ArrayList<String>(values.size()); for (InstanceName value : values) { if (value == null) { list.add(""); } else { list.add(value.toString()); } } return list; }
public InstanceName build() { return new InstanceName(this); } }
public String getFieldValue(String fieldName) { return getFieldValuesMap().get(fieldName); }
public static InstanceName of(String project, String location, String instance) { return newBuilder().setProject(project).setLocation(location).setInstance(instance).build(); }
mockCloudRedis.addResponse(expectedResponse); InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); GetInstanceRequest actualRequest = (GetInstanceRequest) actualRequests.get(0); Assert.assertEquals(name, InstanceName.parse(actualRequest.getName())); Assert.assertTrue( channelProvider.isHeaderSent(
/** * Gets the details of a specific Redis instance. * * <p>Sample code: * * <pre><code> * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { * InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); * Instance response = cloudRedisClient.getInstance(name); * } * </code></pre> * * @param name Required. Redis instance resource name using the form: * `projects/{project_id}/locations/{location_id}/instances/{instance_id}` where `location_id` * refers to a GCP region * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final Instance getInstance(InstanceName name) { GetInstanceRequest request = GetInstanceRequest.newBuilder().setName(name == null ? null : name.toString()).build(); return getInstance(request); }
@Test @SuppressWarnings("all") public void getInstanceExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockCloudRedis.addException(exception); try { InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); client.getInstance(name); Assert.fail("No exception raised"); } catch (InvalidArgumentException e) { // Expected exception } }
/** * Deletes a specific Redis instance. Instance stops serving and data is deleted. * * <p>Sample code: * * <pre><code> * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { * InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); * Empty response = cloudRedisClient.deleteInstanceAsync(name).get(); * } * </code></pre> * * @param name Required. Redis instance resource name using the form: * `projects/{project_id}/locations/{location_id}/instances/{instance_id}` where `location_id` * refers to a GCP region * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ @BetaApi( "The surface for long-running operations is not stable yet and may change in the future.") public final OperationFuture<Empty, OperationMetadata> deleteInstanceAsync(InstanceName name) { DeleteInstanceRequest request = DeleteInstanceRequest.newBuilder().setName(name == null ? null : name.toString()).build(); return deleteInstanceAsync(request); }
@Test @SuppressWarnings("all") public void deleteInstanceExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockCloudRedis.addException(exception); try { InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); client.deleteInstanceAsync(name).get(); Assert.fail("No exception raised"); } catch (ExecutionException e) { Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); InvalidArgumentException apiException = (InvalidArgumentException) e.getCause(); Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); } } }