org.apache.qpid.server.logging
Class AbstractTestLogging

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.apache.qpid.test.utils.QpidTestCase
              extended by org.apache.qpid.test.utils.QpidBrokerTestCase
                  extended by org.apache.qpid.server.logging.AbstractTestLogging
All Implemented Interfaces:
junit.framework.Test
Direct Known Subclasses:
AccessControlLoggingTest, AlertingTest, BindingLoggingTest, BrokerLoggingTest, BrokerStartupTest, ChannelLoggingTest, ConnectionLoggingTest, DurableQueueLoggingTest, ExchangeLoggingTest, ManagementActorLoggingTest, ManagementLoggingTest, MemoryMessageStoreLoggingTest, ProducerFlowControlTest, QueueLoggingTest, SubscriptionLoggingTest, VirtualHostLoggingTest

public class AbstractTestLogging
extends QpidBrokerTestCase

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.


Nested Class Summary
 
Nested classes/interfaces inherited from class org.apache.qpid.test.utils.QpidBrokerTestCase
QpidBrokerTestCase.MessageType
 
Field Summary
(package private)  org.apache.qpid.server.util.InternalBrokerBaseCase _configLoader
           
protected  LogMonitor _monitor
           
(package private)  org.apache.qpid.server.configuration.ServerConfiguration _serverConfiguration
           
static long DEFAULT_LOG_WAIT
           
static String TEST_LOG_PREFIX
           
 
Fields inherited from class org.apache.qpid.test.utils.QpidBrokerTestCase
_broker, _brokerLanguage, _brokerLogPrefix, _brokerOutputStream, _brokerPersistent, _brokers, _configFile, _connectionFactory, _connections, _initialContext, _interleaveBrokerLog, _logger, _output, _outputFile, _testName, BROKER_READY, CONTENT, CPP, DEFAULT_MANAGEMENT_PORT, DEFAULT_MESSAGE_SIZE, DEFAULT_PORT, DEFAULT_SSL_PORT, DEFAULT_VM_PORT, EXTERNAL, INDEX, JAVA, LOGMONITOR_TIMEOUT, QPID_HOME, QpidHome, QUEUE, RECEIVE_TIMEOUT, TOPIC, VM
 
Fields inherited from class org.apache.qpid.test.utils.QpidTestCase
MEMORY_STORE_CLASS_NAME, MS_CLASS_NAME_KEY
 
Constructor Summary
AbstractTestLogging()
           
 
Method Summary
 void assertLoggingNotYetOccured(String log)
          assert that the requested log message has not occured
protected  void dumpLogs(List<String> results)
          Dump the log results.
protected  void dumpLogs(List<String> results, LogMonitor monitor)
          Dump the log results or if there are none, the contents of the monitored log file if the monitor is non-null.
protected  List<String> filterResultsByVirtualHost(List<String> results, String virtualHostName)
          Filter the give result set by the specficifed virtualhost.
protected  List<String> findMatches(String toFind)
           
protected  String fromActor(String log)
          Extract the actor segment from the log message.
protected  String fromMessage(String log)
           
protected  String fromSubject(String log)
          Extract the Subject from the Log Message.
protected  int getChannelID(String log)
          Return the first channel id from the log string ' ch;X' if there is no channel id return -1.
protected  int getConnectionID(String log)
          Given our log message extract the connection ID: The log string will contain the connectionID identified by 'con:' So extract the value shown here by X: 'con:X(' Extract the value between the ':' and '(' and process it as an Integer If we are unable to find the right index or process the substring as an Integer then return -1.
protected  String getLog(String rawLog)
          Extract the log entry from the raw log line which will contain other log4j formatting.
protected  String getLogMessage(List<String> results, int position)
          Extract the log entry from the result set.
protected  String getLogMessageFromEnd(List<String> results, int positionFromEnd)
          Extract the nth-from-last log entry from the result set.
protected  String getMessageID(String log)
           
protected  String getMessageString(String log)
          Return the message String from the given message section
protected  void setLogMessagePrefix()
           
 void setUp()
           
protected  HashMap<Integer,List<String>> splitResultsOnConnectionID(List<String> logMessages)
          Given a list of messages that have been pulled out of a log file Process the results splitting the log statements in to lists based on the actor's connection ID.
 void tearDown()
           
protected  void validateMessageID(String id, String log)
           
protected  List<String> waitAndFindMatches(String toFind)
           
protected  List<String> waitAndFindMatches(String toFind, long wait)
           
 boolean waitForMessage(String message)
           
 boolean waitForMessage(String message, long wait)
           
 
Methods inherited from class org.apache.qpid.test.utils.QpidBrokerTestCase
cleanBroker, createMessage, createNextMessage, drainQueue, getBroker, getBrokerCommand, getClientConnection, getConfigurationStringProperty, getConnection, getConnection, getConnection, getConnectionFactory, getConnectionFactory, getConnectionURL, getInitialContext, getLogger, getManagementPort, getMessageSize, getPort, getPort, getTestConfigFile, getTestQueue, getTestQueueName, getTestVirtualhostsFile, isBroker010, isBroker08, isBrokerStorePersistent, isCppBroker, isExternalBroker, isJavaBroker, makeVirtualHostPersistent, reloadBrokerSecurityConfig, restartBroker, restartBroker, revertLoggingLevels, revertSystemProperties, runBare, saveTestConfiguration, saveTestVirtualhosts, sendMessage, sendMessage, sendMessage, setBrokerEnvironment, setBrokerOnlySystemProperty, setConfigurationProperty, setLoggerLevel, setMessageSize, setSystemProperty, setSystemProperty, setTestClientSystemProperty, startBroker, startBroker, stopBroker, stopBroker
 
