diff options
| author | Martin Ritchie <ritchiem@apache.org> | 2009-08-07 18:03:13 +0000 |
|---|---|---|
| committer | Martin Ritchie <ritchiem@apache.org> | 2009-08-07 18:03:13 +0000 |
| commit | e3d812059df2267648f2d895a590ce73f5b33f5c (patch) | |
| tree | b3e8eb29eb52dcb923646f4188690e766f3b2627 /java | |
| parent | 9b4933e4575c6210809307091e78004ce8b570d6 (diff) | |
| download | qpid-python-e3d812059df2267648f2d895a590ce73f5b33f5c.tar.gz | |
Add a drainQueue method to QTC to allow tests to clean up after themselves
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@802112 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java')
| -rw-r--r-- | java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java | 45 |
1 files changed, 38 insertions, 7 deletions
diff --git a/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java b/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java index 8b1643ed62..26263d5815 100644 --- a/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java +++ b/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java @@ -26,6 +26,8 @@ import javax.jms.Session; import javax.jms.MessageProducer; import javax.jms.Message; import javax.jms.JMSException; +import javax.jms.Queue; +import javax.jms.MessageConsumer; import javax.naming.InitialContext; import javax.naming.NamingException; import java.io.BufferedReader; @@ -248,7 +250,7 @@ public class QpidTestCase extends TestCase { fail("Unable to test without config file:" + _configFile); } - + startBroker(); } @@ -487,12 +489,12 @@ public class QpidTestCase extends TestCase ApplicationRegistry.remove(port); } } - + public void nukeBroker() throws Exception { nukeBroker(0); } - + public void nukeBroker(int port) throws Exception { Process proc = _brokers.get(getPort(port)); @@ -503,7 +505,7 @@ public class QpidTestCase extends TestCase else { String command = "pkill -KILL -f "+getBrokerCommand(getPort(port)); - try + try { Runtime.getRuntime().exec(command); } @@ -699,7 +701,7 @@ public class QpidTestCase extends TestCase protected boolean isExternalBroker() { return !_broker.equals("vm"); - } + } public void restartBroker() throws Exception { @@ -835,7 +837,36 @@ public class QpidTestCase extends TestCase revertSystemProperties(); } - + + /** + * Consume all the messages in the specified queue. Helper to ensure + * persistent tests don't leave data behind. + * + * @param queue the queue to purge + * @throws Exception if a problem occurs + * @return the count of messages drained + */ + protected int drainQueue(Queue queue) throws Exception + { + Connection connection = getConnection(); + + Session session = connection.createSession(false,Session.AUTO_ACKNOWLEDGE); + + MessageConsumer consumer = session.createConsumer(queue); + + connection.start(); + + int count = 0; + while (consumer.receive(1000) != null) + { + count++; + } + + connection.close(); + + return count; + } + public List<Message> sendMessage(Session session, Destination destination, int count) throws Exception { @@ -846,7 +877,7 @@ public class QpidTestCase extends TestCase int count,int batchSize) throws Exception { List<Message> messages = new ArrayList<Message>(count); - + MessageProducer producer = session.createProducer(destination); for (int i = 0; i < count; i++) |
