You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by vy...@apache.org on 2020/09/22 19:56:43 UTC

[logging-log4j2] branch release-2.x updated: Workarounds for Windows-specific "file being used by another process" failures.

This is an automated email from the ASF dual-hosted git repository.

vy pushed a commit to branch release-2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git


The following commit(s) were added to refs/heads/release-2.x by this push:
     new 933ba9a  Workarounds for Windows-specific "file being used by another process" failures.
933ba9a is described below

commit 933ba9ae4a023643e5186a22faed47bab4f5498f
Author: Volkan Yazici <vo...@gmail.com>
AuthorDate: Tue Sep 22 21:49:52 2020 +0200

    Workarounds for Windows-specific "file being used by another process" failures.
---
 .github/workflows/maven.yml                                 |  2 +-
 .../org/apache/logging/log4j/junit/AbstractFileCleaner.java |  5 ++++-
 .../org/apache/logging/log4j/junit/CleanUpDirectories.java  |  6 ++++--
 .../java/org/apache/logging/log4j/junit/CleanUpFiles.java   |  6 ++++--
 .../log4j/core/appender/RandomAccessFileManagerTest.java    | 13 ++++++-------
 5 files changed, 19 insertions(+), 13 deletions(-)

diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml
index 325cf63..3642f3a 100644
--- a/.github/workflows/maven.yml
+++ b/.github/workflows/maven.yml
@@ -52,7 +52,7 @@ jobs:
 
       - name: Build with Maven (Windows)
         if: runner.os == 'Windows'
-        run: ./mvnw -V -B -e -DtrimStackTrace=false "-Dmaven.test.failure.ignore=true" "-Dsurefire.rerunFailingTestsCount=1" --global-toolchains ".github\workflows\maven-toolchains.xml" verify
+        run: ./mvnw -V -B -e "-DtrimStackTrace=false" "-Dmaven.test.failure.ignore=true" "-Dsurefire.rerunFailingTestsCount=1" "-Dlog4j2.junit.fileCleanerSleepPeriodMillis=1000" --global-toolchains ".github\workflows\maven-toolchains.xml" verify
 
       - name: Inspect environment (MacOS)
         if: runner.os == 'macOS'
