3535import java .io .ByteArrayOutputStream ;
3636import java .io .IOException ;
3737import java .io .PrintStream ;
38- import org .junit .Before ;
39- import org .junit .Test ;
38+ import org .junit .jupiter . api . BeforeAll ;
39+ import org .junit .jupiter . api . Test ;
4040import org .junit .jupiter .api .Timeout ;
4141import org .junit .runner .RunWith ;
4242import org .junit .runners .JUnit4 ;
4343import org .mockito .MockedStatic ;
4444
4545@ RunWith (JUnit4 .class )
46- @ Timeout (value = 3 )
46+ @ Timeout (value = 10 )
4747public class QueuedResourceIT {
4848 private static final String PROJECT_ID = "project-id" ;
4949 private static final String ZONE = "europe-west4-a" ;
@@ -52,10 +52,10 @@ public class QueuedResourceIT {
5252 private static final String TPU_SOFTWARE_VERSION = "tpu-vm-tf-2.14.1" ;
5353 private static final String QUEUED_RESOURCE_NAME = "queued-resource" ;
5454 private static final String NETWORK_NAME = "default" ;
55- private ByteArrayOutputStream bout ;
55+ private static ByteArrayOutputStream bout ;
5656
57- @ Before
58- public void setUp () {
57+ @ BeforeAll
58+ public static void setUp () {
5959 bout = new ByteArrayOutputStream ();
6060 System .setOut (new PrintStream (bout ));
6161 }
@@ -75,8 +75,8 @@ public void testCreateQueuedResourceWithSpecifiedNetwork() throws Exception {
7575
7676 QueuedResource returnedQueuedResource =
7777 CreateQueuedResourceWithNetwork .createQueuedResourceWithNetwork (
78- PROJECT_ID , ZONE , QUEUED_RESOURCE_NAME , NODE_NAME ,
79- TPU_TYPE , TPU_SOFTWARE_VERSION , NETWORK_NAME );
78+ PROJECT_ID , ZONE , QUEUED_RESOURCE_NAME , NODE_NAME ,
79+ TPU_TYPE , TPU_SOFTWARE_VERSION , NETWORK_NAME );
8080
8181 verify (mockTpuClient , times (1 ))
8282 .createQueuedResourceAsync (any (CreateQueuedResourceRequest .class ));
@@ -106,7 +106,7 @@ public void testGetQueuedResource() throws IOException {
106106 }
107107
108108 @ Test
109- public void testDeleteTpuVm () {
109+ public void testDeleteForceQueuedResource () {
110110 try (MockedStatic <TpuClient > mockedTpuClient = mockStatic (TpuClient .class )) {
111111 TpuClient mockTpuClient = mock (TpuClient .class );
112112 OperationFuture mockFuture = mock (OperationFuture .class );
@@ -124,4 +124,29 @@ public void testDeleteTpuVm() {
124124 .deleteQueuedResourceAsync (any (DeleteQueuedResourceRequest .class ));
125125 }
126126 }
127+
128+ @ Test
129+ public void testCreateQueuedResourceWithStartupScript () throws Exception {
130+ try (MockedStatic <TpuClient > mockedTpuClient = mockStatic (TpuClient .class )) {
131+ QueuedResource mockQueuedResource = mock (QueuedResource .class );
132+ TpuClient mockTpuClient = mock (TpuClient .class );
133+ OperationFuture mockFuture = mock (OperationFuture .class );
134+
135+ mockedTpuClient .when (() -> TpuClient .create (any (TpuSettings .class )))
136+ .thenReturn (mockTpuClient );
137+ when (mockTpuClient .createQueuedResourceAsync (any (CreateQueuedResourceRequest .class )))
138+ .thenReturn (mockFuture );
139+ when (mockFuture .get ()).thenReturn (mockQueuedResource );
140+
141+ QueuedResource returnedQueuedResource =
142+ CreateQueuedResourceWithStartupScript .createQueuedResource (
143+ PROJECT_ID , ZONE , QUEUED_RESOURCE_NAME , NODE_NAME ,
144+ TPU_TYPE , TPU_SOFTWARE_VERSION );
145+
146+ verify (mockTpuClient , times (1 ))
147+ .createQueuedResourceAsync (any (CreateQueuedResourceRequest .class ));
148+ verify (mockFuture , times (1 )).get ();
149+ assertEquals (returnedQueuedResource , mockQueuedResource );
150+ }
151+ }
127152}
0 commit comments