1616
1717package compute .reservation ;
1818
19- import static com .google .cloud .compute .v1 .ReservationAffinity .ConsumeReservationType .NO_RESERVATION ;
2019import static com .google .common .truth .Truth .assertThat ;
2120import static com .google .common .truth .Truth .assertWithMessage ;
2221
2322import com .google .api .gax .rpc .NotFoundException ;
24- import com .google .cloud .compute .v1 .Instance ;
25- import com .google .cloud .compute .v1 .InstancesClient ;
2623import com .google .cloud .compute .v1 .Reservation ;
2724import com .google .cloud .compute .v1 .ReservationsClient ;
2825import compute .CreateInstanceTemplate ;
2926import compute .CreateRegionalInstanceTemplate ;
30- import compute .DeleteInstance ;
3127import compute .DeleteInstanceTemplate ;
3228import compute .DeleteRegionalInstanceTemplate ;
3329import compute .Util ;
@@ -55,7 +51,6 @@ public class ReservationIT {
5551 private static final String ZONE = "us-west1-a" ;
5652 private static final String REGION = ZONE .substring (0 , ZONE .lastIndexOf ('-' ));
5753 private static ReservationsClient reservationsClient ;
58- private static InstancesClient instancesClient ;
5954 private static String RESERVATION_NAME_GLOBAL ;
6055 private static String RESERVATION_NAME_REGIONAL ;
6156 private static String GLOBAL_INSTANCE_TEMPLATE_URI ;
@@ -66,11 +61,7 @@ public class ReservationIT {
6661 private static final String REGIONAL_INSTANCE_TEMPLATE_NAME =
6762 "test-regional-inst-temp-" + javaVersion + "-"
6863 + UUID .randomUUID ().toString ().substring (0 , 8 );
69- private static final String INSTANCE_NOT_CONSUME_RESERVATION_NAME =
70- "test-instance-not-consume-" + javaVersion + "-"
71- + UUID .randomUUID ().toString ().substring (0 , 8 );
7264 private static final int NUMBER_OF_VMS = 3 ;
73- private static final String MACHINE_TYPE = "n2-standard-32" ;
7465
7566 // Check if the required environment variables are set.
7667 public static void requireEnvVar (String envVarName ) {
@@ -89,7 +80,6 @@ public static void setUp()
8980
9081 // Cleanup existing stale resources.
9182 Util .cleanUpExistingInstanceTemplates ("test-global-inst-temp-" + javaVersion , PROJECT_ID );
92- Util .cleanUpExistingInstanceTemplates ("test-instance-not-consume-" + javaVersion , PROJECT_ID );
9383 Util .cleanUpExistingRegionalInstanceTemplates (
9484 "test-regional-inst-temp-" + javaVersion , PROJECT_ID , ZONE );
9585 Util .cleanUpExistingReservations (
@@ -109,16 +99,6 @@ public static void setUp()
10999 String .format ("projects/%s/regions/%s/instanceTemplates/%s" ,
110100 PROJECT_ID , REGION , REGIONAL_INSTANCE_TEMPLATE_NAME );
111101
112- // Initialize the clients once for all tests
113- reservationsClient = ReservationsClient .create ();
114- instancesClient = InstancesClient .create ();
115-
116- // Cleanup existing stale resources.
117- Util .cleanUpExistingInstances ("test-instance-" , PROJECT_ID , ZONE );
118- Util .cleanUpExistingInstanceTemplates ("test-global-inst-temp-" , PROJECT_ID );
119- Util .cleanUpExistingRegionalInstanceTemplates ("test-regional-inst-temp-" , PROJECT_ID , ZONE );
120- Util .cleanUpExistingReservations ("test-reserv-" , PROJECT_ID , ZONE );
121-
122102 // Create instance template with GLOBAL location.
123103 CreateInstanceTemplate .createInstanceTemplate (PROJECT_ID , GLOBAL_INSTANCE_TEMPLATE_NAME );
124104 assertThat (stdOut .toString ())
@@ -152,9 +132,6 @@ public static void cleanup()
152132 .contains ("Instance template deletion operation status for "
153133 + REGIONAL_INSTANCE_TEMPLATE_NAME );
154134
155- // Delete the instance created for testing.
156- DeleteInstance .deleteInstance (PROJECT_ID , ZONE , INSTANCE_NOT_CONSUME_RESERVATION_NAME );
157-
158135 // Delete all reservations created for testing.
159136 DeleteReservation .deleteReservation (PROJECT_ID , ZONE , RESERVATION_NAME_GLOBAL );
160137 DeleteReservation .deleteReservation (PROJECT_ID , ZONE , RESERVATION_NAME_REGIONAL );
@@ -167,9 +144,7 @@ public static void cleanup()
167144 NotFoundException .class ,
168145 () -> GetReservation .getReservation (PROJECT_ID , RESERVATION_NAME_REGIONAL , ZONE ));
169146
170- // Close the client after all tests
171147 reservationsClient .close ();
172- instancesClient .close ();
173148
174149 stdOut .close ();
175150 System .setOut (out );
@@ -201,19 +176,4 @@ public void testCreateReservationWithRegionInstanceTemplate()
201176 Assert .assertTrue (reservation .getZone ().contains (ZONE ));
202177 Assert .assertEquals (RESERVATION_NAME_REGIONAL , reservation .getName ());
203178 }
204-
205- @ Test
206- public void testCreateInstanceNotConsumeReservation ()
207- throws IOException , ExecutionException , InterruptedException , TimeoutException {
208-
209- CreateInstanceNotConsumeReservation .createInstanceNotConsumeReservation (
210- PROJECT_ID , ZONE , INSTANCE_NOT_CONSUME_RESERVATION_NAME , MACHINE_TYPE );
211-
212- // Verify that the instance was created with the correct consumeReservationType
213- Instance instance = instancesClient .get (
214- PROJECT_ID , ZONE , INSTANCE_NOT_CONSUME_RESERVATION_NAME );
215-
216- Assert .assertEquals (NO_RESERVATION .toString (),
217- instance .getReservationAffinity ().getConsumeReservationType ());
218- }
219179}
0 commit comments