use of com.google.cloud.redis.v1.Instance in project java-spanner by googleapis.
the class InstanceAdminClientTest method createInstanceExceptionTest.
@Test
public void createInstanceExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockInstanceAdmin.addException(exception);
try {
ProjectName parent = ProjectName.of("[PROJECT]");
String instanceId = "instanceId902024336";
Instance instance = Instance.newBuilder().build();
client.createInstanceAsync(parent, instanceId, instance).get();
Assert.fail("No exception raised");
} catch (ExecutionException e) {
Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass());
InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause());
Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode());
}
}
use of com.google.cloud.redis.v1.Instance in project java-spanner by googleapis.
the class InstanceAdminClientTest method getInstanceTest.
@Test
public void getInstanceTest() throws Exception {
Instance expectedResponse = Instance.newBuilder().setName(InstanceName.of("[PROJECT]", "[INSTANCE]").toString()).setConfig(InstanceConfigName.of("[PROJECT]", "[INSTANCE_CONFIG]").toString()).setDisplayName("displayName1714148973").setNodeCount(1539922066).setProcessingUnits(-329117885).putAllLabels(new HashMap<String, String>()).addAllEndpointUris(new ArrayList<String>()).build();
mockInstanceAdmin.addResponse(expectedResponse);
InstanceName name = InstanceName.of("[PROJECT]", "[INSTANCE]");
Instance actualResponse = client.getInstance(name);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockInstanceAdmin.getRequests();
Assert.assertEquals(1, actualRequests.size());
GetInstanceRequest actualRequest = ((GetInstanceRequest) actualRequests.get(0));
Assert.assertEquals(name.toString(), actualRequest.getName());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.redis.v1.Instance in project java-spanner by googleapis.
the class InstanceAdminClientTest method updateInstanceExceptionTest.
@Test
public void updateInstanceExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockInstanceAdmin.addException(exception);
try {
Instance instance = Instance.newBuilder().build();
FieldMask fieldMask = FieldMask.newBuilder().build();
client.updateInstanceAsync(instance, fieldMask).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());
}
}
use of com.google.cloud.redis.v1.Instance in project java-spanner by googleapis.
the class InstanceAdminClientTest method createInstanceExceptionTest2.
@Test
public void createInstanceExceptionTest2() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockInstanceAdmin.addException(exception);
try {
String parent = "parent-995424086";
String instanceId = "instanceId902024336";
Instance instance = Instance.newBuilder().build();
client.createInstanceAsync(parent, instanceId, instance).get();
Assert.fail("No exception raised");
} catch (ExecutionException e) {
Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass());
InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause());
Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode());
}
}
use of com.google.cloud.redis.v1.Instance in project gapic-generator-java by googleapis.
the class AsyncRescheduleMaintenanceLRO method asyncRescheduleMaintenanceLRO.
public static void asyncRescheduleMaintenanceLRO() throws Exception {
// It may require modifications to work in your environment.
try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
RescheduleMaintenanceRequest request = RescheduleMaintenanceRequest.newBuilder().setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()).setScheduleTime(Timestamp.newBuilder().build()).build();
OperationFuture<Instance, Any> future = cloudRedisClient.rescheduleMaintenanceOperationCallable().futureCall(request);
// Do something.
Instance response = future.get();
}
}
Aggregations