1616
1717package tpu ;
1818
19-
19+ import static com . google . common . truth . Truth . assertThat ;
2020import static org .mockito .Mockito .any ;
2121import static org .mockito .Mockito .mock ;
2222import static org .mockito .Mockito .mockStatic ;
3131import com .google .cloud .tpu .v2alpha1 .QueuedResourceName ;
3232import com .google .cloud .tpu .v2alpha1 .TpuClient ;
3333import com .google .cloud .tpu .v2alpha1 .TpuSettings ;
34+ import java .io .ByteArrayOutputStream ;
3435import java .io .IOException ;
35- import java .util .concurrent .TimeUnit ;
36+ import java .io .PrintStream ;
37+ import org .junit .Before ;
3638import org .junit .Test ;
3739import org .junit .jupiter .api .Timeout ;
3840import org .junit .runner .RunWith ;
3941import org .junit .runners .JUnit4 ;
4042import org .mockito .MockedStatic ;
4143
4244@ RunWith (JUnit4 .class )
43- @ Timeout (value = 3 , unit = TimeUnit . MINUTES )
45+ @ Timeout (value = 3 )
4446public class QueuedResourceIT {
4547 private static final String PROJECT_ID = "project-id" ;
4648 private static final String ZONE = "europe-west4-a" ;
@@ -49,11 +51,18 @@ public class QueuedResourceIT {
4951 private static final String TPU_SOFTWARE_VERSION = "tpu-vm-tf-2.14.1" ;
5052 private static final String QUEUED_RESOURCE_NAME = "queued-resource" ;
5153 private static final String NETWORK_NAME = "default" ;
54+ private ByteArrayOutputStream bout ;
55+
56+ @ Before
57+ public void setUp () {
58+ bout = new ByteArrayOutputStream ();
59+ System .setOut (new PrintStream (bout ));
60+ }
5261
5362 @ Test
5463 public void testCreateQueuedResourceWithSpecifiedNetwork () throws Exception {
55- TpuClient mockTpuClient = mock (TpuClient .class );
5664 try (MockedStatic <TpuClient > mockedTpuClient = mockStatic (TpuClient .class )) {
65+ TpuClient mockTpuClient = mock (TpuClient .class );
5766 mockedTpuClient .when (() -> TpuClient .create (any (TpuSettings .class )))
5867 .thenReturn (mockTpuClient );
5968
@@ -71,12 +80,12 @@ public void testCreateQueuedResourceWithSpecifiedNetwork() throws Exception {
7180
7281 @ Test
7382 public void testGetQueuedResource () throws IOException {
74- GetQueuedResource mockGetQueuedResource = mock (GetQueuedResource .class );
75- QueuedResource mockQueuedResource = mock (QueuedResource .class );
7683 try (MockedStatic <TpuClient > mockedTpuClient = mockStatic (TpuClient .class )) {
84+ QueuedResource mockQueuedResource = mock (QueuedResource .class );
7785 mockedTpuClient .when (TpuClient ::create ).thenReturn (mock (TpuClient .class ));
7886 when (mock (TpuClient .class )
7987 .getQueuedResource (any (QueuedResourceName .class ))).thenReturn (mockQueuedResource );
88+ GetQueuedResource mockGetQueuedResource = mock (GetQueuedResource .class );
8089
8190 GetQueuedResource .getQueuedResource (PROJECT_ID , ZONE , NODE_NAME );
8291
@@ -87,16 +96,18 @@ public void testGetQueuedResource() throws IOException {
8796
8897 @ Test
8998 public void testDeleteTpuVm () {
90- TpuClient mockTpuClient = mock (TpuClient .class );
9199 try (MockedStatic <TpuClient > mockedTpuClient = mockStatic (TpuClient .class )) {
100+ TpuClient mockTpuClient = mock (TpuClient .class );
92101 mockedTpuClient .when (() -> TpuClient .create (any (TpuSettings .class )))
93102 .thenReturn (mockTpuClient );
94103
95104 OperationFuture mockFuture = mock (OperationFuture .class );
96105 when (mockTpuClient .deleteQueuedResourceAsync (any (DeleteQueuedResourceRequest .class )))
97106 .thenReturn (mockFuture );
98107 DeleteForceQueuedResource .deleteForceQueuedResource (PROJECT_ID , ZONE , QUEUED_RESOURCE_NAME );
108+ String output = bout .toString ();
99109
110+ assertThat (output ).contains ("Deleted Queued Resource:" );
100111 verify (mockTpuClient , times (1 ))
101112 .deleteQueuedResourceAsync (any (DeleteQueuedResourceRequest .class ));
102113 }
0 commit comments