qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ai...@apache.org
Subject svn commit: r629824 - in /incubator/qpid/branches/M2.1/java: client/src/main/java/org/apache/qpid/client/AMQQueueBrowser.java systests/src/main/java/org/apache/qpid/test/client/QueueBrowserTest.java
Date Thu, 21 Feb 2008 15:28:44 GMT
Author: aidan
Date: Thu Feb 21 07:28:43 2008
New Revision: 629824

URL: http://svn.apache.org/viewvc?rev=629824&view=rev
Log:
QPID-785: Make sure queue browser consumers are auto-close, add test for browsing an empty
queue. Refactor QueueBrowserTest a little to split up responsibilities a bit.

We should move the sendMessage stuff to a super class, there are at least 4 implementations
of that kicking about.

Modified:
    incubator/qpid/branches/M2.1/java/client/src/main/java/org/apache/qpid/client/AMQQueueBrowser.java
    incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/client/QueueBrowserTest.java

Modified: incubator/qpid/branches/M2.1/java/client/src/main/java/org/apache/qpid/client/AMQQueueBrowser.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1/java/client/src/main/java/org/apache/qpid/client/AMQQueueBrowser.java?rev=629824&r1=629823&r2=629824&view=diff
==============================================================================
--- incubator/qpid/branches/M2.1/java/client/src/main/java/org/apache/qpid/client/AMQQueueBrowser.java
(original)
+++ incubator/qpid/branches/M2.1/java/client/src/main/java/org/apache/qpid/client/AMQQueueBrowser.java
Thu Feb 21 07:28:43 2008
@@ -88,6 +88,7 @@
         checkState();
         final BasicMessageConsumer consumer =
             (BasicMessageConsumer) _session.createBrowserConsumer(_queue, _messageSelector,
false);
+        consumer.closeWhenNoMessages(true);
         _consumers.add(consumer);
 
         return new Enumeration()

Modified: incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/client/QueueBrowserTest.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/client/QueueBrowserTest.java?rev=629824&r1=629823&r2=629824&view=diff
==============================================================================
--- incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/client/QueueBrowserTest.java
(original)
+++ incubator/qpid/branches/M2.1/java/systests/src/main/java/org/apache/qpid/test/client/QueueBrowserTest.java
Thu Feb 21 07:28:43 2008
@@ -34,6 +34,8 @@
 import javax.jms.JMSException;
 import javax.jms.QueueReceiver;
 import javax.jms.Message;
+import javax.naming.NamingException;
+
 import java.util.Enumeration;
 
 import junit.framework.TestCase;
@@ -42,8 +44,6 @@
 {
     private static final Logger _logger = Logger.getLogger(QueueBrowserTest.class);
 
-    private static final int MSG_COUNT = 10;
-
     private Connection _clientConnection;
     private Session _clientSession;
     private Queue _queue;
@@ -64,6 +64,10 @@
 
         //Ensure _queue is created
         _clientSession.createConsumer(_queue).close();
+    }
+
+    private void sendMessages(int num) throws JMSException, NamingException
+    {
 
         //Create Producer put some messages on the queue
         Connection producerConnection = ((ConnectionFactory) _context.lookup("connection")).createConnection();
@@ -74,23 +78,17 @@
 
         MessageProducer producer = producerSession.createProducer(_queue);
 
-        for (int msg = 0; msg < MSG_COUNT; msg++)
+        for (int msg = 0; msg < num; msg++)
         {
             producer.send(producerSession.createTextMessage("Message " + msg));
         }
 
         producerConnection.close();
-
     }
 
-    /*
-    * Test Messages Remain on Queue
-    * Create a queu and send messages to it. Browse them and then receive them all to verify
they were still there
-    *
-    */
-
-    public void testQueueBrowserMsgsRemainOnQueue() throws JMSException
+    private void checkQueueDepth(int depth) throws JMSException, NamingException
     {
+        sendMessages(depth);
 
         // create QueueBrowser
         _logger.info("Creating Queue Browser");
@@ -100,7 +98,7 @@
         // check for messages
         if (_logger.isDebugEnabled())
         {
-            _logger.debug("Checking for " + MSG_COUNT + " messages with QueueBrowser");
+            _logger.debug("Checking for " + depth + " messages with QueueBrowser");
         }
 
         int msgCount = 0;
@@ -119,34 +117,54 @@
 
         // check to see if all messages found
 //        assertEquals("browser did not find all messages", MSG_COUNT, msgCount);
-        if (msgCount != MSG_COUNT)
+        if (msgCount != depth)
         {
-            _logger.warn(msgCount + "/" + MSG_COUNT + " messages received.");
+            _logger.warn(msgCount + " off" + depth + " messages received.");
         }
 
         //Close browser
         queueBrowser.close();
-
-        // VERIFY
-
-        // continue and try to receive all messages
-        MessageConsumer consumer = _clientSession.createConsumer(_queue);
-
-        _logger.info("Verify messages are still on the queue");
-
-        Message tempMsg;
-
-        for (msgCount = 0; msgCount < MSG_COUNT; msgCount++)
-        {
-            tempMsg = (TextMessage) consumer.receive(RECEIVE_TIMEOUT);
-            if (tempMsg == null)
-            {
-                fail("Message " + msgCount + " not retrieved from queue");
-            }
-        }
-
-        _logger.info("All messages recevied from queue");
     }
 
-
+    /*
+     * Test Messages Remain on Queue
+     * Create a queu and send messages to it. Browse them and then receive them all to verify
they were still there
+     *
+     */
+
+     public void testQueueBrowserMsgsRemainOnQueue() throws Exception
+     {
+         int messages = 10;
+
+         checkQueueDepth(messages);
+
+         // VERIFY
+
+         // continue and try to receive all messages
+         MessageConsumer consumer = _clientSession.createConsumer(_queue);
+
+         _logger.info("Verify messages are still on the queue");
+
+         Message tempMsg;
+
+         for (int msgCount = 0; msgCount < messages; msgCount++)
+         {
+             tempMsg = (TextMessage) consumer.receive(RECEIVE_TIMEOUT);
+             if (tempMsg == null)
+             {
+                 fail("Message " + msgCount + " not retrieved from queue");
+             }
+         }
+
+         _logger.info("All messages recevied from queue");
+     }
+
+     /**
+      * This tests you can browse an empty queue, see QPID-785
+      * @throws Exception
+      */
+     public void testBrowsingEmptyQueue() throws Exception
+     {
+         checkQueueDepth(0);
+     }
 }



Mime
View raw message