diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/XmlCompleteFileAppenderTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/XmlCompleteFileAppenderTest.java index d5ce1a47e67..c3310ac9303 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/XmlCompleteFileAppenderTest.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/XmlCompleteFileAppenderTest.java @@ -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 root - line3 = reader.readLine(); + + // Locate the first non-empty line after the `` root + while ((line3 = reader.readLine()) != null && line3.trim().isEmpty()) {} + line4 = reader.readLine(); line5 = reader.readLine(); } finally { diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDirectCronTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDirectCronTest.java index 6751d3cb1f6..444016dfd1f 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDirectCronTest.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDirectCronTest.java @@ -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; @@ -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); @@ -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); } } @@ -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 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); } } }