38
38
import org .junit .jupiter .api .AfterAll ;
39
39
import org .junit .jupiter .api .Assertions ;
40
40
import org .junit .jupiter .api .BeforeAll ;
41
+ import org .junit .jupiter .api .MethodOrderer ;
42
+ import org .junit .jupiter .api .Order ;
41
43
import org .junit .jupiter .api .Test ;
44
+ import org .junit .jupiter .api .TestMethodOrder ;
42
45
import org .junit .jupiter .api .Timeout ;
43
46
import org .junit .runner .RunWith ;
44
47
import org .junit .runners .JUnit4 ;
45
48
46
49
@ RunWith (JUnit4 .class )
47
- @ Timeout (value = 25 , unit = TimeUnit .MINUTES )
50
+ @ Timeout (value = 6 , unit = TimeUnit .MINUTES )
51
+ @ TestMethodOrder (MethodOrderer .OrderAnnotation .class )
48
52
public class ReservationIT {
49
53
50
54
private static final String PROJECT_ID = System .getenv ("GOOGLE_CLOUD_PROJECT" );
51
- private static final String ZONE = "us-west1 -a" ;
55
+ private static final String ZONE = "asia-south1 -a" ;
52
56
private static final String REGION = ZONE .substring (0 , ZONE .lastIndexOf ('-' ));
53
- private static ReservationsClient reservationsClient ;
54
- private static String RESERVATION_NAME_GLOBAL ;
55
- private static String RESERVATION_NAME_REGIONAL ;
56
- private static String GLOBAL_INSTANCE_TEMPLATE_URI ;
57
- private static String REGIONAL_INSTANCE_TEMPLATE_URI ;
58
57
static String javaVersion = System .getProperty ("java.version" ).substring (0 , 2 );
58
+ private static ReservationsClient reservationsClient ;
59
+ private static final String RESERVATION_NAME_GLOBAL = "test-reservation-global-" + javaVersion
60
+ + "-" + UUID .randomUUID ().toString ().substring (0 , 8 );
61
+ private static final String RESERVATION_NAME_REGIONAL = "test-reservation-regional-"
62
+ + javaVersion + "-" + UUID .randomUUID ().toString ().substring (0 , 8 );
59
63
private static final String GLOBAL_INSTANCE_TEMPLATE_NAME =
60
64
"test-global-inst-temp-" + javaVersion + "-" + UUID .randomUUID ().toString ().substring (0 , 8 );
61
- private static final String REGIONAL_INSTANCE_TEMPLATE_NAME =
62
- "test-regional-inst-temp-" + javaVersion + "-"
63
- + UUID .randomUUID ().toString ().substring (0 , 8 );
65
+ private static final String REGIONAL_INSTANCE_TEMPLATE_NAME = "test-regional-inst-temp-"
66
+ + javaVersion + "-" + UUID .randomUUID ().toString ().substring (0 , 8 );
67
+ private static final String GLOBAL_INSTANCE_TEMPLATE_URI = String .format (
68
+ "projects/%s/global/instanceTemplates/%s" , PROJECT_ID , GLOBAL_INSTANCE_TEMPLATE_NAME );
69
+ private static final String REGIONAL_INSTANCE_TEMPLATE_URI =
70
+ String .format ("projects/%s/regions/%s/instanceTemplates/%s" ,
71
+ PROJECT_ID , REGION , REGIONAL_INSTANCE_TEMPLATE_NAME );
64
72
private static final int NUMBER_OF_VMS = 3 ;
65
73
66
74
// Check if the required environment variables are set.
@@ -89,16 +97,6 @@ public static void setUp()
89
97
// Initialize the client once for all tests
90
98
reservationsClient = ReservationsClient .create ();
91
99
92
- RESERVATION_NAME_GLOBAL = "test-reservation-global-" + javaVersion + "-"
93
- + UUID .randomUUID ().toString ().substring (0 , 8 );
94
- RESERVATION_NAME_REGIONAL = "test-reservation-regional-" + javaVersion + "-"
95
- + UUID .randomUUID ().toString ().substring (0 , 8 );
96
- GLOBAL_INSTANCE_TEMPLATE_URI = String .format ("projects/%s/global/instanceTemplates/%s" ,
97
- PROJECT_ID , GLOBAL_INSTANCE_TEMPLATE_NAME );
98
- REGIONAL_INSTANCE_TEMPLATE_URI =
99
- String .format ("projects/%s/regions/%s/instanceTemplates/%s" ,
100
- PROJECT_ID , REGION , REGIONAL_INSTANCE_TEMPLATE_NAME );
101
-
102
100
// Create instance template with GLOBAL location.
103
101
CreateInstanceTemplate .createInstanceTemplate (PROJECT_ID , GLOBAL_INSTANCE_TEMPLATE_NAME );
104
102
assertThat (stdOut .toString ())
@@ -152,6 +150,7 @@ public static void cleanup()
152
150
}
153
151
154
152
@ Test
153
+ @ Order (1 )
155
154
public void testCreateReservationWithGlobalInstanceTemplate ()
156
155
throws IOException , ExecutionException , InterruptedException , TimeoutException {
157
156
CreateReservationForInstanceTemplate .createReservationForInstanceTemplate (
@@ -177,4 +176,17 @@ public void testCreateReservationWithRegionInstanceTemplate()
177
176
Assert .assertTrue (reservation .getZone ().contains (ZONE ));
178
177
Assert .assertEquals (RESERVATION_NAME_REGIONAL , reservation .getName ());
179
178
}
179
+
180
+ @ Test
181
+ @ Order (2 )
182
+ public void testUpdateVmsForReservation ()
183
+ throws IOException , ExecutionException , InterruptedException , TimeoutException {
184
+ int newNumberOfVms = 5 ;
185
+ UpdateVmsForReservation .updateVmsForReservation (
186
+ PROJECT_ID , ZONE , RESERVATION_NAME_GLOBAL , newNumberOfVms );
187
+ Reservation reservation = GetReservation .getReservation (
188
+ PROJECT_ID , RESERVATION_NAME_GLOBAL , ZONE );
189
+
190
+ Assert .assertEquals (newNumberOfVms , reservation .getSpecificReservation ().getCount ());
191
+ }
180
192
}
0 commit comments