|  | 
| 16 | 16 |  */ | 
| 17 | 17 | package org.apache.logging.log4j.core.appender.rolling; | 
| 18 | 18 | 
 | 
|  | 19 | +import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; | 
|  | 20 | +import static java.util.Objects.requireNonNull; | 
| 19 | 21 | import static org.assertj.core.api.Assertions.assertThat; | 
| 20 | 22 | import static org.junit.jupiter.api.Assertions.assertEquals; | 
| 21 | 23 | 
 | 
| 22 |  | -import java.io.File; | 
| 23 |  | -import java.io.OutputStream; | 
|  | 24 | +import java.net.URISyntaxException; | 
| 24 | 25 | import java.nio.file.Files; | 
| 25 | 26 | import java.nio.file.Path; | 
| 26 | 27 | import java.util.concurrent.CountDownLatch; | 
|  | 
| 30 | 31 | import org.apache.logging.log4j.core.test.junit.LoggerContextSource; | 
| 31 | 32 | import org.apache.logging.log4j.core.util.CronExpression; | 
| 32 | 33 | 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; | 
| 34 | 36 | import org.junit.jupiter.api.Test; | 
| 35 |  | -import org.junitpioneer.jupiter.DisabledUntil; | 
|  | 37 | +import org.opentest4j.TestAbortedException; | 
| 36 | 38 | 
 | 
| 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 | +    } | 
| 42 | 51 | 
 | 
| 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"; | 
| 46 | 52 |     private final CountDownLatch rollover = new CountDownLatch(2); | 
| 47 | 53 |     private final CountDownLatch reconfigured = new CountDownLatch(1); | 
| 48 | 54 | 
 | 
|  | 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 | + | 
| 49 | 66 |     @Test | 
| 50 |  | -    @CleanUpDirectories(DIR) | 
| 51 |  | -    @LoggerContextSource(value = CONFIG, timeout = 10) | 
|  | 67 | +    @LoggerContextSource(timeout = 10) | 
| 52 | 68 |     public void testAppender(final LoggerContext context, @Named("RollingFile") final RollingFileManager manager) | 
| 53 | 69 |             throws Exception { | 
| 54 | 70 |         manager.addRolloverListener(this); | 
| 55 | 71 |         final Logger logger = context.getLogger(getClass()); | 
| 56 |  | -        final File file = new File(FILE); | 
| 57 |  | -        assertThat(file).exists(); | 
|  | 72 | +        assertThat(loggingPath.resolve("rollingtest.log")).exists(); | 
| 58 | 73 |         logger.debug("This is test message number 1"); | 
| 59 | 74 |         rollover.await(); | 
|  | 75 | +        assertThat(loggingPath).isNotEmptyDirectory().isDirectoryContaining("glob:**.gz"); | 
| 60 | 76 | 
 | 
| 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()); | 
| 66 | 80 |         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 | + | 
| 71 | 83 |         // force a reconfiguration | 
| 72 | 84 |         for (int i = 0; i < 20; ++i) { | 
| 73 | 85 |             logger.debug("Adding new event {}", i); | 
|  | 
0 commit comments