LOG4J2-435 print more status messages to investigate failing test on
unix

Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/6dd574cf
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/6dd574cf
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/6dd574cf

Branch: refs/heads/LOG4J-1181
Commit: 6dd574cf1d94e32b9fa97e487eb5cd744864179e
Parents: 220d6b8
Author: rpopma <[email protected]>
Authored: Sun Nov 29 13:28:26 2015 +0900
Committer: rpopma <[email protected]>
Committed: Sun Nov 29 13:28:26 2015 +0900

----------------------------------------------------------------------
 .../appender/rolling/action/DeleteAction.java   |  5 ++++
 .../rolling/action/PathWithAttributes.java      |  5 ++++
 .../rolling/action/SortingVisitorTest.java      | 24 +++++++++-----------
 3 files changed, 21 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/6dd574cf/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/DeleteAction.java
----------------------------------------------------------------------
diff --git 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/DeleteAction.java
 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/DeleteAction.java
index 7010766..126fb5d 100644
--- 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/DeleteAction.java
+++ 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/DeleteAction.java
@@ -74,11 +74,16 @@ public class DeleteAction extends AbstractPathAction {
     @Override
     public boolean execute(final FileVisitor<Path> visitor) throws IOException 
{
         final List<PathWithAttributes> sortedPaths = getSortedPaths();
+        LOGGER.trace("Sorted paths:");
+        for (PathWithAttributes pathWithAttributes : sortedPaths) {
+            LOGGER.trace(pathWithAttributes);
+        }
 
         for (PathWithAttributes element : sortedPaths) {
             try {
                 visitor.visitFile(element.getPath(), element.getAttributes());
             } catch (final IOException ioex) {
+                LOGGER.error("Error in post-rollover Delete when visiting {}", 
element.getPath(), ioex);
                 visitor.visitFileFailed(element.getPath(), ioex);
             }
         }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/6dd574cf/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/PathWithAttributes.java
----------------------------------------------------------------------
diff --git 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/PathWithAttributes.java
 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/PathWithAttributes.java
index 36833da..836d271 100644
--- 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/PathWithAttributes.java
+++ 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/PathWithAttributes.java
@@ -54,6 +54,11 @@ public class PathWithAttributes implements 
BasicFileAttributes {
         this.size = attributes.size();
         this.fileKey = attributes.fileKey();
     }
+    
+    @Override
+    public String toString() {
+        return path + " (created: " + creationTime + ", modified: " + 
lastModifiedTime + ")";
+    }
 
     /**
      * Returns the path.

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/6dd574cf/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/SortingVisitorTest.java
----------------------------------------------------------------------
diff --git 
a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/SortingVisitorTest.java
 
b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/SortingVisitorTest.java
index 5eb277b..f67be1e 100644
--- 
a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/SortingVisitorTest.java
+++ 
b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/SortingVisitorTest.java
@@ -46,15 +46,13 @@ public class SortingVisitorTest {
     public void setUp() throws Exception {
         base = Files.createTempDirectory("tempDir", new FileAttribute<?>[0]);
         aaa = Files.createTempFile(base, "aaa", null, new FileAttribute<?>[0]);
-        Files.setLastModifiedTime(aaa, 
FileTime.fromMillis(System.currentTimeMillis()));
-        
-        Thread.sleep(1);
         bbb = Files.createTempFile(base, "bbb", null, new FileAttribute<?>[0]);
-        Files.setLastModifiedTime(bbb, 
FileTime.fromMillis(System.currentTimeMillis() + 1));
-        
-        Thread.sleep(1);
         ccc = Files.createTempFile(base, "ccc", null, new FileAttribute<?>[0]);
-        Files.setLastModifiedTime(ccc, 
FileTime.fromMillis(System.currentTimeMillis() + 2));
+        
+        final long now = System.currentTimeMillis();
+        Files.setLastModifiedTime(aaa, FileTime.fromMillis(now));
+        Files.setLastModifiedTime(bbb, FileTime.fromMillis(now + 1));
+        Files.setLastModifiedTime(ccc, FileTime.fromMillis(now + 2));
     }
     
     @After
@@ -74,9 +72,9 @@ public class SortingVisitorTest {
         List<PathWithAttributes> found = visitor.getSortedPaths();
         assertNotNull(found);
         assertEquals("file count", 3, found.size());
-        assertEquals("1st: most recent", ccc, found.get(0).getPath());
-        assertEquals("2nd", bbb, found.get(1).getPath());
-        assertEquals("3rd: oldest", aaa, found.get(2).getPath());
+        assertEquals("1st: most recent; sorted=" + found, ccc, found.get(0));
+        assertEquals("2nd; sorted=" + found, bbb, found.get(1));
+        assertEquals("3rd: oldest; sorted=" + found, aaa, found.get(2));
     }
 
     @Test
@@ -88,8 +86,8 @@ public class SortingVisitorTest {
         List<PathWithAttributes> found = visitor.getSortedPaths();
         assertNotNull(found);
         assertEquals("file count", 3, found.size());
-        assertEquals("1st: oldest first", aaa, found.get(0).getPath());
-        assertEquals("2nd", bbb, found.get(1).getPath());
-        assertEquals("3rd: most recent last", ccc, found.get(2).getPath());
+        assertEquals("1st: oldest first; sorted=" + found, aaa, found.get(0));
+        assertEquals("2nd; sorted=" + found, bbb, found.get(1));
+        assertEquals("3rd: most recent sorted; list=" + found, ccc, 
found.get(2));
     }
 }

Reply via email to