diff --git a/java-compute/google-cloud-compute/src/test/java/com/google/cloud/compute/v1/integration/BaseTest.java b/java-compute/google-cloud-compute/src/test/java/com/google/cloud/compute/v1/integration/BaseTest.java index 1dae34ce376f..784429c5e05f 100644 --- a/java-compute/google-cloud-compute/src/test/java/com/google/cloud/compute/v1/integration/BaseTest.java +++ b/java-compute/google-cloud-compute/src/test/java/com/google/cloud/compute/v1/integration/BaseTest.java @@ -22,9 +22,9 @@ public class BaseTest { protected static final String DEFAULT_PROJECT = ServiceOptions.getDefaultProjectId(); protected static final String DEFAULT_ZONE = "us-central1-a"; protected static final String DEFAULT_REGION = "us-west1"; - protected static final String COMPUTE_PREFIX = "it-test-compute"; + protected static final String COMPUTE_PREFIX = "gapic-"; public static String generateRandomName(String placeholder) { - return COMPUTE_PREFIX + "-" + placeholder + "-" + UUID.randomUUID().toString().substring(0, 8); + return COMPUTE_PREFIX + placeholder + UUID.randomUUID().toString().substring(0, 8); } } diff --git a/java-compute/google-cloud-compute/src/test/java/com/google/cloud/compute/v1/integration/ITAddressesTest.java b/java-compute/google-cloud-compute/src/test/java/com/google/cloud/compute/v1/integration/ITAddressesTest.java index d1ac97ce8ff0..fe7475c2c175 100644 --- a/java-compute/google-cloud-compute/src/test/java/com/google/cloud/compute/v1/integration/ITAddressesTest.java +++ b/java-compute/google-cloud-compute/src/test/java/com/google/cloud/compute/v1/integration/ITAddressesTest.java @@ -35,7 +35,6 @@ import org.junit.Ignore; import org.junit.Test; -@Ignore("Address insertion is flaky. https://github.com/googleapis/google-cloud-java/issues/8552") public class ITAddressesTest extends BaseTest { private static List
addresses; @@ -58,7 +57,7 @@ public void setUpMethod() { @AfterClass public static void tearDown() throws ExecutionException, InterruptedException { for (Address address : addresses) { - addressesClient.deleteAsync(DEFAULT_PROJECT, DEFAULT_REGION, address.getName()); + addressesClient.deleteAsync(DEFAULT_PROJECT, DEFAULT_REGION, address.getName()).get(); } addressesClient.close(); } @@ -124,7 +123,7 @@ private void insertAddress(String description) { .insertAsync(DEFAULT_PROJECT, DEFAULT_REGION, address) .get(60, TimeUnit.SECONDS); } catch (InterruptedException | ExecutionException | TimeoutException e) { - fail("Insert operation failed."); + fail("Insert operation failed: " + e.getMessage()); } addresses.add(address); } diff --git a/java-compute/google-cloud-compute/src/test/java/com/google/cloud/compute/v1/integration/ITSmokeInstancesTest.java b/java-compute/google-cloud-compute/src/test/java/com/google/cloud/compute/v1/integration/ITSmokeInstancesTest.java index 756c097dadbb..c19ba63ea4e7 100644 --- a/java-compute/google-cloud-compute/src/test/java/com/google/cloud/compute/v1/integration/ITSmokeInstancesTest.java +++ b/java-compute/google-cloud-compute/src/test/java/com/google/cloud/compute/v1/integration/ITSmokeInstancesTest.java @@ -72,7 +72,6 @@ public static void setUp() throws IOException { instances = new ArrayList<>(); InstancesSettings instanceSettings = InstancesSettings.newBuilder().build(); instancesClient = InstancesClient.create(instanceSettings); - Util.cleanUpComputeInstances(instancesClient, DEFAULT_PROJECT, DEFAULT_ZONE, COMPUTE_PREFIX); } @@ -84,7 +83,7 @@ public void setUpMethod() { @AfterClass public static void tearDown() throws ExecutionException, InterruptedException { for (Instance instance : instances) { - instancesClient.deleteAsync(DEFAULT_PROJECT, DEFAULT_ZONE, instance.getName()); + instancesClient.deleteAsync(DEFAULT_PROJECT, DEFAULT_ZONE, instance.getName()).get(); } instancesClient.close(); } diff --git a/java-compute/google-cloud-compute/src/test/java/com/google/cloud/compute/v1/integration/Util.java b/java-compute/google-cloud-compute/src/test/java/com/google/cloud/compute/v1/integration/Util.java index 3742a18ec313..1a65c4e7e6af 100644 --- a/java-compute/google-cloud-compute/src/test/java/com/google/cloud/compute/v1/integration/Util.java +++ b/java-compute/google-cloud-compute/src/test/java/com/google/cloud/compute/v1/integration/Util.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 Google LLC + * Copyright 2021 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.google.cloud.compute.v1.integration; import com.google.cloud.compute.v1.Address; @@ -30,9 +29,9 @@ public class Util { // Cleans existing test resources if any. - private static final int DELETION_THRESHOLD_TIME_HOURS = 2; + private static final int DELETION_THRESHOLD_TIME_HOURS = 24; - /** Bring down any instances that are older than 2 hours */ + /** Bring down any instances that are older than 24 hours */ public static void cleanUpComputeInstances( InstancesClient instancesClient, String project, String zone, String prefix) { ListPagedResponse listPagedResponse = instancesClient.list(project, zone); @@ -50,7 +49,7 @@ public static void cleanUpComputeInstances( } } - /** Bring down any addresses that are older than 2 hours */ + /** Bring down any addresses that are older than 24 hours */ public static void cleanUpComputeAddresses( AddressesClient addressesClient, String project, String region, String prefix) { AddressesClient.ListPagedResponse listPagedResponse = addressesClient.list(project, region); diff --git a/java-container/google-cloud-container/src/test/java/com/google/cloud/container/v1/it/ITSystemTest.java b/java-container/google-cloud-container/src/test/java/com/google/cloud/container/v1/it/ITSystemTest.java index 86edf8211d18..083330ac8959 100644 --- a/java-container/google-cloud-container/src/test/java/com/google/cloud/container/v1/it/ITSystemTest.java +++ b/java-container/google-cloud-container/src/test/java/com/google/cloud/container/v1/it/ITSystemTest.java @@ -26,7 +26,6 @@ import com.google.container.v1.ListOperationsResponse; import com.google.container.v1.NodePool; import com.google.container.v1.Operation; -import com.google.container.v1.Operation.Status; import com.google.container.v1.ServerConfig; import java.util.List; import java.util.UUID; @@ -44,11 +43,10 @@ public class ITSystemTest { private static final Logger LOG = Logger.getLogger(ITSystemTest.class.getName()); private static final String PROJECT_ID = ServiceOptions.getDefaultProjectId(); private static final String ZONE = "us-central1-a"; - private static final String CONTAINER_PREFIX = "it-test-container"; private static final String CLUSTER_NAME = - CONTAINER_PREFIX + "-cluster-" + UUID.randomUUID().toString().substring(0, 8); + "test-cluster-" + UUID.randomUUID().toString().substring(0, 8); private static final String NODE_POOL_NAME = - CONTAINER_PREFIX + "-node-pool-" + UUID.randomUUID().toString().substring(0, 8); + "test-node-pool-" + UUID.randomUUID().toString().substring(0, 8); private static final String DETAIL = "test-detail"; private static final String STATUS_MESSAGE = "test-status-message"; private static final String SELF_LINK = @@ -57,15 +55,15 @@ public class ITSystemTest { + "/zones/us-central1-a/clusters/" + CLUSTER_NAME; private static final String NODE_POOL_SEL_LINK = SELF_LINK + "/nodePools/" + NODE_POOL_NAME; - private static final String NETWORK = "java-container-network"; + private static final String NETWORK = "java-container-network-tests"; private static final int INITIAL_NODE_COUNT = 1; @BeforeClass public static void beforeClass() throws Exception { client = ClusterManagerClient.create(); - Util.cleanUpExistingInstanceCluster(client, PROJECT_ID, ZONE, CONTAINER_PREFIX); + Util.cleanUpExistingInstanceCluster(PROJECT_ID, ZONE, client); - /* create node pool* */ + /** create node pool* */ NodePool nodePool = NodePool.newBuilder() .setInitialNodeCount(INITIAL_NODE_COUNT) @@ -74,7 +72,7 @@ public static void beforeClass() throws Exception { .setStatusMessage(STATUS_MESSAGE) .build(); - /* create cluster */ + /** create cluster */ Cluster cluster = Cluster.newBuilder() .setName(CLUSTER_NAME) @@ -86,20 +84,13 @@ public static void beforeClass() throws Exception { .setNetwork(NETWORK) .build(); operation = client.createCluster(PROJECT_ID, ZONE, cluster); - - Operation response = client.getOperation(PROJECT_ID, ZONE, operation.getName()); - // Busy Wait for one minute at a time until Cluster CREATE operation is complete - while (response.getStatus() != Status.DONE) { - LOG.info(String.format("Cluster CREATE Operation Status: %s", response.getStatus())); - Thread.sleep(TimeUnit.MINUTES.toMillis(1)); - response = client.getOperation(PROJECT_ID, ZONE, operation.getName()); - } LOG.info(String.format("%s cluster created successfully.", CLUSTER_NAME)); LOG.info(String.format("%s node pool created successfully.", NODE_POOL_NAME)); } @AfterClass - public static void afterClass() { + public static void afterClass() throws Exception { + Thread.sleep(TimeUnit.MINUTES.toMillis(5)); client.deleteCluster(PROJECT_ID, ZONE, CLUSTER_NAME); LOG.info(String.format("%s cluster deleted successfully.", CLUSTER_NAME)); client.close(); diff --git a/java-container/google-cloud-container/src/test/java/com/google/cloud/container/v1/it/Util.java b/java-container/google-cloud-container/src/test/java/com/google/cloud/container/v1/it/Util.java index d6ead4cb8b0f..426bd42fabc4 100644 --- a/java-container/google-cloud-container/src/test/java/com/google/cloud/container/v1/it/Util.java +++ b/java-container/google-cloud-container/src/test/java/com/google/cloud/container/v1/it/Util.java @@ -19,26 +19,27 @@ import com.google.cloud.container.v1.ClusterManagerClient; import com.google.container.v1.Cluster; import com.google.container.v1.ListClustersResponse; +import java.io.IOException; import java.time.Instant; import java.time.OffsetDateTime; import java.time.temporal.ChronoUnit; import java.util.List; +import java.util.concurrent.ExecutionException; public class Util { - // Cleans existing test resources if any. - private static final int DELETION_THRESHOLD_TIME_HOURS = 2; + private static final int DELETION_THRESHOLD_TIME_HOURS = 24; - /** tear down any clusters that are older than 2 hours * */ + /** tear down any clusters that are older than 24 hours * */ public static void cleanUpExistingInstanceCluster( - ClusterManagerClient client, String projectId, String zone, String prefix) { + String projectId, String zone, ClusterManagerClient client) + throws IOException, ExecutionException, InterruptedException { ListClustersResponse clustersResponse = client.listClusters(projectId, zone); List