diff options
| author | Robert Gemmell <robbie@apache.org> | 2010-09-01 15:06:24 +0000 |
|---|---|---|
| committer | Robert Gemmell <robbie@apache.org> | 2010-09-01 15:06:24 +0000 |
| commit | 003b392b57b5b91aa3f8f5798cc7ffd43f3eeeda (patch) | |
| tree | 56b7b989f3d5d2ee71b24f99c0067fccd9b7b19a | |
| parent | f9d97a68550b8961f40eaa6090d374076650919d (diff) | |
| download | qpid-python-003b392b57b5b91aa3f8f5798cc7ffd43f3eeeda.tar.gz | |
QPID-2838: add common code for repeated validations within test classes, helper methods for log scraping/dumping
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@991561 13f79535-47bb-0310-9956-ffa450edef68
18 files changed, 449 insertions, 543 deletions
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/ManagementActorLoggingTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/ManagementActorLoggingTest.java index 791330178c..19657ef396 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/ManagementActorLoggingTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/ManagementActorLoggingTest.java @@ -93,11 +93,11 @@ public class ManagementActorLoggingTest extends AbstractTestLogging */ public void testJMXManagementConsoleConnection() throws IOException { - List<String> results = _monitor.waitAndFindMatches("MNG-1007", DEFAULT_LOG_WAIT); + List<String> results = waitAndFindMatches("MNG-1007"); assertEquals("Unexpected Management Connection count", 1, results.size()); - String log = getLog(results.get(0)); + String log = getLogMessage(results, 0); validateMessageID("MNG-1007", log); @@ -106,14 +106,14 @@ public class ManagementActorLoggingTest extends AbstractTestLogging // MESSAGE [mng:1(rmi://169.24.29.116)] MNG-1007 : Open : User admin int connectionID = Integer.parseInt(fromActor(getLog(results.get(0))).charAt(4) + ""); - results = _monitor.findMatches("MNG-1008"); + results = findMatches("MNG-1008"); assertEquals("Unexpected Management Connection close count", 0, results.size()); _jmxUtils.close(); _closed = true; - results = _monitor.waitAndFindMatches("MNG-1008", DEFAULT_LOG_WAIT); + results = waitAndFindMatches("MNG-1008"); assertEquals("Unexpected Management Connection count", 1, results.size()); @@ -174,7 +174,7 @@ public class ManagementActorLoggingTest extends AbstractTestLogging exceptionReceived.await(2, TimeUnit.SECONDS)); //Validate results - List<String> results = _monitor.waitAndFindMatches("CON-1002", DEFAULT_LOG_WAIT); + List<String> results = waitAndFindMatches("CON-1002"); assertEquals("Unexpected Connection Close count", 1, results.size()); } @@ -209,11 +209,11 @@ public class ManagementActorLoggingTest extends AbstractTestLogging // Validate //1 - ID is correct - List<String> results = _monitor.waitAndFindMatches("EXH-1001", DEFAULT_LOG_WAIT); + List<String> results = waitAndFindMatches("EXH-1001"); assertEquals("More than one exchange creation found", 1, results.size()); - String log = getLog(results.get(0)); + String log = getLogMessage(results, 0); // Validate correct exchange name assertTrue("Incorrect exchange name created:" + log, log.endsWith(getName())); @@ -233,11 +233,11 @@ public class ManagementActorLoggingTest extends AbstractTestLogging // Validate //1 - ID is correct - List<String> results = _monitor.waitAndFindMatches("EXH-1001", DEFAULT_LOG_WAIT); + List<String> results = waitAndFindMatches("EXH-1001"); assertEquals("More than one exchange creation found", 1, results.size()); - String log = getLog(results.get(0)); + String log = getLogMessage(results, 0); // Validate correct exchange name assertTrue("Incorrect exchange name created:" + log, log.endsWith(getName())); @@ -258,11 +258,11 @@ public class ManagementActorLoggingTest extends AbstractTestLogging // Validate //1 - ID is correct - List<String> results = _monitor.waitAndFindMatches("EXH-1001", DEFAULT_LOG_WAIT); + List<String> results = waitAndFindMatches("EXH-1001"); assertEquals("More than one exchange creation found", 1, results.size()); - String log = getLog(results.get(0)); + String log = getLogMessage(results, 0); // Validate correct exchange name assertTrue("Incorrect exchange name created:" + log, log.endsWith(getName())); @@ -283,11 +283,11 @@ public class ManagementActorLoggingTest extends AbstractTestLogging // Validate //1 - ID is correct - List<String> results = _monitor.waitAndFindMatches("EXH-1001", DEFAULT_LOG_WAIT); + List<String> results = waitAndFindMatches("EXH-1001"); assertEquals("More than one exchange creation found", 1, results.size()); - String log = getLog(results.get(0)); + String log = getLogMessage(results, 0); // Validate correct exchange name assertTrue("Incorrect exchange name created:" + log, log.endsWith(getName())); @@ -326,11 +326,11 @@ public class ManagementActorLoggingTest extends AbstractTestLogging // Validate - List<String> results = _monitor.waitAndFindMatches("QUE-1001", DEFAULT_LOG_WAIT); + List<String> results = waitAndFindMatches("QUE-1001"); assertEquals("More than one queue creation found", 1, results.size()); - String log = getLog(results.get(0)); + String log = getLogMessage(results, 0); // Validate correct queue name String subject = fromSubject(log); @@ -371,7 +371,7 @@ public class ManagementActorLoggingTest extends AbstractTestLogging managedBroker.deleteQueue(getName()); - List<String> results = _monitor.waitAndFindMatches("QUE-1002", DEFAULT_LOG_WAIT); + List<String> results = waitAndFindMatches("QUE-1002"); assertEquals("More than one queue deletion found", 1, results.size()); @@ -417,11 +417,11 @@ public class ManagementActorLoggingTest extends AbstractTestLogging managedExchange.createNewBinding(getName(), getName()); - List<String> results = _monitor.waitAndFindMatches("BND-1001", DEFAULT_LOG_WAIT); + List<String> results = waitAndFindMatches("BND-1001"); assertEquals("More than one bind creation found", 1, results.size()); - String log = getLog(results.get(0)); + String log = getLogMessage(results, 0); // Validate correct binding String subject = fromSubject(log); @@ -444,11 +444,11 @@ public class ManagementActorLoggingTest extends AbstractTestLogging managedExchange.createNewBinding(getName(), getName()); - List<String> results = _monitor.waitAndFindMatches("BND-1001", DEFAULT_LOG_WAIT); + List<String> results = waitAndFindMatches("BND-1001"); assertEquals("More than one bind creation found", 1, results.size()); - String log = getLog(results.get(0)); + String log = getLogMessage(results, 0); // Validate correct binding String subject = fromSubject(log); @@ -471,11 +471,11 @@ public class ManagementActorLoggingTest extends AbstractTestLogging managedExchange.createNewBinding(getName(), getName()); - List<String> results = _monitor.waitAndFindMatches("BND-1001", DEFAULT_LOG_WAIT); + List<String> results = waitAndFindMatches("BND-1001"); assertEquals("More than one bind creation found", 1, results.size()); - String log = getLog(results.get(0)); + String log = getLogMessage(results, 0); // Validate correct binding String subject = fromSubject(log); @@ -518,7 +518,7 @@ public class ManagementActorLoggingTest extends AbstractTestLogging managedBroker.unregisterExchange(getName()); - List<String> results = _monitor.waitAndFindMatches("EXH-1002", DEFAULT_LOG_WAIT); + List<String> results = waitAndFindMatches("EXH-1002"); assertEquals("More than one exchange deletion found", 1, results.size()); diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/BrokerStartupTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/BrokerStartupTest.java index ca20efd2a9..f9227c53ba 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/server/BrokerStartupTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/BrokerStartupTest.java @@ -99,10 +99,10 @@ public class BrokerStartupTest extends AbstractTestLogging startBroker(); assertEquals("Log4j could not load desired configruation.", - 0, _monitor.findMatches("log4j:ERROR Could not read configuration file from URL").size()); + 0, findMatches("log4j:ERROR Could not read configuration file from URL").size()); assertEquals("Logging did not error as expected", - 1, _monitor.waitAndFindMatches("Logging configuration error: unable to read file ", DEFAULT_LOG_WAIT).size()); + 1, waitAndFindMatches("Logging configuration error: unable to read file ").size()); // Perfom some action on the broker to ensure that we hit the DEBUG @@ -120,7 +120,7 @@ public class BrokerStartupTest extends AbstractTestLogging assertEquals(COUNT,drainQueue(queue)); - List<String> results = _monitor.waitAndFindMatches("DEBUG", DEFAULT_LOG_WAIT); + List<String> results = waitAndFindMatches("DEBUG"); try { // Validation diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AbstractTestLogging.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AbstractTestLogging.java index 0a0186e865..96cf2d9b70 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AbstractTestLogging.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AbstractTestLogging.java @@ -33,12 +33,18 @@ import org.apache.qpid.server.virtualhost.VirtualHost; import org.apache.qpid.test.utils.QpidBrokerTestCase; import org.apache.qpid.util.LogMonitor; +import java.io.FileNotFoundException; import java.io.IOException; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; import java.util.List; +/** + * Abstract superclass for logging test set up and utility methods. + * + * So named to prevent it being selected itself as a test to run by the test suite. + */ public class AbstractTestLogging extends QpidBrokerTestCase { public static final long DEFAULT_LOG_WAIT = 2000; @@ -131,7 +137,7 @@ public class AbstractTestLogging extends QpidBrokerTestCase { // Ensure the alert has not occured yet assertEquals("Message has already occured:" + log, 0, - _monitor.findMatches(log).size()); + findMatches(log).size()); } protected void validateMessageID(String id, String log) @@ -321,6 +327,56 @@ public class AbstractTestLogging extends QpidBrokerTestCase int start = rawLog.indexOf("MESSAGE"); return rawLog.substring(start); } + + /** + * Extract the log entry from the result set. Positions are 0-based. + * + * @param results list of log message results to extract from + * @param position position in the list of the message to extract + * @return the message string + */ + protected String getLogMessage(List<String> results, int position) + { + return getLog(results.get(position)); + } + + /** + * Extract the nth-from-last log entry from the result set. + * + * @param results list of log message results to extract from + * @param positionFromEnd position from end of the message list to extract (eg 0 for last) + * @return the message string + */ + protected String getLogMessageFromEnd(List<String> results, int positionFromEnd) + { + int resultSize = results.size(); + return getLogMessage(results, resultSize - 1 - positionFromEnd); + } + + protected List<String> findMatches(String toFind) throws IOException + { + return _monitor.findMatches(toFind); + } + + protected List<String> waitAndFindMatches(String toFind) throws IOException + { + return waitAndFindMatches(toFind, DEFAULT_LOG_WAIT); + } + + protected List<String> waitAndFindMatches(String toFind, long wait) throws IOException + { + return _monitor.waitAndFindMatches(toFind, wait); + } + + public boolean waitForMessage(String message) throws FileNotFoundException, IOException + { + return waitForMessage(message, DEFAULT_LOG_WAIT); + } + + public boolean waitForMessage(String message, long wait) throws FileNotFoundException, IOException + { + return _monitor.waitForMessage(message, wait, true); + } /** * Given a list of messages that have been pulled out of a log file @@ -389,4 +445,30 @@ public class AbstractTestLogging extends QpidBrokerTestCase return filteredResults; } + /** + * Dump the log results. + */ + protected void dumpLogs(List<String> results) throws IOException + { + dumpLogs(results, null); + } + + /** + * Dump the log results or if there are none, the contents of the + * monitored log file if the monitor is non-null. + */ + protected void dumpLogs(List<String> results, LogMonitor monitor) throws IOException + { + System.err.println("Log Dump:"); + for (String log : results) + { + System.err.println(log); + } + + if (results.size() == 0 && monitor != null) + { + System.err.println("Monitored file contents:"); + System.err.println(monitor.readFile()); + } + } } diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AccessControlLoggingTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AccessControlLoggingTest.java index da11117962..b2e35ea8d7 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AccessControlLoggingTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AccessControlLoggingTest.java @@ -80,7 +80,7 @@ public class AccessControlLoggingTest extends AbstractTestLogging conn.start(); ((AMQSession<?, ?>) sess).createQueue(new AMQShortString("allow"), false, false, false); - List<String> matches = _monitor.findMatches(ACL_LOG_PREFIX); + List<String> matches = findMatches(ACL_LOG_PREFIX); assertTrue("Should be no ACL log messages", matches.isEmpty()); } @@ -95,11 +95,11 @@ public class AccessControlLoggingTest extends AbstractTestLogging conn.start(); ((AMQSession<?, ?>) sess).createQueue(new AMQShortString("allow-log"), false, false, false); - List<String> matches = _monitor.findMatches(ACL_LOG_PREFIX); + List<String> matches = findMatches(ACL_LOG_PREFIX); assertEquals("Should only be one ACL log message", 1, matches.size()); - String log = getLog(matches.get(0)); + String log = getLogMessage(matches, 0); String actor = fromActor(log); String subject = fromSubject(log); String message = getMessageString(fromMessage(log)); @@ -131,11 +131,11 @@ public class AccessControlLoggingTest extends AbstractTestLogging assertEquals("Expected ACCESS_REFUSED error code", AMQConstant.ACCESS_REFUSED, amqe.getErrorCode()); } - List<String> matches = _monitor.findMatches(ACL_LOG_PREFIX); + List<String> matches = findMatches(ACL_LOG_PREFIX); assertEquals("Should only be one ACL log message", 1, matches.size()); - String log = getLog(matches.get(0)); + String log = getLogMessage(matches, 0);; String actor = fromActor(log); String subject = fromSubject(log); String message = getMessageString(fromMessage(log)); @@ -167,7 +167,7 @@ public class AccessControlLoggingTest extends AbstractTestLogging assertEquals("Expected ACCESS_REFUSED error code", AMQConstant.ACCESS_REFUSED, amqe.getErrorCode()); } - List<String> matches = _monitor.findMatches(ACL_LOG_PREFIX); + List<String> matches = findMatches(ACL_LOG_PREFIX); assertTrue("Should be no ACL log messages", matches.isEmpty()); } diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AlertingTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AlertingTest.java index d7932dae78..495a8c33c6 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AlertingTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AlertingTest.java @@ -99,7 +99,7 @@ public class AlertingTest extends AbstractTestLogging */ private void wasAlertFired() throws Exception { - if (!_monitor.waitForMessage(MESSAGE_COUNT_ALERT, ALERT_LOG_WAIT_PERIOD)) + if (!waitForMessage(MESSAGE_COUNT_ALERT, ALERT_LOG_WAIT_PERIOD)) { StringBuffer message = new StringBuffer("Could not find 'MESSAGE_COUNT_ALERT' in log file: " + _monitor.getMonitoredFile().getAbsolutePath()); message.append("\n"); diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/BindingLoggingTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/BindingLoggingTest.java index db8d1ae36c..afda7d4ba9 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/BindingLoggingTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/BindingLoggingTest.java @@ -65,15 +65,15 @@ public class BindingLoggingTest extends AbstractTestLogging _topic = (Topic) getInitialContext().lookup(TOPIC); } - private void validateLogMessage(String log, String messageID, String exchange, String message) + private void validateLogMessage(String log, String messageID, String message, String exchange, String rkey, String queueName) { validateMessageID(messageID, log); String subject = fromSubject(log); - assertEquals("Queue not correct.", getName(), + assertEquals("Queue not correct.", queueName, AbstractTestLogSubject.getSlice("qu", subject)); - assertEquals("Routing Key not correct.", getName(), + assertEquals("Routing Key not correct.", rkey, AbstractTestLogSubject.getSlice("rk", subject)); assertEquals("Virtualhost not correct.", "/test", AbstractTestLogSubject.getSlice("vh", subject)); @@ -104,7 +104,7 @@ public class BindingLoggingTest extends AbstractTestLogging { _session.createConsumer(_queue).close(); - List<String> results = _monitor.waitAndFindMatches(BND_PREFIX, DEFAULT_LOG_WAIT); + List<String> results = waitAndFindMatches(BND_PREFIX); // We will have two binds as we bind all queues to the default exchange assertEquals("Result set larger than expected.", 2, results.size()); @@ -112,11 +112,12 @@ public class BindingLoggingTest extends AbstractTestLogging String exchange = "direct/<<default>>"; String messageID = "BND-1001"; String message = "Create"; + String queueName = _queue.getQueueName(); - validateLogMessage(getLog(results.get(0)), messageID, exchange, message); + validateLogMessage(getLogMessage(results, 0), messageID, message, exchange, queueName, queueName); exchange = "direct/amq.direct"; - validateLogMessage(getLog(results.get(1)), messageID, exchange, message); + validateLogMessage(getLogMessage(results, 1), messageID, message, exchange, queueName, queueName); } /** @@ -141,49 +142,26 @@ public class BindingLoggingTest extends AbstractTestLogging _session.createDurableSubscriber(_topic, getName(), SELECTOR, false).close(); - List<String> results = _monitor.waitAndFindMatches(BND_PREFIX, DEFAULT_LOG_WAIT); + List<String> results = waitAndFindMatches(BND_PREFIX); // We will have two binds as we bind all queues to the default exchange assertEquals("Result set larger than expected.", 2, results.size()); - String log = getLog(results.get(0)); - - //Verify the first entry is the default binding - validateMessageID("BND-1001", log); - - String subject = fromSubject(log); - - assertEquals("Queue not correct.", "clientid:" + getName(), - AbstractTestLogSubject.getSlice("qu", subject)); - // NOTE default binding is the queue name - assertEquals("Routing Key not correct.", "clientid:" + getName(), - AbstractTestLogSubject.getSlice("rk", subject)); - assertEquals("Virtualhost not correct.", "/test", - AbstractTestLogSubject.getSlice("vh", subject)); - assertEquals("Exchange not correct.", "direct/<<default>>", - AbstractTestLogSubject.getSlice("ex", fromSubject(log))); - - String message = getMessageString(log); + //Verify the first entry is the default binding + String messageID = "BND-1001"; + String message = "Create"; + + validateLogMessage(getLogMessage(results, 0), messageID, message, + "direct/<<default>>", "clientid:" + getName(), "clientid:" + getName()); //Default binding will be without the selector assertTrue("JMSSelector identified in binding:"+message, !message.contains("jms-selector")); // Perform full testing on the second non default binding - log = getLog(results.get(1)); - validateMessageID("BND-1001", log); - - subject = fromSubject(log); - - assertEquals("Queue not correct.", "clientid:" + getName(), - AbstractTestLogSubject.getSlice("qu", subject)); - assertEquals("Routing Key not correct.", "topic", - AbstractTestLogSubject.getSlice("rk", subject)); - assertEquals("Virtualhost not correct.", "/test", - AbstractTestLogSubject.getSlice("vh", subject)); - assertEquals("Exchange not correct.", "topic/amq.topic", - AbstractTestLogSubject.getSlice("ex", subject)); - - message = getMessageString(log); + message = getMessageString(fromMessage(getLogMessage(results, 1))); + + validateLogMessage(getLogMessage(results, 1), messageID, message, + "topic/amq.topic", "topic", "clientid:" + getName()); assertTrue("JMSSelector not identified in binding:"+message, message.contains("jms-selector")); assertTrue("Selector not part of binding.:"+message, message.contains(SELECTOR)); @@ -212,7 +190,7 @@ public class BindingLoggingTest extends AbstractTestLogging // and so unbind. _session.createConsumer(_session.createTemporaryQueue()).close(); - List<String> results = _monitor.waitAndFindMatches(BND_PREFIX, DEFAULT_LOG_WAIT); + List<String> results = waitAndFindMatches(BND_PREFIX); // We will have two binds as we bind all queues to the default exchange assertEquals("Result not as expected." + results, 4, results.size()); @@ -221,11 +199,11 @@ public class BindingLoggingTest extends AbstractTestLogging String messageID = "BND-1001"; String message = "Create"; - String log = getLog(results.get(0)); + String log = getLogMessage(results, 0); validateMessageID(messageID, log); assertEquals("Log Message not as expected", message, getMessageString(fromMessage(log))); - log = getLog(results.get(1)); + log = getLogMessage(results, 1); validateMessageID(messageID, log); assertEquals("Log Message not as expected", message, getMessageString(fromMessage(log))); @@ -236,32 +214,26 @@ public class BindingLoggingTest extends AbstractTestLogging messageID = "BND-1002"; message = "Deleted"; - log = getLog(results.get(2)); + log = getLogMessage(results, 2); validateMessageID(messageID, log); String subject = fromSubject(log); - - assertTrue("Routing Key does not start with TempQueue:"+AbstractTestLogSubject.getSlice("rk", subject), - AbstractTestLogSubject.getSlice("rk", subject).startsWith("TempQueue")); - assertEquals("Virtualhost not correct.", "/test", - AbstractTestLogSubject.getSlice("vh", subject)); + + validateBindingDeleteArguments(subject, "/test"); boolean defaultFirst = DEFAULT.equals(AbstractTestLogSubject.getSlice("ex", subject)); boolean directFirst = DIRECT.equals(AbstractTestLogSubject.getSlice("ex", subject)); assertEquals("Log Message not as expected", message, getMessageString(fromMessage(log))); - log = getLog(results.get(3)); + log = getLogMessage(results, 3); validateMessageID(messageID, log); subject = fromSubject(log); - assertTrue("Routing Key does not start with TempQueue:"+AbstractTestLogSubject.getSlice("rk", subject), - AbstractTestLogSubject.getSlice("rk", subject).startsWith("TempQueue")); - assertEquals("Virtualhost not correct.", "/test", - AbstractTestLogSubject.getSlice("vh", subject)); - + validateBindingDeleteArguments(subject, "/test"); + if (!defaultFirst) { assertEquals(DEFAULT, AbstractTestLogSubject.getSlice("ex", subject)); @@ -274,6 +246,15 @@ public class BindingLoggingTest extends AbstractTestLogging } assertEquals("Log Message not as expected", message, getMessageString(fromMessage(log))); - + } + + private void validateBindingDeleteArguments(String subject, String vhostName) + { + String routingKey = AbstractTestLogSubject.getSlice("rk", subject); + + assertTrue("Routing Key does not start with TempQueue:"+routingKey, + routingKey.startsWith("TempQueue")); + assertEquals("Virtualhost not correct.", vhostName, + AbstractTestLogSubject.getSlice("vh", subject)); } } diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/BrokerLoggingTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/BrokerLoggingTest.java index b5203742bd..ea6aec61c2 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/BrokerLoggingTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/BrokerLoggingTest.java @@ -96,22 +96,22 @@ public class BrokerLoggingTest extends AbstractTestLogging String configFilePath = _configFile.toString(); // Ensure we wait for TESTID to be logged - _monitor.waitAndFindMatches(TESTID, DEFAULT_LOG_WAIT); + waitAndFindMatches(TESTID); - List<String> results = _monitor.waitAndFindMatches(BRK_LOG_PREFIX, DEFAULT_LOG_WAIT); + List<String> results = waitAndFindMatches(BRK_LOG_PREFIX); try { // Validation assertTrue("BRKer message not logged", results.size() > 0); - String log = getLog(results.get(0)); + String log = getLogMessage(results, 0); //1 validateMessageID(TESTID, log); //2 - results = _monitor.findMatches(TESTID); + results = findMatches(TESTID); assertEquals("More than one configuration message found.", 1, results.size()); @@ -121,11 +121,8 @@ public class BrokerLoggingTest extends AbstractTestLogging } catch (AssertionFailedError afe) { - System.err.println("Log Dump:"); - for (String log : results) - { - System.err.println(log); - } + dumpLogs(results, _monitor); + throw afe; } } @@ -178,9 +175,9 @@ public class BrokerLoggingTest extends AbstractTestLogging getConnection(); // Ensure we wait for TESTID to be logged - _monitor.waitAndFindMatches(TESTID, DEFAULT_LOG_WAIT); + waitAndFindMatches(TESTID); - List<String> results = _monitor.waitAndFindMatches(BRK_LOG_PREFIX, DEFAULT_LOG_WAIT); + List<String> results = waitAndFindMatches(BRK_LOG_PREFIX); try { // Validation @@ -210,7 +207,7 @@ public class BrokerLoggingTest extends AbstractTestLogging //2 assertEquals("More than one log4j configuration message found.", - 1, _monitor.findMatches(TESTID).size()); + 1, findMatches(TESTID).size()); //3 String defaultLog4j = _configFile.getParent() + "/" + Main.DEFAULT_LOG_CONFIG_FILENAME; @@ -224,17 +221,7 @@ public class BrokerLoggingTest extends AbstractTestLogging } catch (AssertionFailedError afe) { - System.err.println("Log Dump:"); - for (String log : results) - { - System.err.println(log); - } - - if (results.size() == 0) - { - System.err.println("Monitored file contents:"); - System.err.println(_monitor.readFile()); - } + dumpLogs(results, _monitor); throw afe; } @@ -279,9 +266,9 @@ public class BrokerLoggingTest extends AbstractTestLogging getConnection(); // Ensure we wait for TESTID to be logged - _monitor.waitAndFindMatches(TESTID, DEFAULT_LOG_WAIT); + waitAndFindMatches(TESTID); - List<String> results = _monitor.waitAndFindMatches(BRK_LOG_PREFIX, DEFAULT_LOG_WAIT); + List<String> results = waitAndFindMatches(BRK_LOG_PREFIX); try { // Validation @@ -310,7 +297,7 @@ public class BrokerLoggingTest extends AbstractTestLogging //2 assertEquals("More than one log4j configuration message found.", - 1, _monitor.findMatches(TESTID).size()); + 1, findMatches(TESTID).size()); //3 assertTrue("Log4j file details not correctly logged:" + getMessageString(log), @@ -323,17 +310,7 @@ public class BrokerLoggingTest extends AbstractTestLogging } catch (AssertionFailedError afe) { - System.err.println("Log Dump:"); - for (String log : results) - { - System.err.println(log); - } - - if (results.size() == 0) - { - System.err.println("Monitored file contents:"); - System.err.println(_monitor.readFile()); - } + dumpLogs(results, _monitor); throw afe; } @@ -368,11 +345,11 @@ public class BrokerLoggingTest extends AbstractTestLogging _monitor = new LogMonitor(_outputFile); // Ensure we wait for TESTID to be logged - _monitor.waitAndFindMatches(TESTID, DEFAULT_LOG_WAIT); + waitAndFindMatches(TESTID); // Retrieve all BRK- log messages so we can check for an erroneous // BRK-1002 message. - List<String> results = _monitor.findMatches(BRK_LOG_PREFIX); + List<String> results = findMatches(BRK_LOG_PREFIX); try { @@ -402,7 +379,7 @@ public class BrokerLoggingTest extends AbstractTestLogging //2 assertEquals("More than one startup message found.", - 1, _monitor.findMatches(TESTID).size()); + 1, findMatches(TESTID).size()); validation = true; } @@ -411,11 +388,8 @@ public class BrokerLoggingTest extends AbstractTestLogging } catch (AssertionFailedError afe) { - System.err.println("Log Dump:"); - for (String log : results) - { - System.err.println(log); - } + dumpLogs(results, _monitor); + throw afe; } } @@ -457,11 +431,11 @@ public class BrokerLoggingTest extends AbstractTestLogging getConnection(); // Ensure we wait for TESTID to be logged - _monitor.waitAndFindMatches(TESTID, DEFAULT_LOG_WAIT); + waitAndFindMatches(TESTID); // Retrieve all BRK- log messages so we can check for an erroneous // BRK-1002 message. - List<String> results = _monitor.findMatches(BRK_LOG_PREFIX); + List<String> results = findMatches(BRK_LOG_PREFIX); try { // Validation @@ -491,7 +465,7 @@ public class BrokerLoggingTest extends AbstractTestLogging //2 assertEquals("More than one listen message found.", - 1, _monitor.findMatches(TESTID).size()); + 1, findMatches(TESTID).size()); //3 String message = getMessageString(log); @@ -505,11 +479,8 @@ public class BrokerLoggingTest extends AbstractTestLogging } catch (AssertionFailedError afe) { - System.err.println("Log Dump:"); - for (String log : results) - { - System.err.println(log); - } + dumpLogs(results, _monitor); + throw afe; } } @@ -562,11 +533,11 @@ public class BrokerLoggingTest extends AbstractTestLogging getConnection(); // Ensure we wait for TESTID to be logged - _monitor.waitAndFindMatches(TESTID, DEFAULT_LOG_WAIT); + waitAndFindMatches(TESTID); // Retrieve all BRK- log messages so we can check for an erroneous // BRK-1002 message. - List<String> results = _monitor.findMatches(BRK_LOG_PREFIX); + List<String> results = findMatches(BRK_LOG_PREFIX); try { // Validation @@ -595,7 +566,7 @@ public class BrokerLoggingTest extends AbstractTestLogging validateMessageID(TESTID, log); //2 - List<String> listenMessages = _monitor.findMatches(TESTID); + List<String> listenMessages = findMatches(TESTID); assertEquals("Two listen messages should be found.", 2, listenMessages .size()); @@ -620,11 +591,8 @@ public class BrokerLoggingTest extends AbstractTestLogging } catch (AssertionFailedError afe) { - System.err.println("Log Dump:"); - for (String log : results) - { - System.err.println(log); - } + dumpLogs(results, _monitor); + throw afe; } } @@ -660,11 +628,11 @@ public class BrokerLoggingTest extends AbstractTestLogging //Ensure the broker has fully started up. getConnection(); // Ensure we wait for TESTID to be logged - _monitor.waitAndFindMatches(TESTID, DEFAULT_LOG_WAIT); + waitAndFindMatches(TESTID); // Retrieve all BRK- log messages so we can check for an erroneous // BRK-1001 message. - List<String> results = _monitor.findMatches(BRK_LOG_PREFIX); + List<String> results = findMatches(BRK_LOG_PREFIX); try { // Validation @@ -695,7 +663,7 @@ public class BrokerLoggingTest extends AbstractTestLogging //2 assertEquals("More than one ready message found.", - 1, _monitor.findMatches(TESTID).size()); + 1, findMatches(TESTID).size()); //3 assertEquals("Ready message not present", "Ready", getMessageString(log)); @@ -707,11 +675,8 @@ public class BrokerLoggingTest extends AbstractTestLogging } catch (AssertionFailedError afe) { - System.err.println("Log Dump:"); - for (String log : results) - { - System.err.println(log); - } + dumpLogs(results, _monitor); + throw afe; } } @@ -753,7 +718,7 @@ public class BrokerLoggingTest extends AbstractTestLogging //Give broker time to shutdown and flush log checkSocketClosed(getPort()); - List<String> results = _monitor.waitAndFindMatches(BRK_LOG_PREFIX, DEFAULT_LOG_WAIT); + List<String> results = waitAndFindMatches(BRK_LOG_PREFIX); try { // Validation @@ -783,7 +748,7 @@ public class BrokerLoggingTest extends AbstractTestLogging //2 assertEquals("More than one listen message found.", - 1, _monitor.findMatches(TESTID).size()); + 1, findMatches(TESTID).size()); //3 String message = getMessageString(log); @@ -800,11 +765,8 @@ public class BrokerLoggingTest extends AbstractTestLogging } catch (AssertionFailedError afe) { - System.err.println("Log Dump:"); - for (String log : results) - { - System.err.println(log); - } + dumpLogs(results, _monitor); + throw afe; } } @@ -861,7 +823,7 @@ public class BrokerLoggingTest extends AbstractTestLogging //Give broker time to shutdown and flush log checkSocketClosed(getPort()); - List<String> results = _monitor.waitAndFindMatches(TESTID, DEFAULT_LOG_WAIT); + List<String> results = waitAndFindMatches(TESTID); try { // Validation @@ -874,7 +836,7 @@ public class BrokerLoggingTest extends AbstractTestLogging validateMessageID(TESTID, log); //2 - List<String> listenMessages = _monitor.findMatches(TESTID); + List<String> listenMessages = findMatches(TESTID); assertEquals("Two shutdown messages should be found.", 2, listenMessages.size()); @@ -896,11 +858,8 @@ public class BrokerLoggingTest extends AbstractTestLogging } catch (AssertionFailedError afe) { - System.err.println("Log Dump:"); - for (String log : results) - { - System.err.println(log); - } + dumpLogs(results, _monitor); + throw afe; } } @@ -943,9 +902,9 @@ public class BrokerLoggingTest extends AbstractTestLogging // Ensure the broker has shutdown before retreving results checkSocketClosed(getPort()); - _monitor.waitAndFindMatches(TESTID, DEFAULT_LOG_WAIT); + waitAndFindMatches(TESTID); - List<String> results = _monitor.waitAndFindMatches(BRK_LOG_PREFIX, DEFAULT_LOG_WAIT); + List<String> results = waitAndFindMatches(BRK_LOG_PREFIX); try { // Validation @@ -969,7 +928,7 @@ public class BrokerLoggingTest extends AbstractTestLogging //2 assertEquals("More than one ready message found.", - 1, _monitor.findMatches(TESTID).size()); + 1, findMatches(TESTID).size()); //3 assertEquals("Stopped message not present", "Stopped", getMessageString(log)); @@ -981,14 +940,7 @@ public class BrokerLoggingTest extends AbstractTestLogging } catch (AssertionFailedError afe) { - System.err.println("Log Dump:"); - for (String log : results) - { - System.err.println(log); - } - - System.err.println("Monitored file contents:"); - System.err.println(_monitor.readFile()); + dumpLogs(results, _monitor); throw afe; } diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/ChannelLoggingTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/ChannelLoggingTest.java index 2d1a204ce4..0e7f4aa166 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/ChannelLoggingTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/ChannelLoggingTest.java @@ -65,21 +65,21 @@ public class ChannelLoggingTest extends AbstractTestLogging ((AMQConnection)connection).createSession(false, Session.AUTO_ACKNOWLEDGE,PREFETCH); // Wait to ensure that the CHN-1004 message is logged - _monitor.waitForMessage("CHN-1004", DEFAULT_LOG_WAIT); + waitForMessage("CHN-1004"); - List<String> results = _monitor.findMatches(CHANNEL_PREFIX); + List<String> results = findMatches(CHANNEL_PREFIX); // Validation assertEquals("CHN messages not logged", 2, results.size()); - String log = getLog(results.get(0)); + String log = getLogMessage(results, 0); // MESSAGE [con:0(guest@anonymous(3273383)/test)/ch:1] CHN-1001 : Create //1 & 2 validateMessageID("CHN-1001", log); assertEquals("Incorrect Channel in actor:"+fromActor(log), 1, getChannelID(fromActor(log))); - log = getLog(results.get(1)); + log = getLogMessage(results, 1); // MESSAGE [con:0(guest@anonymous(3273383)/test)/ch:1] CHN-1004 : Prefetch Size (bytes) {0,number} : Count {1,number} //1 & 2 validateMessageID("CHN-1004", log); @@ -123,9 +123,9 @@ public class ChannelLoggingTest extends AbstractTestLogging connection.start(); // Wait to ensure that the CHN-1002 message is logged - _monitor.waitForMessage("CHN-1002", DEFAULT_LOG_WAIT); + waitForMessage("CHN-1002"); - List<String> results = _monitor.findMatches(CHANNEL_PREFIX); + List<String> results = findMatches(CHANNEL_PREFIX); assertTrue("No CHN messages logged", results.size() > 0); @@ -133,13 +133,17 @@ public class ChannelLoggingTest extends AbstractTestLogging // // INFO - MESSAGE [con:0(guest@anonymous(4205299)/test)/ch:1] [con:0(guest@anonymous(4205299)/test)/ch:1] CHN-1002 : Flow Stopped - // Verify - int resultSize = results.size(); - String log = getLog(results.get(resultSize - 1)); + // Verify the last channel message is stopped + validateChannelStart(results, false); + } - validateMessageID("CHN-1002", log); - assertEquals("Message should be Flow Stopped", "Flow Stopped", getMessageString(fromMessage(log))); + private void validateChannelStart(List<String> results, boolean flowStarted) + { + String log = getLogMessageFromEnd(results, 0); + String flow = flowStarted ? "Started" : "Stopped"; + validateMessageID("CHN-1002", log); + assertEquals("Message should be Flow " + flow, "Flow " + flow, getMessageString(fromMessage(log))); } /** @@ -185,9 +189,9 @@ public class ChannelLoggingTest extends AbstractTestLogging _monitor.waitForMessage(CHANNEL_PREFIX, 2000); // Wait to ensure that the CHN-1002 message is logged - _monitor.waitForMessage("CHN-1002", DEFAULT_LOG_WAIT); + waitForMessage("CHN-1002"); - List<String> results = _monitor.findMatches(CHANNEL_PREFIX); + List<String> results = findMatches(CHANNEL_PREFIX); assertTrue("No CHN messages logged", results.size() > 0); @@ -196,13 +200,8 @@ public class ChannelLoggingTest extends AbstractTestLogging // INFO [qpid.message] MESSAGE [con:1(guest@/127.0.0.1:49869/test)/ch:1] [con:1(guest@/127.0.0.1:49869/test)/ch:1] CHN-1002 : Flow Stopped // INFO [qpid.message] MESSAGE [con:1(guest@/127.0.0.1:49869/test)/ch:1] [con:1(guest@/127.0.0.1:49869/test)/ch:1] CHN-1002 : Flow Started - // Verify the last channel msg is Started. - int resultSize = results.size(); - String log = getLog(results.get(resultSize - 1)); - - validateMessageID("CHN-1002", log); - assertEquals("Message should be Flow Started", "Flow Started", getMessageString(fromMessage(log))); + validateChannelStart(results, true); } /** @@ -237,9 +236,9 @@ public class ChannelLoggingTest extends AbstractTestLogging connection.close(); // Wait to ensure that the CHN-1003 message is logged - _monitor.waitForMessage("CHN-1003", DEFAULT_LOG_WAIT); + waitForMessage("CHN-1003"); - List<String> results = _monitor.findMatches(CHANNEL_PREFIX); + List<String> results = findMatches(CHANNEL_PREFIX); assertTrue("No CHN messages logged", results.size() > 0); @@ -248,14 +247,7 @@ public class ChannelLoggingTest extends AbstractTestLogging // INFO - MESSAGE [con:0(guest@anonymous(4205299)/test)/ch:1] [con:0(guest@anonymous(4205299)/test)/ch:1] CHN-1002 : Flow On // Verify - - int resultSize = results.size(); - String log = getLog(results.get(resultSize - 1)); - - validateMessageID("CHN-1003", log); - assertEquals("Message should be Close", "Close",getMessageString(fromMessage(log))); - assertEquals("Incorrect Channel ID closed.", 1, getChannelID(fromActor(log))); - assertEquals("Incorrect Channel ID closed.", 1, getChannelID(fromSubject(log))); + validateChannelClose(results); } /** @@ -287,20 +279,23 @@ public class ChannelLoggingTest extends AbstractTestLogging connection.createSession(false, Session.AUTO_ACKNOWLEDGE).close(); // Wait to ensure that the CHN-1003 message is logged - _monitor.waitForMessage("CHN-1003", DEFAULT_LOG_WAIT); + waitForMessage("CHN-1003"); - List<String> results = _monitor.findMatches(CHANNEL_PREFIX); + List<String> results = findMatches(CHANNEL_PREFIX); assertTrue("No CHN messages logged", results.size() > 0); // Verify - int resultSize = results.size(); - String log = getLog(results.get(resultSize - 1)); + validateChannelClose(results); + } + + private void validateChannelClose(List<String> results) + { + String log = getLogMessageFromEnd(results, 0); validateMessageID("CHN-1003", log); assertEquals("Message should be Close", "Close",getMessageString(fromMessage(log))); assertEquals("Incorrect Channel ID closed.", 1, getChannelID(fromActor(log))); assertEquals("Incorrect Channel ID closed.", 1, getChannelID(fromSubject(log))); } - }
\ No newline at end of file diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/ConnectionLoggingTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/ConnectionLoggingTest.java index 9bdf2bb7a3..e6b29c392d 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/ConnectionLoggingTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/ConnectionLoggingTest.java @@ -21,7 +21,6 @@ package org.apache.qpid.server.logging; import javax.jms.Connection; -import java.io.File; import java.util.List; import java.util.HashMap; import java.util.TreeSet; @@ -55,7 +54,7 @@ public class ConnectionLoggingTest extends AbstractTestLogging Connection connection = getConnection(); - List<String> results = _monitor.waitAndFindMatches(CONNECTION_PREFIX, DEFAULT_LOG_WAIT); + List<String> results = waitAndFindMatches(CONNECTION_PREFIX); assertTrue("No CON messages logged", results.size() > 0); @@ -84,44 +83,46 @@ public class ConnectionLoggingTest extends AbstractTestLogging // open and close messages from the failed 0-10 negotiation assertTrue("CON messages not logged:" + results.size(), results.size() >= 3); - String log = getLog(results.get(0)); + String log = getLogMessage(results, 0); // MESSAGE [con:1(/127.0.0.1:52540)] CON-1001 : Open //1 & 2 validateMessageID("CON-1001",log); - //We get the size so that we can validate the last three CON- messages - int resultsSize = results.size(); - // This is because when running externally we will also have logged the failed - // 0-10 negotiation messages + // validate the last three CON- messages. + // This is because when running externally we may also have logged the failed + // 0-10 negotiation messages if using 0-8/0-9 on the broker. // 3 - Assert the options are correct - log = getLog(results.get(resultsSize - 1)); // MESSAGE [con:1(/127.0.0.1:52540)] CON-1001 : Open : Client ID : clientid : Protocol Version : 0-9 - validateMessageID("CON-1001",log); - assertTrue("Client ID option is not present", fromMessage(log).contains("Client ID :")); - assertTrue("Client ID value is not present", fromMessage(log).contains(connection.getClientID())); - - assertTrue("Protocol Version option is not present", fromMessage(log).contains("Protocol Version :")); - //fixme there is no way currently to find out the negotiated protocol version - // The delegate is the versioned class ((AMQConnection)connection)._delegate + validateConnectionOpen(results, 0, true, true, connection.getClientID()); - log = getLog(results.get(resultsSize - 2)); // MESSAGE [con:1(/127.0.0.1:52540)] CON-1001 : Open : Protocol Version : 0-9 - validateMessageID("CON-1001",log); - assertTrue("Protocol Version option is not present", fromMessage(log).contains("Protocol Version :")); - //fixme agani we should check the version - // Check that client ID is not present in log - assertTrue("Client ID option is present", !fromMessage(log).contains("Client ID :")); + validateConnectionOpen(results, 1, true, false, null); - log = getLog(results.get(resultsSize - 3)); - validateMessageID("CON-1001",log); - // Check that PV is not present in log - assertTrue("Protocol Version option is present", !fromMessage(log).contains("Protocol Version :")); - // Check that client ID is not present in log - assertTrue("Client ID option is present", !fromMessage(log).contains("Client ID :")); + validateConnectionOpen(results, 2, false, false, null); connection.close(); } + + private void validateConnectionOpen(List<String> results, int positionFromEnd, + boolean protocolVersionPresent, boolean clientIdOptionPresent, String clientIdValue) + { + String log = getLogMessageFromEnd(results, positionFromEnd); + + validateMessageID("CON-1001",log); + + assertEquals("unexpected Client ID option state", clientIdOptionPresent, fromMessage(log).contains("Client ID :")); + + if(clientIdOptionPresent && clientIdValue != null) + { + assertTrue("Client ID value is not present", fromMessage(log).contains(clientIdValue)); + } + + assertEquals("unexpected Protocol Version option state", + protocolVersionPresent, fromMessage(log).contains("Protocol Version :")); + //fixme there is no way currently to find out the negotiated protocol version + // The delegate is the versioned class ((AMQConnection)connection)._delegate + } /** * Description: @@ -147,20 +148,17 @@ public class ConnectionLoggingTest extends AbstractTestLogging getConnection().close(); // Wait to ensure that the desired message is logged - _monitor.waitForMessage("CON-1002", DEFAULT_LOG_WAIT); + waitForMessage("CON-1002"); - List<String> results = _monitor.findMatches(CONNECTION_PREFIX); + List<String> results = findMatches(CONNECTION_PREFIX); // Validation // We should have at least four messages assertTrue("CON messages not logged:" + results.size(), results.size() >= 4); - //We get the size so that we can validate the last set of CON- messages - int resultsSize = results.size(); - // Validate Close message occurs - String log = getLog(results.get(resultsSize - 1)); + String log = getLogMessageFromEnd(results, 0); validateMessageID("CON-1002",log); assertTrue("Message does not end with close:" + log, log.endsWith("Close")); @@ -168,7 +166,7 @@ public class ConnectionLoggingTest extends AbstractTestLogging int connectionID = getConnectionID(log); //Previous log message should be the open - log = getLog(results.get(resultsSize - 2)); + log = getLogMessageFromEnd(results, 1); // MESSAGE [con:1(/127.0.0.1:52540)] CON-1001 : Open : Client ID : clientid : Protocol Version : 0-9 validateMessageID("CON-1001",log); assertEquals("Connection IDs do not match", connectionID, getConnectionID(fromActor(log))); diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/DerbyMessageStoreLoggingTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/DerbyMessageStoreLoggingTest.java index 13b0b7dda1..16c529316a 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/DerbyMessageStoreLoggingTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/DerbyMessageStoreLoggingTest.java @@ -92,7 +92,7 @@ public class DerbyMessageStoreLoggingTest extends MemoryMessageStoreLoggingTest startBroker(); - List<String> results = _monitor.waitAndFindMatches(MESSAGES_STORE_PREFIX, DEFAULT_LOG_WAIT); + List<String> results = waitAndFindMatches(MESSAGES_STORE_PREFIX); // Validation @@ -104,13 +104,13 @@ public class DerbyMessageStoreLoggingTest extends MemoryMessageStoreLoggingTest List<String> vhosts = configuration.getConfig().getList("virtualhosts.virtualhost.name"); //Validate each vhost logs a creation - results = _monitor.waitAndFindMatches("MST-1002", DEFAULT_LOG_WAIT); + results = waitAndFindMatches("MST-1002"); assertEquals("Each vhost did not close its store.", vhosts.size(), results.size()); for (int index = 0; index < results.size(); index++) { - String result = getLog(results.get(index)); + String result = getLogMessage(results, index);; // getSlize will return extract the vhost from vh(/test) -> '/test' // so remove the '/' to get the name @@ -156,7 +156,7 @@ public class DerbyMessageStoreLoggingTest extends MemoryMessageStoreLoggingTest startBroker(); - List<String> results = _monitor.waitAndFindMatches(MESSAGES_STORE_PREFIX, DEFAULT_LOG_WAIT); + List<String> results = waitAndFindMatches(MESSAGES_STORE_PREFIX); // Validation @@ -168,13 +168,13 @@ public class DerbyMessageStoreLoggingTest extends MemoryMessageStoreLoggingTest List<String> vhosts = configuration.getConfig().getList("virtualhosts.virtualhost.name"); //Validate each vhost logs a creation - results = _monitor.waitAndFindMatches("MST-1004", DEFAULT_LOG_WAIT); + results = waitAndFindMatches("MST-1004"); assertTrue("Each vhost did not close its store.", vhosts.size() <= results.size()); for (int index = 0; index < results.size(); index++) { - String result = getLog(results.get(index)); + String result = getLogMessage(results, index);; if (getMessageString(result).contains("Recovery Start :")) { @@ -224,7 +224,7 @@ public class DerbyMessageStoreLoggingTest extends MemoryMessageStoreLoggingTest startBroker(); - List<String> results = _monitor.waitAndFindMatches(MESSAGES_STORE_PREFIX, DEFAULT_LOG_WAIT); + List<String> results = waitAndFindMatches(MESSAGES_STORE_PREFIX); // Validation @@ -236,13 +236,13 @@ public class DerbyMessageStoreLoggingTest extends MemoryMessageStoreLoggingTest List<String> vhosts = configuration.getConfig().getList("virtualhosts.virtualhost.name"); //Validate each vhost logs a creation - results = _monitor.waitAndFindMatches("MST-1006", DEFAULT_LOG_WAIT); + results = waitAndFindMatches("MST-1006"); assertTrue("Each vhost did not close its store.", vhosts.size() <= results.size()); for (int index = 0; index < results.size(); index++) { - String result = getLog(results.get(index)); + String result = getLogMessage(results, index); if (getMessageString(result).contains("Recovery Complete :")) { @@ -291,7 +291,7 @@ public class DerbyMessageStoreLoggingTest extends MemoryMessageStoreLoggingTest startBroker(); - List<String> results = _monitor.waitAndFindMatches(MESSAGES_STORE_PREFIX, DEFAULT_LOG_WAIT); + List<String> results = waitAndFindMatches(MESSAGES_STORE_PREFIX); // Validation @@ -303,7 +303,7 @@ public class DerbyMessageStoreLoggingTest extends MemoryMessageStoreLoggingTest List<String> vhosts = configuration.getConfig().getList("virtualhosts.virtualhost.name"); //Validate each vhost logs a creation - results = _monitor.waitAndFindMatches("MST-1004 : Recovery Start :", DEFAULT_LOG_WAIT); + results = waitAndFindMatches("MST-1004 : Recovery Start :"); // We are only looking for the default queue defined in local host being // recovered. If other tests have made queues in test then we want to @@ -312,7 +312,7 @@ public class DerbyMessageStoreLoggingTest extends MemoryMessageStoreLoggingTest assertEquals("Recovered test queue not found.", 1, results.size()); - String result = getLog(results.get(0)); + String result = getLogMessage(results, 0); // getSlize will return extract the vhost from vh(/test) -> '/test' // so remove the '/' to get the name @@ -357,7 +357,7 @@ public class DerbyMessageStoreLoggingTest extends MemoryMessageStoreLoggingTest startBroker(); - List<String> results = _monitor.waitAndFindMatches(MESSAGES_STORE_PREFIX, DEFAULT_LOG_WAIT); + List<String> results = waitAndFindMatches(MESSAGES_STORE_PREFIX); // Validation @@ -369,7 +369,7 @@ public class DerbyMessageStoreLoggingTest extends MemoryMessageStoreLoggingTest List<String> vhosts = configuration.getConfig().getList("virtualhosts.virtualhost.name"); //Validate each vhost logs a creation - results = _monitor.waitAndFindMatches("MST-1006 : Recovery Complete :", DEFAULT_LOG_WAIT); + results = waitAndFindMatches("MST-1006 : Recovery Complete :"); // We are only looking for the default queue defined in local host being // recovered. If other tests have made queues in test then we want to @@ -378,7 +378,7 @@ public class DerbyMessageStoreLoggingTest extends MemoryMessageStoreLoggingTest assertEquals("Recovered test queue not found.", 1, results.size()); - String result = getLog(results.get(0)); + String result = getLogMessage(results, 0); // getSlize will return extract the vhost from vh(/test) -> '/test' // so remove the '/' to get the name @@ -399,7 +399,7 @@ public class DerbyMessageStoreLoggingTest extends MemoryMessageStoreLoggingTest assertEquals("The store name does not match expected value", storeName, AbstractTestLogSubject.getSlice("ms", fromSubject(result))); - results = _monitor.findMatches("MST-1004 : Recovery Start : test-queue"); + results = findMatches("MST-1004 : Recovery Start : test-queue"); assertEquals("MST-1004 for test-queue not found", 1, results.size()); } @@ -500,7 +500,7 @@ public class DerbyMessageStoreLoggingTest extends MemoryMessageStoreLoggingTest startBroker(); - List<String> results = _monitor.waitAndFindMatches(MESSAGES_STORE_PREFIX, DEFAULT_LOG_WAIT); + List<String> results = waitAndFindMatches(MESSAGES_STORE_PREFIX); // Validation @@ -512,18 +512,18 @@ public class DerbyMessageStoreLoggingTest extends MemoryMessageStoreLoggingTest List<String> vhosts = configuration.getConfig().getList("virtualhosts.virtualhost.name"); //Validate each vhost logs a creation - results = _monitor.waitAndFindMatches("MST-1004 : Recovery Start : " + queueName, DEFAULT_LOG_WAIT); + results = waitAndFindMatches("MST-1004 : Recovery Start : " + queueName); assertEquals("Recovered test queue not found.", 1, results.size()); - String result = getLog(results.get(0)); + String result = getLogMessage(results, 0); validateMessageID("MST-1004", result); assertTrue("MST-1004 does end with queue '" + queueName + "':" + getMessageString(result), getMessageString(result).endsWith(queueName)); - results = _monitor.waitAndFindMatches("MST-1005", DEFAULT_LOG_WAIT); + results = waitAndFindMatches("MST-1005"); assertTrue("Insufficient MST-1005 logged.", results.size()>0); diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/DurableQueueLoggingTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/DurableQueueLoggingTest.java index c43915be35..32adc49521 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/DurableQueueLoggingTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/DurableQueueLoggingTest.java @@ -45,7 +45,6 @@ import java.util.Map; */ public class DurableQueueLoggingTest extends AbstractTestLogging { - protected String DURABLE = "Durable"; protected String TRANSIENT = "Transient"; protected boolean _durable; @@ -53,6 +52,7 @@ public class DurableQueueLoggingTest extends AbstractTestLogging protected Connection _connection; protected Session _session; private static final String QUEUE_PREFIX = "QUE-"; + private static int PRIORITIES = 6; public void setUp() throws Exception { @@ -93,29 +93,12 @@ public class DurableQueueLoggingTest extends AbstractTestLogging _session.createConsumer(queue); - // Validation - // Ensure we have received the QUE log msg. - _monitor.waitForMessage("QUE-1001", DEFAULT_LOG_WAIT); - - List<String> results = _monitor.findMatches(QUEUE_PREFIX); - - // Only 1 Queue message should hav been logged - assertEquals("Result set size not as expected", 1, results.size()); - - String log = getLog(results.get(0)); - - // Message Should be a QUE-1001 - validateMessageID("QUE-1001", log); - - // Queue is Durable - assertEquals(DURABLE + " keyword not correct in log entry", - _durable, fromMessage(log).contains(DURABLE)); + List<String> results = waitForMesssage(); - assertEquals(TRANSIENT + " keyword not correct in log entry.", - !_durable, fromMessage(log).contains(TRANSIENT)); - - assertTrue("Queue does not have correct owner value:" + fromMessage(log), - fromMessage(log).contains("Owner: " + _connection.getClientID())); + String clientID = _connection.getClientID(); + assertNotNull("clientID should not be null", clientID); + + validateQueueProperties(results, false, false, clientID); } /** @@ -147,29 +130,9 @@ public class DurableQueueLoggingTest extends AbstractTestLogging _session.createConsumer(queue); - // Validation - // Ensure we have received the QUE log msg. - _monitor.waitForMessage("QUE-1001", DEFAULT_LOG_WAIT); - - List<String> results = _monitor.findMatches(QUEUE_PREFIX); - - // Only 1 Queue message should hav been logged - assertEquals("Result set size not as expected", 1, results.size()); - - String log = getLog(results.get(0)); - - // Message Should be a QUE-1001 - validateMessageID("QUE-1001", log); - - // Queue is Durable - assertEquals(DURABLE + " keyword not correct in log entry", - _durable, fromMessage(log).contains(DURABLE)); + List<String> results = waitForMesssage(); - assertEquals(TRANSIENT + " keyword not correct in log entry.", - !_durable, fromMessage(log).contains(TRANSIENT)); - - assertFalse("Queue should not contain Owner tag:" + fromMessage(log), - fromMessage(log).contains("Owner")); + validateQueueProperties(results, false, false, null); } /** @@ -201,33 +164,9 @@ public class DurableQueueLoggingTest extends AbstractTestLogging _session.createConsumer(queue); - // Validation - // Ensure we have received the QUE log msg. - _monitor.waitForMessage("QUE-1001", DEFAULT_LOG_WAIT); - - List<String> results = _monitor.findMatches(QUEUE_PREFIX); + List<String> results = waitForMesssage(); - // Only 1 Queue message should hav been logged - assertEquals("Result set size not as expected", 1, results.size()); - - String log = getLog(results.get(0)); - - // Message Should be a QUE-1001 - validateMessageID("QUE-1001", log); - - // Queue is Durable - assertEquals(DURABLE + " keyword not correct in log entry", - _durable, fromMessage(log).contains(DURABLE)); - - assertEquals(TRANSIENT + " keyword not correct in log entry.", - !_durable, fromMessage(log).contains(TRANSIENT)); - - // Queue is AutoDelete - assertTrue("Queue does not have the AutoDelete keyword in log:" + fromMessage(log), - fromMessage(log).contains("AutoDelete")); - - assertFalse("Queue should not contain Owner tag:" + fromMessage(log), - fromMessage(log).contains("Owner")); + validateQueueProperties(results, false, true, null); } /** @@ -254,7 +193,6 @@ public class DurableQueueLoggingTest extends AbstractTestLogging public void testCreateQueuePersistentPriority() throws NamingException, JMSException, IOException, AMQException { // To Create a Priority queue we need to use AMQSession specific code - int PRIORITIES = 6; final Map<String, Object> arguments = new HashMap<String, Object>(); arguments.put("x-qpid-priorities", PRIORITIES); // Need to create a queue that does not exist so use test name @@ -268,33 +206,12 @@ public class DurableQueueLoggingTest extends AbstractTestLogging // as the above Create is Asynchronous _session.createConsumer(queue); - // Validation - // Ensure we have received the QUE log msg. - _monitor.waitForMessage("QUE-1001", DEFAULT_LOG_WAIT); - - List<String> results = _monitor.findMatches(QUEUE_PREFIX); + List<String> results = waitForMesssage(); // Only 1 Queue message should hav been logged assertEquals("Result set size not as expected", 1, results.size()); - String log = getLog(results.get(0)); - - // Message Should be a QUE-1001 - validateMessageID("QUE-1001", log); - - // Queue is Durable - assertEquals(DURABLE + " keyword not correct in log entry", - _durable, fromMessage(log).contains(DURABLE)); - - assertEquals(TRANSIENT + " keyword not correct in log entry.", - !_durable, fromMessage(log).contains(TRANSIENT)); - - // Queue is AutoDelete - assertTrue("Queue does not have the right Priority value keyword in log:" + fromMessage(log), - fromMessage(log).contains("Priority: " + PRIORITIES)); - - assertFalse("Queue should not contain Owner tag:" + fromMessage(log), - fromMessage(log).contains("Owner")); + validateQueueProperties(results, true, false, null); } /** @@ -322,7 +239,6 @@ public class DurableQueueLoggingTest extends AbstractTestLogging public void testCreateQueuePersistentAutoDeletePriority() throws NamingException, JMSException, IOException, AMQException { // To Create a Priority queue we need to use AMQSession specific code - int PRIORITIES = 6; final Map<String, Object> arguments = new HashMap<String, Object>(); arguments.put("x-qpid-priorities", PRIORITIES); // Need to create a queue that does not exist so use test name @@ -336,37 +252,56 @@ public class DurableQueueLoggingTest extends AbstractTestLogging // as the above Create is Asynchronous _session.createConsumer(queue); + List<String> results = waitForMesssage(); + + validateQueueProperties(results, true, true, null); + } + + private List<String> waitForMesssage() throws IOException + { // Validation // Ensure we have received the QUE log msg. - _monitor.waitForMessage("QUE-1001", DEFAULT_LOG_WAIT); + waitForMessage("QUE-1001"); - List<String> results = _monitor.findMatches(QUEUE_PREFIX); + List<String> results = findMatches(QUEUE_PREFIX); // Only 1 Queue message should hav been logged assertEquals("Result set size not as expected", 1, results.size()); + + return results; + } - String log = getLog(results.get(0)); - + public void validateQueueProperties(List<String> results, boolean hasPriority, boolean hasAutodelete, String clientID) + { + String log = getLogMessage(results, 0); + // Message Should be a QUE-1001 validateMessageID("QUE-1001", log); // Queue is Durable assertEquals(DURABLE + " keyword not correct in log entry", - _durable, fromMessage(log).contains(DURABLE)); + _durable, fromMessage(log).contains(DURABLE)); assertEquals(TRANSIENT + " keyword not correct in log entry.", - !_durable, fromMessage(log).contains(TRANSIENT)); + !_durable, fromMessage(log).contains(TRANSIENT)); - // Queue is AutoDelete - assertTrue("Queue does not have the right Priority value keyword in log:" + fromMessage(log), - fromMessage(log).contains("Priority: " + PRIORITIES)); + // Queue is Priority + assertEquals("Unexpected priority status:" + fromMessage(log), hasPriority, + fromMessage(log).contains("Priority: " + PRIORITIES)); // Queue is AutoDelete - assertTrue("Queue does not have the AutoDelete keyword in log:" + fromMessage(log), - fromMessage(log).contains("AutoDelete")); - - assertFalse("Queue should not contain Owner tag:" + fromMessage(log), - fromMessage(log).contains("Owner")); + assertEquals("Unexpected AutoDelete status:" + fromMessage(log), hasAutodelete, + fromMessage(log).contains("AutoDelete")); + + if(clientID != null) + { + assertTrue("Queue does not have correct owner value:" + fromMessage(log), + fromMessage(log).contains("Owner: " + clientID)); + } + else + { + assertFalse("Queue should not contain Owner tag:" + fromMessage(log), + fromMessage(log).contains("Owner")); + } } - } diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/ExchangeLoggingTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/ExchangeLoggingTest.java index 5facafe6aa..67ff8a4328 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/ExchangeLoggingTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/ExchangeLoggingTest.java @@ -95,23 +95,13 @@ public class ExchangeLoggingTest extends AbstractTestLogging // They should all be durable // Ensure we have received the EXH log msg. - _monitor.waitForMessage("EXH-1001", DEFAULT_LOG_WAIT); + waitForMessage("EXH-1001"); - List<String> results = _monitor.findMatches(EXH_PREFIX); + List<String> results = findMatches(EXH_PREFIX); assertTrue("No Results found for Exchange.", results.size()>0); - String log = getLog(results.get(0)); - - validateMessageID("EXH-1001", log); - - String message = getMessageString(fromMessage(log)); - assertTrue("Log Message does not start with create:" + message, - message.startsWith("Create")); - - assertTrue("Log Message does not contain Durable:" + message, - message.contains("Durable")); - + validateExchangeCreate(results, true, false); } /** @@ -135,23 +125,35 @@ public class ExchangeLoggingTest extends AbstractTestLogging _session.createConsumer(_queue); // Ensure we have received the EXH log msg. - _monitor.waitForMessage("EXH-1001", DEFAULT_LOG_WAIT); + waitForMessage("EXH-1001"); - List<String> results = _monitor.findMatches(EXH_PREFIX); + List<String> results = findMatches(EXH_PREFIX); assertEquals("Result set larger than expected.", 1, results.size()); - String log = getLog(results.get(0)); - - validateMessageID("EXH-1001", log); + validateExchangeCreate(results, false, true); + } + private void validateExchangeCreate(List<String> results, boolean durable, boolean checkNameAndType) + { + String log = getLogMessage(results, 0); String message = getMessageString(fromMessage(log)); + + validateMessageID("EXH-1001", log); + assertTrue("Log Message does not start with create:" + message, message.startsWith("Create")); - assertTrue("Log Message does not contain Type:" + message, - message.contains("Type: " + _type)); - assertTrue("Log Message does not contain Name:" + message, - message.contains("Name: " + _name)); + + assertEquals("Unexpected Durable state:" + message, durable, + message.contains("Durable")); + + if(checkNameAndType) + { + assertTrue("Log Message does not contain Type:" + message, + message.contains("Type: " + _type)); + assertTrue("Log Message does not contain Name:" + message, + message.contains("Name: " + _name)); + } } /** @@ -186,24 +188,18 @@ public class ExchangeLoggingTest extends AbstractTestLogging ((AMQConnection) _connection).getProtocolHandler().syncWrite(exchangeDeclare, ExchangeDeleteOkBody.class); //Wait and ensure we get our last EXH-1002 msg - _monitor.waitForMessage("EXH-1002", DEFAULT_LOG_WAIT); + waitForMessage("EXH-1002"); - List<String> results = _monitor.findMatches(EXH_PREFIX); + List<String> results = findMatches(EXH_PREFIX); assertEquals("Result set larger than expected.", 2, results.size()); - String log = getLog(results.get(0)); - - validateMessageID("EXH-1001", log); + validateExchangeCreate(results, false, false); - String message = getMessageString(fromMessage(log)); - assertTrue("Log Message does start with Create", - message.startsWith("Create")); - - log = getLog(results.get(1)); + String log = getLogMessage(results, 1); validateMessageID("EXH-1002", log); - message = getMessageString(fromMessage(log)); + String message = getMessageString(fromMessage(log)); assertEquals("Log Message not as expected", "Deleted", message); } diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/ManagementLoggingTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/ManagementLoggingTest.java index 9ec223f694..d5d3930641 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/ManagementLoggingTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/ManagementLoggingTest.java @@ -21,6 +21,7 @@ package org.apache.qpid.server.logging; import junit.framework.AssertionFailedError; + import org.apache.qpid.util.LogMonitor; import java.util.List; @@ -77,18 +78,12 @@ public class ManagementLoggingTest extends AbstractTestLogging // Management is disabled on InVM brokers. if (isJavaBroker() && isExternalBroker()) { - //Ensure management is on - setConfigurationProperty("management.enabled", "true"); - - startBroker(); - - // Now we can create the monitor as _outputFile will now be defined - _monitor = new LogMonitor(_outputFile); + startBrokerAndCreateMonitor(true, false); // Ensure we have received the MNG log msg. - _monitor.waitForMessage("MNG-1001", DEFAULT_LOG_WAIT); + waitForMessage("MNG-1001"); - List<String> results = _monitor.findMatches(MNG_PREFIX); + List<String> results = findMatches(MNG_PREFIX); try { @@ -96,13 +91,13 @@ public class ManagementLoggingTest extends AbstractTestLogging assertTrue("MNGer message not logged", results.size() > 0); - String log = getLog(results.get(0)); + String log = getLogMessage(results, 0); //1 validateMessageID("MNG-1001", log); //2 - results = _monitor.findMatches("MNG-1001"); + results = findMatches("MNG-1001"); assertEquals("More than one startup message found.", 1, results.size()); @@ -112,11 +107,7 @@ public class ManagementLoggingTest extends AbstractTestLogging } catch (AssertionFailedError afe) { - System.err.println("Log Dump:"); - for (String log : results) - { - System.err.println(log); - } + dumpLogs(results, _monitor); throw afe; } } @@ -140,15 +131,9 @@ public class ManagementLoggingTest extends AbstractTestLogging // Management is disabled on InVM brokers. if (isJavaBroker() && isExternalBroker()) { - //Ensure management is off - setConfigurationProperty("management.enabled", "false"); + startBrokerAndCreateMonitor(false, false); - startBroker(); - - // Now we can create the monitor as _outputFile will now be defined - _monitor = new LogMonitor(_outputFile); - - List<String> results = _monitor.findMatches(MNG_PREFIX); + List<String> results = findMatches(MNG_PREFIX); try { // Validation @@ -157,11 +142,7 @@ public class ManagementLoggingTest extends AbstractTestLogging } catch (AssertionFailedError afe) { - System.err.println("Log Dump:"); - for (String log : results) - { - System.err.println(log); - } + dumpLogs(results, _monitor); throw afe; } } @@ -211,28 +192,22 @@ public class ManagementLoggingTest extends AbstractTestLogging // Management is disabled on InVM brokers. if (isJavaBroker() && isExternalBroker()) { - //Ensure management is on - setConfigurationProperty("management.enabled", "true"); - - startBroker(); - - // Now we can create the monitor as _outputFile will now be defined - _monitor = new LogMonitor(_outputFile); - - List<String> results = _monitor.waitAndFindMatches("MNG-1002", DEFAULT_LOG_WAIT); + startBrokerAndCreateMonitor(true, false); + + List<String> results = waitAndFindMatches("MNG-1002"); try { // Validation assertEquals("MNGer message not logged expected message", 2, results.size()); - String log = getLog(results.get(0)); + String log = getLogMessage(results, 0); //1 validateMessageID("MNG-1002", log); // Validate we only have one MNG-1002 - results = _monitor.findMatches("MNG-1002"); + results = findMatches("MNG-1002"); assertEquals("More than two RMI entries found.", 2, results.size()); @@ -242,7 +217,7 @@ public class ManagementLoggingTest extends AbstractTestLogging assertTrue("RMI Registry port not as expected(" + mPort + ").:" + getMessageString(log), getMessageString(log).endsWith(String.valueOf(mPort))); - log = getLog(results.get(1)); + log = getLogMessage(results, 1); //1 validateMessageID("MNG-1002", log); @@ -255,15 +230,12 @@ public class ManagementLoggingTest extends AbstractTestLogging } catch (AssertionFailedError afe) { - System.err.println("Log Dump:"); - for (String log : results) - { - System.err.println(log); - } + dumpLogs(results, _monitor); throw afe; } } } + /** * Description: * Using the default configuration with SSL enabled for the management port the SSL Keystore path should be reported via MNG-1006 @@ -284,30 +256,22 @@ public class ManagementLoggingTest extends AbstractTestLogging // Management is disabled on InVM brokers. if (isJavaBroker() && isExternalBroker()) { - //Ensure management is on - setConfigurationProperty("management.enabled", "true"); - // This test requires we have an ssl connection - setConfigurationProperty("management.ssl.enabled", "true"); + startBrokerAndCreateMonitor(true, true); - startBroker(); - - // Now we can create the monitor as _outputFile will now be defined - _monitor = new LogMonitor(_outputFile); - - List<String> results = _monitor.waitAndFindMatches("MNG-1006", DEFAULT_LOG_WAIT); + List<String> results = waitAndFindMatches("MNG-1006"); try { // Validation assertTrue("MNGer message not logged", results.size() > 0); - String log = getLog(results.get(0)); + String log = getLogMessage(results, 0); //1 validateMessageID("MNG-1006", log); // Validate we only have one MNG-1002 - results = _monitor.findMatches("MNG-1006"); + results = findMatches("MNG-1006"); assertEquals("More than one SSL Keystore entry found.", 1, results.size()); @@ -318,14 +282,27 @@ public class ManagementLoggingTest extends AbstractTestLogging } catch (AssertionFailedError afe) { - System.err.println("Log Dump:"); - for (String log : results) - { - System.err.println(log); - } + dumpLogs(results, _monitor); throw afe; } } } + + private void startBrokerAndCreateMonitor(boolean managementEnabled, boolean useManagementSSL) throws Exception + { + //Ensure management is on + setConfigurationProperty("management.enabled", String.valueOf(managementEnabled)); + + if(useManagementSSL) + { + // This test requires we have an ssl connection + setConfigurationProperty("management.ssl.enabled", "true"); + } + + startBroker(); + + // Now we can create the monitor as _outputFile will now be defined + _monitor = new LogMonitor(_outputFile); + } } diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/MemoryMessageStoreLoggingTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/MemoryMessageStoreLoggingTest.java index 389cae03ab..877560ea14 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/MemoryMessageStoreLoggingTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/MemoryMessageStoreLoggingTest.java @@ -78,18 +78,18 @@ public class MemoryMessageStoreLoggingTest extends AbstractTestLogging super.setUp(); - List<String> results = _monitor.waitAndFindMatches(MESSAGES_STORE_PREFIX, DEFAULT_LOG_WAIT); + List<String> results = waitAndFindMatches(MESSAGES_STORE_PREFIX); // Validation assertTrue("MST messages not logged", results.size() > 0); - String log = getLog(results.get(0)); + String log = getLogMessage(results, 0); //1 assertEquals("MST-1001 is not the first MST message", "MST-1001", getMessageID(fromMessage(log))); //Validate each vhost logs a creation - results = _monitor.waitAndFindMatches("MST-1001", DEFAULT_LOG_WAIT); + results = waitAndFindMatches("MST-1001"); // Load VirtualHost list from file. List<String> vhosts = Arrays.asList(_serverConfiguration.getVirtualHosts()); @@ -98,7 +98,7 @@ public class MemoryMessageStoreLoggingTest extends AbstractTestLogging for (int index = 0; index < results.size(); index++) { - String result = getLog(results.get(index)); + String result = getLogMessage(results, index); // getSlice will return extract the vhost from vh(/test) -> '/test' // so remove the '/' to get the name @@ -145,7 +145,7 @@ public class MemoryMessageStoreLoggingTest extends AbstractTestLogging //Stop the broker so we get the close messages. stopBroker(); - List<String> results = _monitor.waitAndFindMatches(MESSAGES_STORE_PREFIX, DEFAULT_LOG_WAIT); + List<String> results = waitAndFindMatches(MESSAGES_STORE_PREFIX); // Validation @@ -157,13 +157,13 @@ public class MemoryMessageStoreLoggingTest extends AbstractTestLogging List<String> vhosts = Arrays.asList(configuration.getVirtualHosts()); //Validate each vhost logs a creation - results = _monitor.waitAndFindMatches("MST-1003", DEFAULT_LOG_WAIT); + results = waitAndFindMatches("MST-1003"); assertEquals("Each vhost did not close its store.", vhosts.size(), results.size()); for (int index = 0; index < results.size(); index++) { - String result = getLog(results.get(index)); + String result = getLogMessage(results, index); // getSlice will return extract the vhost from vh(/test) -> '/test' // so remove the '/' to get the name diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/QueueLoggingTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/QueueLoggingTest.java index 0637271c0c..14e0904b78 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/QueueLoggingTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/QueueLoggingTest.java @@ -95,21 +95,21 @@ public class QueueLoggingTest extends AbstractTestLogging // Validation //Ensure that we wait for the QUE log message - _monitor.waitAndFindMatches("QUE-1002", DEFAULT_LOG_WAIT); + waitAndFindMatches("QUE-1002"); - List<String> results = _monitor.findMatches(QUEUE_PREFIX); + List<String> results = findMatches(QUEUE_PREFIX); // Only 1 Queue message should hav been logged assertEquals("Result set size not as expected", 2, results.size()); - String log = getLog(results.get(0)); + String log = getLogMessage(results, 0); // Message Should be a QUE-1001 validateMessageID("QUE-1001", log); String createdQueueName = AbstractTestLogSubject.getSlice("qu", fromSubject(log)); - log = getLog(results.get(1)); + log = getLogMessage(results, 1); // Message Should be a QUE-1002 validateMessageID("QUE-1002", log); @@ -149,21 +149,21 @@ public class QueueLoggingTest extends AbstractTestLogging // Validation //Ensure that we wait for the QUE log message - _monitor.waitAndFindMatches("QUE-1002", DEFAULT_LOG_WAIT); + waitAndFindMatches("QUE-1002"); - List<String> results = _monitor.findMatches(QUEUE_PREFIX); + List<String> results = findMatches(QUEUE_PREFIX); // Only 1 Queue message should hav been logged assertEquals("Result set size not as expected", 2, results.size()); - String log = getLog(results.get(0)); + String log = getLogMessage(results, 0); // Message Should be a QUE-1001 validateMessageID("QUE-1001", log); String createdQueueName = AbstractTestLogSubject.getSlice("qu", fromSubject(log)); - log = getLog(results.get(1)); + log = getLogMessage(results, 1); // Message Should be a QUE-1002 validateMessageID("QUE-1002", log); diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/SubscriptionLoggingTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/SubscriptionLoggingTest.java index 6a0e2f1e86..a0b81a7658 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/SubscriptionLoggingTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/SubscriptionLoggingTest.java @@ -92,13 +92,13 @@ public class SubscriptionLoggingTest extends AbstractTestLogging //Validate //Ensure that we wait for the SUB log message - _monitor.waitAndFindMatches("SUB-1001", DEFAULT_LOG_WAIT); + waitAndFindMatches("SUB-1001"); - List<String> results = _monitor.findMatches(SUB_PREFIX); + List<String> results = findMatches(SUB_PREFIX); assertEquals("Result set larger than expected.", 1, results.size()); - String log = getLog(results.get(0)); + String log = getLogMessage(results, 0); validateMessageID("SUB-1001", log); @@ -130,13 +130,13 @@ public class SubscriptionLoggingTest extends AbstractTestLogging //Validate //Ensure that we wait for the SUB log message - _monitor.waitAndFindMatches("SUB-1001", DEFAULT_LOG_WAIT); + waitAndFindMatches("SUB-1001"); - List<String> results = _monitor.findMatches(SUB_PREFIX); + List<String> results = findMatches(SUB_PREFIX); assertEquals("Result set not as expected.", 1, results.size()); - String log = getLog(results.get(0)); + String log = getLogMessage(results, 0); validateMessageID("SUB-1001", log); @@ -169,13 +169,13 @@ public class SubscriptionLoggingTest extends AbstractTestLogging //Validate //Ensure that we wait for the SUB log message - _monitor.waitAndFindMatches("SUB-1001", DEFAULT_LOG_WAIT); + waitAndFindMatches("SUB-1001"); - List<String> results = _monitor.findMatches(SUB_PREFIX); + List<String> results = findMatches(SUB_PREFIX); assertEquals("Result set larger than expected.", 2, results.size()); - String log = getLog(results.get(0)); + String log = getLogMessage(results, 0); validateMessageID("SUB-1001", log); @@ -185,7 +185,7 @@ public class SubscriptionLoggingTest extends AbstractTestLogging // Beacause it is an auto close and we have no messages on the queue we // will get a close message - log = getLog(results.get(1)); + log = getLogMessage(results, 1); validateMessageID("SUB-1002", log); } @@ -216,13 +216,13 @@ public class SubscriptionLoggingTest extends AbstractTestLogging //Validate //Ensure that we wait for the SUB log message - _monitor.waitAndFindMatches("SUB-1001", DEFAULT_LOG_WAIT); + waitAndFindMatches("SUB-1001"); - List<String> results = _monitor.findMatches(SUB_PREFIX); + List<String> results = findMatches(SUB_PREFIX); assertEquals("Result set larger than expected.", 1, results.size()); - String log = getLog(results.get(0)); + String log = getLogMessage(results, 0); validateMessageID("SUB-1001", log); @@ -257,13 +257,13 @@ public class SubscriptionLoggingTest extends AbstractTestLogging //Validate //Ensure that we wait for the SUB log message - _monitor.waitAndFindMatches("SUB-1001", DEFAULT_LOG_WAIT); + waitAndFindMatches("SUB-1001"); - List<String> results = _monitor.findMatches(SUB_PREFIX); + List<String> results = findMatches(SUB_PREFIX); assertEquals("Result set larger than expected.", 1, results.size()); - String log = getLog(results.get(0)); + String log = getLogMessage(results, 0); validateMessageID("SUB-1001", log); @@ -298,18 +298,18 @@ public class SubscriptionLoggingTest extends AbstractTestLogging //Validate //Ensure that we wait for the SUB log message - _monitor.waitAndFindMatches("SUB-1002", DEFAULT_LOG_WAIT); + waitAndFindMatches("SUB-1002"); - List<String> results = _monitor.findMatches(SUB_PREFIX); + List<String> results = findMatches(SUB_PREFIX); //3 assertEquals("Result set larger than expected.", 2, results.size()); // 2 - String log = getLog(results.get(0)); + String log = getLogMessage(results, 0); validateMessageID("SUB-1001", log); // 1 - log = getLog(results.get(1)); + log = getLogMessage(results, 1); validateMessageID("SUB-1002", log); String message = getMessageString(fromMessage(log)); @@ -386,7 +386,7 @@ public class SubscriptionLoggingTest extends AbstractTestLogging _session.commit(); //Validate - List<String> results = _monitor.waitAndFindMatches("SUB-1003", DEFAULT_LOG_WAIT); + List<String> results = waitAndFindMatches("SUB-1003"); try { @@ -403,17 +403,17 @@ public class SubscriptionLoggingTest extends AbstractTestLogging // Validate Initial Suspension String expectedState = "SUSPENDED"; - String log = getLog(results.get(0)); + String log = getLogMessage(results, 0); validateSubscriptionState(log, expectedState); // After being suspended the subscription should become active. expectedState = "ACTIVE"; - log = getLog(results.get(1)); + log = getLogMessage(results, 1); validateSubscriptionState(log, expectedState); // Validate that it was re-suspended expectedState = "SUSPENDED"; - log = getLog(results.get(2)); + log = getLogMessage(results, 2); validateSubscriptionState(log, expectedState); // We only need validate the state. } diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/VirtualHostLoggingTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/VirtualHostLoggingTest.java index 3c5ba3956b..17423123ca 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/VirtualHostLoggingTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/VirtualHostLoggingTest.java @@ -27,7 +27,6 @@ import java.util.List; import junit.framework.AssertionFailedError; import org.apache.qpid.server.configuration.ServerConfiguration; -import org.apache.qpid.server.util.InternalBrokerBaseCase; /** * Virtualhost Test Cases @@ -62,10 +61,10 @@ public class VirtualHostLoggingTest extends AbstractTestLogging public void testVirtualhostCreation() throws Exception { //Wait for the correct VHT message to arrive. - _monitor.waitForMessage(VHT_PREFIX + "1001", DEFAULT_LOG_WAIT); + waitForMessage(VHT_PREFIX + "1001"); //Validate each vhost logs a creation - List<String> results = _monitor.findMatches(VHT_PREFIX + "1001"); + List<String> results = findMatches(VHT_PREFIX + "1001"); try { @@ -76,7 +75,7 @@ public class VirtualHostLoggingTest extends AbstractTestLogging for (int index = 0; index < results.size(); index++) { // Retrieve the vhostname from the log entry message 'Created : <vhostname>' - String result = getLog(results.get(index)); + String result = getLogMessage(results, index); String vhostName = getMessageString(fromMessage(result)).split(" ")[2]; assertTrue("Virtualhost named in log not found in config file:" + vhostName + ":" + vhosts, vhosts.contains(vhostName)); @@ -84,11 +83,8 @@ public class VirtualHostLoggingTest extends AbstractTestLogging } catch (AssertionFailedError afe) { - System.err.println("Log Dump:"); - for (String log : results) - { - System.err.println(log); - } + dumpLogs(results, _monitor); + throw afe; } } @@ -113,10 +109,10 @@ public class VirtualHostLoggingTest extends AbstractTestLogging stopBroker(); // Wait for the correct VHT message to arrive. - _monitor.waitForMessage(VHT_PREFIX + "1002", DEFAULT_LOG_WAIT); + waitForMessage(VHT_PREFIX + "1002"); // Validate each vhost logs a closure - List<String> results = _monitor.findMatches(VHT_PREFIX + "1002"); + List<String> results = findMatches(VHT_PREFIX + "1002"); try { @@ -129,11 +125,8 @@ public class VirtualHostLoggingTest extends AbstractTestLogging } catch (AssertionFailedError afe) { - System.err.println("Log Dump:"); - for (String log : results) - { - System.err.println(log); - } + dumpLogs(results, _monitor); + throw afe; } } diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/queue/ProducerFlowControlTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/queue/ProducerFlowControlTest.java index 58350a0538..f78b327209 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/server/queue/ProducerFlowControlTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/queue/ProducerFlowControlTest.java @@ -39,13 +39,10 @@ import java.io.IOException; public class ProducerFlowControlTest extends AbstractTestLogging { - private static final int TIMEOUT = 1500; - + private static final int TIMEOUT = 10000; private static final Logger _logger = Logger.getLogger(ProducerFlowControlTest.class); - private static final int MSG_COUNT = 50; - private Connection producerConnection; private MessageProducer producer; private Session producerSession; @@ -159,7 +156,7 @@ public class ProducerFlowControlTest extends AbstractTestLogging sendMessagesAsync(producer, producerSession, 5, 50L); Thread.sleep(5000); - List<String> results = _monitor.waitAndFindMatches("QUE-1003", DEFAULT_LOG_WAIT); + List<String> results = waitAndFindMatches("QUE-1003"); assertEquals("Did not find correct number of QUE-1003 queue overfull messages", 1, results.size()); @@ -169,7 +166,7 @@ public class ProducerFlowControlTest extends AbstractTestLogging while(consumer.receive(1000) != null); - results = _monitor.waitAndFindMatches("QUE-1004", DEFAULT_LOG_WAIT); + results = waitAndFindMatches("QUE-1004"); assertEquals("Did not find correct number of UNDERFULL queue underfull messages", 1, results.size()); @@ -203,10 +200,10 @@ public class ProducerFlowControlTest extends AbstractTestLogging // try to send 5 messages (should block after 4) MessageSender sender = sendMessagesAsync(producer, producerSession, 5, 50L); - Thread.sleep(10000); - List<String> results = _monitor.waitAndFindMatches("Message send delayed by", 10000); + Thread.sleep(TIMEOUT); + List<String> results = waitAndFindMatches("Message send delayed by", TIMEOUT); assertTrue("No delay messages logged by client",results.size()!=0); - results = _monitor.findMatches("Message send failed due to timeout waiting on broker enforced flow control"); + results = findMatches("Message send failed due to timeout waiting on broker enforced flow control"); assertEquals("Incorrect number of send failure messages logged by client",1,results.size()); |
