Author: kwall
Date: Thu Sep 22 15:19:29 2011
New Revision: 1174196
URL: http://svn.apache.org/viewvc?rev=1174196&view=rev
Log:
QPID-3501: LogMonitor can corrupt test logs files and cause tests subclassing
AbstractLoggingTests to fail.
Modified:
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/ManagementActorLoggingTest.java
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AlertingTest.java
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/BindingLoggingTest.java
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/DerbyMessageStoreLoggingTest.java
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/DurableQueueLoggingTest.java
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/ExchangeLoggingTest.java
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/QueueLoggingTest.java
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/SubscriptionLoggingTest.java
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/queue/ProducerFlowControlTest.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/management/jmx/ManagementActorLoggingTest.java
URL:
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/ManagementActorLoggingTest.java?rev=1174196&r1=1174195&r2=1174196&view=diff
==============================================================================
---
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/ManagementActorLoggingTest.java
(original)
+++
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/ManagementActorLoggingTest.java
Thu Sep 22 15:19:29 2011
@@ -106,7 +106,7 @@ public class ManagementActorLoggingTest
});
//Remove the connection close from any 0-10 connections
- _monitor.reset();
+ _monitor.markDiscardPoint();
// Get a managedConnection
ManagedConnection mangedConnection =
_jmxUtils.getManagedObject(ManagedConnection.class,
"org.apache.qpid:type=VirtualHost.Connection,*");
@@ -147,7 +147,7 @@ public class ManagementActorLoggingTest
*/
public void testCreateExchangeDirectTransientViaManagementConsole() throws
IOException, JMException
{
- _monitor.reset();
+ _monitor.markDiscardPoint();
_jmxUtils.createExchange("test", getName(), "direct", false);
@@ -171,7 +171,7 @@ public class ManagementActorLoggingTest
public void testCreateExchangeTopicTransientViaManagementConsole() throws
IOException, JMException
{
//Remove any previous exchange declares
- _monitor.reset();
+ _monitor.markDiscardPoint();
_jmxUtils.createExchange("test", getName(), "topic", false);
@@ -196,7 +196,7 @@ public class ManagementActorLoggingTest
public void testCreateExchangeFanoutTransientViaManagementConsole() throws
IOException, JMException
{
//Remove any previous exchange declares
- _monitor.reset();
+ _monitor.markDiscardPoint();
_jmxUtils.createExchange("test", getName(), "fanout", false);
@@ -221,7 +221,7 @@ public class ManagementActorLoggingTest
public void testCreateExchangeHeadersTransientViaManagementConsole()
throws IOException, JMException
{
//Remove any previous exchange declares
- _monitor.reset();
+ _monitor.markDiscardPoint();
_jmxUtils.createExchange("test", getName(), "headers", false);
@@ -265,7 +265,7 @@ public class ManagementActorLoggingTest
public void testCreateQueueTransientViaManagementConsole() throws
IOException, JMException
{
//Remove any previous queue declares
- _monitor.reset();
+ _monitor.markDiscardPoint();
_jmxUtils.createQueue("test", getName(), null, false);
@@ -308,7 +308,7 @@ public class ManagementActorLoggingTest
public void testQueueDeleteViaManagementConsole() throws IOException,
JMException
{
//Remove any previous queue declares
- _monitor.reset();
+ _monitor.markDiscardPoint();
_jmxUtils.createQueue("test", getName(), null, false);
@@ -354,7 +354,7 @@ public class ManagementActorLoggingTest
public void testBindingCreateOnDirectViaManagementConsole() throws
IOException, JMException
{
//Remove any previous queue declares
- _monitor.reset();
+ _monitor.markDiscardPoint();
_jmxUtils.createQueue("test", getName(), null, false);
@@ -381,7 +381,7 @@ public class ManagementActorLoggingTest
public void testBindingCreateOnTopicViaManagementConsole() throws
IOException, JMException
{
//Remove any previous queue declares
- _monitor.reset();
+ _monitor.markDiscardPoint();
_jmxUtils.createQueue("test", getName(), null, false);
@@ -408,7 +408,7 @@ public class ManagementActorLoggingTest
public void testBindingCreateOnFanoutViaManagementConsole() throws
IOException, JMException
{
//Remove any previous queue declares
- _monitor.reset();
+ _monitor.markDiscardPoint();
_jmxUtils.createQueue("test", getName(), null, false);
@@ -455,7 +455,7 @@ public class ManagementActorLoggingTest
public void testUnRegisterExchangeViaManagementConsole() throws
IOException, JMException
{
//Remove any previous queue declares
- _monitor.reset();
+ _monitor.markDiscardPoint();
_jmxUtils.createExchange("test", getName(), "direct", false);
Modified:
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AlertingTest.java
URL:
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AlertingTest.java?rev=1174196&r1=1174195&r2=1174196&view=diff
==============================================================================
---
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AlertingTest.java
(original)
+++
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AlertingTest.java
Thu Sep 22 15:19:29 2011
@@ -136,7 +136,7 @@ public class AlertingTest extends Abstra
stopBroker();
// Rest the monitoring clearing the current output file.
- _monitor.reset();
+ _monitor.markDiscardPoint();
startBroker();
wasAlertFired();
}
@@ -169,7 +169,7 @@ public class AlertingTest extends Abstra
stopBroker();
- _monitor.reset();
+ _monitor.markDiscardPoint();
// Change max message count to 5, start broker and make sure that
that's triggered at the right time
setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST +
".queues.maximumMessageCount", "5");
Modified:
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/BindingLoggingTest.java
URL:
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/BindingLoggingTest.java?rev=1174196&r1=1174195&r2=1174196&view=diff
==============================================================================
---
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/BindingLoggingTest.java
(original)
+++
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/BindingLoggingTest.java
Thu Sep 22 15:19:29 2011
@@ -55,7 +55,7 @@ public class BindingLoggingTest extends
{
super.setUp();
//Ignore broker startup messages
- _monitor.reset();
+ _monitor.markDiscardPoint();
_connection = getConnection();
Modified:
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/DerbyMessageStoreLoggingTest.java
URL:
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/DerbyMessageStoreLoggingTest.java?rev=1174196&r1=1174195&r2=1174196&view=diff
==============================================================================
---
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/DerbyMessageStoreLoggingTest.java
(original)
+++
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/DerbyMessageStoreLoggingTest.java
Thu Sep 22 15:19:29 2011
@@ -496,7 +496,7 @@ public class DerbyMessageStoreLoggingTes
stopBroker();
// Clear our monitor
- _monitor.reset();
+ _monitor.markDiscardPoint();
startBroker();
Modified:
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/DurableQueueLoggingTest.java
URL:
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/DurableQueueLoggingTest.java?rev=1174196&r1=1174195&r2=1174196&view=diff
==============================================================================
---
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/DurableQueueLoggingTest.java
(original)
+++
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/DurableQueueLoggingTest.java
Thu Sep 22 15:19:29 2011
@@ -58,7 +58,7 @@ public class DurableQueueLoggingTest ext
{
super.setUp();
//Ensure we only have logs from our test
- _monitor.reset();
+ _monitor.markDiscardPoint();
_connection = getConnection();
_session = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Modified:
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/ExchangeLoggingTest.java
URL:
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/ExchangeLoggingTest.java?rev=1174196&r1=1174195&r2=1174196&view=diff
==============================================================================
---
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/ExchangeLoggingTest.java
(original)
+++
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/ExchangeLoggingTest.java
Thu Sep 22 15:19:29 2011
@@ -125,7 +125,7 @@ public class ExchangeLoggingTest extends
public void testExchangeCreate() throws JMSException, IOException
{
//Ignore broker startup messages
- _monitor.reset();
+ _monitor.markDiscardPoint();
_session.createConsumer(_queue);
// Ensure we have received the EXH log msg.
@@ -179,7 +179,7 @@ public class ExchangeLoggingTest extends
public void testExchangeDelete() throws Exception, IOException
{
//Ignore broker startup messages
- _monitor.reset();
+ _monitor.markDiscardPoint();
//create the exchange by creating a consumer
_session.createConsumer(_queue);
@@ -220,7 +220,7 @@ public class ExchangeLoggingTest extends
public void testDiscardedMessage() throws Exception
{
//Ignore broker startup messages
- _monitor.reset();
+ _monitor.markDiscardPoint();
if (!isBroker010())
{
Modified:
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/QueueLoggingTest.java
URL:
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/QueueLoggingTest.java?rev=1174196&r1=1174195&r2=1174196&view=diff
==============================================================================
---
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/QueueLoggingTest.java
(original)
+++
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/QueueLoggingTest.java
Thu Sep 22 15:19:29 2011
@@ -53,7 +53,7 @@ public class QueueLoggingTest extends Ab
{
super.setUp();
//Remove broker startup logging messages
- _monitor.reset();
+ _monitor.markDiscardPoint();
_connection = getConnection();
_session = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Modified:
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/SubscriptionLoggingTest.java
URL:
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/SubscriptionLoggingTest.java?rev=1174196&r1=1174195&r2=1174196&view=diff
==============================================================================
---
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/SubscriptionLoggingTest.java
(original)
+++
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/SubscriptionLoggingTest.java
Thu Sep 22 15:19:29 2011
@@ -58,7 +58,7 @@ public class SubscriptionLoggingTest ext
{
super.setUp();
//Remove broker startup logging messages
- _monitor.reset();
+ _monitor.markDiscardPoint();
_connection = getConnection();
Modified:
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/queue/ProducerFlowControlTest.java
URL:
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/queue/ProducerFlowControlTest.java?rev=1174196&r1=1174195&r2=1174196&view=diff
==============================================================================
---
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/queue/ProducerFlowControlTest.java
(original)
+++
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/queue/ProducerFlowControlTest.java
Thu Sep 22 15:19:29 2011
@@ -64,7 +64,7 @@ public class ProducerFlowControlTest ext
_jmxUtilConnected=false;
super.setUp();
- _monitor.reset();
+ _monitor.markDiscardPoint();
producerConnection = getConnection();
producerSession = producerConnection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
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=1174196&r1=1174195&r2=1174196&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
Thu Sep 22 15:19:29 2011
@@ -219,6 +219,11 @@ public class QpidBrokerTestCase extends
_outputFile = new File(String.format("%s/TEST-%s.out", _output,
qname));
out = new PrintStream(_outputFile);
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
+ // beyond we must change either code (or config) to ensure that
ConsoleAppender#setFollow
+ // is set to true otherwise log4j logging will not respect the
following reassignment.
+
System.setOut(out);
System.setErr(err);
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=1174196&r1=1174195&r2=1174196&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
Thu Sep 22 15:19:29 2011
@@ -27,10 +27,9 @@ import org.apache.log4j.SimpleLayout;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
-import java.io.OutputStreamWriter;
+import java.io.LineNumberReader;
import java.util.ArrayList;
import java.util.List;
import java.util.LinkedList;
@@ -50,6 +49,8 @@ public class LogMonitor
// The appender we added to the get messages
private FileAppender _appender;
+ private int _linesToSkip = 0;
+
/**
* Create a new LogMonitor that creates a new Log4j Appender and monitors
* all log4j output via the current configuration.
@@ -116,7 +117,9 @@ public class LogMonitor
}
/**
- * Checks the log for instances of the search string.
+ * Checks the log for instances of the search string. If the caller
+ * has previously called {@link #markDiscardPoint()}, lines up until the
discard
+ * point are not considered.
*
* The pattern parameter can take any valid argument used in
String.contains()
*
@@ -130,17 +133,39 @@ public class LogMonitor
*/
public List<String> findMatches(String pattern) throws IOException
{
- return FileUtils.searchFile(_logfile, pattern);
+
+ List<String> results = new LinkedList<String>();
+
+ LineNumberReader reader = new LineNumberReader(new
FileReader(_logfile));
+ try
+ {
+ while (reader.ready())
+ {
+ String line = reader.readLine();
+ if (reader.getLineNumber() > _linesToSkip &&
line.contains(pattern))
+ {
+ results.add(line);
+ }
+ }
+ }
+ finally
+ {
+ reader.close();
+ }
+
+ return results;
}
/**
- * Checks the log file for a given message to appear.
+ * Checks the log file for a given message to appear. If the caller
+ * has previously called {@link #markDiscardPoint()}, lines up until the
discard
+ * point are not considered.
*
* @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 ot find the message.
+ * 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
@@ -151,39 +176,54 @@ public class LogMonitor
{
// Loop through alerts until we're done or wait ms seconds have passed,
// just in case the logfile takes a while to flush.
- BufferedReader reader = new BufferedReader(new FileReader(_logfile));
- boolean found = false;
- long endtime = System.currentTimeMillis() + wait;
- ArrayList<String> contents = new ArrayList<String>();
- while (!found && System.currentTimeMillis() < endtime)
+ LineNumberReader reader = null;
+ try
{
- while (reader.ready())
+ reader = new LineNumberReader(new FileReader(_logfile));
+
+ boolean found = false;
+ long endtime = System.currentTimeMillis() + wait;
+ ArrayList<String> contents = new ArrayList<String>();
+ while (!found && System.currentTimeMillis() < endtime)
{
- String line = reader.readLine();
- contents.add(line);
- if (line.contains(message))
+ while (reader.ready())
+ {
+ String line = reader.readLine();
+
+ if (reader.getLineNumber() > _linesToSkip)
+ {
+ contents.add(line);
+ if (line.contains(message))
+ {
+ found = true;
+ }
+ }
+ }
+ }
+ if (!found && printFileOnFailure)
+ {
+ for (String line : contents)
{
- found = true;
+ System.out.println(line);
}
}
+ return found;
+
}
- if (!found && printFileOnFailure)
+ finally
{
- for (String line : contents)
+ if (reader != null)
{
- System.out.println(line);
+ reader.close();
}
}
- return found;
}
-
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
*
@@ -208,14 +248,37 @@ public class LogMonitor
}
/**
- * Clears the log file and writes: 'Log Monitor Reset' at the start of the
file
+ * Marks the discard point in 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 if there is a problem with
the log file
*/
- public void reset() throws FileNotFoundException, IOException
+ public void markDiscardPoint() throws FileNotFoundException, IOException
+ {
+ _linesToSkip = countLinesInFile();
+ }
+
+ private int countLinesInFile() throws IOException
{
- new FileOutputStream(_logfile).getChannel().truncate(0);
+ int lineCount = 0;
+ BufferedReader br = null;
+ try
+ {
+ br = new BufferedReader(new FileReader(_logfile));
+ while(br.readLine() != null)
+ {
+ lineCount++;
+ }
+
+ return lineCount;
+ }
+ finally
+ {
+ if (br != null)
+ {
+ br.close();
+ }
+ }
}
/**
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=1174196&r1=1174195&r2=1174196&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
Thu Sep 22 15:19:29 2011
@@ -155,7 +155,7 @@ public class LogMonitorTest extends Test
String notLogged = "This text was not logged";
- validateLogDoesNotContainsMessage(_monitor, notLogged);
+ validateLogDoesNotContainMessage(_monitor, notLogged);
}
public void testWaitForMessage_Timeout() throws IOException
@@ -175,21 +175,20 @@ public class LogMonitorTest extends Test
_monitor.waitForMessage(message, TIME_OUT));
}
- public void testReset() throws IOException
+ public void testDiscardPoint() throws IOException
{
- String message = getName() + ": Test Message";
-
- Logger.getRootLogger().warn(message);
-
- validateLogContainsMessage(_monitor, message);
+ String firstMessage = getName() + ": Test Message1";
+ Logger.getRootLogger().warn(firstMessage);
- String LOG_RESET_TEXT = "Log Monitor Reset";
+ validateLogContainsMessage(_monitor, firstMessage);
- validateLogDoesNotContainsMessage(_monitor, LOG_RESET_TEXT);
+ _monitor.markDiscardPoint();
- _monitor.reset();
+ validateLogDoesNotContainMessage(_monitor, firstMessage);
- assertEquals("", _monitor.readFile());
+ String secondMessage = getName() + ": Test Message2";
+ Logger.getRootLogger().warn(secondMessage);
+ validateLogContainsMessage(_monitor, secondMessage);
}
public void testRead() throws IOException
@@ -214,7 +213,7 @@ public class LogMonitorTest extends Test
*
* @throws IOException if a problems occurs
*/
- protected void validateLogDoesNotContainsMessage(LogMonitor log, String
message)
+ protected void validateLogDoesNotContainMessage(LogMonitor log, String
message)
throws IOException
{
List<String> results = log.findMatches(message);
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:[email protected]