Methods inherited from class org.apache.qpid.test.utils.QpidTestCase
getTestProfileMessageStoreClassName, run
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, runTest, setName, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail, failNotEquals, failNotSame, failSame
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_LOG_WAIT

public static final long DEFAULT_LOG_WAIT
See Also:
Constant Field Values

TEST_LOG_PREFIX

public static final String TEST_LOG_PREFIX
See Also:
Constant Field Values

_monitor

protected LogMonitor _monitor

_serverConfiguration

org.apache.qpid.server.configuration.ServerConfiguration _serverConfiguration

_configLoader

org.apache.qpid.server.util.InternalBrokerBaseCase _configLoader
Constructor Detail

AbstractTestLogging

public AbstractTestLogging()
Method Detail

setUp

public void setUp()
           throws Exception
Overrides:
setUp in class QpidBrokerTestCase
Throws:
Exception

setLogMessagePrefix

protected void setLogMessagePrefix()

tearDown

public void tearDown()
              throws Exception
Overrides:
tearDown in class QpidBrokerTestCase
Throws:
Exception

assertLoggingNotYetOccured

public void assertLoggingNotYetOccured(String log)
                                throws IOException
assert that the requested log message has not occured

Parameters:
log -
Throws:
IOException

validateMessageID

protected void validateMessageID(String id,
                                 String log)

getMessageID

protected String getMessageID(String log)

getChannelID

protected int getChannelID(String log)
Return the first channel id from the log string ' ch;X' if there is no channel id return -1.

Parameters:
log - the log string to search.
Returns:
channel id or -1 if no channel id exists.

fromMessage

protected String fromMessage(String log)

fromSubject

protected String fromSubject(String log)
Extract the Subject from the Log Message. The subject is the second block inclosed in brackets '[ ]'. If there is no Subject or the second block of brackets '[ ]' cannot be identified then an empty String ("") is returned. The brackets '[ ]' are not included in the returned String.

Parameters:
log - The log message to process
Returns:
the Subject string or the empty string ("") if the subject can't be identified.

fromActor

protected String fromActor(String log)
Extract the actor segment from the log message. The Actor segment is the first section enclosed in '[ ]'. No analysis is performed to ensure that the first '[ ]' section of the given log is really an Actor segment. The brackets '[ ]' are not included in the returned String.

Parameters:
log - the Log Message
Returns:
the Actor segment or "" if unable to locate '[ ]' section

getMessageString

protected String getMessageString(String log)
Return the message String from the given message section

Parameters:
log - the Message Section
Returns:
the Message String.

getConnectionID

protected int getConnectionID(String log)
Given our log message extract the connection ID: The log string will contain the connectionID identified by 'con:' So extract the value shown here by X: 'con:X(' Extract the value between the ':' and '(' and process it as an Integer If we are unable to find the right index or process the substring as an Integer then return -1.

Parameters:
log - the log String to process
Returns:
the connection ID or -1.

getLog

protected String getLog(String rawLog)
Extract the log entry from the raw log line which will contain other log4j formatting. This formatting may impead our testing process so extract the log message as we know it to be formatted. This starts with the string MESSAGE

Parameters:
rawLog - the raw log
Returns:
the log we are expecting to be printed without the log4j prefixes

getLogMessage

protected String getLogMessage(List<String> results,
                               int position)
Extract the log entry from the result set. Positions are 0-based.

Parameters:
results - list of log message results to extract from
position - position in the list of the message to extract
Returns:
the message string

getLogMessageFromEnd

protected String getLogMessageFromEnd(List<String> results,
                                      int positionFromEnd)
Extract the nth-from-last log entry from the result set.

Parameters:
results - list of log message results to extract from
positionFromEnd - position from end of the message list to extract (eg 0 for last)
Returns:
the message string

findMatches

protected List<String> findMatches(String toFind)
                            throws IOException
Throws:
IOException

waitAndFindMatches

protected List<String> waitAndFindMatches(String toFind)
                                   throws IOException
Throws:
IOException

waitAndFindMatches

protected List<String> waitAndFindMatches(String toFind,
                                          long wait)
                                   throws IOException
Throws:
IOException

waitForMessage

public boolean waitForMessage(String message)
                       throws FileNotFoundException,
                              IOException
Throws:
FileNotFoundException
IOException

waitForMessage

public boolean waitForMessage(String message,
                              long wait)
                       throws FileNotFoundException,
                              IOException
Throws:
FileNotFoundException
IOException

splitResultsOnConnectionID

protected HashMap<Integer,List<String>> splitResultsOnConnectionID(List<String> logMessages)
Given a list of messages that have been pulled out of a log file Process the results splitting the log statements in to lists based on the actor's connection ID. So for each log entry extract the Connecition ID from the Actor of the log Then use that as a key to a HashMap storing the list of log messages for that connection.

Parameters:
logMessages - The list of mixed connection log messages
Returns:
Map indexed by connection id to a list of log messages just for that connection.

filterResultsByVirtualHost

protected List<String> filterResultsByVirtualHost(List<String> results,
                                                  String virtualHostName)
Filter the give result set by the specficifed virtualhost. This is done using the getSlice to identify the virtualhost (vh) in the log message

Parameters:
results - full list of logs
virtualHostName - the virtualhostName to filter on
Returns:
the list of messages only for that virtualhost

dumpLogs

protected void dumpLogs(List<String> results)
                 throws IOException
Dump the log results.

Throws:
IOException

dumpLogs

protected void dumpLogs(List<String> results,
                        LogMonitor monitor)
                 throws IOException
Dump the log results or if there are none, the contents of the monitored log file if the monitor is non-null.

Throws:
IOException


Licensed to the Apache Software Foundation