Skip to content

Commit 60c62ee

Browse files
rjuare8vy
andauthored
Stabilize RollingAppenderDirectCronTest and XmlCompleteFileAppenderTest (#3946)
Co-authored-by: Volkan Yazıcı <[email protected]>
1 parent 13e37d8 commit 60c62ee

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/XmlCompleteFileAppenderTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,10 @@ public void testFlushAtEndOfBatch() throws Exception {
8282
try (final BufferedReader reader = new BufferedReader(new FileReader(logFile))) {
8383
line1 = reader.readLine();
8484
line2 = reader.readLine();
85-
reader.readLine(); // ignore the empty line after the <Events> root
86-
line3 = reader.readLine();
85+
86+
// Locate the first non-empty line after the `<Events>` root
87+
while ((line3 = reader.readLine()) != null && line3.trim().isEmpty()) {}
88+
8789
line4 = reader.readLine();
8890
line5 = reader.readLine();
8991
} finally {

log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDirectCronTest.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818

1919
import static org.assertj.core.api.Assertions.assertThat;
2020
import static org.awaitility.Awaitility.waitAtMost;
21-
import static org.junit.jupiter.api.Assertions.fail;
2221

23-
import java.io.IOException;
2422
import java.nio.file.Files;
2523
import java.nio.file.Path;
2624
import java.nio.file.Paths;
@@ -70,7 +68,7 @@ void testAppender(final LoggerContext ctx, @Named("RollingFile") final RollingFi
7068
private static class RolloverDelay implements RolloverListener {
7169
private final Logger logger = StatusLogger.getLogger();
7270
private volatile CountDownLatch latch;
73-
private volatile AssertionError assertion;
71+
private volatile Exception verificationFailure;
7472

7573
public RolloverDelay(final RollingFileManager manager) {
7674
latch = new CountDownLatch(1);
@@ -80,9 +78,9 @@ public RolloverDelay(final RollingFileManager manager) {
8078
public void waitForRollover() {
8179
waitAtMost(5, TimeUnit.SECONDS)
8280
.alias("Rollover timeout")
83-
.until(() -> latch.getCount() == 0 || assertion != null);
84-
if (assertion != null) {
85-
throw assertion;
81+
.until(() -> latch.getCount() == 0 || verificationFailure != null);
82+
if (verificationFailure != null) {
83+
throw new RuntimeException(verificationFailure);
8684
}
8785
}
8886

@@ -102,16 +100,15 @@ public void rolloverComplete(final String fileName) {
102100
final Path path = Paths.get(fileName);
103101
final Matcher matcher = FILE_PATTERN.matcher(path.getFileName().toString());
104102
assertThat(matcher).as("Rolled file").matches();
105-
try {
103+
waitAtMost(2, TimeUnit.SECONDS).untilAsserted(() -> {
106104
final List<String> lines = Files.readAllLines(path);
107105
assertThat(lines).isNotEmpty();
108106
assertThat(lines.get(0)).startsWith(matcher.group(1));
109-
} catch (final IOException ex) {
110-
fail("Unable to read file " + fileName + ": " + ex.getMessage());
111-
}
107+
});
112108
latch.countDown();
113-
} catch (final AssertionError ex) {
114-
assertion = ex;
109+
} catch (final Exception ex) {
110+
verificationFailure =
111+
new RuntimeException("Rollover completion verification failure for file: " + fileName, ex);
115112
}
116113
}
117114
}

0 commit comments

Comments
 (0)