Skip to content

Commit

Permalink
Disable OnStartupTriggeringPolicy tests on UNIX
Browse files Browse the repository at this point in the history
  • Loading branch information
ppkarwasz committed May 20, 2024
1 parent a15240f commit 7b92b6f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assumptions.assumeTrue;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
Expand Down Expand Up @@ -68,6 +69,19 @@ public void testPolicy() throws Exception {
final FileTime fileTime = FileTime.fromMillis(timeStamp);
final BasicFileAttributeView attrs = Files.getFileAttributeView(target, BasicFileAttributeView.class);
attrs.setTimes(fileTime, fileTime, fileTime);

/*
* POSIX does not define a file creation timestamp.
* Depending on the system `creationTime` might be:
* * 0,
* * the last modification time
* * or the time the file was actually created.
*
* This test fails if the latter occurs, since the file is created after the JVM.
*/
final FileTime creationTime = attrs.readAttributes().creationTime();
assumeTrue(creationTime.equals(fileTime) || creationTime.toMillis() == 0L);

final PatternLayout layout = PatternLayout.newBuilder()
.withPattern("%msg")
.withConfiguration(configuration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.apache.logging.log4j.core.appender.rolling;

import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assumptions.assumeTrue;

import java.nio.file.DirectoryStream;
import java.nio.file.Files;
Expand Down Expand Up @@ -52,7 +53,19 @@ public static void setup() throws Exception {
final Path target = loggingPath.resolve(FILENAME);
Files.copy(Paths.get(SOURCE, FILENAME), target, StandardCopyOption.COPY_ATTRIBUTES);
final FileTime newTime = FileTime.from(Instant.now().minus(1, ChronoUnit.DAYS));
Files.getFileAttributeView(target, BasicFileAttributeView.class).setTimes(newTime, newTime, newTime);
final BasicFileAttributeView attrs = Files.getFileAttributeView(target, BasicFileAttributeView.class);
attrs.setTimes(newTime, newTime, newTime);
/*
* POSIX does not define a file creation timestamp.
* Depending on the system `creationTime` might be:
* * 0,
* * the last modification time
* * or the time the file was actually created.
*
* This test fails if the latter occurs, since the file is created after the JVM.
*/
final FileTime creationTime = attrs.readAttributes().creationTime();
assumeTrue(creationTime.equals(newTime) || creationTime.toMillis() == 0L);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assumptions.assumeTrue;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -68,7 +69,19 @@ public static void setup() throws Exception {
Files.createDirectories(DIR);
Files.write(FILE, "Hello, world".getBytes(), StandardOpenOption.CREATE);
final FileTime newTime = FileTime.from(Instant.now().minus(2, ChronoUnit.DAYS));
Files.getFileAttributeView(FILE, BasicFileAttributeView.class).setTimes(newTime, newTime, newTime);
final BasicFileAttributeView attrs = Files.getFileAttributeView(FILE, BasicFileAttributeView.class);
attrs.setTimes(newTime, newTime, newTime);
/*
* POSIX does not define a file creation timestamp.
* Depending on the system `creationTime` might be:
* * 0,
* * the last modification time
* * or the time the file was actually created.
*
* This test fails if the latter occurs, since the file is created after the JVM.
*/
final FileTime creationTime = attrs.readAttributes().creationTime();
assumeTrue(creationTime.equals(newTime) || creationTime.toMillis() == 0L);
}

@AfterClass
Expand Down

0 comments on commit 7b92b6f

Please sign in to comment.