[jboss-cvs] JBoss Messaging SVN: r2483 - trunk/tests/src/org/jboss/test/messaging/jms.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Feb 27 20:56:59 EST 2007


Author: clebert.suconic at jboss.com
Date: 2007-02-27 20:56:58 -0500 (Tue, 27 Feb 2007)
New Revision: 2483

Modified:
   trunk/tests/src/org/jboss/test/messaging/jms/QueueTest.java
Log:
http://jira.jboss.org/jira/browse/JBMESSAGING-899 - adding test

Modified: trunk/tests/src/org/jboss/test/messaging/jms/QueueTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/QueueTest.java	2007-02-28 01:22:47 UTC (rev 2482)
+++ trunk/tests/src/org/jboss/test/messaging/jms/QueueTest.java	2007-02-28 01:56:58 UTC (rev 2483)
@@ -31,6 +31,7 @@
 import javax.naming.InitialContext;
 
 import org.jboss.jms.client.JBossConnectionFactory;
+import org.jboss.jms.client.JBossConnection;
 import org.jboss.test.messaging.MessagingTestCase;
 import org.jboss.test.messaging.tools.ServerManagement;
 
@@ -117,6 +118,71 @@
       }
    }
 
+
+   public void testClosedConsumerBeforeStart() throws Exception
+   {
+      Queue queue = (Queue)ic.lookup("/queue/TestQueue");
+
+      // Maybe we could remove this counter after we are sure this test is fixed!
+      // I had to use a counter because this can work in some iterations.
+      for (int counter=0;counter<20;counter++)
+      {
+
+         log.info("Iteration = " + counter);
+
+         Connection conn1 = cf.createConnection();
+
+         assertEquals(0, ((JBossConnection)conn1).getServerID());
+
+         Connection conn2 = cf.createConnection();
+
+         assertEquals(0, ((JBossConnection)conn2).getServerID());
+
+         try
+         {
+            Session s = conn1.createSession(true, Session.AUTO_ACKNOWLEDGE);
+
+            MessageProducer p = s.createProducer(queue);
+
+            for (int i = 0; i < 20; i++)
+            {
+               p.send(s.createTextMessage("message " + i));
+            }
+
+            s.commit();
+
+            Session s2 = conn2.createSession(true, Session.AUTO_ACKNOWLEDGE);
+
+            // these next three lines are an anti-pattern but they shouldn't loose any messages
+            MessageConsumer c2 = s2.createConsumer(queue);
+            conn2.start();
+            c2.close();
+
+            c2 = s2.createConsumer(queue);
+
+            for (int i = 0; i < 20; i++)
+            {
+               TextMessage txt = (TextMessage)c2.receive(5000);
+               assertNotNull(txt);
+               assertEquals("message " + i, txt.getText());
+            }
+
+            assertNull(c2.receive(1000));
+         }
+         finally
+         {
+            if (conn1 != null)
+            {
+               conn1.close();
+            }
+            if (conn2 != null)
+            {
+               conn2.close();
+            }
+         }
+      }
+   }
+
    /**
     * The simplest possible queue test.
     */




More information about the jboss-cvs-commits mailing list