Search in sources :

Example 96 with Instance

use of com.google.cloud.redis.v1.Instance in project java-compute by googleapis.

the class ITSmokeInstancesTest method testDefaultResource.

@Test
public void testDefaultResource() throws InterruptedException {
    Instance instanceResource = Instance.newBuilder().build();
    try {
        instancesClient.insertAsync(DEFAULT_PROJECT, DEFAULT_ZONE, instanceResource).get();
        fail("Did not catch the exception");
    } catch (ExecutionException ex) {
        String message = "com.google.api.gax.rpc.InvalidArgumentException: Bad Request";
        Assert.assertEquals(message, ex.getMessage());
    }
}
Also used : Instance(com.google.cloud.compute.v1.Instance) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 97 with Instance

use of com.google.cloud.redis.v1.Instance in project java-compute by googleapis.

the class ITSmokeInstancesTest method testPatch.

@Test
public void testPatch() throws ExecutionException, InterruptedException {
    Instance resultInstance = insertInstance();
    Assert.assertFalse(resultInstance.getShieldedInstanceConfig().getEnableSecureBoot());
    instancesClient.stopAsync(DEFAULT_PROJECT, DEFAULT_ZONE, INSTANCE).get();
    ShieldedInstanceConfig shieldedInstanceConfigResource = ShieldedInstanceConfig.newBuilder().setEnableSecureBoot(true).build();
    instancesClient.updateShieldedInstanceConfigAsync(DEFAULT_PROJECT, DEFAULT_ZONE, INSTANCE, shieldedInstanceConfigResource).get();
    Instance updInstance = getInstance();
    Assert.assertTrue(updInstance.getShieldedInstanceConfig().getEnableSecureBoot());
}
Also used : Instance(com.google.cloud.compute.v1.Instance) ShieldedInstanceConfig(com.google.cloud.compute.v1.ShieldedInstanceConfig) Test(org.junit.Test)

Example 98 with Instance

use of com.google.cloud.redis.v1.Instance in project java-compute by googleapis.

the class ITSmokeInstancesTest method testResizeGroupToZero.

@Test
public void testResizeGroupToZero() throws IOException, ExecutionException, InterruptedException {
    // We test here: 1)set body field to zero
    // 2)set query param to zero
    List<String> instanceGroupManagersToClean = new ArrayList<>();
    List<String> instanceTemplatesToClean = new ArrayList<>();
    InstanceTemplatesClient instanceTemplatesClient = InstanceTemplatesClient.create();
    InstanceGroupManagersClient instanceGroupManagersClient = InstanceGroupManagersClient.create();
    String templateName = generateRandomName("template");
    String instanceGroupManagerName = generateRandomName("igm");
    Instance instance = insertInstance();
    InstanceTemplate instanceTemplate = InstanceTemplate.newBuilder().setSourceInstance(instance.getSelfLink()).setName(templateName).build();
    Operation insertOperation = instanceTemplatesClient.insertAsync(DEFAULT_PROJECT, instanceTemplate).get();
    instanceTemplatesToClean.add(templateName);
    try {
        InstanceGroupManager instanceGroupManager = InstanceGroupManager.newBuilder().setName(instanceGroupManagerName).setBaseInstanceName("java-gapic").setInstanceTemplate(insertOperation.getTargetLink()).setTargetSize(0).build();
        instanceGroupManagersClient.insertAsync(DEFAULT_PROJECT, DEFAULT_ZONE, instanceGroupManager).get();
        instanceGroupManagersToClean.add(instanceGroupManagerName);
        InstanceGroupManager fetched = instanceGroupManagersClient.get(DEFAULT_PROJECT, DEFAULT_ZONE, instanceGroupManagerName);
        Assert.assertEquals(0, fetched.getTargetSize());
        instanceGroupManagersClient.resizeAsync(DEFAULT_PROJECT, DEFAULT_ZONE, instanceGroupManagerName, 1).get();
        InstanceGroupManager resizedIGM = instanceGroupManagersClient.get(DEFAULT_PROJECT, DEFAULT_ZONE, instanceGroupManagerName);
        Assert.assertEquals(1, resizedIGM.getTargetSize());
        instanceGroupManagersClient.resizeAsync(DEFAULT_PROJECT, DEFAULT_ZONE, instanceGroupManagerName, 0).get();
        InstanceGroupManager instanceGroupManagerResized = instanceGroupManagersClient.get(DEFAULT_PROJECT, DEFAULT_ZONE, instanceGroupManagerName);
        Assert.assertEquals(0, instanceGroupManagerResized.getTargetSize());
    } finally {
        for (String name : instanceGroupManagersToClean) {
            instanceGroupManagersClient.deleteAsync(DEFAULT_PROJECT, DEFAULT_ZONE, name).get();
        }
        for (String name : instanceTemplatesToClean) {
            instanceTemplatesClient.deleteAsync(DEFAULT_PROJECT, name).get();
        }
    }
}
Also used : InstanceGroupManager(com.google.cloud.compute.v1.InstanceGroupManager) InstanceGroupManagersClient(com.google.cloud.compute.v1.InstanceGroupManagersClient) Instance(com.google.cloud.compute.v1.Instance) ArrayList(java.util.ArrayList) Operation(com.google.cloud.compute.v1.Operation) InstanceTemplatesClient(com.google.cloud.compute.v1.InstanceTemplatesClient) InstanceTemplate(com.google.cloud.compute.v1.InstanceTemplate) Test(org.junit.Test)

