qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kw...@apache.org
Subject svn commit: r1691202 - in /qpid/java/trunk/broker-core/src: main/java/org/apache/qpid/server/logging/ main/java/org/apache/qpid/server/logging/logback/ test/java/org/apache/qpid/server/logging/logback/
Date Wed, 15 Jul 2015 12:59:03 GMT
Author: kwall
Date: Wed Jul 15 12:59:02 2015
New Revision: 1691202

URL: http://svn.apache.org/r1691202
Log:
QPID-6614: [Java Broker] Order the list rolled files by last modification time

Work by Lorenz Quack <quack.lorenz@gmail.com> and Keith Wall

Modified:
    qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/logging/BrokerFileLogger.java
    qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/logging/BrokerFileLoggerImpl.java
    qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/logging/VirtualHostFileLogger.java
    qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/logging/VirtualHostFileLoggerImpl.java
    qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/logging/logback/RolloverWatcher.java
    qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/logging/logback/RolloverWatcherTest.java

Modified: qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/logging/BrokerFileLogger.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/logging/BrokerFileLogger.java?rev=1691202&r1=1691201&r2=1691202&view=diff
==============================================================================
--- qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/logging/BrokerFileLogger.java
(original)
+++ qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/logging/BrokerFileLogger.java
Wed Jul 15 12:59:02 2015
@@ -21,6 +21,7 @@
 package org.apache.qpid.server.logging;
 
 import java.util.Collection;
+import java.util.List;
 import java.util.Set;
 
 import org.apache.qpid.server.model.BrokerLogger;
@@ -65,7 +66,7 @@ public interface BrokerFileLogger<X exte
     String getLayout();
 
     @DerivedAttribute
-    Collection<LogFileDetails> getLogFiles();
+    List<LogFileDetails> getLogFiles();
 
     @ManagedOperation(nonModifying = true)
     Content getFile(@Param(name = "fileName") String fileName);

Modified: qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/logging/BrokerFileLoggerImpl.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/logging/BrokerFileLoggerImpl.java?rev=1691202&r1=1691201&r2=1691202&view=diff
==============================================================================
--- qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/logging/BrokerFileLoggerImpl.java
(original)
+++ qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/logging/BrokerFileLoggerImpl.java
Wed Jul 15 12:59:02 2015
@@ -24,7 +24,7 @@ import java.io.File;
 import java.io.IOError;
 import java.io.IOException;
 import java.security.AccessControlException;
-import java.util.Collection;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.Executors;
@@ -149,7 +149,7 @@ public class BrokerFileLoggerImpl extend
     }
 
     @Override
-    public Collection<LogFileDetails> getLogFiles()
+    public List<LogFileDetails> getLogFiles()
     {
         return _rolloverWatcher.getLogFileDetails();
     }

Modified: qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/logging/VirtualHostFileLogger.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/logging/VirtualHostFileLogger.java?rev=1691202&r1=1691201&r2=1691202&view=diff
==============================================================================
--- qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/logging/VirtualHostFileLogger.java
(original)
+++ qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/logging/VirtualHostFileLogger.java
Wed Jul 15 12:59:02 2015
@@ -22,6 +22,7 @@ package org.apache.qpid.server.logging;
 
 
 import java.util.Collection;
+import java.util.List;
 import java.util.Set;
 
 import org.apache.qpid.server.model.DerivedAttribute;
@@ -61,7 +62,7 @@ public interface VirtualHostFileLogger<X
     String getLayout();
 
     @DerivedAttribute
-    Collection<LogFileDetails> getLogFiles();
+    List<LogFileDetails> getLogFiles();
 
     @ManagedOperation(nonModifying = true)
     Content getFile(@Param(name = "fileName") String fileName);

