3939@ SuppressWarnings ("checkstyle:abbreviationaswordinname" )
4040public class LoggingIT {
4141
42+ private final String QUICKSTART_LOG = "my-log" ;
43+ private final String TEST_WRITE_LOG = "test-log" ;
44+
4245 private ByteArrayOutputStream bout ;
4346 private PrintStream out ;
4447 private Logging logging = LoggingOptions .getDefaultInstance ().getService ();
@@ -56,37 +59,36 @@ public void setUp() {
5659
5760 @ After
5861 public void tearDown () {
62+ // Clean up created logs
63+ deleteLog (QUICKSTART_LOG );
64+ deleteLog (TEST_WRITE_LOG );
65+
5966 System .setOut (null );
6067 }
6168
6269 @ Test
6370 public void testQuickstart () throws Exception {
64- String logName = "my-log" ;
65- deleteLog (logName );
66- QuickstartSample .main (logName );
71+ QuickstartSample .main (QUICKSTART_LOG );
6772 String got = bout .toString ();
6873 assertThat (got ).contains ("Logged: Hello, world!" );
69- deleteLog (logName );
7074 }
7175
72- @ Test (timeout = 10000 )
76+ @ Test (timeout = 20000 )
7377 public void testWriteAndListLogs () throws Exception {
74- String logName = "test-log" ;
75- deleteLog (logName );
7678 // write a log entry
7779 LogEntry entry = LogEntry .newBuilder (StringPayload .of ("Hello world again" ))
78- .setLogName (logName )
80+ .setLogName (TEST_WRITE_LOG )
7981 .setResource (MonitoredResource .newBuilder ("global" ).build ())
8082 .build ();
8183 logging .write (Collections .singleton (entry ));
8284 // flush out log immediately
8385 logging .flush ();
8486 bout .reset ();
87+ // Check if the log is listed yet
8588 while (bout .toString ().isEmpty ()) {
86- ListLogs .main (logName );
89+ ListLogs .main (TEST_WRITE_LOG );
8790 Thread .sleep (1000 );
8891 }
8992 assertThat (bout .toString ().contains ("Hello world again" )).isTrue ();
90- deleteLog (logName );
9193 }
9294}
0 commit comments