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 | 1f4631825b8feb04fe792b364ecbf1e38c76bd7d (patch) | |
| tree | 655dd751eb7bac234ec28fd019336b16bd3841df | |
| parent | 915b9284d0a37bf8f9b50003bf11b6ddae33e419 (diff) | |
| download | qpid-python-1f4631825b8feb04fe792b364ecbf1e38c76bd7d.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@802112 13f79535-47bb-0310-9956-ffa450edef68
| -rw-r--r-- | qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java | 45 |
1 files changed, 38 insertions, 7 deletions
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java index 8b1643ed62..26263d5815 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java +++ b/qpid/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++) |
