You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by kw...@apache.org on 2011/09/23 12:55:29 UTC

svn commit: r1174648 - in /qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid: server/logging/AbstractTestLogging.java test/utils/QpidBrokerTestCase.java util/LogMonitor.java util/LogMonitorTest.java

Author: kwall
Date: Fri Sep 23 10:55:28 2011
New Revision: 1174648

URL: http://svn.apache.org/viewvc?rev=1174648&view=rev
Log:
QPID-3501: LogMonitor duplicates chunks of log file if it fails to find match. Avoid busy-wait in LogMonitor whilst polling log file. Make QpidBrokerTestCase use a autoflushing PrintStream for writing broker messages to log (client side messages were already autoflushed as this is a default behaviour of the log4j Appender).

Modified:
    qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AbstractTestLogging.java
    qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java
    qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/util/LogMonitor.java
    qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/util/LogMonitorTest.java

Modified: qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AbstractTestLogging.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AbstractTestLogging.java?rev=1174648&r1=1174647&r2=1174648&view=diff
==============================================================================
--- qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AbstractTestLogging.java (original)
+++ qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AbstractTestLogging.java Fri Sep 23 10:55:28 2011
@@ -349,7 +349,7 @@ public class AbstractTestLogging extends
 
     public boolean waitForMessage(String message, long wait) throws FileNotFoundException, IOException
     {
-        return _monitor.waitForMessage(message, wait, true);
+        return _monitor.waitForMessage(message, wait);
     }
 
     /**

Modified: qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java?rev=1174648&r1=1174647&r2=1174648&view=diff
==============================================================================
--- qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java (original)
+++ qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java Fri Sep 23 10:55:28 2011
@@ -52,7 +52,6 @@ import javax.naming.NamingException;
 import org.apache.commons.configuration.ConfigurationException;
 import org.apache.commons.configuration.XMLConfiguration;
 import org.apache.commons.lang.StringUtils;
-import org.apache.log4j.Level;
 import org.apache.log4j.Logger;
 import org.apache.qpid.AMQException;
 import org.apache.qpid.client.AMQConnectionFactory;
@@ -217,7 +216,7 @@ public class QpidBrokerTestCase extends 
         if (redirected)
         {
             _outputFile = new File(String.format("%s/TEST-%s.out", _output, qname));
-            out = new PrintStream(_outputFile);
+            out = new PrintStream(new FileOutputStream(_outputFile), true);
             err = new PrintStream(String.format("%s/TEST-%s.err", _output, qname));
 
             // This is relying on behaviour specific to log4j 1.2.12.   If we were to upgrade to 1.2.13 or

Modified: qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/util/LogMonitor.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/util/LogMonitor.java?rev=1174648&r1=1174647&r2=1174648&view=diff
==============================================================================
--- qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/util/LogMonitor.java (original)
+++ qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/util/LogMonitor.java Fri Sep 23 10:55:28 2011
@@ -30,7 +30,6 @@ import java.io.FileNotFoundException;
 import java.io.FileReader;
 import java.io.IOException;
 import java.io.LineNumberReader;
-import java.util.ArrayList;
 import java.util.List;
 import java.util.LinkedList;
 
@@ -44,10 +43,10 @@ import java.util.LinkedList;
 public class LogMonitor
 {
     // The file that the log statements will be written to.
-    private File _logfile;
+    private final File _logfile;
 
     // The appender we added to the get messages
-    private FileAppender _appender;
+    private final FileAppender _appender;
 
     private int _linesToSkip = 0;
 
@@ -79,6 +78,7 @@ public class LogMonitor
         if (file != null && file.exists())
         {
             _logfile = file;
+            _appender = null;
         }
         else
         {
@@ -100,13 +100,13 @@ public class LogMonitor
      * @param wait    the time in ms to wait for the message to occur
      * @return true if the message was found
      *
-     * @throws java.io.FileNotFoundException if the Log file can nolonger be found
+     * @throws java.io.FileNotFoundException if the Log file can no longer be found
      * @throws IOException                   thrown when reading the log file
      */
     public List<String> waitAndFindMatches(String message, long wait)
             throws FileNotFoundException, IOException
     {
-        if (waitForMessage(message, wait, true))
+        if (waitForMessage(message, wait))
         {
             return findMatches(message);
         }
@@ -163,15 +163,12 @@ public class LogMonitor
      *
      * @param message the message to wait for in the log
      * @param wait    the time in ms to wait for the message to occur
-     *
-     * @param printFileOnFailure should we print the contents that have been
-     * read if we fail to find the message.
      * @return true if the message was found
      *
-     * @throws java.io.FileNotFoundException if the Log file can nolonger be found
+     * @throws java.io.FileNotFoundException if the Log file can no longer be found
      * @throws IOException                   thrown when reading the log file
      */
-    public boolean waitForMessage(String message, long wait, boolean printFileOnFailure)
+    public boolean waitForMessage(String message, long wait)
             throws FileNotFoundException, IOException
     {
         // Loop through alerts until we're done or wait ms seconds have passed,
@@ -183,28 +180,32 @@ public class LogMonitor
 
             boolean found = false;
             long endtime = System.currentTimeMillis() + wait;
-            ArrayList<String> contents = new ArrayList<String>();
             while (!found && System.currentTimeMillis() < endtime)
             {
-                while (reader.ready())
+                boolean ready = true;
+                while (ready = reader.ready())
                 {
                     String line = reader.readLine();
 
                     if (reader.getLineNumber() > _linesToSkip)
                     {
-                        contents.add(line);
                         if (line.contains(message))
                         {
                             found = true;
+                            break;
                         }
                     }
                 }
-            }
-            if (!found && printFileOnFailure)
-            {
-                for (String line : contents)
+                if (!ready)
                 {
-                    System.out.println(line);
+                    try
+                    {
+                        Thread.sleep(50);
+                    }
+                    catch (InterruptedException ie)
+                    {
+                        Thread.currentThread().interrupt();
+                    }
                 }
             }
             return found;
@@ -219,17 +220,12 @@ public class LogMonitor
         }
     }
     
-    public boolean waitForMessage(String message, long alertLogWaitPeriod) throws FileNotFoundException, IOException
-    {
-       return waitForMessage(message, alertLogWaitPeriod, true);
-    }
-
     /**
      * Read the log file in to memory as a String
      *
      * @return the current contents of the log file
      *
-     * @throws java.io.FileNotFoundException if the Log file can nolonger be found
+     * @throws java.io.FileNotFoundException if the Log file can no longer be found
      * @throws IOException                   thrown when reading the log file
      */
     public String readFile() throws FileNotFoundException, IOException

Modified: qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/util/LogMonitorTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/util/LogMonitorTest.java?rev=1174648&r1=1174647&r2=1174648&view=diff
==============================================================================
--- qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/util/LogMonitorTest.java (original)
+++ qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/util/LogMonitorTest.java Fri Sep 23 10:55:28 2011
@@ -168,7 +168,7 @@ public class LogMonitorTest extends Test
 
         // Verify that we can time out waiting for a message
         assertFalse("Message was logged ",
-                    _monitor.waitForMessage(message, TIME_OUT / 2, false));
+                    _monitor.waitForMessage(message, TIME_OUT / 2));
 
         // Verify that the message did eventually get logged.
         assertTrue("Message was never logged.",



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org