Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix build #219

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 0 additions & 25 deletions src/test/java/com/google/cloud/compute/v1/it/BaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.google.auth.Credentials;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.cloud.ServiceOptions;
import com.google.cloud.Timestamp;
import com.google.cloud.compute.v1.DiskTypeSettings;
import com.google.cloud.compute.v1.Firewall;
import com.google.cloud.compute.v1.FirewallClient;
Expand All @@ -45,7 +44,6 @@
import com.google.cloud.compute.v1.ZoneOperationSettings;
import com.google.common.collect.Lists;
import java.io.IOException;
import java.util.Calendar;
import java.util.List;
import org.junit.AfterClass;
import org.junit.BeforeClass;
Expand Down Expand Up @@ -140,27 +138,4 @@ static void cleanUpNetwork(Network network) throws IOException {

waitForOperation(networkClient.deleteNetwork(network.getSelfLink()));
}

static void cleanUpNetworks() throws IOException {
NetworkSettings networkSettings =
NetworkSettings.newBuilder().setCredentialsProvider(credentialsProvider).build();
NetworkClient networkClient = NetworkClient.create(networkSettings);

// clean up resources older than 1 hour
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.HOUR_OF_DAY, -1);
Timestamp cutoff = Timestamp.of(calendar.getTime());
Comment on lines -150 to -152
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This cleanUpNetworks was here to delete old networks that are not cleaned up in previous test runs. We have a hard limit of ~10 networks on the project which cannot be changed.


// clean up old networks
List<Network> networks =
Lists.newArrayList(networkClient.listNetworks(DEFAULT_PROJECT).iterateAll());
for (Network network : networks) {
if (network.getName().startsWith("test-")) {
Timestamp createdAt = Timestamp.parseTimestamp(network.getCreationTimestamp());
if (createdAt.compareTo(cutoff) < 0) {
cleanUpNetwork(network);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ public class ITFirewallTest extends BaseTest {

@BeforeClass
public static void setUp() throws IOException {
cleanUpNetworks();

FirewallSettings firewallSettings =
FirewallSettings.newBuilder().setCredentialsProvider(credentialsProvider).build();
firewallClient = FirewallClient.create(firewallSettings);
Expand Down Expand Up @@ -94,6 +92,7 @@ public static void tearDown() throws IOException {
cleanUpNetwork(firewallNetwork);
}

resourcesToCleanUp.clear();
firewallClient.close();
networkClient.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ public class ITNetworkTest extends BaseTest {

@BeforeClass
public static void setUp() throws IOException {
cleanUpNetworks();

NetworkSettings networkSettings =
NetworkSettings.newBuilder().setCredentialsProvider(credentialsProvider).build();
networkClient = NetworkClient.create(networkSettings);
Expand Down