diff --git a/log4j-api/src/test/java/org/apache/logging/log4j/junit/AbstractFileCleaner.java b/log4j-api/src/test/java/org/apache/logging/log4j/junit/AbstractFileCleaner.java
index c5d2bc4..ce57b80 100644
--- a/log4j-api/src/test/java/org/apache/logging/log4j/junit/AbstractFileCleaner.java
+++ b/log4j-api/src/test/java/org/apache/logging/log4j/junit/AbstractFileCleaner.java
@@ -34,8 +34,11 @@ import java.util.stream.Collectors;
 import static org.junit.jupiter.api.Assertions.fail;
 
 abstract class AbstractFileCleaner implements BeforeEachCallback, AfterEachCallback {
+
     private static final int MAX_TRIES = Integer.getInteger("log4j2.junit.fileCleanerMaxTries", 10);
 
+    private static final int SLEEP_PERIOD_MILLIS = Integer.getInteger("log4j2.junit.fileCleanerSleepPeriodMillis", 200);
+
     @Override
     public void beforeEach(final ExtensionContext context) throws Exception {
         clean(context);
@@ -64,7 +67,7 @@ abstract class AbstractFileCleaner implements BeforeEachCallback, AfterEachCallb
                         failures.put(path, e);
                     }
                     try {
-                        TimeUnit.MILLISECONDS.sleep(200);
+                        TimeUnit.MILLISECONDS.sleep(SLEEP_PERIOD_MILLIS);
                     } catch (final InterruptedException ignored) {
                         failures.put(path, new InterruptedIOException());
                         Thread.currentThread().interrupt();
diff --git a/log4j-api/src/test/java/org/apache/logging/log4j/junit/CleanUpDirectories.java b/log4j-api/src/test/java/org/apache/logging/log4j/junit/CleanUpDirectories.java
index 6c398e6..151bb85 100644
--- a/log4j-api/src/test/java/org/apache/logging/log4j/junit/CleanUpDirectories.java
+++ b/log4j-api/src/test/java/org/apache/logging/log4j/junit/CleanUpDirectories.java
@@ -28,9 +28,11 @@ import java.lang.annotation.Target;
 
 /**
  * JUnit extension to automatically clean up a list of directories and their contents before and after test execution.
- * This will automatically retry deletion up to 10 times per file while pausing a short duration each time.
- * This can be overridden with the system property {@code log4j2.junit.fileCleanerMaxTries}.
+ * This will automatically retry deletion up to 10 times per file while pausing for 200ms each time.
+ * These can be overridden with system properties {@code log4j2.junit.fileCleanerMaxTries} and
+ * {@code log4j2.junit.fileCleanerSleepPeriodMillis}.
  *
+ * @see DirectoryCleaner
  * @see CleanUpFiles
  * @since 2.14.0
  */
diff --git a/log4j-api/src/test/java/org/apache/logging/log4j/junit/CleanUpFiles.java b/log4j-api/src/test/java/org/apache/logging/log4j/junit/CleanUpFiles.java
index a3b9ca6..e00ca42 100644
--- a/log4j-api/src/test/java/org/apache/logging/log4j/junit/CleanUpFiles.java
+++ b/log4j-api/src/test/java/org/apache/logging/log4j/junit/CleanUpFiles.java
@@ -28,9 +28,11 @@ import java.lang.annotation.Target;
 
 /**
  * JUnit extension to automatically clean up a list of files before and after test execution.
- * This will automatically retry deletion up to 10 times per file while pausing a short duration each time.
- * This can be overridden with the system property {@code log4j2.junit.fileCleanerMaxTries}.
+ * This will automatically retry deletion up to 10 times per file while pausing for 200ms each time.
+ * These can be overridden with system properties {@code log4j2.junit.fileCleanerMaxTries} and
+ * {@code log4j2.junit.fileCleanerSleepPeriodMillis}.
  *
+ * @see FileCleaner
  * @see CleanUpDirectories
  * @since 2.14.0
  */
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/RandomAccessFileManagerTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/RandomAccessFileManagerTest.java
index 62b2bec..6227f37 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/RandomAccessFileManagerTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/RandomAccessFileManagerTest.java
@@ -38,12 +38,11 @@ public class RandomAccessFileManagerTest {
 
     /**
      * Test method for
-     * {@link org.apache.logging.log4j.core.appender.RandomAccessFileManager#writeBytes(byte[], int, int)}
-     * .
+     * {@link org.apache.logging.log4j.core.appender.RandomAccessFileManager#writeBytes(byte[], int, int)}.
      */
     @Test
     public void testWrite_multiplesOfBufferSize() throws IOException {
-        final File file = new File(tempDir, "random-access-file.bin");
+        final File file = new File(tempDir, "testWrite_multiplesOfBufferSize.bin");
         try (final RandomAccessFile raf = new RandomAccessFile(file, "rw")) {
             final OutputStream os = NullOutputStream.getInstance();
             final RandomAccessFileManager manager = new RandomAccessFileManager(null, raf, file.getName(),
@@ -65,7 +64,7 @@ public class RandomAccessFileManagerTest {
      */
     @Test
     public void testWrite_dataExceedingBufferSize() throws IOException {
-        final File file = new File(tempDir, "random-access-file.bin");
+        final File file = new File(tempDir, "testWrite_dataExceedingBufferSize.bin");
         try (final RandomAccessFile raf = new RandomAccessFile(file, "rw")) {
             final OutputStream os = NullOutputStream.getInstance();
             final RandomAccessFileManager manager = new RandomAccessFileManager(null, raf, file.getName(),
@@ -84,7 +83,7 @@ public class RandomAccessFileManagerTest {
 
     @Test
     public void testConfigurableBufferSize() throws IOException {
-        final File file = new File(tempDir, "random-access-file.bin");
+        final File file = new File(tempDir, "testConfigurableBufferSize.bin");
         try (final RandomAccessFile raf = new RandomAccessFile(file, "rw")) {
             final OutputStream os = NullOutputStream.getInstance();
             final int bufferSize = 4 * 1024;
@@ -100,7 +99,7 @@ public class RandomAccessFileManagerTest {
 
     @Test
     public void testWrite_dataExceedingMinBufferSize() throws IOException {
-        final File file = new File(tempDir, "random-access-file.bin");
+        final File file = new File(tempDir, "testWrite_dataExceedingMinBufferSize.bin");
         try (final RandomAccessFile raf = new RandomAccessFile(file, "rw")) {
             final OutputStream os = NullOutputStream.getInstance();
             final int bufferSize = 1;
@@ -121,7 +120,7 @@ public class RandomAccessFileManagerTest {
     @Test
     public void testAppendDoesNotOverwriteExistingFile() throws IOException {
         final boolean isAppend = true;
-        final File file = new File(tempDir, "random-access-file.bin");
+        final File file = new File(tempDir, "testAppendDoesNotOverwriteExistingFile.bin");
         assertEquals(0, file.length());
 
         final byte[] bytes = new byte[4 * 1024];