You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by pk...@apache.org on 2024/05/20 10:22:07 UTC
(logging-log4j2) branch main updated: Disable `OnStartupTriggeringPolicy` tests on UNIX
This is an automated email from the ASF dual-hosted git repository.
pkarwasz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
The following commit(s) were added to refs/heads/main by this push:
new 53e3b85978 Disable `OnStartupTriggeringPolicy` tests on UNIX
53e3b85978 is described below
commit 53e3b85978fd0dc5bccee44adca7dc94b5c33679
Author: Piotr P. Karwasz <pi...@karwasz.org>
AuthorDate: Mon May 20 12:04:20 2024 +0200
Disable `OnStartupTriggeringPolicy` tests on UNIX
---
.../rolling/OnStartupTriggeringPolicyTest.java | 14 ++++++++++++++
.../rolling/RollingAppenderOnStartupTest.java | 15 ++++++++++++++-
.../appender/rolling/RollingAppenderRestartTest.java | 19 ++++++++++++++++---
3 files changed, 44 insertions(+), 4 deletions(-)
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/OnStartupTriggeringPolicyTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/OnStartupTriggeringPolicyTest.java
index 8fe8fa1075..5417f44695 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/OnStartupTriggeringPolicyTest.java
+++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/OnStartupTriggeringPolicyTest.java
@@ -18,6 +18,7 @@ package org.apache.logging.log4j.core.appender.rolling;
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;
@@ -68,6 +69,19 @@ public class OnStartupTriggeringPolicyTest {
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()
.setPattern("%msg")
.setConfiguration(configuration)
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderOnStartupTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderOnStartupTest.java
index 52616bed11..bde331e3ea 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderOnStartupTest.java
+++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderOnStartupTest.java
@@ -17,6 +17,7 @@
package org.apache.logging.log4j.core.appender.rolling;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
import java.io.IOException;
import java.nio.file.DirectoryStream;
@@ -52,7 +53,19 @@ public class RollingAppenderOnStartupTest {
final Path target =
Files.copy(SOURCE.resolve(FILENAME), loggingPath.resolve(FILENAME), 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
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderRestartTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderRestartTest.java
index cc0857334d..80e46f8516 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderRestartTest.java
+++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderRestartTest.java
@@ -20,8 +20,9 @@ import static org.apache.logging.log4j.core.test.hamcrest.Descriptors.that;
import static org.apache.logging.log4j.core.test.hamcrest.FileMatchers.hasName;
import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.hasItemInArray;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
import java.io.File;
import java.io.IOException;
@@ -71,7 +72,19 @@ public class RollingAppenderRestartTest implements RolloverListener {
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