[Jboss-cvs] JBoss Messaging SVN: r1278 - branches/Branch_1_0/tests/src/org/jboss/test/messaging/jms

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Sep 11 20:33:58 EDT 2006


Author: ovidiu.feodorov at jboss.com
Date: 2006-09-11 20:33:57 -0400 (Mon, 11 Sep 2006)
New Revision: 1278

Modified:
   branches/Branch_1_0/tests/src/org/jboss/test/messaging/jms/MiscellaneousTest.java
Log:
added test that fails (testClosingConnectionFromMessageListener()) for http://jira.jboss.org/jira/browse/JBMESSAGING-542

Modified: branches/Branch_1_0/tests/src/org/jboss/test/messaging/jms/MiscellaneousTest.java
===================================================================
--- branches/Branch_1_0/tests/src/org/jboss/test/messaging/jms/MiscellaneousTest.java	2006-09-12 00:32:35 UTC (rev 1277)
+++ branches/Branch_1_0/tests/src/org/jboss/test/messaging/jms/MiscellaneousTest.java	2006-09-12 00:33:57 UTC (rev 1278)
@@ -29,6 +29,9 @@
 import javax.jms.Session;
 import javax.jms.TextMessage;
 import javax.jms.QueueBrowser;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageListener;
 import javax.naming.InitialContext;
 
 import org.jboss.test.messaging.MessagingTestCase;
@@ -37,7 +40,7 @@
 import java.util.Enumeration;
 
 /**
- * Various use cases, added here while trying things.
+ * Various use cases, added here while trying things or fixing forum issues.
  *
  * @author <a href="mailto:ovidiu at jboss.org">Ovidiu Feodorov</a>
  * @version <tt>$Revision$</tt>
@@ -90,6 +93,57 @@
       conn.close();
    }
 
+   /**
+    * Test case for http://jira.jboss.org/jira/browse/JBMESSAGING-542
+    */
+   public void testClosingConnectionFromMessageListener() throws Exception
+   {
+
+      ConnectionFactory cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
+      Queue queue = (Queue)ic.lookup("/queue/MiscellaneousQueue");
+
+      // load the queue
+
+      Connection c = cf.createConnection();
+      Session s = c.createSession(false, Session.AUTO_ACKNOWLEDGE);
+      MessageProducer prod = s.createProducer(queue);
+      Message m = s.createMessage();
+      prod.send(m);
+      c.close();
+
+      final Result result = new Result();
+      final Connection conn = cf.createConnection();
+      s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+      MessageConsumer cons = s.createConsumer(queue);
+      cons.setMessageListener(new MessageListener()
+      {
+         public void onMessage(Message m)
+         {
+            // close the connection on the same thread that processed the message
+            try
+            {
+               log.debug("attempting close");
+               conn.close();
+               log.debug("conn closed");
+               result.setSuccess();
+            }
+            catch(Exception e)
+            {
+               result.setFailure(e);
+            }
+         }
+      });
+
+      conn.start();
+
+      // wait for the message to propagate
+      Thread.sleep(3000);
+
+      assertTrue(result.isSuccess());
+      assertNull(result.getFailure());
+
+   }
+
    // Package protected ---------------------------------------------
 
    // Protected -----------------------------------------------------
@@ -122,4 +176,36 @@
 
    // Inner classes -------------------------------------------------
 
+   private class Result
+   {
+      private boolean success;
+      private Exception e;
+
+      public Result()
+      {
+         success = false;
+         e = null;
+      }
+
+      public synchronized void setSuccess()
+      {
+         success = true;
+      }
+
+      public synchronized boolean isSuccess()
+      {
+         return success;
+      }
+
+      public synchronized void setFailure(Exception e)
+      {
+         this.e = e;
+      }
+
+      public synchronized Exception getFailure()
+      {
+         return e;
+      }
+   }
+
 }




More information about the jboss-cvs-commits mailing list