summaryrefslogtreecommitdiff
path: root/java/client/src
diff options
context:
space:
mode:
authorMartin Ritchie <ritchiem@apache.org>2007-09-27 14:27:22 +0000
committerMartin Ritchie <ritchiem@apache.org>2007-09-27 14:27:22 +0000
commit972614c8446ec8ec2a4f6c55fee4d5cc4b46e84b (patch)
treef3b7bb28b44b9fbd4207bb0943307590a8313e64 /java/client/src
parent7286cb7d1d4f2f370c2df414cdb5150f9b658b00 (diff)
downloadqpid-python-972614c8446ec8ec2a4f6c55fee4d5cc4b46e84b.tar.gz
QPID-596 : ConnectionStartTest was broken. I've fixed it but here is the problem for those like me that like to know why:
Previously: The setUp method created a producer connection and then sent a message - This will result in that message being bounced as there is no consumer. The first test should fail but the test was wrong, which caused it to pass. There was an assert that was expecting the receive a message yet the test was recieve() == null !!!! The second test worked because the broker was not killed between tests This left the queue created so on the second run the message was delivered causing the test to succeed. Now: Fixed the InVM broker setup/teardown so the client is created first and the broker removed at the end of the test. Also updated the asserts to be more explicit rather than having the == null or !=null put that as assertNull/NotNull. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/branches/M2.1@580022 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/client/src')
-rw-r--r--java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ConnectionStartTest.java53
1 files changed, 34 insertions, 19 deletions
diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ConnectionStartTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ConnectionStartTest.java
index daa1086561..1d108b9c5c 100644
--- a/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ConnectionStartTest.java
+++ b/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ConnectionStartTest.java
@@ -20,8 +20,11 @@
*/
package org.apache.qpid.test.unit.client.connection;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
+import junit.framework.TestCase;
+import org.apache.qpid.client.AMQConnection;
+import org.apache.qpid.client.AMQQueue;
+import org.apache.qpid.client.AMQSession;
+import org.apache.qpid.client.transport.TransportConnection;
import javax.jms.JMSException;
import javax.jms.Message;
@@ -30,14 +33,20 @@ import javax.jms.MessageListener;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;
+import javax.jms.Queue;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
-import junit.framework.TestCase;
-
-import org.apache.qpid.client.AMQConnection;
-import org.apache.qpid.client.AMQQueue;
-import org.apache.qpid.client.AMQSession;
-import org.apache.qpid.client.transport.TransportConnection;
-
+/**
+ * ConnectionStartTest:
+ * This test verifies that a fresh connection is not started and no messages are delivered until the connection is
+ * started.
+ *
+ * After the connection is started then the message should be there, and the connection started.
+ *
+ * This Test verifies that using receive() and a messageListener does not cause message delivery before start is called.
+ *
+ */
public class ConnectionStartTest extends TestCase
{
@@ -54,11 +63,18 @@ public class ConnectionStartTest extends TestCase
try
{
+ // Create Consumer Connection
+ _connection = new AMQConnection(_broker, "guest", "guest", "fred", "test");
+ _consumerSess = _connection.createSession(false, AMQSession.AUTO_ACKNOWLEDGE);
- AMQConnection pubCon = new AMQConnection(_broker, "guest", "guest", "fred", "test");
+ Queue queue = _consumerSess.createQueue("ConnectionStartTest");
+
+ _consumer = _consumerSess.createConsumer(queue);
- AMQQueue queue = new AMQQueue(pubCon,"ConnectionStartTest");
+
+ // Create Producer Connection to send message
+ AMQConnection pubCon = new AMQConnection(_broker, "guest", "guest", "fred", "test");
Session pubSess = pubCon.createSession(false, AMQSession.AUTO_ACKNOWLEDGE);
@@ -66,12 +82,6 @@ public class ConnectionStartTest extends TestCase
pub.send(pubSess.createTextMessage("Initial Message"));
- _connection = new AMQConnection(_broker, "guest", "guest", "fred", "test");
-
- _consumerSess = _connection.createSession(false, AMQSession.AUTO_ACKNOWLEDGE);
-
- _consumer = _consumerSess.createConsumer(queue);
-
pubCon.close();
}
@@ -85,6 +95,7 @@ public class ConnectionStartTest extends TestCase
{
_connection.close();
TransportConnection.killVMBroker(1);
+ super.tearDown();
}
public void testSimpleReceiveConnection()
@@ -94,9 +105,9 @@ public class ConnectionStartTest extends TestCase
assertTrue("Connection should not be started", !_connection.started());
//Note that this next line will start the dispatcher in the session
// should really not be called before _connection start
- assertTrue("There should not be messages waiting for the consumer", _consumer.receiveNoWait() == null);
+ assertNull("There should not be messages waiting for the consumer", _consumer.receiveNoWait());
_connection.start();
- assertTrue("There should be messages waiting for the consumer", _consumer.receive(1000) == null);
+ assertNotNull("There should be messages waiting for the consumer", _consumer.receive(1000));
assertTrue("Connection should be started", _connection.started());
}
@@ -131,7 +142,11 @@ public class ConnectionStartTest extends TestCase
}
});
+ // Ensure that setting a ML doesn't start the connection
assertTrue("Connection should not be started", !_connection.started());
+ // Ensure that the message wasn't delivered while the connection was stopped.
+ assertEquals("Message latch should still be set",1,_gotMessage.getCount());
+
_connection.start();
assertTrue("Connection should be started", _connection.started());