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..cbe07e4ee3bd 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,8 @@ 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"; public static String generateRandomName(String placeholder) { - return COMPUTE_PREFIX + "-" + placeholder + "-" + UUID.randomUUID().toString().substring(0, 8); + return "gapic-" + 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 5c442ea8fe66..f36ffdb304cd 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 @@ -46,7 +46,6 @@ public static void setUp() throws IOException { addresses = new ArrayList<>(); AddressesSettings addressesSettings = AddressesSettings.newBuilder().build(); addressesClient = AddressesClient.create(addressesSettings); - Util.cleanUpComputeAddresses(addressesClient, DEFAULT_PROJECT, DEFAULT_REGION, COMPUTE_PREFIX); } @Before @@ -57,7 +56,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(); } 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..33bec397c973 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,8 +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); } @Before @@ -84,7 +82,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 deleted file mode 100644 index 50a51a509a19..000000000000 --- a/java-compute/google-cloud-compute/src/test/java/com/google/cloud/compute/v1/integration/Util.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.google.cloud.compute.v1.integration; - -import com.google.cloud.compute.v1.Address; -import com.google.cloud.compute.v1.AddressesClient; -import com.google.cloud.compute.v1.DeleteInstanceRequest; -import com.google.cloud.compute.v1.Instance; -import com.google.cloud.compute.v1.InstancesClient; -import com.google.cloud.compute.v1.InstancesClient.ListPagedResponse; -import java.time.Instant; -import java.time.OffsetDateTime; -import java.time.ZonedDateTime; -import java.time.temporal.ChronoUnit; - -public class Util { - - // Cleans existing test resources if any. - private static final int DELETION_THRESHOLD_TIME_HOURS = 24; - - /** 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); - for (Instance instance : listPagedResponse.iterateAll()) { - if (isCreatedBeforeThresholdTime( - ZonedDateTime.parse(instance.getCreationTimestamp()).toInstant()) - && instance.getName().startsWith(prefix)) { - instancesClient.deleteAsync( - DeleteInstanceRequest.newBuilder() - .setInstance(instance.getName()) - .setProject(project) - .setZone(zone) - .build()); - } - } - } - - /** 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); - for (Address address : listPagedResponse.iterateAll()) { - if (isCreatedBeforeThresholdTime(address.getCreationTimestamp()) - && address.getName().startsWith(prefix)) { - addressesClient.deleteAsync(project, region, address.getName()); - } - } - } - - private static boolean isCreatedBeforeThresholdTime(Instant instant) { - return instant.isBefore(Instant.now().minus(DELETION_THRESHOLD_TIME_HOURS, ChronoUnit.HOURS)); - } - - private static boolean isCreatedBeforeThresholdTime(String timestamp) { - return OffsetDateTime.parse(timestamp) - .toInstant() - .isBefore(Instant.now().minus(DELETION_THRESHOLD_TIME_HOURS, ChronoUnit.HOURS)); - } -} 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 5348c06b811e..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 = 24; /** 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 clusters = clustersResponse.getClustersList(); for (Cluster cluster : clusters) { - if (isCreatedBeforeThresholdTime(cluster.getCreateTime()) - && cluster.getName().startsWith(prefix)) { + if (isCreatedBeforeThresholdTime(cluster.getCreateTime())) { client.deleteCluster(projectId, zone, cluster.getName()); } } diff --git a/java-notebooks/google-cloud-notebooks/src/test/java/com/google/cloud/notebooks/v1beta1/it/ITNotebookServiceClientTest.java b/java-notebooks/google-cloud-notebooks/src/test/java/com/google/cloud/notebooks/v1beta1/it/ITNotebookServiceClientTest.java index a394b48791e8..5f56091c9e93 100644 --- a/java-notebooks/google-cloud-notebooks/src/test/java/com/google/cloud/notebooks/v1beta1/it/ITNotebookServiceClientTest.java +++ b/java-notebooks/google-cloud-notebooks/src/test/java/com/google/cloud/notebooks/v1beta1/it/ITNotebookServiceClientTest.java @@ -53,9 +53,8 @@ public class ITNotebookServiceClientTest { private static final String PARENT = "projects/" + PROJECT_ID + "/locations/" + LOCATION; private static NotebookServiceClient client; private static final String ID = UUID.randomUUID().toString().substring(0, 8); - private static final String NOTEBOOK_PREFIX = "it-test-notebook"; - private static final String NOTEBOOK_INSTANCE_ID = NOTEBOOK_PREFIX + "-instance-id-" + ID; - private static final String ENVIRONMENT_ID = NOTEBOOK_PREFIX + "-environment-id-" + ID; + private static final String NOTEBOOK_INSTANCE_ID = "test-notebook-instance-id-" + ID; + private static final String ENVIRONMENT_ID = "test-environment-id-" + ID; private static final String INSTANCE_NAME = PARENT + "/instances/" + NOTEBOOK_INSTANCE_ID; private static final String ENVIRONMENT_NAME = PARENT + "/environments/" + ENVIRONMENT_ID; private static Instance expectedNotebookInstance; @@ -67,8 +66,6 @@ public class ITNotebookServiceClientTest { public static void setUp() throws IOException, ExecutionException, InterruptedException { // Create Test Notebook Instance client = NotebookServiceClient.create(); - Util.cleanUpNotebookInstances(client, PARENT, NOTEBOOK_PREFIX); - ContainerImage containerImage = ContainerImage.newBuilder().setRepository(FieldBehavior.OPTIONAL.name()).build(); diff --git a/java-notebooks/google-cloud-notebooks/src/test/java/com/google/cloud/notebooks/v1beta1/it/Util.java b/java-notebooks/google-cloud-notebooks/src/test/java/com/google/cloud/notebooks/v1beta1/it/Util.java deleted file mode 100644 index 8ad349fa6985..000000000000 --- a/java-notebooks/google-cloud-notebooks/src/test/java/com/google/cloud/notebooks/v1beta1/it/Util.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.google.cloud.notebooks.v1beta1.it; - -import com.google.cloud.notebooks.v1beta1.DeleteInstanceRequest; -import com.google.cloud.notebooks.v1beta1.Instance; -import com.google.cloud.notebooks.v1beta1.ListInstancesRequest; -import com.google.cloud.notebooks.v1beta1.NotebookServiceClient; -import com.google.cloud.notebooks.v1beta1.NotebookServiceClient.ListInstancesPagedResponse; -import com.google.protobuf.util.Timestamps; -import java.time.Instant; -import java.time.temporal.ChronoUnit; - -public class Util { - - // Cleans existing test resources if any. - private static final int DELETION_THRESHOLD_TIME_HOURS = 24; - - /** Bring down any instances that are older than 24 hours */ - public static void cleanUpNotebookInstances( - NotebookServiceClient client, String parent, String prefix) { - ListInstancesPagedResponse listInstancesPagedResponse = - client.listInstances(ListInstancesRequest.newBuilder().setParent(parent).build()); - for (Instance instance : listInstancesPagedResponse.iterateAll()) { - if (isCreatedBeforeThresholdTime( - Instant.ofEpochMilli(Timestamps.toMillis(instance.getCreateTime()))) - && instance.getName().startsWith(prefix)) { - client.deleteInstanceAsync( - DeleteInstanceRequest.newBuilder().setName(instance.getName()).build()); - } - } - } - - private static boolean isCreatedBeforeThresholdTime(Instant instant) { - return instant.isBefore(Instant.now().minus(DELETION_THRESHOLD_TIME_HOURS, ChronoUnit.HOURS)); - } -} diff --git a/java-vision/google-cloud-vision/src/test/java/com/google/cloud/vision/it/ITSystemTest.java b/java-vision/google-cloud-vision/src/test/java/com/google/cloud/vision/it/ITSystemTest.java index 35837ecf52a6..517fc799a122 100644 --- a/java-vision/google-cloud-vision/src/test/java/com/google/cloud/vision/it/ITSystemTest.java +++ b/java-vision/google-cloud-vision/src/test/java/com/google/cloud/vision/it/ITSystemTest.java @@ -99,8 +99,8 @@ public class ITSystemTest { private static final String ID = UUID.randomUUID().toString().substring(0, 8); // GraalVM native-image test uses the project root as working directory, not google-cloud-vision private static final String RESOURCES = - Files.exists(Paths.get("java-vision", "google-cloud-vision", "src", "test", "resources")) - ? "java-vision/google-cloud-vision/src/test/resources/" + Files.exists(Paths.get("google-cloud-vision", "src", "test", "resources")) + ? "google-cloud-vision/src/test/resources/" : "src/test/resources/"; private static final String GCS_BUCKET_ENV_VAR = "GOOGLE_CLOUD_TESTS_VISION_BUCKET";