Example 99 with Instance

use of com.google.cloud.redis.v1.Instance in project java-compute by googleapis.

the class ITSmokeInstancesTest method testAggregatedList.

@Test
public void testAggregatedList() throws ExecutionException, InterruptedException {
    insertInstance();
    boolean presented = false;
    InstancesClient.AggregatedListPagedResponse response = instancesClient.aggregatedList(DEFAULT_PROJECT);
    for (Map.Entry<String, InstancesScopedList> entry : response.iterateAll()) {
        if (entry.getKey().equals("zones/" + DEFAULT_ZONE)) {
            for (Instance instance : entry.getValue().getInstancesList()) {
                if (instance.getName().equals(INSTANCE)) {
                    presented = true;
                    assertInstanceDetails(instance);
                }
            }
        }
    }
    Assert.assertTrue(presented);
}
Also used : InstancesScopedList(com.google.cloud.compute.v1.InstancesScopedList) Instance(com.google.cloud.compute.v1.Instance) InstancesClient(com.google.cloud.compute.v1.InstancesClient) Map(java.util.Map) Test(org.junit.Test)

Example 100 with Instance

use of com.google.cloud.redis.v1.Instance in project java-compute by googleapis.

the class ITSmokeInstancesTest method testUpdateInstanceDescToEmpty.

@Test
public void testUpdateInstanceDescToEmpty() throws ExecutionException, InterruptedException {
    // We test here: 1)set body field to an empty string
    // 2)unset body field
    Instance resultInstance = insertInstance();
    Assert.assertEquals("test", resultInstance.getDescription());
    Assert.assertEquals(0, resultInstance.getScheduling().getMinNodeCpus());
    Instance descInstance = resultInstance.toBuilder().setDescription("").build();
    instancesClient.updateAsync(DEFAULT_PROJECT, DEFAULT_ZONE, INSTANCE, descInstance).get();
    Instance updated = getInstance();
    assertInstanceDetails(updated);
    Assert.assertEquals("", updated.getDescription());
    Assert.assertEquals(0, resultInstance.getScheduling().getMinNodeCpus());
}
Also used : Instance(com.google.cloud.compute.v1.Instance) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)41 Instance (com.google.cloud.redis.v1beta1.Instance)34 CloudRedisClient (com.google.cloud.redis.v1beta1.CloudRedisClient)30 Instance (com.google.cloud.compute.v1.Instance)25 InstancesClient (com.google.cloud.compute.v1.InstancesClient)19 ByteString (com.google.protobuf.ByteString)17 AbstractMessage (com.google.protobuf.AbstractMessage)15 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 AttachedDisk (com.google.cloud.compute.v1.AttachedDisk)9 Instance (com.google.cloud.notebooks.v1beta1.Instance)9 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)7 Any (com.google.protobuf.Any)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 Operation (com.google.longrunning.Operation)6