Skip to content

Commit 269a7ed

Browse files
Fixed test
1 parent 33989e0 commit 269a7ed

File tree

2 files changed

+8
-17
lines changed

2 files changed

+8
-17
lines changed

compute/cloud-client/src/test/java/compute/Util.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import com.google.cloud.compute.v1.Reservation;
3030
import com.google.cloud.compute.v1.ReservationsClient;
3131
import com.google.cloud.compute.v1.Snapshot;
32-
import com.google.cloud.compute.v1.StoragePool;
3332
import compute.deleteprotection.SetDeleteProtection;
3433
import compute.reservation.DeleteReservation;
3534
import java.io.IOException;
@@ -50,7 +49,7 @@ public abstract class Util {
5049
// resources
5150
// and delete the listed resources based on the timestamp.
5251

53-
private static final int DELETION_THRESHOLD_TIME_HOURS = 1;
52+
private static final int DELETION_THRESHOLD_TIME_MINUTES = 30;
5453
// comma separate list of zone names
5554
private static final String TEST_ZONES_NAME = "JAVA_DOCS_COMPUTE_TEST_ZONES";
5655
private static final String DEFAULT_ZONES = "us-central1-a,us-west1-a,asia-south1-a";
@@ -119,7 +118,7 @@ && isCreatedBeforeThresholdTime(instance.getCreationTimestamp())) {
119118

120119
public static boolean isCreatedBeforeThresholdTime(String timestamp) {
121120
return OffsetDateTime.parse(timestamp).toInstant()
122-
.isBefore(Instant.now().minus(DELETION_THRESHOLD_TIME_HOURS, ChronoUnit.HOURS));
121+
.isBefore(Instant.now().minus(DELETION_THRESHOLD_TIME_MINUTES, ChronoUnit.MINUTES));
123122
}
124123

125124
public static String getBase64EncodedKey() {
@@ -180,7 +179,7 @@ public static String getEnvVar(String envVarName, String defaultValue) {
180179
return val;
181180
}
182181

183-
// Delete reservation which starts with the given prefixToDelete and
182+
// Delete reservations which starts with the given prefixToDelete and
184183
// has creation timestamp >24 hours.
185184
public static void cleanUpExistingReservations(
186185
String prefixToDelete, String projectId, String zone)
@@ -216,12 +215,8 @@ public static boolean containPrefixToDeleteAndZone(
216215
containPrefixAndZone = ((Disk) resource).getName().contains(prefixToDelete)
217216
&& ((Disk) resource).getZone().contains(zone);
218217
}
219-
if (resource instanceof StoragePool) {
220-
containPrefixAndZone = ((StoragePool) resource).getName().contains(prefixToDelete)
221-
&& ((StoragePool) resource).getZone().contains(zone);
222-
}
223218
} catch (NullPointerException e) {
224-
System.err.println("Resource not found, skipping deletion:");
219+
System.out.println("Resource not found, skipping deletion:");
225220
}
226221
return containPrefixAndZone;
227222
}
@@ -237,7 +232,7 @@ public static boolean containPrefixToDelete(
237232
containPrefixToDelete = ((Snapshot) resource).getName().contains(prefixToDelete);
238233
}
239234
} catch (NullPointerException e) {
240-
System.err.println("Resource not found, skipping deletion:");
235+
System.out.println("Resource not found, skipping deletion:");
241236
}
242237
return containPrefixToDelete;
243238
}

compute/cloud-client/src/test/java/compute/reservation/ReservationIT.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,16 @@
3939
import java.util.concurrent.TimeUnit;
4040
import java.util.concurrent.TimeoutException;
4141
import org.junit.Assert;
42-
import org.junit.FixMethodOrder;
4342
import org.junit.jupiter.api.AfterAll;
4443
import org.junit.jupiter.api.Assertions;
4544
import org.junit.jupiter.api.BeforeAll;
4645
import org.junit.jupiter.api.Test;
4746
import org.junit.jupiter.api.Timeout;
4847
import org.junit.runner.RunWith;
4948
import org.junit.runners.JUnit4;
50-
import org.junit.runners.MethodSorters;
5149

5250
@RunWith(JUnit4.class)
5351
@Timeout(value = 25, unit = TimeUnit.MINUTES)
54-
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
5552
public class ReservationIT {
5653

5754
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
@@ -104,7 +101,6 @@ public static void setUp()
104101
Util.cleanUpExistingInstanceTemplates("test-global-inst-temp-", PROJECT_ID);
105102
Util.cleanUpExistingRegionalInstanceTemplates("test-regional-inst-temp-", PROJECT_ID, ZONE);
106103
Util.cleanUpExistingReservations("test-reserv-", PROJECT_ID, ZONE);
107-
TimeUnit.MINUTES.sleep(5);
108104

109105
// Create instance template with GLOBAL location.
110106
CreateInstanceTemplate.createInstanceTemplate(PROJECT_ID, GLOBAL_INSTANCE_TEMPLATE_NAME);
@@ -163,7 +159,7 @@ public static void cleanup()
163159
}
164160

165161
@Test
166-
public void firstCreateReservationWithGlobalInstanceTemplateTest()
162+
public void testCreateReservationWithGlobalInstanceTemplate()
167163
throws IOException, ExecutionException, InterruptedException, TimeoutException {
168164
CreateReservationForInstanceTemplate.createReservationForInstanceTemplate(
169165
PROJECT_ID, RESERVATION_NAME_GLOBAL,
@@ -176,7 +172,7 @@ public void firstCreateReservationWithGlobalInstanceTemplateTest()
176172
}
177173

178174
@Test
179-
public void firstCreateReservationWithRegionInstanceTemplateTest()
175+
public void testCreateReservationWithRegionInstanceTemplate()
180176
throws IOException, ExecutionException, InterruptedException, TimeoutException {
181177
CreateReservationForInstanceTemplate.createReservationForInstanceTemplate(
182178
PROJECT_ID, RESERVATION_NAME_REGIONAL, REGIONAL_INSTANCE_TEMPLATE_URI,
@@ -196,7 +192,7 @@ public void testCreateInstanceNotConsumeReservation()
196192
CreateInstanceNotConsumeReservation.createInstanceNotConsumeReservation(
197193
PROJECT_ID, ZONE, INSTANCE_NOT_CONSUME_RESERVATION_NAME, MACHINE_TYPE);
198194

199-
// Verify that the instance was created with the correct reservation and consumeReservationType
195+
// Verify that the instance was created with the correct consumeReservationType
200196
Instance instance = instancesClient.get(
201197
PROJECT_ID, ZONE, INSTANCE_NOT_CONSUME_RESERVATION_NAME);
202198

0 commit comments

Comments
 (0)