Skip to content

Commit 7b92b6f

Browse files
committed
Disable OnStartupTriggeringPolicy tests on UNIX
1 parent a15240f commit 7b92b6f

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

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

+14
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import static org.junit.jupiter.api.Assertions.assertEquals;
2020
import static org.junit.jupiter.api.Assertions.assertTrue;
21+
import static org.junit.jupiter.api.Assumptions.assumeTrue;
2122

2223
import java.io.ByteArrayInputStream;
2324
import java.io.InputStream;
@@ -68,6 +69,19 @@ public void testPolicy() throws Exception {
6869
final FileTime fileTime = FileTime.fromMillis(timeStamp);
6970
final BasicFileAttributeView attrs = Files.getFileAttributeView(target, BasicFileAttributeView.class);
7071
attrs.setTimes(fileTime, fileTime, fileTime);
72+
73+
/*
74+
* POSIX does not define a file creation timestamp.
75+
* Depending on the system `creationTime` might be:
76+
* * 0,
77+
* * the last modification time
78+
* * or the time the file was actually created.
79+
*
80+
* This test fails if the latter occurs, since the file is created after the JVM.
81+
*/
82+
final FileTime creationTime = attrs.readAttributes().creationTime();
83+
assumeTrue(creationTime.equals(fileTime) || creationTime.toMillis() == 0L);
84+
7185
final PatternLayout layout = PatternLayout.newBuilder()
7286
.withPattern("%msg")
7387
.withConfiguration(configuration)

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

+14-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.apache.logging.log4j.core.appender.rolling;
1818

1919
import static org.junit.Assert.assertTrue;
20+
import static org.junit.jupiter.api.Assumptions.assumeTrue;
2021

2122
import java.nio.file.DirectoryStream;
2223
import java.nio.file.Files;
@@ -52,7 +53,19 @@ public static void setup() throws Exception {
5253
final Path target = loggingPath.resolve(FILENAME);
5354
Files.copy(Paths.get(SOURCE, FILENAME), target, StandardCopyOption.COPY_ATTRIBUTES);
5455
final FileTime newTime = FileTime.from(Instant.now().minus(1, ChronoUnit.DAYS));
55-
Files.getFileAttributeView(target, BasicFileAttributeView.class).setTimes(newTime, newTime, newTime);
56+
final BasicFileAttributeView attrs = Files.getFileAttributeView(target, BasicFileAttributeView.class);
57+
attrs.setTimes(newTime, newTime, newTime);
58+
/*
59+
* POSIX does not define a file creation timestamp.
60+
* Depending on the system `creationTime` might be:
61+
* * 0,
62+
* * the last modification time
63+
* * or the time the file was actually created.
64+
*
65+
* This test fails if the latter occurs, since the file is created after the JVM.
66+
*/
67+
final FileTime creationTime = attrs.readAttributes().creationTime();
68+
assumeTrue(creationTime.equals(newTime) || creationTime.toMillis() == 0L);
5669
}
5770

5871
@Test

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

+14-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import static org.junit.jupiter.api.Assertions.assertNotNull;
2424
import static org.junit.jupiter.api.Assertions.assertTrue;
2525
import static org.junit.jupiter.api.Assertions.fail;
26+
import static org.junit.jupiter.api.Assumptions.assumeTrue;
2627

2728
import java.io.File;
2829
import java.io.IOException;
@@ -68,7 +69,19 @@ public static void setup() throws Exception {
6869
Files.createDirectories(DIR);
6970
Files.write(FILE, "Hello, world".getBytes(), StandardOpenOption.CREATE);
7071
final FileTime newTime = FileTime.from(Instant.now().minus(2, ChronoUnit.DAYS));
71-
Files.getFileAttributeView(FILE, BasicFileAttributeView.class).setTimes(newTime, newTime, newTime);
72+
final BasicFileAttributeView attrs = Files.getFileAttributeView(FILE, BasicFileAttributeView.class);
73+
attrs.setTimes(newTime, newTime, newTime);
74+
/*
75+
* POSIX does not define a file creation timestamp.
76+
* Depending on the system `creationTime` might be:
77+
* * 0,
78+
* * the last modification time
79+
* * or the time the file was actually created.
80+
*
81+
* This test fails if the latter occurs, since the file is created after the JVM.
82+
*/
83+
final FileTime creationTime = attrs.readAttributes().creationTime();
84+
assumeTrue(creationTime.equals(newTime) || creationTime.toMillis() == 0L);
7285
}
7386

7487
@AfterClass

0 commit comments

Comments
 (0)