39
39
@ SuppressWarnings ("checkstyle:abbreviationaswordinname" )
40
40
public class LoggingIT {
41
41
42
+ private final String QUICKSTART_LOG = "my-log" ;
43
+ private final String TEST_WRITE_LOG = "test-log" ;
44
+
42
45
private ByteArrayOutputStream bout ;
43
46
private PrintStream out ;
44
47
private Logging logging = LoggingOptions .getDefaultInstance ().getService ();
@@ -56,37 +59,36 @@ public void setUp() {
56
59
57
60
@ After
58
61
public void tearDown () {
62
+ // Clean up created logs
63
+ deleteLog (QUICKSTART_LOG );
64
+ deleteLog (TEST_WRITE_LOG );
65
+
59
66
System .setOut (null );
60
67
}
61
68
62
69
@ Test
63
70
public void testQuickstart () throws Exception {
64
- String logName = "my-log" ;
65
- deleteLog (logName );
66
- QuickstartSample .main (logName );
71
+ QuickstartSample .main (QUICKSTART_LOG );
67
72
String got = bout .toString ();
68
73
assertThat (got ).contains ("Logged: Hello, world!" );
69
- deleteLog (logName );
70
74
}
71
75
72
- @ Test (timeout = 10000 )
76
+ @ Test (timeout = 20000 )
73
77
public void testWriteAndListLogs () throws Exception {
74
- String logName = "test-log" ;
75
- deleteLog (logName );
76
78
// write a log entry
77
79
LogEntry entry = LogEntry .newBuilder (StringPayload .of ("Hello world again" ))
78
- .setLogName (logName )
80
+ .setLogName (TEST_WRITE_LOG )
79
81
.setResource (MonitoredResource .newBuilder ("global" ).build ())
80
82
.build ();
81
83
logging .write (Collections .singleton (entry ));
82
84
// flush out log immediately
83
85
logging .flush ();
84
86
bout .reset ();
87
+ // Check if the log is listed yet
85
88
while (bout .toString ().isEmpty ()) {
86
- ListLogs .main (logName );
89
+ ListLogs .main (TEST_WRITE_LOG );
87
90
Thread .sleep (1000 );
88
91
}
89
92
assertThat (bout .toString ().contains ("Hello world again" )).isTrue ();
90
- deleteLog (logName );
91
93
}
92
94
}
0 commit comments