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/08/26 07:25:12 UTC

[logging-log4j2] branch master updated (4052a1c -> fcedbb2)

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

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


    omit 4052a1c  Try improving RollingDirectSizeTimeNewDirectoryTest to alleviate test report failures.
     new fcedbb2  Try improving RollingDirectSizeTimeNewDirectoryTest to alleviate test report failures.

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (4052a1c)
            \
             N -- N -- N   refs/heads/master (fcedbb2)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


[logging-log4j2] 01/01: Try improving RollingDirectSizeTimeNewDirectoryTest to alleviate test report failures.

Posted by vy...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit fcedbb2834da27948477fdb96403fe2d8b1f15af
Author: Volkan Yazıcı <vo...@gmail.com>
AuthorDate: Tue Aug 25 16:22:40 2020 +0200

    Try improving RollingDirectSizeTimeNewDirectoryTest to alleviate test report failures.
---
 .../RollingDirectSizeTimeNewDirectoryTest.java     | 93 +++++++++++++---------
 pom.xml                                            |  2 +-
 2 files changed, 57 insertions(+), 38 deletions(-)

diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingDirectSizeTimeNewDirectoryTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingDirectSizeTimeNewDirectoryTest.java
index 9978aa8..9afbfa9 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingDirectSizeTimeNewDirectoryTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingDirectSizeTimeNewDirectoryTest.java
@@ -16,47 +16,39 @@
  */
 package org.apache.logging.log4j.core.appender.rolling;
 
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.filefilter.TrueFileFilter;
 import org.apache.logging.log4j.Logger;
 import org.apache.logging.log4j.junit.LoggerContextRule;
-import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.RuleChain;
 
 import java.io.File;
 import java.util.Arrays;
-import java.util.List;
+import java.util.Iterator;
 
-import static java.util.Arrays.asList;
-import static java.util.Collections.sort;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.*;
 
-/**
- * Tests
- */
 public class RollingDirectSizeTimeNewDirectoryTest {
+
     private static final String CONFIG = "log4j-rolling-size-time-new-directory.xml";
 
+    // Note that the path is hardcoded in the configuration!
     private static final String DIR = "target/rolling-size-time-new-directory";
 
-    public static LoggerContextRule loggerContextRule = LoggerContextRule.createShutdownTimeoutLoggerContextRule(CONFIG);
+    public static LoggerContextRule loggerContextRule =
+            LoggerContextRule.createShutdownTimeoutLoggerContextRule(CONFIG);
 
     @Rule
     public RuleChain chain = loggerContextRule.withCleanFoldersRule(DIR);
 
-    private Logger logger;
-
-    @Before
-    public void setUp() throws Exception {
-        this.logger = loggerContextRule.getLogger(RollingDirectSizeTimeNewDirectoryTest.class.getName());
-    }
-
-
     @Test
     public void streamClosedError() throws Exception {
+
+        final Logger logger =
+                loggerContextRule.getLogger(RollingDirectSizeTimeNewDirectoryTest.class);
+
         for (int i = 0; i < 1000; i++) {
             logger.info("nHq6p9kgfvWfjzDRYbZp");
         }
@@ -65,25 +57,52 @@ public class RollingDirectSizeTimeNewDirectoryTest {
             logger.info("nHq6p9kgfvWfjzDRYbZp");
         }
 
-        File tempDirectoryAsFile = new File(DIR);
-        File[] loggingFolders = tempDirectoryAsFile.listFiles();
-        assertNotNull(loggingFolders);
-        // Check if two folders were created
-        assertTrue("Not enough directories created", loggingFolders.length >= 2);
-        Arrays.sort(loggingFolders);
-        for (int i = 0; i < loggingFolders.length; ++i) {
-            File dir = loggingFolders[i];
-            File[] files = dir.listFiles();
-            assertTrue("No files in directory " + dir.toString(), files != null && files.length > 0);
-            if (i > 0 && i < loggingFolders.length - 1) {
-                if (files.length < 3) {
-                    System.out.println("Only " + files.length + " files created in " + dir.toString());
-                    for (File logFile : files) {
-                        System.out.println("File name: " + logFile.getName() + " size: " + logFile.length());
-                    }
-                    fail();
+        final File logDir = new File(DIR);
+        final File[] logFolders = logDir.listFiles();
+        assertNotNull(logFolders);
+        Arrays.sort(logFolders);
+
+        try {
+
+            final int minExpectedLogFolderCount = 2;
+            assertTrue(
+                    "was expecting at least " + minExpectedLogFolderCount + " folders, " +
+                            "found " + logFolders.length,
+                    logFolders.length >= minExpectedLogFolderCount);
+
+            for (int logFolderIndex = 0; logFolderIndex < logFolders.length; ++logFolderIndex) {
+
+                File logFolder = logFolders[logFolderIndex];
+                File[] logFiles = logFolder.listFiles();
+                assertTrue(
+                        "no files found in folder: " + logFolder,
+                        logFiles != null && logFiles.length > 0);
+
+                final int minExpectedLogFileCount = 2;
+                if (logFolderIndex > 0
+                        && logFolderIndex < logFolders.length - 1) {
+                    assertTrue(
+                            "was expecting at least " + minExpectedLogFileCount + " files, " +
+                                    "found " + logFiles.length + ": " + Arrays.toString(logFiles),
+                            logFiles.length >= minExpectedLogFileCount);
                 }
             }
+
+        } catch (AssertionError error) {
+            System.out.format("log directory (%s) contents:%n", DIR);
+            final Iterator<File> fileIterator =
+                    FileUtils.iterateFilesAndDirs(
+                            logDir, TrueFileFilter.TRUE, TrueFileFilter.TRUE);
+            int totalFileCount = 0;
+            while (fileIterator.hasNext()) {
+                totalFileCount++;
+                final File file = fileIterator.next();
+                System.out.format("-> %s (%d)%n", file, file.length());
+            }
+            System.out.format("total file count: %d%n", totalFileCount);
+            throw new AssertionError("check failure", error);
         }
+
     }
+
 }
diff --git a/pom.xml b/pom.xml
index 006bd57..35883b3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -861,7 +861,7 @@
       <dependency>
         <groupId>commons-io</groupId>
         <artifactId>commons-io</artifactId>
-        <version>2.6</version>
+        <version>2.7</version>
         <scope>test</scope>
       </dependency>
       <!-- Used for testing JsonTemplateLayout -->