You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rg...@apache.org on 2021/04/07 04:30:57 UTC

[logging-log4j2] branch master updated: Add clean step to log4j-plugins. Add wait to RollingAppenderRestartTest

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

rgoers pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git


The following commit(s) were added to refs/heads/master by this push:
     new 3313e6f  Add clean step to log4j-plugins. Add wait to RollingAppenderRestartTest
3313e6f is described below

commit 3313e6f9d8b987b8a9d3c4b8ee3498a6b8fead5e
Author: Ralph Goers <rg...@apache.org>
AuthorDate: Tue Apr 6 21:30:48 2021 -0700

    Add clean step to log4j-plugins. Add wait to RollingAppenderRestartTest
---
 .../rolling/RollingAppenderRestartTest.java        | 22 +++++++++++++++++++++-
 log4j-plugins/pom.xml                              | 13 +++++++++++++
 2 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderRestartTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderRestartTest.java
index 20cef41..2230232 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderRestartTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderRestartTest.java
@@ -18,6 +18,7 @@ package org.apache.logging.log4j.core.appender.rolling;
 
 import org.apache.commons.io.file.PathUtils;
 import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.appender.RollingFileAppender;
 import org.apache.logging.log4j.core.junit.LoggerContextRule;
 import org.hamcrest.Matcher;
 import org.junit.AfterClass;
@@ -37,20 +38,24 @@ import java.nio.file.attribute.FileTime;
 import java.time.Instant;
 import java.time.temporal.ChronoUnit;
 import java.util.Arrays;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
 
 import static org.apache.logging.log4j.core.hamcrest.Descriptors.that;
 import static org.apache.logging.log4j.core.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;
 
-public class RollingAppenderRestartTest {
+public class RollingAppenderRestartTest implements RolloverListener {
 
     private static final String CONFIG = "log4j-rolling-restart.xml";
 
     // Note that both paths are hardcoded in the configuration!
     private static final Path DIR = Paths.get("target/rolling-restart");
     private static final Path FILE = DIR.resolve("test.log");
+    private static final CountDownLatch latch = new CountDownLatch(1);
 
     private final LoggerContextRule loggerContextRule =
             LoggerContextRule.createShutdownTimeoutLoggerContextRule(CONFIG);
@@ -81,7 +86,13 @@ public class RollingAppenderRestartTest {
     @Test
     public void testAppender() throws Exception {
         final Logger logger = loggerContextRule.getLogger();
+        final RollingFileAppender appender = (RollingFileAppender) loggerContextRule.getAppender("RollingFile");
+        assertNotNull("No RollingFile Appender", appender);
+        appender.getManager().addRolloverListener(this);
         logger.info("This is test message number 1");
+        latch.await(100, TimeUnit.MILLISECONDS);
+        // Delay to allow asynchronous gzip to complete.
+        Thread.sleep(200);
         final Matcher<File[]> hasGzippedFile = hasItemInArray(that(hasName(that(endsWith(".gz")))));
         final File[] files = DIR.toFile().listFiles();
         assertTrue(
@@ -89,4 +100,13 @@ public class RollingAppenderRestartTest {
                 hasGzippedFile.matches(files));
     }
 
+    @Override
+    public void rolloverTriggered(String fileName) {
+
+    }
+
+    @Override
+    public void rolloverComplete(String fileName) {
+        latch.countDown();
+    }
 }
diff --git a/log4j-plugins/pom.xml b/log4j-plugins/pom.xml
index 9fd7229..e1c5883 100644
--- a/log4j-plugins/pom.xml
+++ b/log4j-plugins/pom.xml
@@ -73,6 +73,19 @@
   <build>
     <plugins>
       <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-clean-plugin</artifactId>
+        <executions>
+          <execution>
+            <id>clean</id>
+            <phase>initialize</phase>
+            <goals>
+              <goal>clean</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+      <plugin>
         <artifactId>maven-compiler-plugin</artifactId>
         <executions>
           <execution>