Skip to content
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 @@ -82,8 +82,10 @@ public void testFlushAtEndOfBatch() throws Exception {
try (final BufferedReader reader = new BufferedReader(new FileReader(logFile))) {
line1 = reader.readLine();
line2 = reader.readLine();
reader.readLine(); // ignore the empty line after the <Events> root
line3 = reader.readLine();

// Locate the first non-empty line after the `<Events>` root
while ((line3 = reader.readLine()) != null && line3.trim().isEmpty()) {}

line4 = reader.readLine();
line5 = reader.readLine();
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.waitAtMost;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down Expand Up @@ -70,7 +68,7 @@ void testAppender(final LoggerContext ctx, @Named("RollingFile") final RollingFi
private static class RolloverDelay implements RolloverListener {
private final Logger logger = StatusLogger.getLogger();
private volatile CountDownLatch latch;
private volatile AssertionError assertion;
private volatile Exception verificationFailure;

public RolloverDelay(final RollingFileManager manager) {
latch = new CountDownLatch(1);
Expand All @@ -80,9 +78,9 @@ public RolloverDelay(final RollingFileManager manager) {
public void waitForRollover() {
waitAtMost(5, TimeUnit.SECONDS)
.alias("Rollover timeout")
.until(() -> latch.getCount() == 0 || assertion != null);
if (assertion != null) {
throw assertion;
.until(() -> latch.getCount() == 0 || verificationFailure != null);
if (verificationFailure != null) {
throw new RuntimeException(verificationFailure);
}
}

Expand All @@ -102,16 +100,15 @@ public void rolloverComplete(final String fileName) {
final Path path = Paths.get(fileName);
final Matcher matcher = FILE_PATTERN.matcher(path.getFileName().toString());
assertThat(matcher).as("Rolled file").matches();
try {
waitAtMost(2, TimeUnit.SECONDS).untilAsserted(() -> {
final List<String> lines = Files.readAllLines(path);
assertThat(lines).isNotEmpty();
assertThat(lines.get(0)).startsWith(matcher.group(1));
} catch (final IOException ex) {
fail("Unable to read file " + fileName + ": " + ex.getMessage());
}
});
latch.countDown();
} catch (final AssertionError ex) {
assertion = ex;
} catch (final Exception ex) {
verificationFailure =
new RuntimeException("Rollover completion verification failure for file: " + fileName, ex);
}
}
}
Expand Down