You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ri...@apache.org on 2007/09/27 16:27:23 UTC

svn commit: r580022 - /incubator/qpid/branches/M2.1/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ConnectionStartTest.java

Author: ritchiem
Date: Thu Sep 27 07:27:22 2007
New Revision: 580022

URL: http://svn.apache.org/viewvc?rev=580022&view=rev
Log:
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.


Modified:
    incubator/qpid/branches/M2.1/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ConnectionStartTest.java

Modified: incubator/qpid/branches/M2.1/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ConnectionStartTest.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ConnectionStartTest.java?rev=580022&r1=580021&r2=580022&view=diff
==============================================================================
--- incubator/qpid/branches/M2.1/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ConnectionStartTest.java (original)
+++ incubator/qpid/branches/M2.1/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ConnectionStartTest.java Thu Sep 27 07:27:22 2007
@@ -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.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 @@
 
         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");
 
-            AMQQueue queue = new AMQQueue(pubCon,"ConnectionStartTest");
+            _consumer = _consumerSess.createConsumer(queue);
+
+
+            // 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 @@
 
             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 @@
     {
         _connection.close();
         TransportConnection.killVMBroker(1);
+        super.tearDown();
     }
 
     public void testSimpleReceiveConnection()
@@ -94,9 +105,9 @@
             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 @@
                 }
             });
 
+            // 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());