Search in sources :

Example 86 with Instance

use of com.google.cloud.redis.v1beta1.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());
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) Instance(com.google.spanner.admin.instance.v1.Instance) StatusRuntimeException(io.grpc.StatusRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) FieldMask(com.google.protobuf.FieldMask) Test(org.junit.Test)

Example 87 with Instance

use of com.google.cloud.redis.v1beta1.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());
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) Instance(com.google.spanner.admin.instance.v1.Instance) StatusRuntimeException(io.grpc.StatusRuntimeException) ByteString(com.google.protobuf.ByteString) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 88 with Instance

use of com.google.cloud.redis.v1beta1.Instance in project gapic-generator-java by googleapis.

the class AsyncRescheduleMaintenance method asyncRescheduleMaintenance.

public static void asyncRescheduleMaintenance() 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();
        ApiFuture<Operation> future = cloudRedisClient.rescheduleMaintenanceCallable().futureCall(request);
        // Do something.
        Operation response = future.get();
    }
}
Also used : CloudRedisClient(com.google.cloud.redis.v1beta1.CloudRedisClient) RescheduleMaintenanceRequest(com.google.cloud.redis.v1beta1.RescheduleMaintenanceRequest) Operation(com.google.longrunning.Operation)

Example 89 with Instance

use of com.google.cloud.redis.v1beta1.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();
    }
}
Also used : CloudRedisClient(com.google.cloud.redis.v1beta1.CloudRedisClient) Instance(com.google.cloud.redis.v1beta1.Instance) RescheduleMaintenanceRequest(com.google.cloud.redis.v1beta1.RescheduleMaintenanceRequest) Any(com.google.protobuf.Any)

Example 90 with Instance

use of com.google.cloud.redis.v1beta1.Instance in project gapic-generator-java by googleapis.

the class SyncRescheduleMaintenance method syncRescheduleMaintenance.

public static void syncRescheduleMaintenance() 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();
        Instance response = cloudRedisClient.rescheduleMaintenanceAsync(request).get();
    }
}
Also used : CloudRedisClient(com.google.cloud.redis.v1beta1.CloudRedisClient) Instance(com.google.cloud.redis.v1beta1.Instance) RescheduleMaintenanceRequest(com.google.cloud.redis.v1beta1.RescheduleMaintenanceRequest)

Aggregations

Test (org.junit.Test)43 CloudRedisClient (com.google.cloud.redis.v1beta1.CloudRedisClient)42 Instance (com.google.cloud.redis.v1beta1.Instance)34 Instance (com.google.cloud.compute.v1.Instance)25 InstancesClient (com.google.cloud.compute.v1.InstancesClient)19 AbstractMessage (com.google.protobuf.AbstractMessage)17 ByteString (com.google.protobuf.ByteString)17 Operation (com.google.cloud.compute.v1.Operation)13 Instance (com.google.spanner.admin.instance.v1.Instance)11 Instance (com.google.bigtable.admin.v2.Instance)10 InsertInstanceRequest (com.google.cloud.compute.v1.InsertInstanceRequest)10 Operation (com.google.longrunning.Operation)10 AttachedDisk (com.google.cloud.compute.v1.AttachedDisk)9 Instance (com.google.cloud.notebooks.v1beta1.Instance)9 Any (com.google.protobuf.Any)8 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)7 FieldMask (com.google.protobuf.FieldMask)7 StatusRuntimeException (io.grpc.StatusRuntimeException)7 ArrayList (java.util.ArrayList)7 NetworkInterface (com.google.cloud.compute.v1.NetworkInterface)6