Author: ritchiem
Date: Mon Mar 17 10:25:12 2008
New Revision: 637979
URL: http://svn.apache.org/viewvc?rev=637979&view=rev
Log:
QPID-854 : Fixed QueueBrowser tests that use ClientAck and Transacted, which
appear to leave msgs behind per test. Even though each test should be on a new
VM broker.
Modified:
incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/VMTestCase.java
Modified:
incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/VMTestCase.java
URL:
http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/VMTestCase.java?rev=637979&r1=637978&r2=637979&view=diff
==============================================================================
---
incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/VMTestCase.java
(original)
+++
incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/VMTestCase.java
Mon Mar 17 10:25:12 2008
@@ -26,10 +26,19 @@
import org.apache.qpid.jndi.PropertiesFileInitialContextFactory;
import org.apache.qpid.server.registry.ApplicationRegistry;
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.Session;
import javax.naming.Context;
+import javax.naming.NamingException;
import javax.naming.spi.InitialContextFactory;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Hashtable;
+import java.util.Iterator;
import java.util.Map;
public class VMTestCase extends TestCase
@@ -104,10 +113,36 @@
protected void tearDown() throws Exception
{
+ purgeQueues();
+
TransportConnection.killVMBroker(1);
ApplicationRegistry.remove(1);
super.tearDown();
+ }
+
+ private void purgeQueues() throws NamingException, JMSException
+ {
+ Connection connection = ((ConnectionFactory)
_context.lookup("connection")).createConnection();
+
+ Session session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
+
+ Iterator<String> queueNames = new
HashSet<String>(_queues.values()).iterator();
+
+
+ //todo this could be replaced with an AMQP purge queue command.
+ while (queueNames.hasNext())
+ {
+ MessageConsumer consumer =
session.createConsumer(session.createQueue(queueNames.next()));
+
+ Message message = consumer.receive(RECEIVE_TIMEOUT);
+
+ while (message != null)
+ {
+ message = consumer.receive(RECEIVE_TIMEOUT);
+ }
+
+ }
}
public int getMessageCount(String queueName)