Author: ritchiem
Date: Wed Mar 19 02:39:50 2008
New Revision: 638760
URL: http://svn.apache.org/viewvc?rev=638760&view=rev
Log:
QPID-854 : Tests were failing as the new connection hadn't been started. Also
replaced purgeQueue with checkQueuesClean as the tests should ensure they have
tidied up.. if they haven't then something has gone wrong. So purging will just
hide that issue. Used a second connection in the QBAAT to validate the messages
to be sure they are still there. This also fixes the issues with Transacted and
ClientAck where the messages would of course go back on the queue as no ack or
commit were performed. Using a new connection is also cleaner as it ensures the
queue browsing has no side effects for other users of the system.
Modified:
incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/VMTestCase.java
incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/client/QueueBrowserAutoAckTest.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=638760&r1=638759&r2=638760&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
Wed Mar 19 02:39:50 2008
@@ -21,16 +21,18 @@
package org.apache.qpid.test;
import junit.framework.TestCase;
+import org.apache.qpid.client.AMQDestination;
+import org.apache.qpid.client.AMQSession;
import org.apache.qpid.client.transport.TransportConnection;
import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.jndi.PropertiesFileInitialContextFactory;
import org.apache.qpid.server.registry.ApplicationRegistry;
+import org.apache.qpid.AMQException;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.MessageConsumer;
+import javax.jms.Queue;
import javax.jms.Session;
import javax.naming.Context;
import javax.naming.NamingException;
@@ -94,14 +96,14 @@
env.put("connectionfactory." + c.getKey(), c.getValue());
}
- env.put("queue.queue", "queue");
+ _queues.put("queue", "queue");
for (Map.Entry<String, String> q : _queues.entrySet())
{
env.put("queue." + q.getKey(), q.getValue());
}
- env.put("topic.topic", "topic");
+ _topics.put("topic", "topic");
for (Map.Entry<String, String> t : _topics.entrySet())
{
@@ -113,7 +115,7 @@
protected void tearDown() throws Exception
{
- purgeQueues();
+ checkQueuesClean();
TransportConnection.killVMBroker(1);
ApplicationRegistry.remove(1);
@@ -121,29 +123,35 @@
super.tearDown();
}
- private void purgeQueues() throws NamingException, JMSException
+ private void checkQueuesClean() throws NamingException, JMSException
{
Connection connection = ((ConnectionFactory)
_context.lookup("connection")).createConnection();
Session session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
+ connection.start();
Iterator<String> queueNames = new
HashSet<String>(_queues.values()).iterator();
+ assertTrue("QueueNames doesn't have next", queueNames.hasNext());
- //todo this could be replaced with an AMQP purge queue command.
while (queueNames.hasNext())
{
- MessageConsumer consumer =
session.createConsumer(session.createQueue(queueNames.next()));
+ Queue queue = session.createQueue(queueNames.next());
- Message message = consumer.receive(RECEIVE_TIMEOUT);
-
- while (message != null)
+ //Validate that the queue are reporting empty.
+ long queueDepth = 0;
+ try
+ {
+ queueDepth = ((AMQSession)
session).getQueueDepth((AMQDestination) queue);
+ }
+ catch (AMQException e)
{
- message = consumer.receive(RECEIVE_TIMEOUT);
+ //ignore
}
+ assertEquals("Session reports Queue depth not as expected", 0,
queueDepth);
}
-
+
connection.close();
}
Modified:
incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/client/QueueBrowserAutoAckTest.java
URL:
http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/client/QueueBrowserAutoAckTest.java?rev=638760&r1=638759&r2=638760&view=diff
==============================================================================
---
incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/client/QueueBrowserAutoAckTest.java
(original)
+++
incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/client/QueueBrowserAutoAckTest.java
Wed Mar 19 02:39:50 2008
@@ -62,6 +62,8 @@
_clientSession = _clientConnection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
+ //Ensure there are no messages on the queue to start with.
+ checkQueueDepth(0);
}
public void tearDown() throws Exception
@@ -139,6 +141,7 @@
_logger.debug("Checking for " + depth + " messages with
QueueBrowser");
}
+ //Check what the session believes the queue count to be.
long queueDepth = 0;
try
@@ -151,7 +154,7 @@
assertEquals("Session reports Queue depth not as expected", depth,
queueDepth);
-
+ // Browse the queue to get a second opinion
int msgCount = 0;
Enumeration msgs = queueBrowser.getEnumeration();
@@ -277,8 +280,23 @@
protected void validate(int messages) throws JMSException
{
- // continue and try to receive all messages
- MessageConsumer consumer = _clientSession.createConsumer(_queue);
+ //Create a new connection to validate message content
+ Connection connection = null;
+
+ try
+ {
+ connection = ((ConnectionFactory)
_context.lookup("connection")).createConnection();
+ }
+ catch (NamingException e)
+ {
+ fail("Unable to make validation connection");
+ }
+
+ Session session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
+
+ connection.start();
+
+ MessageConsumer consumer = session.createConsumer(_queue);
_logger.info("Verify messages are still on the queue");
@@ -293,13 +311,13 @@
}
}
- consumer.close();
+ //Close this new connection
+ connection.close();
_logger.info("All messages recevied from queue");
//ensure no message left.
checkQueueDepth(0);
-
}
protected void checkQueueDepthWithSelectors(int clients, int
totalMessages) throws JMSException
@@ -387,7 +405,7 @@
checkQueueDepth(messages);
- for (int clients = 1; clients < 10; clients++)
+ for (int clients = 2; clients <= 10; clients++)
{
checkQueueDepthWithSelectors(clients, messages);
}
@@ -458,8 +476,6 @@
public void testFailoverAsQueueBrowserCreated() throws JMSException
{
- System.err.println("Disabled... this appears to be a bug in mina.");
-
// The IoServiceListenerSupport seems to get stuck in with a
managedSession that isn't closing when requested.
// So it hangs waiting for the session.
int messages = 50;