diff options
| author | Martin Ritchie <ritchiem@apache.org> | 2010-02-04 11:42:18 +0000 |
|---|---|---|
| committer | Martin Ritchie <ritchiem@apache.org> | 2010-02-04 11:42:18 +0000 |
| commit | 404b34af7b72cded97f580095238cec5a6c79fe2 (patch) | |
| tree | c4c4832d10f999b90f5ffdc5c6000a3f2747fd3a /qpid/java/systests | |
| parent | 9815d9deb03ed7fbaa2701a76906b09774ba87b9 (diff) | |
| download | qpid-python-404b34af7b72cded97f580095238cec5a6c79fe2.tar.gz | |
QPID-2059 : One of the main causes of SubscriptionLoggingTest failing was that the aynchronous broker call preceding the log scraping would not always have time to complete the logging to file.
So I have added a waitAndFindMessages method that will attempt to retreive the required string for a set period of time. If it is found then it will perform the findMessages as before. I have updated the LoggingTests to use this method first. This will ensure that we have a more sophoiticated wait that just adding Thread.sleep()s to the tests.
git-svn-id: https://svn.apache.org/repos/asf/qpid/branches/0.5.x-dev@906459 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/systests')
19 files changed, 119 insertions, 115 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 2e107ada34..51076fe358 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 @@ -88,7 +88,7 @@ public class ManagementActorLoggingTest extends AbstractTestLogging */ public void testJMXManagementConsoleConnection() throws IOException { - List<String> results = _monitor.findMatches("MNG-1007"); + List<String> results = _monitor.waitAndFindMatches("MNG-1007", DEFAULT_LOG_WAIT); assertEquals("Unexpected Management Connection count", 1, results.size()); @@ -107,7 +107,7 @@ public class ManagementActorLoggingTest extends AbstractTestLogging _jmxUtils.close(); - results = _monitor.findMatches("MNG-1008"); + results = _monitor.waitAndFindMatches("MNG-1008", DEFAULT_LOG_WAIT); assertEquals("Unexpected Management Connection count", 1, results.size()); @@ -168,7 +168,7 @@ public class ManagementActorLoggingTest extends AbstractTestLogging exceptionReceived.await(2, TimeUnit.SECONDS)); //Validate results - List<String> results = _monitor.findMatches("CON-1002"); + List<String> results = _monitor.waitAndFindMatches("CON-1002", DEFAULT_LOG_WAIT); assertEquals("Unexpected Connection Close count", 1, results.size()); } @@ -203,7 +203,7 @@ public class ManagementActorLoggingTest extends AbstractTestLogging // Validate //1 - ID is correct - List<String> results = _monitor.findMatches("EXH-1001"); + List<String> results = _monitor.waitAndFindMatches("EXH-1001", DEFAULT_LOG_WAIT); assertEquals("More than one exchange creation found", 1, results.size()); @@ -227,7 +227,7 @@ public class ManagementActorLoggingTest extends AbstractTestLogging // Validate //1 - ID is correct - List<String> results = _monitor.findMatches("EXH-1001"); + List<String> results = _monitor.waitAndFindMatches("EXH-1001", DEFAULT_LOG_WAIT); assertEquals("More than one exchange creation found", 1, results.size()); @@ -252,7 +252,7 @@ public class ManagementActorLoggingTest extends AbstractTestLogging // Validate //1 - ID is correct - List<String> results = _monitor.findMatches("EXH-1001"); + List<String> results = _monitor.waitAndFindMatches("EXH-1001", DEFAULT_LOG_WAIT); assertEquals("More than one exchange creation found", 1, results.size()); @@ -277,7 +277,7 @@ public class ManagementActorLoggingTest extends AbstractTestLogging // Validate //1 - ID is correct - List<String> results = _monitor.findMatches("EXH-1001"); + List<String> results = _monitor.waitAndFindMatches("EXH-1001", DEFAULT_LOG_WAIT); assertEquals("More than one exchange creation found", 1, results.size()); @@ -320,7 +320,7 @@ public class ManagementActorLoggingTest extends AbstractTestLogging // Validate - List<String> results = _monitor.findMatches("QUE-1001"); + List<String> results = _monitor.waitAndFindMatches("QUE-1001", DEFAULT_LOG_WAIT); assertEquals("More than one queue creation found", 1, results.size()); @@ -365,7 +365,7 @@ public class ManagementActorLoggingTest extends AbstractTestLogging managedBroker.deleteQueue(getName()); - List<String> results = _monitor.findMatches("QUE-1002"); + List<String> results = _monitor.waitAndFindMatches("QUE-1002", DEFAULT_LOG_WAIT); assertEquals("More than one queue deletion found", 1, results.size()); @@ -411,7 +411,7 @@ public class ManagementActorLoggingTest extends AbstractTestLogging managedExchange.createNewBinding(getName(), getName()); - List<String> results = _monitor.findMatches("BND-1001"); + List<String> results = _monitor.waitAndFindMatches("BND-1001", DEFAULT_LOG_WAIT); assertEquals("More than one bind creation found", 1, results.size()); @@ -438,7 +438,7 @@ public class ManagementActorLoggingTest extends AbstractTestLogging managedExchange.createNewBinding(getName(), getName()); - List<String> results = _monitor.findMatches("BND-1001"); + List<String> results = _monitor.waitAndFindMatches("BND-1001", DEFAULT_LOG_WAIT); assertEquals("More than one bind creation found", 1, results.size()); @@ -465,7 +465,7 @@ public class ManagementActorLoggingTest extends AbstractTestLogging managedExchange.createNewBinding(getName(), getName()); - List<String> results = _monitor.findMatches("BND-1001"); + List<String> results = _monitor.waitAndFindMatches("BND-1001", DEFAULT_LOG_WAIT); assertEquals("More than one bind creation found", 1, results.size()); @@ -512,7 +512,7 @@ public class ManagementActorLoggingTest extends AbstractTestLogging managedBroker.unregisterExchange(getName()); - List<String> results = _monitor.findMatches("EXH-1002"); + List<String> results = _monitor.waitAndFindMatches("EXH-1002", DEFAULT_LOG_WAIT); 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 e7975f8d24..ca20efd2a9 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 @@ -102,7 +102,7 @@ public class BrokerStartupTest extends AbstractTestLogging 0, _monitor.findMatches("log4j:ERROR Could not read configuration file from URL").size()); assertEquals("Logging did not error as expected", - 1, _monitor.findMatches("Logging configuration error: unable to read file ").size()); + 1, _monitor.waitAndFindMatches("Logging configuration error: unable to read file ", DEFAULT_LOG_WAIT).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.findMatches("DEBUG"); + List<String> results = _monitor.waitAndFindMatches("DEBUG", DEFAULT_LOG_WAIT); 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 e7d1c8b896..ce05c95473 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 @@ -32,6 +32,7 @@ import java.util.List; public class AbstractTestLogging extends QpidTestCase { + public static final long DEFAULT_LOG_WAIT = 2000; protected LogMonitor _monitor; @Override 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 683abee4da..3429edd6bc 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 @@ -47,13 +47,6 @@ public class AlertingTest extends AbstractTestLogging public void setUp() throws Exception { - // set QPID_WORK to be [QPID_WORK|io.tmpdir]/<testName> - // This ensures that each of these tests operate independantly. - setSystemProperty("QPID_WORK", - System.getProperty("QPID_WORK", - System.getProperty("java.io.tmpdir")) - + File.separator + getName()); - // Update the configuration to make our virtualhost Persistent. makeVirtualHostPersistent(VIRTUALHOST); 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 ba05dc6b3e..affbc82c5a 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 @@ -104,7 +104,7 @@ public class BindingLoggingTest extends AbstractTestLogging { _session.createConsumer(_queue).close(); - List<String> results = _monitor.findMatches(BND_PREFIX); + List<String> results = _monitor.waitAndFindMatches(BND_PREFIX, DEFAULT_LOG_WAIT); // We will have two binds as we bind all queues to the default exchange assertEquals("Result set larger than expected.", 2, results.size()); @@ -141,7 +141,7 @@ public class BindingLoggingTest extends AbstractTestLogging _session.createDurableSubscriber(_topic, getName(), SELECTOR, false).close(); - List<String> results = _monitor.findMatches(BND_PREFIX); + List<String> results = _monitor.waitAndFindMatches(BND_PREFIX, DEFAULT_LOG_WAIT); // We will have two binds as we bind all queues to the default exchange assertEquals("Result set larger than expected.", 2, results.size()); @@ -212,7 +212,7 @@ public class BindingLoggingTest extends AbstractTestLogging // and so unbind. _session.createConsumer(_session.createTemporaryQueue()).close(); - List<String> results = _monitor.findMatches(BND_PREFIX); + List<String> results = _monitor.waitAndFindMatches(BND_PREFIX, DEFAULT_LOG_WAIT); // We will have two binds as we bind all queues to the default exchange assertEquals("Result set larger than expected.", 4, results.size()); 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 b00a71315e..7c143285f9 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 @@ -47,6 +47,8 @@ import java.util.List; */ public class BrokerLoggingTest extends AbstractTestLogging { + private static final String BRK_LOG_PREFIX = "BRK-"; + public void setUp() throws Exception { // We either do this here or have a null check in tearDown. @@ -91,7 +93,7 @@ public class BrokerLoggingTest extends AbstractTestLogging String configFilePath = _configFile.toString(); - List<String> results = _monitor.findMatches("BRK-"); + List<String> results = _monitor.waitAndFindMatches(BRK_LOG_PREFIX, DEFAULT_LOG_WAIT); try { // Validation @@ -170,7 +172,7 @@ public class BrokerLoggingTest extends AbstractTestLogging // Ensure broker has fully started up. getConnection(); - List<String> results = _monitor.findMatches("BRK-"); + List<String> results = _monitor.waitAndFindMatches(BRK_LOG_PREFIX, DEFAULT_LOG_WAIT); try { // Validation @@ -268,7 +270,7 @@ public class BrokerLoggingTest extends AbstractTestLogging // Ensure broker has fully started up. getConnection(); - List<String> results = _monitor.findMatches("BRK-"); + List<String> results = _monitor.waitAndFindMatches(BRK_LOG_PREFIX, DEFAULT_LOG_WAIT); try { // Validation @@ -354,7 +356,7 @@ public class BrokerLoggingTest extends AbstractTestLogging // Now we can create the monitor as _outputFile will now be defined _monitor = new LogMonitor(_outputFile); - List<String> results = _monitor.findMatches("BRK-"); + List<String> results = _monitor.waitAndFindMatches(BRK_LOG_PREFIX, DEFAULT_LOG_WAIT); try { // Validation @@ -437,7 +439,7 @@ public class BrokerLoggingTest extends AbstractTestLogging // Ensure broker has fully started up. getConnection(); - List<String> results = _monitor.findMatches("BRK-"); + List<String> results = _monitor.waitAndFindMatches(BRK_LOG_PREFIX, DEFAULT_LOG_WAIT); try { // Validation @@ -537,7 +539,7 @@ public class BrokerLoggingTest extends AbstractTestLogging // Ensure broker has fully started up. getConnection(); - List<String> results = _monitor.findMatches("BRK-"); + List<String> results = _monitor.waitAndFindMatches(BRK_LOG_PREFIX, DEFAULT_LOG_WAIT); try { // Validation @@ -631,7 +633,7 @@ public class BrokerLoggingTest extends AbstractTestLogging //Ensure the broker has fully started up. getConnection(); - List<String> results = _monitor.findMatches("BRK-"); + List<String> results = _monitor.waitAndFindMatches(BRK_LOG_PREFIX, DEFAULT_LOG_WAIT); try { // Validation @@ -720,7 +722,7 @@ public class BrokerLoggingTest extends AbstractTestLogging //Give broker time to shutdown and flush log checkSocketClosed(getPort()); - List<String> results = _monitor.findMatches("BRK-"); + List<String> results = _monitor.waitAndFindMatches(BRK_LOG_PREFIX, DEFAULT_LOG_WAIT); try { // Validation @@ -828,7 +830,7 @@ public class BrokerLoggingTest extends AbstractTestLogging //Give broker time to shutdown and flush log checkSocketClosed(getPort()); - List<String> results = _monitor.findMatches(TESTID); + List<String> results = _monitor.waitAndFindMatches(TESTID, DEFAULT_LOG_WAIT); try { // Validation @@ -910,7 +912,7 @@ public class BrokerLoggingTest extends AbstractTestLogging // Ensure the broker has shutdown before retreving results checkSocketClosed(getPort()); - List<String> results = _monitor.findMatches("BRK-"); + List<String> results = _monitor.waitAndFindMatches(BRK_LOG_PREFIX, DEFAULT_LOG_WAIT); try { // Validation 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 ea0199570c..10044fe24d 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 @@ -26,24 +26,14 @@ import javax.jms.Connection; import javax.jms.MessageConsumer; import javax.jms.Queue; import javax.jms.Session; -import java.io.File; import java.util.List; public class ChannelLoggingTest extends AbstractTestLogging { private static final String CHANNEL_PREFIX = "CHN-"; - public void setUp() throws Exception - { - // set QPID_WORK to be [QPID_WORK|io.tmpdir]/<testName> - setSystemProperty("QPID_WORK", - System.getProperty("QPID_WORK", - System.getProperty("java.io.tmpdir")) - + File.separator + getName()); - - //Start the broker - super.setUp(); - } + // No explicit startup configuration is required for this test + // so no setUp() method /** * Description: @@ -74,7 +64,7 @@ public class ChannelLoggingTest extends AbstractTestLogging // Test that calling session.close gives us the expected output ((AMQConnection)connection).createSession(false, Session.AUTO_ACKNOWLEDGE,PREFETCH); - List<String> results = _monitor.findMatches(CHANNEL_PREFIX); + List<String> results = _monitor.waitAndFindMatches(CHANNEL_PREFIX, DEFAULT_LOG_WAIT); // Validation @@ -129,7 +119,7 @@ public class ChannelLoggingTest extends AbstractTestLogging connection.start(); - List<String> results = _monitor.findMatches(CHANNEL_PREFIX); + List<String> results = _monitor.waitAndFindMatches(CHANNEL_PREFIX, DEFAULT_LOG_WAIT); assertTrue("No CHN messages logged", results.size() > 0); @@ -183,22 +173,27 @@ public class ChannelLoggingTest extends AbstractTestLogging //Call receive to send the Flow On message consumer.receiveNoWait(); - List<String> results = _monitor.findMatches(CHANNEL_PREFIX); + //Wait for up to 2 seconds for message to appear + // ignore response as we will use the findMatches afterwards just + // incase it did take more than 2 seconds to log. + _monitor.waitForMessage(CHANNEL_PREFIX, 2000); + + List<String> results = _monitor.waitAndFindMatches(CHANNEL_PREFIX, DEFAULT_LOG_WAIT); assertTrue("No CHN messages logged", results.size() > 0); - // The last two channel messages should be: + // The last two channel messages(before the close) should be: // - // INFO - MESSAGE [con:0(guest@anonymous(4205299)/test)/ch:1] [con:0(guest@anonymous(4205299)/test)/ch:1] CHN-1002 : Flow On + // 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 + // 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))); - } /** @@ -232,7 +227,7 @@ public class ChannelLoggingTest extends AbstractTestLogging // Close the connection to verify the created session closing is logged. connection.close(); - List<String> results = _monitor.findMatches(CHANNEL_PREFIX); + List<String> results = _monitor.waitAndFindMatches(CHANNEL_PREFIX, DEFAULT_LOG_WAIT); assertTrue("No CHN messages logged", results.size() > 0); @@ -279,7 +274,7 @@ public class ChannelLoggingTest extends AbstractTestLogging // Create a session and then close it connection.createSession(false, Session.AUTO_ACKNOWLEDGE).close(); - List<String> results = _monitor.findMatches(CHANNEL_PREFIX); + List<String> results = _monitor.waitAndFindMatches(CHANNEL_PREFIX, DEFAULT_LOG_WAIT); assertTrue("No CHN messages logged", results.size() > 0); 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 503129072b..6256d4964a 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 @@ -30,17 +30,8 @@ public class ConnectionLoggingTest extends AbstractTestLogging { private static final String CONNECTION_PREFIX = "CON-"; - public void setUp() throws Exception - { - // set QPID_WORK to be [QPID_WORK|io.tmpdir]/<testName> - setSystemProperty("QPID_WORK", - System.getProperty("QPID_WORK", - System.getProperty("java.io.tmpdir")) - + File.separator + getName()); - - //Start the broker - super.setUp(); - } + // No explicit startup configuration is required for this test + // so no setUp() method /** * Description: @@ -64,7 +55,7 @@ public class ConnectionLoggingTest extends AbstractTestLogging Connection connection = getConnection(); - List<String> results = _monitor.findMatches(CONNECTION_PREFIX); + List<String> results = _monitor.waitAndFindMatches(CONNECTION_PREFIX, DEFAULT_LOG_WAIT); assertTrue("No CON messages logged", results.size() > 0); @@ -155,7 +146,7 @@ public class ConnectionLoggingTest extends AbstractTestLogging // Open and then close the conneciton getConnection().close(); - List<String> results = _monitor.findMatches(CONNECTION_PREFIX); + List<String> results = _monitor.waitAndFindMatches(CONNECTION_PREFIX, DEFAULT_LOG_WAIT); // Validation 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 cc3993249c..d021aa89a7 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 @@ -91,7 +91,7 @@ public class DerbyMessageStoreLoggingTest extends MemoryMessageStoreLoggingTest startBroker(); - List<String> results = _monitor.findMatches(MESSAGES_STORE_PREFIX); + List<String> results = _monitor.waitAndFindMatches(MESSAGES_STORE_PREFIX, DEFAULT_LOG_WAIT); // Validation @@ -102,7 +102,7 @@ public class DerbyMessageStoreLoggingTest extends MemoryMessageStoreLoggingTest List<String> vhosts = configuration.getConfig().getList("virtualhosts.virtualhost.name"); //Validate each vhost logs a creation - results = _monitor.findMatches("MST-1002"); + results = _monitor.waitAndFindMatches("MST-1002", DEFAULT_LOG_WAIT); assertEquals("Each vhost did not close its store.", vhosts.size(), results.size()); @@ -154,7 +154,7 @@ public class DerbyMessageStoreLoggingTest extends MemoryMessageStoreLoggingTest startBroker(); - List<String> results = _monitor.findMatches(MESSAGES_STORE_PREFIX); + List<String> results = _monitor.waitAndFindMatches(MESSAGES_STORE_PREFIX, DEFAULT_LOG_WAIT); // Validation @@ -165,7 +165,7 @@ public class DerbyMessageStoreLoggingTest extends MemoryMessageStoreLoggingTest List<String> vhosts = configuration.getConfig().getList("virtualhosts.virtualhost.name"); //Validate each vhost logs a creation - results = _monitor.findMatches("MST-1004"); + results = _monitor.waitAndFindMatches("MST-1004", DEFAULT_LOG_WAIT); assertTrue("Each vhost did not close its store.", vhosts.size() <= results.size()); @@ -221,7 +221,7 @@ public class DerbyMessageStoreLoggingTest extends MemoryMessageStoreLoggingTest startBroker(); - List<String> results = _monitor.findMatches(MESSAGES_STORE_PREFIX); + List<String> results = _monitor.waitAndFindMatches(MESSAGES_STORE_PREFIX, DEFAULT_LOG_WAIT); // Validation @@ -232,7 +232,7 @@ public class DerbyMessageStoreLoggingTest extends MemoryMessageStoreLoggingTest List<String> vhosts = configuration.getConfig().getList("virtualhosts.virtualhost.name"); //Validate each vhost logs a creation - results = _monitor.findMatches("MST-1006"); + results = _monitor.waitAndFindMatches("MST-1006", DEFAULT_LOG_WAIT); assertTrue("Each vhost did not close its store.", vhosts.size() <= results.size()); @@ -287,7 +287,7 @@ public class DerbyMessageStoreLoggingTest extends MemoryMessageStoreLoggingTest startBroker(); - List<String> results = _monitor.findMatches(MESSAGES_STORE_PREFIX); + List<String> results = _monitor.waitAndFindMatches(MESSAGES_STORE_PREFIX, DEFAULT_LOG_WAIT); // Validation @@ -298,7 +298,7 @@ public class DerbyMessageStoreLoggingTest extends MemoryMessageStoreLoggingTest List<String> vhosts = configuration.getConfig().getList("virtualhosts.virtualhost.name"); //Validate each vhost logs a creation - results = _monitor.findMatches("MST-1004 : Recovery Start :"); + results = _monitor.waitAndFindMatches("MST-1004 : Recovery Start :", DEFAULT_LOG_WAIT); // 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 @@ -352,7 +352,7 @@ public class DerbyMessageStoreLoggingTest extends MemoryMessageStoreLoggingTest startBroker(); - List<String> results = _monitor.findMatches(MESSAGES_STORE_PREFIX); + List<String> results = _monitor.waitAndFindMatches(MESSAGES_STORE_PREFIX, DEFAULT_LOG_WAIT); // Validation @@ -363,7 +363,7 @@ public class DerbyMessageStoreLoggingTest extends MemoryMessageStoreLoggingTest List<String> vhosts = configuration.getConfig().getList("virtualhosts.virtualhost.name"); //Validate each vhost logs a creation - results = _monitor.findMatches("MST-1006 : Recovery Complete :"); + results = _monitor.waitAndFindMatches("MST-1006 : Recovery Complete :", DEFAULT_LOG_WAIT); // 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 @@ -494,7 +494,7 @@ public class DerbyMessageStoreLoggingTest extends MemoryMessageStoreLoggingTest startBroker(); - List<String> results = _monitor.findMatches(MESSAGES_STORE_PREFIX); + List<String> results = _monitor.waitAndFindMatches(MESSAGES_STORE_PREFIX, DEFAULT_LOG_WAIT); // Validation @@ -505,7 +505,7 @@ public class DerbyMessageStoreLoggingTest extends MemoryMessageStoreLoggingTest List<String> vhosts = configuration.getConfig().getList("virtualhosts.virtualhost.name"); //Validate each vhost logs a creation - results = _monitor.findMatches("MST-1004 : Recovery Start : " + queueName); + results = _monitor.waitAndFindMatches("MST-1004 : Recovery Start : " + queueName, DEFAULT_LOG_WAIT); assertEquals("Recovered test queue not found.", 1, results.size()); 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 287a3fe412..48c1b6e487 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 @@ -94,7 +94,7 @@ public class DurableQueueLoggingTest extends AbstractTestLogging _session.createConsumer(queue); // Validation - List<String> results = _monitor.findMatches(QUEUE_PREFIX); + List<String> results = _monitor.waitAndFindMatches(QUEUE_PREFIX, DEFAULT_LOG_WAIT); // Only 1 Queue message should hav been logged assertEquals("Result set size not as expected", 1, results.size()); @@ -145,7 +145,7 @@ public class DurableQueueLoggingTest extends AbstractTestLogging _session.createConsumer(queue); // Validation - List<String> results = _monitor.findMatches(QUEUE_PREFIX); + List<String> results = _monitor.waitAndFindMatches(QUEUE_PREFIX, DEFAULT_LOG_WAIT); // Only 1 Queue message should hav been logged assertEquals("Result set size not as expected", 1, results.size()); @@ -196,7 +196,7 @@ public class DurableQueueLoggingTest extends AbstractTestLogging _session.createConsumer(queue); // Validation - List<String> results = _monitor.findMatches(QUEUE_PREFIX); + List<String> results = _monitor.waitAndFindMatches(QUEUE_PREFIX, DEFAULT_LOG_WAIT); // Only 1 Queue message should hav been logged assertEquals("Result set size not as expected", 1, results.size()); @@ -256,7 +256,7 @@ public class DurableQueueLoggingTest extends AbstractTestLogging _session.createConsumer(_session.createQueue(getTestQueueName())); // Validation - List<String> results = _monitor.findMatches(QUEUE_PREFIX); + List<String> results = _monitor.waitAndFindMatches(QUEUE_PREFIX, DEFAULT_LOG_WAIT); // Only 1 Queue message should hav been logged assertEquals("Result set size not as expected", 1, results.size()); @@ -317,7 +317,7 @@ public class DurableQueueLoggingTest extends AbstractTestLogging _session.createConsumer(_session.createQueue(getTestQueueName())); // Validation - List<String> results = _monitor.findMatches(QUEUE_PREFIX); + List<String> results = _monitor.waitAndFindMatches(QUEUE_PREFIX, DEFAULT_LOG_WAIT); // Only 1 Queue message should hav been logged assertEquals("Result set size not as expected", 1, results.size()); 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 778201e3e4..7ffbaa4fc9 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 @@ -94,7 +94,7 @@ public class ExchangeLoggingTest extends AbstractTestLogging // They should all be durable - List<String> results = _monitor.findMatches(EXH_PREFIX); + List<String> results = _monitor.waitAndFindMatches(EXH_PREFIX, DEFAULT_LOG_WAIT); assertTrue("No Results found for Exchange.", results.size()>0); @@ -132,7 +132,7 @@ public class ExchangeLoggingTest extends AbstractTestLogging _session.createConsumer(_queue); - List<String> results = _monitor.findMatches(EXH_PREFIX); + List<String> results = _monitor.waitAndFindMatches(EXH_PREFIX, DEFAULT_LOG_WAIT); assertEquals("Result set larger than expected.", 1, results.size()); @@ -180,7 +180,7 @@ public class ExchangeLoggingTest extends AbstractTestLogging ((AMQConnection) _connection).getProtocolHandler().syncWrite(exchangeDeclare, ExchangeDeleteOkBody.class); - List<String> results = _monitor.findMatches(EXH_PREFIX); + List<String> results = _monitor.waitAndFindMatches(EXH_PREFIX, DEFAULT_LOG_WAIT); assertEquals("Result set larger than expected.", 2, results.size()); 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 8b7c881a32..906e37e46f 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 @@ -85,7 +85,7 @@ public class ManagementLoggingTest extends AbstractTestLogging // 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 = _monitor.waitAndFindMatches(MNG_PREFIX, DEFAULT_LOG_WAIT); try { // Validation @@ -144,7 +144,7 @@ public class ManagementLoggingTest extends AbstractTestLogging // 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 = _monitor.waitAndFindMatches(MNG_PREFIX, DEFAULT_LOG_WAIT); try { // Validation @@ -215,7 +215,7 @@ public class ManagementLoggingTest extends AbstractTestLogging // Now we can create the monitor as _outputFile will now be defined _monitor = new LogMonitor(_outputFile); - List<String> results = _monitor.findMatches("MNG-1002"); + List<String> results = _monitor.waitAndFindMatches("MNG-1002", DEFAULT_LOG_WAIT); try { // Validation @@ -290,7 +290,7 @@ public class ManagementLoggingTest extends AbstractTestLogging // Now we can create the monitor as _outputFile will now be defined _monitor = new LogMonitor(_outputFile); - List<String> results = _monitor.findMatches("MNG-1006"); + List<String> results = _monitor.waitAndFindMatches("MNG-1006", DEFAULT_LOG_WAIT); try { // Validation 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 2298ba4da0..d63bb77c47 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,7 +78,7 @@ public class MemoryMessageStoreLoggingTest extends AbstractTestLogging startBroker(); - List<String> results = _monitor.findMatches(MESSAGES_STORE_PREFIX); + List<String> results = _monitor.waitAndFindMatches(MESSAGES_STORE_PREFIX, DEFAULT_LOG_WAIT); // Validation @@ -149,7 +149,7 @@ public class MemoryMessageStoreLoggingTest extends AbstractTestLogging //Stop the broker so we get the close messages. stopBroker(); - List<String> results = _monitor.findMatches(MESSAGES_STORE_PREFIX); + List<String> results = _monitor.waitAndFindMatches(MESSAGES_STORE_PREFIX, DEFAULT_LOG_WAIT); // Validation 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 150f462d0f..639516a083 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 @@ -94,7 +94,7 @@ public class QueueLoggingTest extends AbstractTestLogging _session.close(); // Validation - List<String> results = _monitor.findMatches(QUEUE_PREFIX); + List<String> results = _monitor.waitAndFindMatches(QUEUE_PREFIX, DEFAULT_LOG_WAIT); // Only 1 Queue message should hav been logged assertEquals("Result set size not as expected", 2, results.size()); @@ -145,7 +145,7 @@ public class QueueLoggingTest extends AbstractTestLogging _session.createConsumer(_session.createTemporaryQueue()).close(); // Validation - List<String> results = _monitor.findMatches(QUEUE_PREFIX); + List<String> results = _monitor.waitAndFindMatches(QUEUE_PREFIX, DEFAULT_LOG_WAIT); // Only 1 Queue message should hav been logged assertEquals("Result set size not as expected", 2, results.size()); 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 eb6e2ba666..425be0fce9 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 @@ -91,7 +91,7 @@ public class SubscriptionLoggingTest extends AbstractTestLogging //Validate - List<String> results = _monitor.findMatches(SUB_PREFIX); + List<String> results = _monitor.waitAndFindMatches(SUB_PREFIX, DEFAULT_LOG_WAIT); assertEquals("Result set larger than expected.", 1, results.size()); @@ -125,13 +125,8 @@ public class SubscriptionLoggingTest extends AbstractTestLogging { _session.createDurableSubscriber(_topic, getName()); - //Wait for up to 2 seconds for message to appear - // ignore response as we will use the findMatches afterwards just - // incase it did take more than 2 seconds to log. - _monitor.waitForMessage(SUB_PREFIX, 2000); - //Validate - List<String> results = _monitor.findMatches(SUB_PREFIX); + List<String> results = _monitor.waitAndFindMatches(SUB_PREFIX, 2000); assertEquals("Result set not as expected.", 1, results.size()); @@ -167,7 +162,7 @@ public class SubscriptionLoggingTest extends AbstractTestLogging _session.createBrowser(_queue); //Validate - List<String> results = _monitor.findMatches(SUB_PREFIX); + List<String> results = _monitor.waitAndFindMatches(SUB_PREFIX, DEFAULT_LOG_WAIT); assertEquals("Result set larger than expected.", 2, results.size()); @@ -211,7 +206,7 @@ public class SubscriptionLoggingTest extends AbstractTestLogging //Validate - List<String> results = _monitor.findMatches(SUB_PREFIX); + List<String> results = _monitor.waitAndFindMatches(SUB_PREFIX, DEFAULT_LOG_WAIT); assertEquals("Result set larger than expected.", 1, results.size()); @@ -249,7 +244,7 @@ public class SubscriptionLoggingTest extends AbstractTestLogging //Validate - List<String> results = _monitor.findMatches(SUB_PREFIX); + List<String> results = _monitor.waitAndFindMatches(SUB_PREFIX, 2000); assertEquals("Result set larger than expected.", 1, results.size()); @@ -287,7 +282,7 @@ public class SubscriptionLoggingTest extends AbstractTestLogging _session.createConsumer(_queue).close(); //Validate - List<String> results = _monitor.findMatches(SUB_PREFIX); + List<String> results = _monitor.waitAndFindMatches(SUB_PREFIX, DEFAULT_LOG_WAIT); //3 assertEquals("Result set larger than expected.", 2, results.size()); @@ -373,7 +368,7 @@ public class SubscriptionLoggingTest extends AbstractTestLogging _session.commit(); //Validate - List<String> results = _monitor.findMatches("SUB-1003"); + List<String> results = _monitor.waitAndFindMatches("SUB-1003", DEFAULT_LOG_WAIT); try { 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 f4a0c8b27d..17e2d2e554 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 @@ -60,7 +60,7 @@ public class VirtualHostLoggingTest extends AbstractTestLogging public void testVirtualhostCreation() throws Exception { - List<String> results = _monitor.findMatches(VHT_PREFIX); + List<String> results = _monitor.waitAndFindMatches(VHT_PREFIX, DEFAULT_LOG_WAIT); try { // Validation @@ -112,7 +112,7 @@ public class VirtualHostLoggingTest extends AbstractTestLogging { stopBroker(); - List<String> results = _monitor.findMatches(VHT_PREFIX); + List<String> results = _monitor.waitAndFindMatches(VHT_PREFIX, DEFAULT_LOG_WAIT); try { // Validation 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 0538b60e22..7d34326ffb 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 @@ -160,7 +160,7 @@ public class ProducerFlowControlTest extends AbstractTestLogging sendMessagesAsync(producer, producerSession, 5, 50L); Thread.sleep(5000); - List<String> results = _monitor.findMatches("QUE-1003"); + List<String> results = _monitor.waitAndFindMatches("QUE-1003", DEFAULT_LOG_WAIT); assertEquals("Did not find correct number of QUE-1003 queue overfull messages", 1, results.size()); @@ -170,7 +170,7 @@ public class ProducerFlowControlTest extends AbstractTestLogging while(consumer.receive(1000) != null); - results = _monitor.findMatches("QUE-1004"); + results = _monitor.waitAndFindMatches("QUE-1004", DEFAULT_LOG_WAIT); assertEquals("Did not find correct number of QUE_UNDERFULL queue underfull messages", 1, results.size()); @@ -205,7 +205,7 @@ public class ProducerFlowControlTest extends AbstractTestLogging MessageSender sender = sendMessagesAsync(producer, producerSession, 5, 50L); Thread.sleep(10000); - List<String> results = _monitor.findMatches("Message send delayed by"); + List<String> results = _monitor.waitAndFindMatches("Message send delayed by", 10000); assertTrue("Incorrect number of delay messages logged by client - expect at least 3, got " + results.size(),3 <= results.size()); results = _monitor.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()); diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/util/LogMonitor.java b/qpid/java/systests/src/main/java/org/apache/qpid/util/LogMonitor.java index 7d55c68b75..a5e2b80f64 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/util/LogMonitor.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/util/LogMonitor.java @@ -33,6 +33,7 @@ import java.io.IOException; import java.io.OutputStreamWriter; import java.util.ArrayList; import java.util.List; +import java.util.LinkedList; /** * Utility to simplify the monitoring of Log4j file output @@ -91,6 +92,30 @@ public class LogMonitor } /** + * Checks the log file for a given message to appear and returns all + * instances of that appearance. + * + * @param message the message to wait for in the log + * @param wait the time in ms to wait for the message to occur + * @return true if the message was found + * + * @throws java.io.FileNotFoundException if the Log file can nolonger be found + * @throws IOException thrown when reading the log file + */ + public List<String> waitAndFindMatches(String message, long wait) + throws FileNotFoundException, IOException + { + if (waitForMessage(message, wait, true)) + { + return findMatches(message); + } + else + { + return new LinkedList<String>(); + } + } + + /** * Checks the log for instances of the search string. * * The pattern parameter can take any valid argument used in String.contains() @@ -114,6 +139,8 @@ public class LogMonitor * @param message the message to wait for in the log * @param wait the time in ms to wait for the message to occur * + * @param printFileOnFailure should we print the contents that have been + * read if we fail ot find the message. * @return true if the message was found * * @throws java.io.FileNotFoundException if the Log file can nolonger be found diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/util/LogMonitorTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/util/LogMonitorTest.java index 2b9fe8e039..a99abe4b94 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/util/LogMonitorTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/util/LogMonitorTest.java @@ -224,7 +224,7 @@ public class LogMonitorTest extends TestCase assertEquals("Incorrect result set size", 0, results.size()); } - /** + /** * Validate that the LogMonitor can match the given string in the log * * @param log The LogMonitor to check |
