Skip to content

Commit

Permalink
chore: Adding java IT diffs
Browse files Browse the repository at this point in the history
  • Loading branch information
ddixit14 committed Sep 29, 2022
1 parent 427df3a commit 6a5df4f
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 128 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 =
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Cluster> 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());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit 6a5df4f

Please sign in to comment.