Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase Logging Testing stability #903

Merged
merged 2 commits into from
Nov 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,16 @@ public static void main(String... args) throws Exception {

String logFilter = "logName=projects/" + options.getProjectId() + "/logs/" + logName;

// List log entries
// List all log entries
Page<LogEntry> entries = logging.listLogEntries(
EntryListOption.filter(logFilter));
for (LogEntry logEntry : entries.iterateAll()) {
System.out.println(logEntry);
}
// Use entries.getNextPage() to paginate
do {
for (LogEntry logEntry : entries.iterateAll()) {
System.out.println(logEntry);
}
entries = entries.getNextPage();
} while(entries != null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are forms of getting entries that aren't fully paged, but are infinite. I'm presuming you've verified that this is actually paged?


}
// [END listlogs]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
@SuppressWarnings("checkstyle:abbreviationaswordinname")
public class LoggingIT {

private final String QUICKSTART_LOG = "my-log";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these go to $TEMP?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the name of the log in StackDriver that it can later be referred by, not the location it's logging too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM

private final String TEST_WRITE_LOG = "test-log";

private ByteArrayOutputStream bout;
private PrintStream out;
private Logging logging = LoggingOptions.getDefaultInstance().getService();
Expand All @@ -56,37 +59,36 @@ public void setUp() {

@After
public void tearDown() {
// Clean up created logs
deleteLog(QUICKSTART_LOG);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you want to do this @before as well? incase something broke last time?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm concerned that part of the reasons the tests are failing periodically is that the deletes are actually being registered after the test line is logged. By moving the cleanup to the tearDown, it should always clean up unless the build is somehow forced to stop between the file log and that this exact moment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just concerned that some crash happens and it doesn't execute - so I ask Q's. If you are happy, I'm happy. (ie you don't think that will happen)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sgtm

deleteLog(TEST_WRITE_LOG);

System.setOut(null);
}

@Test
public void testQuickstart() throws Exception {
String logName = "my-log";
deleteLog(logName);
QuickstartSample.main(logName);
QuickstartSample.main(QUICKSTART_LOG);
String got = bout.toString();
assertThat(got).contains("Logged: Hello, world!");
deleteLog(logName);
}

@Test(timeout = 10000)
@Test(timeout = 20000)
public void testWriteAndListLogs() throws Exception {
String logName = "test-log";
deleteLog(logName);
// write a log entry
LogEntry entry = LogEntry.newBuilder(StringPayload.of("Hello world again"))
.setLogName(logName)
.setLogName(TEST_WRITE_LOG)
.setResource(MonitoredResource.newBuilder("global").build())
.build();
logging.write(Collections.singleton(entry));
// flush out log immediately
logging.flush();
bout.reset();
// Check if the log is listed yet
while (bout.toString().isEmpty()) {
ListLogs.main(logName);
ListLogs.main(TEST_WRITE_LOG);
Thread.sleep(1000);
}
assertThat(bout.toString().contains("Hello world again")).isTrue();
deleteLog(logName);
}
}