Modified: qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/logging/VirtualHostFileLoggerImpl.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/logging/VirtualHostFileLoggerImpl.java?rev=1691202&r1=1691201&r2=1691202&view=diff
==============================================================================
--- qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/logging/VirtualHostFileLoggerImpl.java
(original)
+++ qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/logging/VirtualHostFileLoggerImpl.java
Wed Jul 15 12:59:02 2015
@@ -22,7 +22,7 @@ package org.apache.qpid.server.logging;
 
 import java.io.File;
 import java.security.AccessControlException;
-import java.util.Collection;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.Executors;
@@ -138,7 +138,7 @@ public class VirtualHostFileLoggerImpl e
     }
 
     @Override
-    public Collection<LogFileDetails> getLogFiles()
+    public List<LogFileDetails> getLogFiles()
     {
         return _rolloverWatcher.getLogFileDetails();
     }

Modified: qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/logging/logback/RolloverWatcher.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/logging/logback/RolloverWatcher.java?rev=1691202&r1=1691201&r2=1691202&view=diff
==============================================================================
--- qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/logging/logback/RolloverWatcher.java
(original)
+++ qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/logging/logback/RolloverWatcher.java
Wed Jul 15 12:59:02 2015
@@ -26,6 +26,7 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Comparator;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
@@ -42,6 +43,14 @@ import org.apache.qpid.server.logging.Zi
 public class RolloverWatcher implements RollingPolicyDecorator.RolloverListener
 {
     private static final Logger LOGGER = LoggerFactory.getLogger(RolloverWatcher.class);
+    private static final Comparator<LogFileDetails> LAST_MODIFIED_COMPARATOR = new
Comparator<LogFileDetails>()
+    {
+        @Override
+        public int compare(final LogFileDetails o1, final LogFileDetails o2)
+        {
+            return (int) (o2.getLastModified() - o1.getLastModified());
+        }
+    };
     private final Path _activeFilePath;
     private volatile Collection<String> _rolledFiles;
     private volatile Path _baseFolder;
@@ -111,6 +120,7 @@ public class RolloverWatcher implements
             LogFileDetails details = getFileDetails(file);
             results.add(details);
         }
+        Collections.sort(results, LAST_MODIFIED_COMPARATOR);
         return results;
     }
 

Modified: qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/logging/logback/RolloverWatcherTest.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/logging/logback/RolloverWatcherTest.java?rev=1691202&r1=1691201&r2=1691202&view=diff
==============================================================================
--- qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/logging/logback/RolloverWatcherTest.java
(original)
+++ qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/logging/logback/RolloverWatcherTest.java
Wed Jul 15 12:59:02 2015
@@ -69,6 +69,39 @@ public class RolloverWatcherTest extends
                 new HashSet<>(_rolloverWatcher.getRolledFiles()));
     }
 
+    public void testGetLogFileDetailsIsOrdered() throws Exception
+    {
+
+        String[] files = {"test1", "test2"};
+        List<String> expectedOrder = new ArrayList<>();
+
+        _activeFile.createNewFile();
+        expectedOrder.add(_activeFile.toPath().getFileName().toString());
+
+        long lastModified = System.currentTimeMillis() - (1000 * 60 * 5);
+        for(String filename : files)
+        {
+            File file = new File(_baseFolder, filename);
+            file.createNewFile();
+            file.setLastModified(lastModified);
+            lastModified += 1000 * 30;
+            expectedOrder.add(1, filename);
+        }
+
+        _rolloverWatcher.onRollover(_baseFolder.toPath(), files);
+
+        List<LogFileDetails> orderedDetails = _rolloverWatcher.getLogFileDetails();
+
+        assertEquals("Unexpected number of log file details", expectedOrder.size(), orderedDetails.size());
+
+        for (int i = 0; i < expectedOrder.size(); i++)
+        {
+            String expectedFilename = expectedOrder.get(i);
+            String actualFilename = orderedDetails.get(i).getName();
+            assertEquals("Unexpected filename at position " + i, expectedFilename, actualFilename);
+        }
+    }
+
     public void testGetTypedContentForActiveFile() throws Exception
     {
         _rolloverWatcher.onRollover(_baseFolder.toPath(), new String[]{});



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message