You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by gg...@apache.org on 2020/11/12 20:36:10 UTC

[logging-log4j2] branch release-2.x updated: Fix test on slow machines.

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

ggregory 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 b3485ed  Fix test on slow machines.
b3485ed is described below

commit b3485ed87cb8d0c9d7a1ce76456669e05f50dd6a
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Thu Nov 12 15:36:03 2020 -0500

    Fix test on slow machines.
---
 .../RollingDirectSizeTimeNewDirectoryTest.java     | 29 +++++++++++-----------
 1 file changed, 15 insertions(+), 14 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 91b8cb4..4bf667c 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
@@ -24,6 +24,7 @@ import java.util.Arrays;
 
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.filefilter.TrueFileFilter;
+import org.apache.commons.lang3.ArrayUtils;
 import org.apache.logging.log4j.Logger;
 import org.apache.logging.log4j.junit.LoggerContextRule;
 import org.junit.Rule;
@@ -46,8 +47,7 @@ public class RollingDirectSizeTimeNewDirectoryTest {
     @Test
     public void streamClosedError() throws Exception {
 
-        final Logger logger =
-                loggerContextRule.getLogger(RollingDirectSizeTimeNewDirectoryTest.class);
+        final Logger logger = loggerContextRule.getLogger(RollingDirectSizeTimeNewDirectoryTest.class);
 
         for (int i = 0; i < 1000; i++) {
             logger.info("nHq6p9kgfvWfjzDRYbZp");
@@ -59,32 +59,33 @@ public class RollingDirectSizeTimeNewDirectoryTest {
 
         final File logDir = new File(DIR);
         final File[] logFolders = logDir.listFiles();
-        assertNotNull(logFolders);
+        assertNotNull("Not a folder: " + logDir, logFolders);
         Arrays.sort(logFolders);
 
         try {
-
             final int minExpectedLogFolderCount = 2;
             assertTrue(
-                    "was expecting at least " + minExpectedLogFolderCount + " folders, " +
-                            "found " + logFolders.length,
+                    "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();
+                assertNotNull("Not a folder: " + logFolder, logFiles);
                 Arrays.sort(logFiles);
-                assertTrue(
-                        "no files found in folder: " + logFolder,
-                        logFiles != null && logFiles.length > 0);
-
+                if (logFolderIndex == 0 && logFolders.length > 0 && logFiles.length == 0) {
+                    // In a slow execution period, it is possible for the initial directory to be
+                    // empty because it has not received events yet. If this is the case, then the
+                    // next directory MUST contain at least one log file.
+                } else {
+                    assertTrue("no files found in folder: " + logFolder, ArrayUtils.isNotEmpty(logFiles));
+                }
                 final int minExpectedLogFileCount = 2;
-                if (logFolderIndex > 0
-                        && logFolderIndex < logFolders.length - 1) {
+                if (logFolderIndex > 0 && logFolderIndex < logFolders.length - 1) {
                     assertTrue(
-                            "was expecting at least " + minExpectedLogFileCount + " files, " +
-                                    "found " + logFiles.length + ": " + Arrays.toString(logFiles),
+                            "was expecting at least " + minExpectedLogFileCount + " files, " + "found "
+                                    + logFiles.length + ": " + Arrays.toString(logFiles),
                             logFiles.length >= minExpectedLogFileCount);
                 }
             }