Skip to content

Commit 5a04e52

Browse files
committed
Fix Windows test failure
1 parent 3738d15 commit 5a04e52

File tree

3 files changed

+40
-27
lines changed

3 files changed

+40
-27
lines changed

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

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@
1616
*/
1717
package org.apache.logging.log4j.core.appender.rolling;
1818

19+
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
20+
import static java.util.Objects.requireNonNull;
1921
import static org.assertj.core.api.Assertions.assertThat;
2022
import static org.junit.jupiter.api.Assertions.assertEquals;
2123

22-
import java.io.File;
23-
import java.io.OutputStream;
24+
import java.net.URISyntaxException;
2425
import java.nio.file.Files;
2526
import java.nio.file.Path;
2627
import java.util.concurrent.CountDownLatch;
@@ -30,44 +31,55 @@
3031
import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
3132
import org.apache.logging.log4j.core.util.CronExpression;
3233
import org.apache.logging.log4j.plugins.Named;
33-
import org.apache.logging.log4j.test.junit.CleanUpDirectories;
34+
import org.apache.logging.log4j.test.junit.TempLoggingDir;
35+
import org.junit.jupiter.api.BeforeEach;
3436
import org.junit.jupiter.api.Test;
35-
import org.junitpioneer.jupiter.DisabledUntil;
37+
import org.opentest4j.TestAbortedException;
3638

37-
/**
38-
*
39-
*/
40-
@DisabledUntil(date = "2024-04-01", reason = "Temporarily disabled due to deadlocks.")
41-
public class RollingAppenderCronTest extends AbstractRollingListenerTest {
39+
class RollingAppenderCronTest extends AbstractRollingListenerTest {
40+
41+
private static final Path CONFIG;
42+
43+
static {
44+
try {
45+
CONFIG = Path.of(requireNonNull(RollingAppenderCronTest.class.getResource("RollingAppenderCronTest.xml"))
46+
.toURI());
47+
} catch (final URISyntaxException e) {
48+
throw new TestAbortedException("Unable to compute configuration location.", e);
49+
}
50+
}
4251

43-
private static final String CONFIG = "log4j-rolling-cron.xml";
44-
private static final String DIR = "target/rolling-cron";
45-
private static final String FILE = "target/rolling-cron/rollingtest.log";
4652
private final CountDownLatch rollover = new CountDownLatch(2);
4753
private final CountDownLatch reconfigured = new CountDownLatch(1);
4854

55+
@TempLoggingDir
56+
private static Path loggingPath;
57+
58+
@BeforeEach
59+
void beforeEach() throws Exception {
60+
final Path src =
61+
Path.of(requireNonNull(RollingAppenderCronTest.class.getResource("RollingAppenderCronTest.old.xml"))
62+
.toURI());
63+
Files.copy(src, CONFIG, REPLACE_EXISTING);
64+
}
65+
4966
@Test
50-
@CleanUpDirectories(DIR)
51-
@LoggerContextSource(value = CONFIG, timeout = 10)
67+
@LoggerContextSource(timeout = 10)
5268
public void testAppender(final LoggerContext context, @Named("RollingFile") final RollingFileManager manager)
5369
throws Exception {
5470
manager.addRolloverListener(this);
5571
final Logger logger = context.getLogger(getClass());
56-
final File file = new File(FILE);
57-
assertThat(file).exists();
72+
assertThat(loggingPath.resolve("rollingtest.log")).exists();
5873
logger.debug("This is test message number 1");
5974
rollover.await();
75+
assertThat(loggingPath).isNotEmptyDirectory().isDirectoryContaining("glob:**.gz");
6076

61-
final File dir = new File(DIR);
62-
assertThat(dir).isNotEmptyDirectory();
63-
assertThat(dir).isDirectoryContaining("glob:**.gz");
64-
65-
final Path src = Path.of("target", "test-classes", "log4j-rolling-cron2.xml");
77+
final Path src =
78+
Path.of(requireNonNull(RollingAppenderCronTest.class.getResource("RollingAppenderCronTest.new.xml"))
79+
.toURI());
6680
context.addConfigurationStartedListener(ignored -> reconfigured.countDown());
67-
try (final OutputStream os =
68-
Files.newOutputStream(Path.of("target", "test-classes", "log4j-rolling-cron.xml"))) {
69-
Files.copy(src, os);
70-
}
81+
Files.copy(src, CONFIG, REPLACE_EXISTING);
82+
7183
// force a reconfiguration
7284
for (int i = 0; i < 20; ++i) {
7385
logger.debug("Adding new event {}", i);

log4j-core-test/src/test/resources/log4j-rolling-cron.xml renamed to log4j-core-test/src/test/resources/org/apache/logging/log4j/core/appender/rolling/RollingAppenderCronTest.old.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
-->
1818
<Configuration status="off" name="RollingCronTest" monitorInterval="1">
1919
<Properties>
20-
<Property name="filename">target/rolling-cron/rollingtest.log</Property>
20+
<Property name="filename">${test:logging.path}/rollingtest.log</Property>
2121
</Properties>
2222
<Filters>
2323
<ThresholdFilter level="debug"/>
@@ -27,7 +27,8 @@
2727
<Console name="STDOUT">
2828
<PatternLayout pattern="%m%n"/>
2929
</Console>
30-
<RollingFile name="RollingFile" fileName="${filename}" filePattern="target/rolling-cron/test1-%d{MM-dd-yy-HH-mm-ss}.log.gz">
30+
<RollingFile name="RollingFile" fileName="${filename}"
31+
filePattern="${test:logging.path}/test1-%d{MM-dd-yy-HH-mm-ss}.log.gz">
3132
<PatternLayout>
3233
<Pattern>%d %p %C{1.} [%t] %m%n</Pattern>
3334
</PatternLayout>

0 commit comments

Comments
 (0)