[jboss-cvs] JBossAS SVN: r57858 - in trunk/testsuite: . src/main/org/jboss/test/jbossmessaging src/main/org/jboss/test/jbossmessaging/test src/resources/jbossmessaging

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Oct 26 15:20:38 EDT 2006


Author: rachmatowicz at jboss.com
Date: 2006-10-26 15:20:36 -0400 (Thu, 26 Oct 2006)
New Revision: 57858

Added:
   trunk/testsuite/src/main/org/jboss/test/jbossmessaging/MockServerSessionPool.java
   trunk/testsuite/src/main/org/jboss/test/jbossmessaging/test/ConnectionConsumerUnitTestCase.java
   trunk/testsuite/src/main/org/jboss/test/jbossmessaging/test/DuplicateClientIDUnitTestCase.java
   trunk/testsuite/src/main/org/jboss/test/jbossmessaging/test/JBossJMSUnitTest.java
   trunk/testsuite/src/main/org/jboss/test/jbossmessaging/test/JBossSessionRecoverUnitTestCase.java
   trunk/testsuite/src/main/org/jboss/test/jbossmessaging/test/Jms11UnitTest.java
   trunk/testsuite/src/main/org/jboss/test/jbossmessaging/test/MessageBodyUnitTestCase.java
   trunk/testsuite/src/main/org/jboss/test/jbossmessaging/test/MessageTypesUnitTestCase.java
   trunk/testsuite/src/main/org/jboss/test/jbossmessaging/test/MessagingRefactoringUnitTestCase.java
   trunk/testsuite/src/main/org/jboss/test/jbossmessaging/test/RollBackUnitTestCase.java
   trunk/testsuite/src/main/org/jboss/test/jbossmessaging/test/SessionCloseStressTestCase.java
   trunk/testsuite/src/resources/jbossmessaging/test-destinations-service.xml
Modified:
   trunk/testsuite/build.xml
   trunk/testsuite/src/main/org/jboss/test/jbossmessaging/JMSTestCase.java
   trunk/testsuite/src/resources/jbossmessaging/provider.properties
Log:
A set of refactored generic JMS test cases

Modified: trunk/testsuite/build.xml
===================================================================
--- trunk/testsuite/build.xml	2006-10-26 19:15:55 UTC (rev 57857)
+++ trunk/testsuite/build.xml	2006-10-26 19:20:36 UTC (rev 57858)
@@ -855,7 +855,7 @@
       <antcall target="tests-compatibility"/>
       <antcall target="tests-webservice-ssl"/>
       <antcall target="tests-aop-scoped"/>
-      <antcall target="tests-jbossmessaging"/>
+      <!-- <antcall target="tests-jbossmessaging"/> -->
       <antcall target="tests-report"/>
       <record name="${basedir}/build.log" action="stop"/>
    </target>

Modified: trunk/testsuite/src/main/org/jboss/test/jbossmessaging/JMSTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/jbossmessaging/JMSTestCase.java	2006-10-26 19:15:55 UTC (rev 57857)
+++ trunk/testsuite/src/main/org/jboss/test/jbossmessaging/JMSTestCase.java	2006-10-26 19:20:36 UTC (rev 57858)
@@ -21,6 +21,11 @@
 */
 package org.jboss.test.jbossmessaging;
 
+import java.util.Properties; 
+import javax.naming.InitialContext;
+import javax.naming.NamingEnumeration;
+import javax.naming.NameClassPair;
+
 import org.objectweb.jtests.jms.admin.Admin;
 import org.objectweb.jtests.jms.admin.AdminFactory;
 
@@ -37,7 +42,8 @@
  */
 public class JMSTestCase extends JBossTestCase
 {
-    private Logger log = Logger.getLogger(JMSTestCase.class);
+    private static String PROP_FILE_NAME = "provider.properties" ;
+    private static String PROP_NAME = "jms.provider.resources.dir" ;
 
     protected Admin admin;
 
@@ -45,7 +51,7 @@
      * Constructor for JMSTestCase object
      * @param name test case name
      */
-    public JMSTestCase(String name) throws Exception
+    public JMSTestCase(String name) 
     {
 	super(name);
     }
@@ -54,7 +60,8 @@
      * Create the Admin object to perform all JMS adminsitrative functions
      * in a JMS provider-independent manner
      */
-    protected void setUp() {
+    protected void setUp() throws Exception 
+    {
     	try {
 	    log.info("setting up Admin") ;
 	    // get the Admin implementation for the current JMS provider
@@ -65,28 +72,67 @@
 	}
     }
 
-    public void createQueue(String name) {
+    /**
+     * Create a JMS Queue.
+     *
+     * The Queue is created dynamically, in a JMS provider-specific manner, 
+     * according to the instance of the Admin interface currently in use.
+     *
+     * @param name The name of the Queue to be created.
+     */
+    public void createQueue(String name) 
+    {
         try {
             admin.createQueue(name) ;
         } catch (Exception e) {
             e.printStackTrace() ;
         }
     }
-    public void deleteQueue(String name) {
+
+    /**
+     * Delete a JMS Queue.
+     *
+     * The Queue is deleted dynamically, in a JMS provider-specific manner,
+     * according to the instance of the Admin interface currently in use.
+     *
+     * @param name The name of the Queue to be deleted.
+     */
+    public void deleteQueue(String name) 
+    {
         try {
             admin.deleteQueue(name) ;
         } catch (Exception e) {
             e.printStackTrace() ;
         }
     }
-    public void createTopic(String name) {
+
+    /**
+     * Create a JMS Topic.
+     *
+     * The Topic is created dynamically, in a JMS provider-specific manner,
+     * according to the instance of the Admin interface currently in use.
+     *
+     * @param name The name of the Topic to be created.
+     */
+    public void createTopic(String name) 
+    {
         try {
             admin.createTopic(name) ;
         } catch (Exception e) {
             e.printStackTrace() ;
         }
     }
-    public void deleteTopic(String name) {
+
+    /**
+     * Delete a JMS Topic.
+     *
+     * The Topic is deleted dynamically, in a JMS provider-specific manner,
+     * according to the instance of the Admin interface currently in use.
+     *
+     * @param name The name of the Topic to be deleted.
+     */
+    public void deleteTopic(String name) 
+    {
         try {
             admin.deleteTopic(name) ;
         } catch (Exception e) {
@@ -94,7 +140,16 @@
         }
     }
 
-    public void createConnectionFactory(String name) {
+    /**
+     * Create a JMS ConnectionFactory.
+     *
+     * The ConnectionFactory is created dynamically, in a JMS provider-specific manner,
+     * according to the instance of the Admin interface currently in use.
+     *
+     * @param name The name of the ConnectionFactory to be created.
+     */
+    public void createConnectionFactory(String name) 
+    {
 	try {
 	    admin.createConnectionFactory(name) ; 
 	} catch (Exception e) {
@@ -102,7 +157,16 @@
 	}
     }
 
-    public void deleteConnectionFactory(String name) {
+    /**
+     * Delete a JMS ConnectionFactory.
+     *
+     * The ConnectionFactory is deleted dynamically, in a JMS provider-specific manner,
+     * according to the instance of the Admin interface currently in use.
+     *
+     * @param name The name of the ConnectionFactory to be deleted.
+     */
+    public void deleteConnectionFactory(String name) 
+    {
         try {
             admin.deleteConnectionFactory(name) ;
         } catch (Exception e) {
@@ -110,4 +174,58 @@
         }
     }
 
+    protected void dumpJNDIContext(String context)
+    {
+        try
+	    {
+		log.info("Dumping JNDI context:" + context) ;
+
+		// dump out the context name-value bindings
+		InitialContext ic = getInitialContext() ;
+		NamingEnumeration list = ic.list(context);
+
+		while (list.hasMore()) {
+		    NameClassPair nc = (NameClassPair)list.next();
+		    log.info(nc.toString());
+		}
+		log.info("Dumped JNDI context") ;
+	    } catch (Exception e) {
+		e.printStackTrace() ;
+	    }
+    }
+
+    /**
+     * Given a resource file name, prepend a directory qualifier to that name,
+     * according to the instance of the JMS provider currently in use. 
+     *
+     * The directory name prepended is determined by the value of the property 
+     * jms.provider.resources.dir in the provider.properties resources file. 
+     *
+     * @param name The name of the resources file.
+     */
+    public static String getJMSResourceRelativePathname(String name) 
+    {
+	String directoryName ;
+
+	// not our problem - let someone else handle it
+	if (name == null)
+	    return name ;
+
+        try {
+	    // get the JMS provider specific directory name
+            Properties props = new Properties() ;
+	    props.load(ClassLoader.getSystemResourceAsStream(PROP_FILE_NAME)) ;
+	    directoryName = props.getProperty(PROP_NAME) ;
+        } catch (Exception e) {
+            throw new NestedRuntimeException(e) ;
+        }
+
+	if (directoryName == null) {
+	    throw new NestedRuntimeException("Property " + PROP_NAME + " has not been found in the file "
+					     + PROP_FILE_NAME + ".") ;
+	}
+
+	// return the resource name with directory prepended
+	return (String) (directoryName + "/" + name) ;
+    }
 }

Added: trunk/testsuite/src/main/org/jboss/test/jbossmessaging/MockServerSessionPool.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/jbossmessaging/MockServerSessionPool.java	2006-10-26 19:15:55 UTC (rev 57857)
+++ trunk/testsuite/src/main/org/jboss/test/jbossmessaging/MockServerSessionPool.java	2006-10-26 19:20:36 UTC (rev 57858)
@@ -0,0 +1,50 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.jbossmessaging;
+
+import javax.jms.JMSException;
+import javax.jms.ServerSession;
+import javax.jms.ServerSessionPool;
+
+/**
+ * MockServerSessionPool.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 39152 $
+ */
+public class MockServerSessionPool implements ServerSessionPool
+{
+   /**
+    * Get a new instance of the mock
+    * 
+    * @return the instance
+    */
+   public static ServerSessionPool getServerSessionPool()
+   {
+      return new MockServerSessionPool();
+   }
+   
+   public ServerSession getServerSession() throws JMSException
+   {
+      throw new org.jboss.util.NotImplementedException("FIXME NYI getServerSession");
+   }
+}

Added: trunk/testsuite/src/main/org/jboss/test/jbossmessaging/test/ConnectionConsumerUnitTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/jbossmessaging/test/ConnectionConsumerUnitTestCase.java	2006-10-26 19:15:55 UTC (rev 57857)
+++ trunk/testsuite/src/main/org/jboss/test/jbossmessaging/test/ConnectionConsumerUnitTestCase.java	2006-10-26 19:20:36 UTC (rev 57858)
@@ -0,0 +1,151 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.jbossmessaging.test;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.JMSException;
+import javax.jms.Queue;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueSession;
+import javax.jms.Session;
+import javax.jms.Topic;
+import javax.jms.TopicConnection;
+import javax.jms.TopicConnectionFactory;
+import javax.jms.TopicSession;
+import javax.naming.InitialContext;
+
+import org.jboss.test.jbossmessaging.JMSTestCase;
+import org.jboss.test.jbossmessaging.MockServerSessionPool;
+
+/**
+ * ConnectionConsumerUnitTestCase.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 39152 $
+ */
+public class ConnectionConsumerUnitTestCase extends JMSTestCase
+{
+   /**
+    * Create a new ConnectionConsumerUnitTestCase.
+    * 
+    * @param name the test name
+    */
+   public ConnectionConsumerUnitTestCase(String name)
+   {
+      super(name);
+   }
+   
+   public void testConnectionConsumerWrongTemporaryDestination() throws Exception
+   {
+      InitialContext ctx = getInitialContext();
+      ConnectionFactory factory = (ConnectionFactory) ctx.lookup("ConnectionFactory");
+      Queue queue = null;
+      Connection connection = factory.createConnection();
+      try
+      {
+         Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         queue = s.createTemporaryQueue();
+         Connection connection2 = factory.createConnection();
+         try
+         {
+            connection2.createConnectionConsumer(queue, "", MockServerSessionPool.getServerSessionPool(), 1);
+            fail("Expected an error listening to a temporary destination from a different connection");
+         }
+         catch (JMSException expected)
+         {
+            log.debug("Got the expected jms exception", expected);
+         }
+         finally
+         {
+            connection2.close();
+         }
+      }
+      finally
+      {
+         connection.close();
+      }
+   }
+   
+   public void testQueueConnectionConsumerWrongTemporaryDestination() throws Exception
+   {
+      InitialContext ctx = getInitialContext();
+      QueueConnectionFactory factory = (QueueConnectionFactory) ctx.lookup("ConnectionFactory");
+      Queue queue = null;
+      QueueConnection connection = factory.createQueueConnection();
+      try
+      {
+         QueueSession s = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+         queue = s.createTemporaryQueue();
+         QueueConnection connection2 = factory.createQueueConnection();
+         try
+         {
+            connection2.createConnectionConsumer(queue, "", MockServerSessionPool.getServerSessionPool(), 1);
+            fail("Expected an error listening to a temporary destination from a different connection");
+         }
+         catch (JMSException expected)
+         {
+            log.debug("Got the expected jms exception", expected);
+         }
+         finally
+         {
+            connection2.close();
+         }
+      }
+      finally
+      {
+         connection.close();
+      }
+   }
+   
+   public void testTopicConnectionConsumerWrongTemporaryDestination() throws Exception
+   {
+      InitialContext ctx = getInitialContext();
+      TopicConnectionFactory factory = (TopicConnectionFactory) ctx.lookup("ConnectionFactory");
+      Topic topic = null;
+      TopicConnection connection = factory.createTopicConnection();
+      try
+      {
+         TopicSession s = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+         topic = s.createTemporaryTopic();
+         TopicConnection connection2 = factory.createTopicConnection();
+         try
+         {
+            connection2.createConnectionConsumer(topic, "", MockServerSessionPool.getServerSessionPool(), 1);
+            fail("Expected an error listening to a temporary destination from a different connection");
+         }
+         catch (JMSException expected)
+         {
+            log.debug("Got the expected jms exception", expected);
+         }
+         finally
+         {
+            connection2.close();
+         }
+      }
+      finally
+      {
+         connection.close();
+      }
+   }
+}

Added: trunk/testsuite/src/main/org/jboss/test/jbossmessaging/test/DuplicateClientIDUnitTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/jbossmessaging/test/DuplicateClientIDUnitTestCase.java	2006-10-26 19:15:55 UTC (rev 57857)
+++ trunk/testsuite/src/main/org/jboss/test/jbossmessaging/test/DuplicateClientIDUnitTestCase.java	2006-10-26 19:20:36 UTC (rev 57858)
@@ -0,0 +1,115 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.test.jbossmessaging.test;
+
+import javax.jms.InvalidClientIDException;
+import javax.jms.JMSException;
+import javax.jms.TopicConnection;
+import javax.jms.TopicConnectionFactory;
+import javax.naming.Context;
+
+import org.jboss.test.jbossmessaging.JMSTestCase;
+
+/**
+ * Duplciate client id tests
+ *
+ * @author <a href="mailto:richard.achmatowicz at jboss.org>Richard Achmatowicz</a>
+ * @author <a href="mailto:adrian at jboss.org>Adrian Brock</a>
+ * @version <tt>$Revision: 37406 $</tt>
+ */
+public class DuplicateClientIDUnitTestCase extends JMSTestCase
+{
+   static String TOPIC_FACTORY = "ConnectionFactory";
+   
+   public DuplicateClientIDUnitTestCase(String name) throws Exception
+   {
+      super(name);
+   }
+
+   public void testDuplicateClientID() throws Exception
+   {
+      TopicConnection c1 = getTopicConnectionFactory().createTopicConnection();
+      try
+      {
+         c1.setClientID("testClientID");
+         TopicConnection c2 = getTopicConnectionFactory().createTopicConnection();
+         try
+         {
+            c2.setClientID("testClientID");
+            fail("Should not be here - duplicate client id");
+         }
+         catch (InvalidClientIDException expected)
+         {
+         }
+         finally
+         {
+            c2.close();
+         }
+      }
+      finally
+      {
+         c1.close();
+      }
+   }
+
+   public void testPreconfiguredDuplicateClientID() throws Exception
+   {
+      TopicConnection c1 = getTopicConnectionFactory().createTopicConnection("john", "needle");
+      try
+      {
+         try
+         {
+            TopicConnection c2 = getTopicConnectionFactory().createTopicConnection("john", "needle");
+            c2.close();
+            fail("Should not be here - duplicate client id");
+         }
+         catch (JMSException expected)
+         {
+         }
+      }
+      finally
+      {
+         c1.close();
+      }
+   }
+
+   public void testNotDuplicateClientID() throws Exception
+   {
+      TopicConnection c1 = getTopicConnectionFactory().createTopicConnection();
+      try
+      {
+         TopicConnection c2 = getTopicConnectionFactory().createTopicConnection();
+         c2.close();
+      }
+      finally
+      {
+         c1.close();
+      }
+   }
+
+   protected TopicConnectionFactory getTopicConnectionFactory() throws Exception
+   {
+      Context context = getInitialContext();
+      return (TopicConnectionFactory) context.lookup(TOPIC_FACTORY);
+   }
+}
+

Added: trunk/testsuite/src/main/org/jboss/test/jbossmessaging/test/JBossJMSUnitTest.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/jbossmessaging/test/JBossJMSUnitTest.java	2006-10-26 19:15:55 UTC (rev 57857)
+++ trunk/testsuite/src/main/org/jboss/test/jbossmessaging/test/JBossJMSUnitTest.java	2006-10-26 19:20:36 UTC (rev 57858)
@@ -0,0 +1,1340 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.test.jbossmessaging.test;
+
+import java.util.Enumeration;
+
+import javax.jms.DeliveryMode;
+import javax.jms.InvalidDestinationException;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.Queue;
+import javax.jms.QueueBrowser;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueReceiver;
+import javax.jms.QueueRequestor;
+import javax.jms.QueueSender;
+import javax.jms.QueueSession;
+import javax.jms.ServerSession;
+import javax.jms.ServerSessionPool;
+import javax.jms.Session;
+import javax.jms.TemporaryQueue;
+import javax.jms.TemporaryTopic;
+import javax.jms.TextMessage;
+import javax.jms.Topic;
+import javax.jms.TopicConnection;
+import javax.jms.TopicConnectionFactory;
+import javax.jms.TopicPublisher;
+import javax.jms.TopicSession;
+import javax.jms.TopicSubscriber;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import org.apache.log4j.Category;
+import org.jboss.test.jbossmessaging.JMSTestCase;
+
+import EDU.oswego.cs.dl.util.concurrent.CountDown;
+
+/**
+ * Basic jms tests.
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: 37406 $
+ */
+public class JBossJMSUnitTest extends JMSTestCase
+{
+   /** The default TopicFactory jndi name */
+   static String TOPIC_FACTORY = "ConnectionFactory";
+   /** The default QueueFactory jndi name */
+   static String QUEUE_FACTORY = "ConnectionFactory";
+
+   static String TEST_QUEUE = "queue/testQueue";
+   static String TEST_TOPIC = "topic/testTopic";
+   static String TEST_DURABLE_TOPIC = "topic/testDurableTopic";
+
+   //JMSProviderAdapter providerAdapter;
+   static Context context;
+   static QueueConnection queueConnection;
+   static TopicConnection topicConnection;
+
+   public JBossJMSUnitTest(String name) throws Exception
+   {
+      super(name);
+   }
+
+   // Emptys out all the messages in a queue
+   protected void drainQueue() throws Exception
+   {
+      QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+      Queue queue = (Queue) context.lookup(TEST_QUEUE);
+
+      QueueReceiver receiver = session.createReceiver(queue);
+      Message message = receiver.receive(50);
+      int c = 0;
+      while (message != null)
+      {
+         message = receiver.receive(50);
+         c++;
+      }
+
+      if (c != 0)
+         getLog().debug("  Drained " + c + " messages from the queue");
+
+      session.close();
+   }
+
+   protected void connect() throws Exception
+   {
+
+      if (context == null)
+      {
+
+         context = new InitialContext();
+
+      }
+      QueueConnectionFactory queueFactory = (QueueConnectionFactory) context.lookup(QUEUE_FACTORY);
+      queueConnection = queueFactory.createQueueConnection();
+
+      TopicConnectionFactory topicFactory = (TopicConnectionFactory) context.lookup(TOPIC_FACTORY);
+      topicConnection = topicFactory.createTopicConnection();
+
+      getLog().debug("Connection to spyderMQ established.");
+
+   }
+
+   protected void disconnect() throws Exception
+   {
+      queueConnection.close();
+      topicConnection.close();
+   }
+
+   /**
+    * Test that messages are ordered by message arrival and priority.
+    * This also tests :
+    * 		Using a non-transacted AUTO_ACKNOWLEDGE session
+    *		Using a QueueReceiver
+    *		Using a QueueSender
+    *			Sending PERSITENT and NON_PERSISTENT text messages.
+    *		Using a QueueBrowser
+    */
+   public void testQueueMessageOrder() throws Exception
+   {
+
+      getLog().debug("Starting QueueMessageOrder test");
+
+      connect();
+
+      queueConnection.start();
+
+      drainQueue();
+
+      QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+      Queue queue = (Queue) context.lookup(TEST_QUEUE);
+      QueueSender sender = session.createSender(queue);
+
+      TextMessage message = session.createTextMessage();
+      message.setText("Normal message");
+      sender.send(message, DeliveryMode.NON_PERSISTENT, 4, 0);
+      //sender.send(queue, message, DeliveryMode.NON_PERSISTENT, 4, 0);
+      message.setText("Persistent message");
+      sender.send(message, DeliveryMode.PERSISTENT, 4, 0);
+      //sender.send(queue, message, DeliveryMode.PERSISTENT, 4, 0);
+      message.setText("High Priority Persistent message");
+      sender.send(message, DeliveryMode.PERSISTENT, 10, 0);
+      //sender.send(queue, message, DeliveryMode.PERSISTENT, 10, 0);
+
+      //message.setText("Expiring Persistent message");
+      //sender.send(queue, message, DeliveryMode.NON_PERSISTENT, 4, 1);
+
+      QueueBrowser browser = session.createBrowser(queue);
+      Enumeration i = browser.getEnumeration();
+      //message = (TextMessage)enum.nextElement();
+      //if( !message.getText().equals("High Priority Persistent message") )
+      //	throw new Exception("Queue is not prioritizing messages correctly. Unexpected Message:"+message);
+      getLog().debug(message.getText());
+
+      message = (TextMessage) i.nextElement();
+      //if( !message.getText().equals("Normal message") )
+      //	throw new Exception("Queue is not ordering messages correctly. Unexpected Message:"+message);
+      getLog().debug(message.getText());
+
+      message = (TextMessage) i.nextElement();
+      //if( !message.getText().equals("Persistent message") )
+      //	throw new Exception("Queue is not ordering messages correctly. Unexpected Message:"+message);
+      getLog().debug(message.getText());
+
+      // if( enum.hasMoreElements() )
+      //	throw new Exception("Queue does not expire messages correctly. Unexpected Message:"+enum.nextElement());
+
+      disconnect();
+      getLog().debug("QueueMessageOrder passed");
+   }
+
+   /**
+    * Test that a using QueueRequestor works.
+    * this also tests that :
+    *		temporary queues work.
+    */
+   public void testRequestReplyQueue() throws Exception
+   {
+
+      getLog().debug("Starting RequestReplyQueue test");
+      connect();
+
+      {
+         queueConnection.start();
+         drainQueue();
+      }
+
+      Thread serverThread = new Thread()
+      {
+         public void run()
+         {
+            Category log = Category.getInstance(getClass().getName());
+            try
+            {
+               log.debug("Server Thread Started");
+               QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+               Queue queue = (Queue) context.lookup(TEST_QUEUE);
+
+               QueueReceiver queueReceiver = session.createReceiver(queue);
+
+               boolean done = false;
+               while (!done)
+               {
+                  TextMessage message = (TextMessage) queueReceiver.receive();
+                  Queue tempQueue = (Queue) message.getJMSReplyTo();
+
+                  QueueSender replySender = session.createSender(tempQueue);
+                  TextMessage reply = session.createTextMessage();
+                  reply.setText("Request Processed");
+                  reply.setJMSCorrelationID(message.getJMSMessageID());
+                  replySender.send(reply);
+
+                  if (message.getText().equals("Quit"))
+                     done = true;
+               }
+
+               session.close();
+               log.debug("Server Thread Finished");
+
+            }
+            catch (Exception e)
+            {
+               log.error("Error", e);
+            }
+         }
+      };
+
+      serverThread.start();
+
+      QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+      Queue queue = (Queue) context.lookup(TEST_QUEUE);
+
+      QueueRequestor queueRequestor = new QueueRequestor(session, queue);
+      TextMessage message = session.createTextMessage();
+      message.setText("Request Test");
+
+      for (int i = 0; i < 5; i++)
+      {
+
+         getLog().debug("Making client request #" + i);
+         TextMessage reply = (TextMessage) queueRequestor.request(message);
+         String replyID = new String(reply.getJMSCorrelationID());
+         if (!replyID.equals(message.getJMSMessageID()))
+            throw new Exception("REQUEST: ERROR: Reply does not match sent message");
+
+      }
+
+      getLog().debug("Making client request to shut server down.");
+      message.setText("Quit");
+      queueRequestor.request(message);
+
+      serverThread.join();
+      disconnect();
+
+      getLog().debug("RequestReplyQueue passed");
+   }
+
+   /**
+    * Test that temporary queues can be deleted.
+    */
+   public void testTemporaryQueueDelete() throws Exception
+   {
+
+      getLog().debug("Starting TemporaryQueueDelete test");
+      connect();
+
+      QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+      TemporaryQueue queue = session.createTemporaryQueue();
+
+      queue.delete();
+
+      disconnect();
+
+      getLog().debug("TemporaryQueueDelete passed");
+   }
+
+   /**
+    * Test that temporary topics can be deleted.
+    */
+   public void testTemporaryTopicDelete() throws Exception
+   {
+
+      getLog().debug("Starting TemporaryTopicDelete test");
+      connect();
+
+      TopicSession session = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+      TemporaryTopic topic = session.createTemporaryTopic();
+
+      topic.delete();
+
+      disconnect();
+
+      getLog().debug("TemporaryTopicDelete passed");
+   }
+
+   /**
+    * Test invalid destination trying to send a message.
+    */
+   public void testInvalidDestinationQueueSend() throws Exception
+   {
+
+      getLog().debug("Starting InvaidDestinationQueueSend test");
+      connect();
+
+      QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+      TemporaryQueue queue = session.createTemporaryQueue();
+      QueueSender sender = session.createSender(queue);
+      queue.delete();
+
+      TextMessage message = session.createTextMessage("hello");
+      boolean caught = false;
+      try
+      {
+         sender.send(message);
+      }
+      catch (InvalidDestinationException expected)
+      {
+         caught = true;
+      }
+
+      disconnect();
+
+      assertTrue("Expected an InvalidDestinationException", caught);
+
+      getLog().debug("InvaldDestinationQueueSend passed");
+   }
+
+   /**
+    * Test invalid destination trying to browse a message.
+    */
+   public void testInvalidDestinationQueueBrowse() throws Exception
+   {
+
+      getLog().debug("Starting InvalidDestinationQueueBrowse test");
+      connect();
+
+      QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+      TemporaryQueue queue = session.createTemporaryQueue();
+      QueueBrowser browser = session.createBrowser(queue);
+      queue.delete();
+
+      boolean caught = false;
+      try
+      {
+         browser.getEnumeration();
+      }
+      catch (InvalidDestinationException expected)
+      {
+         caught = true;
+      }
+
+      disconnect();
+
+      assertTrue("Expected an InvalidDestinationException", caught);
+
+      getLog().debug("InvalidDestinationQueueBrowse passed");
+   }
+
+   /**
+    * Test invalid destination trying to send a message.
+    */
+   public void testInvalidDestinationTopicPublish() throws Exception
+   {
+
+      getLog().debug("Starting InvaidDestinationTopicPublish test");
+      connect();
+
+      TopicSession session = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+      TemporaryTopic topic = session.createTemporaryTopic();
+      TopicPublisher publisher = session.createPublisher(topic);
+      topic.delete();
+
+      TextMessage message = session.createTextMessage("hello");
+      boolean caught = false;
+      try
+      {
+         publisher.publish(message);
+      }
+      catch (InvalidDestinationException expected)
+      {
+         caught = true;
+      }
+
+      disconnect();
+
+      assertTrue("Expected an InvalidDestinationException", caught);
+
+      getLog().debug("InvaldDestinationTopicPublish passed");
+   }
+
+   /**
+    * Test errors trying on topic subscribe.
+    */
+   public void testErrorsTopicSubscribe() throws Exception
+   {
+
+      getLog().debug("Starting InvalidDestinationTopicSubscribe test");
+      connect();
+
+      try
+      {
+         TopicSession session = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+         Topic topic = (Topic) context.lookup(TEST_TOPIC);
+         TemporaryTopic temp = session.createTemporaryTopic();
+
+         boolean caught = false;
+         try
+         {
+            session.createSubscriber(null);
+         }
+         catch (InvalidDestinationException expected)
+         {
+            caught = true;
+         }
+         assertTrue("Expected an InvalidDestinationException for a null topic", caught);
+
+         caught = false;
+         try
+         {
+            session.createSubscriber(null, null, true);
+         }
+         catch (InvalidDestinationException expected)
+         {
+            caught = true;
+         }
+         assertTrue("Expected an InvalidDestinationException for a null topic", caught);
+
+         caught = false;
+         try
+         {
+            session.createDurableSubscriber(null, "NotUsed");
+         }
+         catch (InvalidDestinationException expected)
+         {
+            caught = true;
+         }
+         assertTrue("Expected an InvalidDestinationException for a null topic", caught);
+
+         caught = false;
+         try
+         {
+            session.createDurableSubscriber(temp, "NotUsed");
+         }
+         catch (InvalidDestinationException expected)
+         {
+            caught = true;
+         }
+         assertTrue("Expected an InvalidDestinationException for a temporary topic", caught);
+
+         caught = false;
+         try
+         {
+            session.createDurableSubscriber(null, "NotUsed", null, true);
+         }
+         catch (InvalidDestinationException expected)
+         {
+            caught = true;
+         }
+         assertTrue("Expected an InvalidDestinationException for a null topic", caught);
+
+         caught = false;
+         try
+         {
+            session.createDurableSubscriber(temp, "NotUsed", null, true);
+         }
+         catch (InvalidDestinationException expected)
+         {
+            caught = true;
+         }
+         assertTrue("Expected an InvalidDestinationException for a temporary topic", caught);
+
+         caught = false;
+         try
+         {
+            session.createDurableSubscriber(topic, null);
+         }
+         catch (Exception expected)
+         {
+            caught = true;
+         }
+         assertTrue("Expected a Exception for a null subscription", caught);
+
+         caught = false;
+         try
+         {
+            session.createDurableSubscriber(topic, null, null, false);
+         }
+         catch (Exception expected)
+         {
+            caught = true;
+         }
+         assertTrue("Expected a Exception for a null subscription", caught);
+
+         caught = false;
+         try
+         {
+            session.createDurableSubscriber(topic, "  ");
+         }
+         catch (Exception expected)
+         {
+            caught = true;
+         }
+         assertTrue("Expected a Exception for an empty subscription", caught);
+
+         caught = false;
+         try
+         {
+            session.createDurableSubscriber(topic, "  ", null, false);
+         }
+         catch (Exception expected)
+         {
+            caught = true;
+         }
+         assertTrue("Expected a Exception for an empty subscription", caught);
+      }
+      finally
+      {
+         disconnect();
+      }
+
+      getLog().debug("InvalidDestinationTopicSubscriber passed");
+   }
+
+   /**
+    * Test create queue.
+    */
+   public void testCreateQueue() throws Exception
+   {
+
+      getLog().debug("Starting create queue test");
+      connect();
+
+      QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+
+      Queue jndiQueue = (Queue) getInitialContext().lookup("queue/testQueue");
+      Queue createQueue = session.createQueue(jndiQueue.getQueueName());
+      assertTrue("Failed for " + QUEUE_FACTORY, jndiQueue.equals(createQueue));
+
+      getLog().debug("InvalidDestinationTopicSubscriber passed");
+   }
+
+   public void testMessageListener() throws Exception
+   {
+      getLog().debug("Starting create queue test");
+
+      connect();
+      queueConnection.start();
+      drainQueue();
+      final CountDown counter1 = new CountDown(3);
+
+      QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+      Queue queue = (Queue) context.lookup(TEST_QUEUE);
+
+      QueueReceiver receiver = session.createReceiver(queue);
+      receiver.setMessageListener(new MessageListener()
+      {
+         public void onMessage(Message msg)
+         {
+            Category log = Category.getInstance(getClass().getName());
+            log.debug("ML");
+            try
+            {
+               if (msg instanceof TextMessage)
+               {
+                  log.debug(((TextMessage) msg).getText());
+                  counter1.release();
+               }
+            }
+            catch (Exception e)
+            {
+            }
+         }
+      });
+
+      QueueSender sender = session.createSender(queue);
+
+      TextMessage message = session.createTextMessage();
+      message.setText("Normal message");
+      sender.send(message, DeliveryMode.NON_PERSISTENT, 4, 0);
+      //sender.send(queue, message, DeliveryMode.NON_PERSISTENT, 4, 0);
+      message.setText("Persistent message");
+      sender.send(message, DeliveryMode.PERSISTENT, 4, 0);
+      //sender.send(queue, message, DeliveryMode.PERSISTENT, 4, 0);
+      message.setText("High Priority Persistent message");
+      sender.send(message, DeliveryMode.PERSISTENT, 10, 0);
+      //sender.send(queue, message, DeliveryMode.PERSISTENT, 10, 0);
+
+      // Wait for the msgs to be received
+      counter1.acquire();
+      log.debug("MessageListener1 received the TMs sent");
+
+      final CountDown counter2 = new CountDown(2);
+      receiver.setMessageListener(new MessageListener()
+      {
+         public void onMessage(Message msg)
+         {
+            Category log = Category.getInstance(getClass().getName());
+            log.debug("ML 2");
+            try
+            {
+               if (msg instanceof TextMessage)
+               {
+                  log.debug(((TextMessage) msg).getText());
+                  counter2.release();
+               }
+            }
+            catch (Exception e)
+            {
+            }
+         }
+      });
+
+      message.setText("Persistent message");
+      sender.send(message, DeliveryMode.PERSISTENT, 4, 0);
+      //sender.send(queue, message, DeliveryMode.PERSISTENT, 4, 0);
+      message.setText("High Priority Persistent message");
+      sender.send(message, DeliveryMode.PERSISTENT, 10, 0);
+      //sender.send(queue, message, DeliveryMode.PERSISTENT, 10, 0);
+
+      // Wait for the msgs to be received
+      counter2.acquire();
+      log.debug("MessageListener2 received the TMs sent");
+
+      receiver.setMessageListener(null);
+
+      message.setText("Persistent message");
+      sender.send(message, DeliveryMode.PERSISTENT, 4, 0);
+      //sender.send(queue, message, DeliveryMode.PERSISTENT, 4, 0);
+      message.setText("High Priority Persistent message");
+      sender.send(message, DeliveryMode.PERSISTENT, 10, 0);
+      //sender.send(queue, message, DeliveryMode.PERSISTENT, 10, 0);
+
+      sender.close();
+      drainQueue();
+      disconnect();
+      getLog().debug("MessageListener test passed");
+   }
+
+   public void testApplicationServerStuff() throws Exception
+   {
+      getLog().debug("Starting testing app server stuff");
+      connect();
+
+      Queue testQueue = (Queue) context.lookup(TEST_QUEUE);
+      final QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+
+      session.setMessageListener(new MessageListener()
+      {
+         public void onMessage(Message mess)
+         {
+            Category log = Category.getInstance(getClass().getName());
+            log.debug("Processing message");
+            try
+            {
+               if (mess instanceof TextMessage)
+                  log.debug(((TextMessage) mess).getText());
+            }
+            catch (Exception e)
+            {
+               log.error("Error", e);
+            }
+         }
+      });
+
+      QueueSender sender = session.createSender(testQueue);
+      sender.send(session.createTextMessage("Hi"));
+      sender.send(session.createTextMessage("There"));
+      sender.send(session.createTextMessage("Guys"));
+      queueConnection.createConnectionConsumer(testQueue, null, new ServerSessionPool()
+      {
+         public ServerSession getServerSession()
+         {
+            Category.getInstance(getClass().getName()).debug("Getting server session.");
+            return new ServerSession()
+            {
+               public Session getSession()
+               {
+                  return session;
+               }
+               public void start()
+               {
+                  Category.getInstance(getClass().getName()).debug("Starting server session.");
+                  session.run();
+               }
+            };
+         }
+      }, 10);
+
+      queueConnection.start();
+
+      try
+      {
+         Thread.sleep(5 * 1000);
+      }
+      catch (Exception e)
+      {
+      }
+
+      disconnect();
+      getLog().debug("Testing app server stuff passed");
+   }
+
+   //simply put a few messages on the test queue for next time.
+   /*   public void testPM() throws Exception
+      {
+         getLog().debug("Starting testing pm");
+         connect();
+         
+         Queue testQueue = (Queue)context.lookup(TEST_QUEUE);
+         QueueSession session = queueConnection.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);
+         QueueSender sender = session.createSender(testQueue);
+         sender.send(session.createTextMessage("From last time"));
+         sender.send(session.createTextMessage("From last time"));
+         sender.send(session.createTextMessage("From last time"));
+         sender.close();
+         session.close();
+         disconnect();
+         getLog().debug("Testing pm stuff passed");
+      }
+   */
+   private void drainMessagesForTopic(TopicSubscriber sub) throws JMSException
+   {
+      Message msg = sub.receive(50);
+      int c = 0;
+      while (msg != null)
+      {
+         c++;
+         if (msg instanceof TextMessage)
+            getLog().debug(((TextMessage) msg).getText());
+         msg = sub.receive(50);
+      }
+      getLog().debug("Received " + c + " messages from topic.");
+   }
+
+   public void testTopics() throws Exception
+   {
+      getLog().debug("Starting Topic test");
+      connect();
+
+      TopicConnectionFactory topicFactory = (TopicConnectionFactory) context.lookup(TOPIC_FACTORY);
+      topicConnection = topicFactory.createTopicConnection("john", "needle");
+
+      topicConnection.start();
+
+      //set up some subscribers to the topic
+      TopicSession session = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+      Topic topic = (Topic) context.lookup(TEST_TOPIC);
+
+      TopicSubscriber sub1 = session.createDurableSubscriber(topic, "sub1");
+      TopicSubscriber sub2 = session.createSubscriber(topic);
+      TopicSubscriber sub3 = session.createSubscriber(topic);
+
+      //Now a sender
+      TopicPublisher sender = session.createPublisher(topic);
+
+      //send some messages
+      sender.publish(session.createTextMessage("Message 1"));
+      sender.publish(session.createTextMessage("Message 2"));
+      sender.publish(session.createTextMessage("Message 3"));
+      drainMessagesForTopic(sub1);
+      drainMessagesForTopic(sub2);
+      drainMessagesForTopic(sub3);
+
+      //close some subscribers
+      sub1.close();
+      sub2.close();
+
+      //send some more messages
+      sender.publish(session.createTextMessage("Message 4"));
+      sender.publish(session.createTextMessage("Message 5"));
+      sender.publish(session.createTextMessage("Message 6"));
+
+      //give time for message 4 to be negatively acked (as it will be cause last receive timed out)
+      try
+      {
+         Thread.sleep(5 * 1000);
+      }
+      catch (InterruptedException e)
+      {
+      }
+
+      drainMessagesForTopic(sub3);
+
+      //open subscribers again.
+      sub1 = session.createDurableSubscriber(topic, "sub1");
+      sub2 = session.createSubscriber(topic);
+
+      //Send a final message
+      sender.publish(session.createTextMessage("Final message"));
+      sender.close();
+
+      drainMessagesForTopic(sub1);
+      drainMessagesForTopic(sub2);
+      drainMessagesForTopic(sub3);
+
+      sub1.close();
+      sub2.close();
+      sub3.close();
+
+      session.unsubscribe("sub1");
+
+      topicConnection.stop();
+      topicConnection.close();
+
+      disconnect();
+      getLog().debug("Topic test passed");
+   }
+
+   /**
+    * Test to seeif the NoLocal feature of topics works.
+    * Messages published from the same connection should not
+    * be received by Subscribers on the same connection.
+    */
+   public void testTopicNoLocal() throws Exception
+   {
+      getLog().debug("Starting TopicNoLocal test");
+      connect();
+
+      TopicConnectionFactory topicFactory = (TopicConnectionFactory) context.lookup(TOPIC_FACTORY);
+      TopicConnection topicConnection1 = topicFactory.createTopicConnection();
+      topicConnection1.start();
+      TopicConnection topicConnection2 = topicFactory.createTopicConnection();
+      topicConnection2.start();
+
+      // We don't want local messages on this topic.
+      TopicSession session1 = topicConnection1.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+      Topic topic = (Topic) context.lookup(TEST_TOPIC);
+      TopicSubscriber subscriber1 = session1.createSubscriber(topic, null, true);
+      TopicPublisher sender1 = session1.createPublisher(topic);
+
+      //Now a sender
+      TopicSession session2 = topicConnection2.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+      TopicPublisher sender2 = session2.createPublisher(topic);
+
+      drainMessagesForTopic(subscriber1);
+
+      //send some messages
+      sender1.publish(session1.createTextMessage("Local Message"));
+      sender2.publish(session2.createTextMessage("Remote Message"));
+
+      // Get the messages, we should get the remote message
+      // but not the local message
+      TextMessage msg1 = (TextMessage) subscriber1.receive(2000);
+      if (msg1 == null)
+      {
+         fail("Did not get any messages");
+      }
+      else
+      {
+         getLog().debug("Got message: " + msg1);
+         if (msg1.getText().equals("Local Message"))
+         {
+            fail("Got a local message");
+         }
+         TextMessage msg2 = (TextMessage) subscriber1.receive(2000);
+         if (msg2 != null)
+         {
+            getLog().debug("Got message: " + msg2);
+            fail("Got an extra message.  msg1:" + msg1 + ", msg2:" + msg2);
+         }
+      }
+
+      topicConnection1.stop();
+      topicConnection1.close();
+      topicConnection2.stop();
+      topicConnection2.close();
+
+      disconnect();
+      getLog().debug("TopicNoLocal test passed");
+   }
+
+   /**
+    * Test to see whether no local works if a message
+    * was created somewhere else.
+    */
+   public void testTopicNoLocalBounce() throws Exception
+   {
+      getLog().debug("Starting TopicNoLocalBounce test");
+      connect();
+
+      TopicConnectionFactory topicFactory = (TopicConnectionFactory) context.lookup(TOPIC_FACTORY);
+      TopicConnection topicConnection1 = topicFactory.createTopicConnection();
+      topicConnection1.start();
+      TopicConnection topicConnection2 = topicFactory.createTopicConnection();
+      topicConnection2.start();
+
+      // Session 1
+      TopicSession session1 = topicConnection1.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+      Topic topic = (Topic) context.lookup(TEST_TOPIC);
+      TopicSubscriber subscriber1 = session1.createSubscriber(topic, null, true);
+      TopicPublisher sender1 = session1.createPublisher(topic);
+
+      // Session 2
+      TopicSession session2 = topicConnection2.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+      TopicSubscriber subscriber2 = session2.createSubscriber(topic, null, true);
+      TopicPublisher sender2 = session2.createPublisher(topic);
+
+      drainMessagesForTopic(subscriber1);
+      drainMessagesForTopic(subscriber2);
+
+      //send the message
+      sender1.publish(session1.createTextMessage("Message"));
+
+      assertTrue("Subscriber1 should not get a message", subscriber1.receiveNoWait() == null);
+      TextMessage msg = (TextMessage) subscriber2.receive(2000);
+      assertTrue("Subscriber2 should get a message, got " + msg, msg != null && msg.getText().equals("Message"));
+
+      //send it back
+      sender2.publish(msg);
+
+      msg = (TextMessage) subscriber1.receive(2000);
+      assertTrue("Subscriber1 should get a message, got " + msg, msg != null && msg.getText().equals("Message"));
+      assertTrue("Subscriber2 should not get a message", subscriber2.receiveNoWait() == null);
+
+      topicConnection1.stop();
+      topicConnection1.close();
+      topicConnection2.stop();
+      topicConnection2.close();
+
+      disconnect();
+      getLog().debug("TopicNoLocalBounce test passed");
+   }
+
+   /**
+    * Test subscribing to a topic with one selector, then changing to another
+    */
+   public void testTopicSelectorChange() throws Exception
+   {
+      getLog().debug("Starting TopicSelectorChange test");
+
+      getLog().debug("Create topic connection");
+      TopicConnectionFactory topicFactory = (TopicConnectionFactory) context.lookup(TOPIC_FACTORY);
+      topicConnection = topicFactory.createTopicConnection("john", "needle");
+      topicConnection.start();
+
+      try
+      {
+         getLog().debug("Retrieving Topic");
+         Topic topic = (Topic) context.lookup(TEST_DURABLE_TOPIC);
+
+         getLog().debug("Creating a send session");
+         TopicSession sendSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+         TopicPublisher sender = sendSession.createPublisher(topic);
+
+         getLog().debug("Clearing the topic");
+         TopicSession subSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+         TopicSubscriber subscriber = subSession.createDurableSubscriber(topic, "test");
+         Message message = subscriber.receive(50);
+         while (message != null)
+            message = subscriber.receive(50);
+         subSession.close();
+
+         getLog().debug("Subscribing to topic, looking for Value = 'A'");
+         subSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+         subscriber = subSession.createDurableSubscriber(topic, "test", "Value = 'A'", false);
+
+         getLog().debug("Send some messages");
+         message = sendSession.createTextMessage("Message1");
+         message.setStringProperty("Value", "A");
+         sender.publish(message);
+         message = sendSession.createTextMessage("Message2");
+         message.setStringProperty("Value", "A");
+         sender.publish(message);
+         message = sendSession.createTextMessage("Message3");
+         message.setStringProperty("Value", "B");
+         sender.publish(message);
+
+         getLog().debug("Retrieving the A messages");
+         message = subscriber.receive(2000);
+         assertTrue("Expected message 1", message != null);
+         assertTrue("Should get an A", message.getStringProperty("Value").equals("A"));
+         message = subscriber.receive(2000);
+         assertTrue("Expected message 2", message != null);
+         assertTrue("Should get a second A", message.getStringProperty("Value").equals("A"));
+         assertTrue("That should be it for A", subscriber.receive(2000) == null);
+
+         getLog().debug("Closing the subscriber without acknowledgement");
+         subSession.close();
+
+         getLog().debug("Subscribing to topic, looking for Value = 'B'");
+         subSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+         subscriber = subSession.createDurableSubscriber(topic, "test", "Value = 'B'", false);
+
+         getLog().debug("Retrieving the non-existent B messages");
+         assertTrue("B should not be there", subscriber.receive(2000) == null);
+
+         getLog().debug("Closing the subscriber.");
+         subSession.close();
+
+         getLog().debug("Subscribing to topic, looking for those Value = 'A'");
+         subSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+         subscriber = subSession.createDurableSubscriber(topic, "test", "Value = 'A'", false);
+         assertTrue("Should not be any A the subscription was changed", subscriber.receive(2000) == null);
+         subSession.close();
+
+         getLog().debug("Subscribing to topic, looking for everything");
+         subSession = topicConnection.createTopicSession(false, Session.CLIENT_ACKNOWLEDGE);
+         subscriber = subSession.createDurableSubscriber(topic, "test", null, false);
+
+         message = sendSession.createTextMessage("Message4");
+         message.setStringProperty("Value", "A");
+         sender.publish(message);
+
+         message = subscriber.receive(2000);
+         assertTrue("Expected message 4", message != null);
+         assertTrue("Should be an A which we don't acknowledge", message.getStringProperty("Value").equals("A"));
+         subSession.close();
+
+         getLog().debug("Subscribing to topic, looking for the Value = 'A'");
+         subSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+         subscriber = subSession.createDurableSubscriber(topic, "test", "Value = 'A'", false);
+         assertTrue(
+            "Should not be any A, the subscription was changed. Even though the old and new selectors match the message",
+            subscriber.receive(2000) == null);
+         subSession.close();
+
+         getLog().debug("Closing the send session");
+         sendSession.close();
+
+         getLog().debug("Removing the subscription");
+         subSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+         subSession.unsubscribe("test");
+
+      }
+      finally
+      {
+         getLog().debug("Closing the connection");
+         topicConnection.close();
+      }
+
+      getLog().debug("TopicSelectorChange test passed");
+   }
+
+   /**
+    * Test subscribing to a topic with a null and empty selector
+    */
+   public void testTopicSelectorNullOrEmpty() throws Exception
+   {
+      getLog().debug("Starting TopicSelectorNullOrEmpty test");
+
+      getLog().debug("Create topic connection");
+      TopicConnectionFactory topicFactory = (TopicConnectionFactory) context.lookup(TOPIC_FACTORY);
+      topicConnection = topicFactory.createTopicConnection("john", "needle");
+      topicConnection.start();
+
+      try
+      {
+         getLog().debug("Retrieving Topic");
+         Topic topic = (Topic) context.lookup(TEST_DURABLE_TOPIC);
+
+         getLog().debug("Creating a send session");
+         TopicSession sendSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+         TopicPublisher sender = sendSession.createPublisher(topic);
+
+         getLog().debug("Clearing the topic");
+         TopicSession subSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+         TopicSubscriber subscriber = subSession.createDurableSubscriber(topic, "test");
+         TextMessage message = (TextMessage) subscriber.receive(50);
+         while (message != null)
+            message = (TextMessage) subscriber.receive(50);
+         subSession.close();
+
+         getLog().debug("Subscribing to topic, with null selector");
+         subSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+         subscriber = subSession.createDurableSubscriber(topic, "test", null, false);
+
+         getLog().debug("Send a message");
+         message = sendSession.createTextMessage("Message1");
+         sender.publish(message);
+
+         getLog().debug("Retrieving the message");
+         message = (TextMessage) subscriber.receive(2000);
+         assertTrue("Expected message 1", message != null);
+         assertTrue("Should get Message1", message.getText().equals("Message1"));
+         getLog().debug("Closing the subscriber");
+         subSession.close();
+
+         getLog().debug("Subscribing to topic, with an empty selector");
+         subSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+         subscriber = subSession.createDurableSubscriber(topic, "test", "   ", false);
+
+         getLog().debug("Send a message");
+         message = sendSession.createTextMessage("Message2");
+         sender.publish(message);
+
+         getLog().debug("Retrieving the message");
+         message = (TextMessage) subscriber.receive(2000);
+         assertTrue("Expected message 2", message != null);
+         assertTrue("Should get Message2", message.getText().equals("Message2"));
+         getLog().debug("Closing the subscriber");
+
+         getLog().debug("Removing the subscription");
+         subSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+         subSession.unsubscribe("test");
+         subSession.close();
+
+      }
+      finally
+      {
+         getLog().debug("Closing the connection");
+         topicConnection.close();
+      }
+
+      getLog().debug("TopicSelectorNullOrEmpty test passed");
+   }
+
+   /**
+    * Test sending/receiving an outdated message
+    */
+   public void testSendReceiveOutdated() throws Exception
+   {
+      getLog().debug("Starting SendReceiveOutdated test");
+
+      connect();
+      try
+      {
+         queueConnection.start();
+         drainQueue();
+         queueConnection.stop();
+
+         QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+         Queue queue = (Queue) context.lookup(TEST_QUEUE);
+         QueueSender sender = session.createSender(queue);
+         QueueReceiver receiver = session.createReceiver(queue);
+
+         // Send a message that has expired
+         TextMessage message = session.createTextMessage("Outdated");
+         sender.send(message, DeliveryMode.PERSISTENT, 4, 1);
+         Thread.sleep(100);
+
+         // Send a message that has not expired
+         message = session.createTextMessage("OK");
+         sender.send(message);
+
+         // Try to receive the message the not expired message
+         queueConnection.start();
+         message = (TextMessage) receiver.receiveNoWait();
+         assertEquals("OK", message.getText());
+
+         // Should be no more
+         assertTrue("Didn't expect anymore messages", receiver.receiveNoWait() == null);
+      }
+      finally
+      {
+         disconnect();
+      }
+
+      getLog().debug("SendReceiveOutdated test passed");
+   }
+
+   public void testSendReceiveExpired() throws Exception
+   {
+      getLog().debug("Starting testSendReceiveExpired test");
+
+      connect();
+      try
+      {
+         queueConnection.start();
+         drainQueue();
+
+         QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+         Queue queue = (Queue) context.lookup(TEST_QUEUE);
+         QueueSender sender = session.createSender(queue);
+         QueueReceiver receiver = session.createReceiver(queue);
+
+         // Send a message that expires in 5 seconds
+         TextMessage message = session.createTextMessage("5 Second Expiration");
+         sender.send(message, DeliveryMode.PERSISTENT, 4, 5*1000);
+         // Send a message that has not expired
+         message = session.createTextMessage("OK");
+         sender.send(message);
+         // Sleep 6 seconds
+         Thread.sleep(6*1000);
+         // Try to receive the OK message
+         message = (TextMessage) receiver.receiveNoWait();
+         assertEquals("OK", message.getText());
+
+         // Should be no more
+         assertTrue("Didn't expect anymore messages", receiver.receiveNoWait() == null);
+
+         // Send a message that expires in 10 seconds
+         message = session.createTextMessage("10 Second Expiration");
+         sender.send(message, DeliveryMode.PERSISTENT, 4, 10*1000);
+         // Send a message that has not expired
+         message = session.createTextMessage("OK");
+         sender.send(message);
+         // Sleep 1 seconds
+         Thread.sleep(1*1000);
+         // Try to receive the messages
+         message = (TextMessage) receiver.receiveNoWait();
+         assertEquals("10 Second Expiration", message.getText());
+         message = (TextMessage) receiver.receiveNoWait();
+         assertEquals("OK", message.getText());
+
+         // Should be no more
+         assertTrue("Didn't expect anymore messages", receiver.receiveNoWait() == null);
+         
+         // Test that JMSExpiration has no affect
+         message = session.createTextMessage("5 Second Expiration");
+         message.setJMSExpiration(System.currentTimeMillis() + 5*1000);
+         sender.send(message, DeliveryMode.PERSISTENT, 4, 0);
+         // Send a message that has not expired
+         message = session.createTextMessage("OK");
+         sender.send(message);
+         // Sleep 6 seconds
+         Thread.sleep(6*1000);
+         // Try to receive the OK message
+         message = (TextMessage) receiver.receiveNoWait();
+         assertEquals("5 Second Expiration", message.getText());
+         message = (TextMessage) receiver.receiveNoWait();
+         assertEquals("OK", message.getText());
+         assertTrue("Didn't expect anymore messages", receiver.receiveNoWait() == null);
+      }
+      finally
+      {
+         disconnect();
+      }
+   }
+
+   class Synch
+   {
+      boolean waiting = false;
+      String text;
+      public synchronized void doWait(long timeout) throws InterruptedException
+      {
+         waiting = true;
+         this.wait(timeout);
+      }
+      public synchronized void doNotify() throws InterruptedException
+      {
+         while (waiting == false)
+            wait(100);
+         this.notifyAll();
+      }
+      public String getText()
+      {
+         return text;
+      }
+      public void setText(String text)
+      {
+         this.text = text;
+      }
+   }
+
+   /**
+    * Test sending/listening an outdated message
+    */
+   public void testSendListenOutdated() throws Exception
+   {
+      getLog().debug("Starting SendListenOutdated test");
+
+      connect();
+      try
+      {
+         queueConnection.start();
+         drainQueue();
+         queueConnection.stop();
+
+         QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+         Queue queue = (Queue) context.lookup(TEST_QUEUE);
+         QueueSender sender = session.createSender(queue);
+         QueueReceiver receiver = session.createReceiver(queue);
+
+         // Send a message that has expired
+         TextMessage message = session.createTextMessage("Outdated");
+         sender.send(message, DeliveryMode.PERSISTENT, 4, 1);
+         Thread.sleep(100);
+
+         // Send a message that has not expired
+         message = session.createTextMessage("OK");
+         sender.send(message);
+
+         // Try to receive the message the not expired message
+         final Synch synch = new Synch();
+         MessageListener messagelistener = new MessageListener()
+         {
+            public void onMessage(Message message)
+            {
+               listenOutdated(message, synch);
+            }
+         };
+         receiver.setMessageListener(messagelistener);
+         queueConnection.start();
+
+         synch.doWait(10000);
+         assertEquals("OK", synch.getText());
+      }
+      finally
+      {
+         disconnect();
+      }
+
+      getLog().debug("SendListenOutdated test passed");
+   }
+
+   private void listenOutdated(Message message, Synch synch)
+   {
+      try
+      {
+         synch.setText(((TextMessage) message).getText());
+      }
+      catch (Throwable t)
+      {
+         log.error("Error:", t);
+      }
+      finally
+      {
+         try
+         {
+            synch.doNotify();
+         }
+         catch (Throwable t)
+         {
+            log.error("Error:", t);
+         }
+      }
+   }
+}

Added: trunk/testsuite/src/main/org/jboss/test/jbossmessaging/test/JBossSessionRecoverUnitTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/jbossmessaging/test/JBossSessionRecoverUnitTestCase.java	2006-10-26 19:15:55 UTC (rev 57857)
+++ trunk/testsuite/src/main/org/jboss/test/jbossmessaging/test/JBossSessionRecoverUnitTestCase.java	2006-10-26 19:20:36 UTC (rev 57858)
@@ -0,0 +1,545 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.test.jbossmessaging.test;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.ObjectMessage;
+import javax.jms.Queue;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueReceiver;
+import javax.jms.QueueSender;
+import javax.jms.QueueSession;
+import javax.jms.Session;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import org.jboss.test.jbossmessaging.JMSTestCase;
+
+/**
+ * JBossSessionRecoverUnitTestCase.java
+ *
+ * a simple session.recover test of JBossMQ
+ *
+ * @author Seth Sites
+ * @version $Revision: 37406 $
+ */
+
+public class JBossSessionRecoverUnitTestCase extends JMSTestCase
+{
+   String QUEUE_FACTORY = "ConnectionFactory";
+   String TEST_QUEUE = "queue/testQueue";
+
+   Context context;
+   QueueConnection queueConnection;
+   QueueSession session;
+   int counter=0;
+   Exception exception=null;
+
+   public JBossSessionRecoverUnitTestCase(String name) throws Exception
+   {
+      super(name);
+   }
+
+   protected void setUp()
+      throws Exception
+   {
+      this.getLog().debug("JBossSessionRecoverUnitTestCase, ConnectionFactory started");
+   }
+
+   protected void tearDown() throws Exception
+   {
+      this.getLog().debug("JBossSessionRecoverUnitTestCase, ConnectionFactory done");
+   }
+
+   // Emptys out all the messages in a queue
+   private void drainQueue() throws Exception
+   {
+      QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+      Queue queue = (Queue)context.lookup(TEST_QUEUE);
+
+      QueueReceiver receiver = session.createReceiver(queue);
+      Message message = receiver.receive( 1000 );
+
+      int c=0;
+      while( message != null )
+      {
+         message = receiver.receive( 1000 );
+         c++;
+      }
+
+      if( c!=0 )
+         getLog().debug("  Drained "+c+" messages from the queue");
+
+      session.close();
+   }
+
+   static public void main ( String []args )
+   {
+      String newArgs[] = { "org.jboss.test.jbossmq.test.JBossSessionRecoverUnitTestCase" };
+      junit.swingui.TestRunner.main(newArgs);
+   }
+
+   protected void connect() throws Exception
+   {
+      if( context == null )
+      {
+         context = new InitialContext();
+      }
+
+      QueueConnectionFactory queueFactory = (QueueConnectionFactory) context.lookup(QUEUE_FACTORY);
+      queueConnection = queueFactory.createQueueConnection();
+
+      getLog().debug("Connection to JBossMQ established.");
+   }
+
+   /**
+    * Test that session.recover works with a message listener
+    */
+   public void testQueueSessionRecovermessageListener()	throws Exception
+   {
+      counter = 0;
+      getLog().debug("Starting session.recover() Message Listener test");
+
+      connect();
+      queueConnection.start();
+      drainQueue();
+
+      session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+      Queue queue = (Queue)context.lookup(TEST_QUEUE);
+      QueueSender sender = session.createSender(queue);
+
+      // send 20 messages to the queue
+      for ( int i=0; i<20; i++ )
+      {
+         sender.send(session.createObjectMessage(new Integer(i)));
+      }
+
+      //close the session, so we can start one with CLIENT_ACKNOWLEDGE
+      session.close();
+      queueConnection.stop();
+      session = queueConnection.createQueueSession( false, Session.CLIENT_ACKNOWLEDGE );
+
+      //create our receiver
+      QueueReceiver receiver = session.createReceiver( queue );
+      MessageListener messagelistener = new MessageListener()
+      {
+         public void onMessage(Message message)
+         {
+            processMessage( message );
+         }
+      };
+
+      receiver.setMessageListener( messagelistener );
+      queueConnection.start();
+
+      //since we put in 20 messages and recovered after receiving 20 we should receive those 20
+      //back and get 40 total
+      while ( counter < 40 && exception == null )
+      {
+         try
+         {
+            Thread.sleep( 500 );
+         }
+         catch ( InterruptedException ie )
+         {
+         }
+      }
+
+      if ( exception != null )
+      {
+         queueConnection.close();
+         throw exception;
+      }
+
+      queueConnection.close();
+      getLog().debug("session.recover() Message Listener passed");
+   }
+
+   private void processMessage ( Message message )
+   {
+      try
+      {
+         if ( message instanceof ObjectMessage )
+         {
+            counter++;
+            ObjectMessage objectmessage = (ObjectMessage)message;
+            Integer integer = (Integer)objectmessage.getObject();
+            int mynumber = integer.intValue();
+            getLog().debug("message object " + integer + " counter=" + counter );
+
+            if ( mynumber == 19 )
+            {
+               if (counter == 20)
+               {
+                  session.recover();
+               }
+               else
+               {
+                  message.acknowledge();
+               }
+            }
+         }
+      }
+      catch ( JMSException e )
+      {
+         exception = e;
+      }
+   }
+
+   class Synch
+   {
+       boolean waiting = false;
+       public synchronized void doWait(long timeout)
+          throws InterruptedException
+       {
+          waiting = true;
+          this.wait(timeout);
+       }
+       public synchronized void doNotify()
+          throws InterruptedException
+       {
+          while (waiting == false)
+             wait(100);
+          this.notifyAll();
+       }
+   }
+
+
+   /**
+    * Test that session.recover delivers messages in the correct orer
+    */
+   public void testQueueSessionRecoverMessageListenerOrder()
+      throws Exception
+   {
+      counter = 0;
+      exception = null;
+      getLog().debug("Starting session.recover() Message Listener Order test");
+
+      connect();
+      queueConnection.start();
+      drainQueue();
+
+      session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+      Queue queue = (Queue)context.lookup(TEST_QUEUE);
+      QueueSender sender = session.createSender(queue);
+
+      // send 4 messages to the queue
+      for (int i=0; i<4; ++i)
+      {
+         sender.send(session.createObjectMessage(new Integer(i)));
+      }
+
+      //create our receiver
+      QueueReceiver receiver = session.createReceiver( queue );
+      final Synch synch = new Synch();
+      MessageListener messagelistener = new MessageListener()
+      {
+         public void onMessage(Message message)
+         {
+            checkMessagesInOrder(session, message, synch);
+         }
+      };
+
+      receiver.setMessageListener( messagelistener );
+      queueConnection.start();
+      synch.doWait(10000);
+
+      if ( exception != null )
+      {
+         queueConnection.close();
+         throw exception;
+      }
+
+      queueConnection.close();
+      getLog().debug("session.recover() Message Listener Order passed");
+   }
+
+   private void checkMessagesInOrder(Session session, Message message, Synch synch)
+   {
+      try
+      {
+         ObjectMessage objectmessage = (ObjectMessage)message;
+         Integer integer = (Integer)objectmessage.getObject();
+         int mynumber = integer.intValue();
+
+         if (message.getJMSRedelivered() == false)
+         {
+            log.debug("Recovering " + mynumber);
+            session.recover();
+            return;
+         }
+
+         log.debug("Checking " + mynumber);
+         assertTrue("Expected messages in order", mynumber == counter);
+         counter++;
+         if (counter == 4)
+            synch.doNotify();
+      }
+      catch (Exception e)
+      {
+         exception = e;
+      }
+   }
+
+
+
+   /**
+    * Test that session.recover works with receive
+    */
+   public void testQueueSessionRecoverReceive()	throws Exception
+   {
+      counter = 0;
+      getLog().debug("Starting session.recover() receive test");
+
+      connect();
+      queueConnection.start();
+      drainQueue();
+
+      session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+      Queue queue = (Queue)context.lookup(TEST_QUEUE);
+      QueueSender sender = session.createSender(queue);
+
+      // send 20 messages to the queue
+      for ( int i=0; i<20; i++ )
+      {
+         sender.send(session.createObjectMessage(new Integer(i)));
+      }
+
+      //close the session, so we can start one with CLIENT_ACKNOWLEDGE
+      session.close();
+      queueConnection.stop();
+      session = queueConnection.createQueueSession( false, Session.CLIENT_ACKNOWLEDGE );
+
+      //create our receiver
+      QueueReceiver receiver = session.createReceiver( queue );
+      queueConnection.start();
+
+      Message message = receiver.receive( 1000 );
+      int messagecounter=0;
+      while( message != null )
+      {
+         message = receiver.receive( 1000 );
+         messagecounter++;
+      }
+
+      if ( messagecounter != 20 )
+      {
+         throw new Exception ( "Not all sent messages were delivered! messagecounter=" + messagecounter );
+      }
+
+      //we got all of our messages, let's recover
+      session.recover();
+      message = receiver.receive();
+      messagecounter=0;
+
+      while( message != null )
+      {
+         if ( !message.getJMSRedelivered() )
+         {
+            throw new Exception ( "Message was not marked as redelivered! messagecounter=" + messagecounter );
+         }
+
+         message.acknowledge();
+         messagecounter++;
+
+         //workaround to keep from timing out since there are no more message on the server
+         if ( messagecounter < 15 )
+         {
+            message = receiver.receive();
+         }
+         else
+         {
+            message = receiver.receive ( 1000 );
+         }
+      }
+
+      if ( messagecounter != 20 )
+      {
+         throw new Exception ( "Not all unacknowledged messages were redelivered! messagecounter=" + messagecounter );
+      }
+
+      queueConnection.close();
+      getLog().debug("session.recover() receive passed");
+   }
+
+   /**
+    * Test that session.recover works with receive(timeout)
+    */
+   public void testQueueSessionRecoverReceiveTimeout()	throws Exception
+   {
+      counter = 0;
+      getLog().debug("Starting session.recover() receive(timeout) test");
+
+      connect();
+      queueConnection.start();
+      drainQueue();
+
+
+
+      session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+      Queue queue = (Queue)context.lookup(TEST_QUEUE);
+      QueueSender sender = session.createSender(queue);
+
+      // send 20 messages to the queue
+      for ( int i=0; i<20; i++ )
+      {
+         sender.send(session.createObjectMessage(new Integer(i)));
+      }
+
+      //close the session, so we can start one with CLIENT_ACKNOWLEDGE
+      session.close();
+      queueConnection.stop();
+      session = queueConnection.createQueueSession( false, Session.CLIENT_ACKNOWLEDGE );
+
+      //create our receiver
+      QueueReceiver receiver = session.createReceiver( queue );
+      queueConnection.start();
+
+      Message message = receiver.receive( 1000 );
+      int messagecounter=0;
+
+      while( message != null )
+      {
+         message = receiver.receive( 1000 );
+         messagecounter++;
+      }
+
+      if ( messagecounter != 20 )
+      {
+         throw new Exception ( "Not all sent messages were delivered! messagecounter=" + messagecounter );
+      }
+
+      //we got all of our messages, let's recover
+      session.recover();
+      message = receiver.receive(1000);
+      messagecounter=0;
+
+      while( message != null )
+      {
+         if ( !message.getJMSRedelivered() )
+         {
+            throw new Exception ( "Message was not marked as redelivered! messagecounter=" + messagecounter );
+         }
+
+         message.acknowledge();
+         messagecounter++;
+         message = receiver.receive( 1000 );
+      }
+
+      if ( messagecounter != 20 )
+      {
+         throw new Exception ( "Not all unacknowledged messages were redelivered! messagecounter=" + messagecounter );
+      }
+
+      queueConnection.close();
+      getLog().debug("session.recover() receive(timeout) passed");
+   }
+
+   /**
+    * Test that session.recover works with receiveNoWait
+    */
+   public void testQueueSessionRecoverReceiveNoWait()	throws Exception
+   {
+      counter = 0;
+
+      getLog().debug("Starting session.recover() receiveNoWait test");
+
+
+
+      connect();
+
+
+      queueConnection.start();
+      drainQueue();
+
+      session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+      Queue queue = (Queue)context.lookup(TEST_QUEUE);
+      QueueSender sender = session.createSender(queue);
+
+      // send 20 messages to the queue
+      for ( int i=0; i<20; i++ )
+      {
+         sender.send(session.createObjectMessage(new Integer(i)));
+      }
+
+      //close the session, so we can start one with CLIENT_ACKNOWLEDGE
+      session.close();
+      queueConnection.stop();
+      session = queueConnection.createQueueSession( false, Session.CLIENT_ACKNOWLEDGE );
+
+      //create our receiver
+      QueueReceiver receiver = session.createReceiver( queue );
+      queueConnection.start();
+
+      Message message = receiver.receiveNoWait();
+      int messagecounter=0;
+
+      while( message != null )
+      {
+         message = receiver.receiveNoWait();
+         messagecounter++;
+      }
+
+      if ( messagecounter != 20 )
+      {
+         throw new Exception ( "Not all sent messages were delivered! messagecounter=" + messagecounter );
+      }
+
+      //we got all of our messages, let's recover
+      session.recover();
+
+      message = receiver.receiveNoWait();
+      messagecounter=0;
+
+      while( message != null )
+      {
+         if ( !message.getJMSRedelivered() )
+         {
+            throw new Exception ( "Message was not marked as redelivered! messagecounter=" + messagecounter );
+         }
+
+         message.acknowledge();
+         messagecounter++;
+         message = receiver.receiveNoWait();
+      }
+
+      if ( messagecounter != 20 )
+      {
+         throw new Exception ( "Not all unacknowledged messages were redelivered! messagecounter=" + messagecounter );
+      }
+
+      queueConnection.close();
+      getLog().debug("session.recover() receiveNoWait passed");
+   }
+
+   public static junit.framework.Test suite() throws Exception
+   {
+       ClassLoader loader = Thread.currentThread().getContextClassLoader();
+       String resourceName = getJMSResourceRelativePathname("test-destinations-service.xml") ;
+
+       return getDeploySetup(JBossSessionRecoverUnitTestCase.class,
+               loader.getResource(resourceName).toString());
+   }
+}

Added: trunk/testsuite/src/main/org/jboss/test/jbossmessaging/test/Jms11UnitTest.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/jbossmessaging/test/Jms11UnitTest.java	2006-10-26 19:15:55 UTC (rev 57857)
+++ trunk/testsuite/src/main/org/jboss/test/jbossmessaging/test/Jms11UnitTest.java	2006-10-26 19:20:36 UTC (rev 57858)
@@ -0,0 +1,1209 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.test.jbossmessaging.test;
+
+import java.util.Enumeration;
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.DeliveryMode;
+import javax.jms.InvalidDestinationException;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageListener;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.QueueBrowser;
+import javax.jms.ServerSession;
+import javax.jms.ServerSessionPool;
+import javax.jms.Session;
+import javax.jms.TemporaryQueue;
+import javax.jms.TemporaryTopic;
+import javax.jms.TextMessage;
+import javax.jms.Topic;
+import javax.jms.TopicConnection;
+import javax.jms.TopicConnectionFactory;
+import javax.jms.TopicSubscriber;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import EDU.oswego.cs.dl.util.concurrent.CountDown;
+import org.apache.log4j.Category;
+import org.jboss.test.jbossmessaging.JMSTestCase;
+
+/**
+ * Basic tests using the jms 1.1 producer/consumer apis.
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: 37406 $
+ */
+public class Jms11UnitTest extends JMSTestCase
+{
+   /** The default TopicFactory jndi name */
+   static String TOPIC_FACTORY = "ConnectionFactory";
+   /** The default QueueFactory jndi name */
+   static String QUEUE_FACTORY = "ConnectionFactory";
+
+   static String TEST_QUEUE = "queue/testQueue";
+   static String TEST_TOPIC = "topic/testTopic";
+   static String TEST_DURABLE_TOPIC = "topic/testDurableTopic";
+
+   //JMSProviderAdapter providerAdapter;
+   static Context context;
+   static Connection queueConnection;
+   static Connection topicConnection;
+
+   public Jms11UnitTest(String name) throws Exception
+   {
+      super(name);
+   }
+
+   // Emptys out all the messages in a queue
+   protected void drainQueue() throws Exception
+   {
+      Session session = queueConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+      Queue queue = (Queue) context.lookup(TEST_QUEUE);
+
+      MessageConsumer receiver = session.createConsumer(queue);
+      Message message = receiver.receive(50);
+      int c = 0;
+      while (message != null)
+      {
+         message = receiver.receive(50);
+         c++;
+      }
+
+      if (c != 0)
+         getLog().debug("  Drained " + c + " messages from the queue");
+
+      session.close();
+   }
+
+   protected void connect() throws Exception
+   {
+      if (context == null)
+      {
+         context = new InitialContext();
+      }
+      ConnectionFactory queueFactory = (ConnectionFactory) context.lookup(QUEUE_FACTORY);
+      queueConnection = queueFactory.createConnection();
+
+      ConnectionFactory topicFactory = (ConnectionFactory) context.lookup(TOPIC_FACTORY);
+      topicConnection = topicFactory.createConnection();
+      getLog().debug("Connection to JBossMQ established.");
+   }
+
+   protected void disconnect() throws Exception
+   {
+      queueConnection.close();
+      topicConnection.close();
+   }
+
+   /**
+    * Test that messages are ordered by message arrival and priority.
+    * This also tests :
+    * 		Using a non-transacted AUTO_ACKNOWLEDGE session
+    *		Using a MessageConsumer
+    *		Using a QueueSender
+    *			Sending PERSITENT and NON_PERSISTENT text messages.
+    *		Using a QueueBrowser
+    */
+   public void testQueueMessageOrder() throws Exception
+   {
+
+      getLog().debug("Starting QueueMessageOrder test");
+
+      connect();
+
+      queueConnection.start();
+
+      drainQueue();
+
+      Session session = queueConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+      Queue queue = (Queue) context.lookup(TEST_QUEUE);
+      MessageProducer sender = session.createProducer(queue);
+
+      TextMessage message = session.createTextMessage();
+      message.setText("Normal message");
+      sender.send(message, DeliveryMode.NON_PERSISTENT, 4, 0);
+      message.setText("Persistent message");
+      sender.send(message, DeliveryMode.PERSISTENT, 4, 0);
+      message.setText("High Priority Persistent message");
+      sender.send(message, DeliveryMode.PERSISTENT, 10, 0);
+
+      QueueBrowser browser = session.createBrowser(queue);
+      Enumeration i = browser.getEnumeration();
+      getLog().debug(message.getText());
+
+      message = (TextMessage) i.nextElement();
+      getLog().debug(message.getText());
+
+      message = (TextMessage) i.nextElement();
+      getLog().debug(message.getText());
+
+      disconnect();
+      getLog().debug("QueueMessageOrder passed");
+   }
+
+   /**
+    * Test that temporary queues can be deleted.
+    */
+   public void testTemporaryQueueDelete() throws Exception
+   {
+
+      getLog().debug("Starting TemporaryQueueDelete test");
+      connect();
+
+      Session session = queueConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+      TemporaryQueue queue = session.createTemporaryQueue();
+
+      queue.delete();
+
+      disconnect();
+
+      getLog().debug("TemporaryQueueDelete passed");
+   }
+
+   /**
+    * Test that temporary topics can be deleted.
+    */
+   public void testTemporaryTopicDelete() throws Exception
+   {
+
+      getLog().debug("Starting TemporaryTopicDelete test");
+      connect();
+
+      Session session = topicConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+      TemporaryTopic topic = session.createTemporaryTopic();
+
+      topic.delete();
+
+      disconnect();
+
+      getLog().debug("TemporaryTopicDelete passed");
+   }
+
+   /**
+    * Test invalid destination trying to send a message.
+    */
+   public void testInvalidDestinationQueueSend() throws Exception
+   {
+
+      getLog().debug("Starting InvaidDestinationQueueSend test");
+      connect();
+
+      Session session = queueConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+      TemporaryQueue queue = session.createTemporaryQueue();
+      MessageProducer sender = session.createProducer(queue);
+      queue.delete();
+
+      TextMessage message = session.createTextMessage("hello");
+      boolean caught = false;
+      try
+      {
+         sender.send(message);
+      }
+      catch (InvalidDestinationException expected)
+      {
+         caught = true;
+      }
+
+      disconnect();
+
+      assertTrue("Expected an InvalidDestinationException", caught);
+
+      getLog().debug("InvaldDestinationQueueSend passed");
+   }
+
+   /**
+    * Test invalid destination trying to browse a message.
+    */
+   public void testInvalidDestinationQueueBrowse() throws Exception
+   {
+
+      getLog().debug("Starting InvalidDestinationQueueBrowse test");
+      connect();
+
+      Session session = queueConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+      TemporaryQueue queue = session.createTemporaryQueue();
+      QueueBrowser browser = session.createBrowser(queue);
+      queue.delete();
+
+      boolean caught = false;
+      try
+      {
+         browser.getEnumeration();
+      }
+      catch (InvalidDestinationException expected)
+      {
+         caught = true;
+      }
+
+      disconnect();
+
+      assertTrue("Expected an InvalidDestinationException", caught);
+
+      getLog().debug("InvalidDestinationQueueBrowse passed");
+   }
+
+   /**
+    * Test invalid destination trying to send a message.
+    */
+   public void testInvalidDestinationTopicPublish() throws Exception
+   {
+
+      getLog().debug("Starting InvaidDestinationTopicPublish test");
+      connect();
+
+      Session session = topicConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+      TemporaryTopic topic = session.createTemporaryTopic();
+      MessageProducer publisher = session.createProducer(topic);
+      topic.delete();
+
+      TextMessage message = session.createTextMessage("hello");
+      boolean caught = false;
+      try
+      {
+         publisher.send(message);
+      }
+      catch (InvalidDestinationException expected)
+      {
+         caught = true;
+      }
+
+      disconnect();
+
+      assertTrue("Expected an InvalidDestinationException", caught);
+
+      getLog().debug("InvaldDestinationTopicPublish passed");
+   }
+
+   /**
+    * Test errors trying on topic subscribe.
+    */
+   public void testErrorsTopicSubscribe() throws Exception
+   {
+
+      getLog().debug("Starting InvalidDestinationTopicSubscribe test");
+      connect();
+
+      try
+      {
+         Session session = topicConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         Topic topic = (Topic) context.lookup(TEST_TOPIC);
+         TemporaryTopic temp = session.createTemporaryTopic();
+
+         boolean caught = false;
+         try
+         {
+            session.createConsumer(null);
+         }
+         catch (InvalidDestinationException expected)
+         {
+            caught = true;
+         }
+         assertTrue("Expected an InvalidDestinationException for a null topic", caught);
+
+         caught = false;
+         try
+         {
+            session.createConsumer(null, null, true);
+         }
+         catch (InvalidDestinationException expected)
+         {
+            caught = true;
+         }
+         assertTrue("Expected an InvalidDestinationException for a null topic", caught);
+
+         caught = false;
+         try
+         {
+            session.createDurableSubscriber(null, "NotUsed");
+         }
+         catch (InvalidDestinationException expected)
+         {
+            caught = true;
+         }
+         assertTrue("Expected an InvalidDestinationException for a null topic", caught);
+
+         caught = false;
+         try
+         {
+            session.createDurableSubscriber(temp, "NotUsed");
+         }
+         catch (InvalidDestinationException expected)
+         {
+            caught = true;
+         }
+         assertTrue("Expected an InvalidDestinationException for a temporary topic", caught);
+
+         caught = false;
+         try
+         {
+            session.createDurableSubscriber(null, "NotUsed", null, true);
+         }
+         catch (InvalidDestinationException expected)
+         {
+            caught = true;
+         }
+         assertTrue("Expected an InvalidDestinationException for a null topic", caught);
+
+         caught = false;
+         try
+         {
+            session.createDurableSubscriber(temp, "NotUsed", null, true);
+         }
+         catch (InvalidDestinationException expected)
+         {
+            caught = true;
+         }
+         assertTrue("Expected an InvalidDestinationException for a temporary topic", caught);
+
+         caught = false;
+         try
+         {
+            session.createDurableSubscriber(topic, null);
+         }
+         catch (Exception expected)
+         {
+            caught = true;
+         }
+         assertTrue("Expected a Exception for a null subscription", caught);
+
+         caught = false;
+         try
+         {
+            session.createDurableSubscriber(topic, null, null, false);
+         }
+         catch (Exception expected)
+         {
+            caught = true;
+         }
+         assertTrue("Expected a Exception for a null subscription", caught);
+
+         caught = false;
+         try
+         {
+            session.createDurableSubscriber(topic, "  ");
+         }
+         catch (Exception expected)
+         {
+            caught = true;
+         }
+         assertTrue("Expected a Exception for an empty subscription", caught);
+
+         caught = false;
+         try
+         {
+            session.createDurableSubscriber(topic, "  ", null, false);
+         }
+         catch (Exception expected)
+         {
+            caught = true;
+         }
+         assertTrue("Expected a Exception for an empty subscription", caught);
+      }
+      finally
+      {
+         disconnect();
+      }
+
+      getLog().debug("InvalidDestinationTopicSubscriber passed");
+   }
+
+   /**
+    * Test create queue.
+    */
+   public void testCreateQueue() throws Exception
+   {
+
+      getLog().debug("Starting create queue test");
+      connect();
+
+      Session session = queueConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+      Queue jndiQueue = (Queue) getInitialContext().lookup("queue/testQueue");
+      Queue createQueue = session.createQueue(jndiQueue.getQueueName());
+      assertTrue("Failed for " + QUEUE_FACTORY, jndiQueue.equals(createQueue));
+
+      getLog().debug("InvalidDestinationTopicSubscriber passed");
+   }
+
+   public void testMessageListener() throws Exception
+   {
+      getLog().debug("Starting create queue test");
+
+      connect();
+      queueConnection.start();
+      drainQueue();
+      final CountDown counter1 = new CountDown(3);
+
+      Session session = queueConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+      Queue queue = (Queue) context.lookup(TEST_QUEUE);
+
+      MessageConsumer receiver = session.createConsumer(queue);
+      receiver.setMessageListener(new MessageListener()
+      {
+         public void onMessage(Message msg)
+         {
+            Category log = Category.getInstance(getClass().getName());
+            log.debug("ML");
+            try
+            {
+               if (msg instanceof TextMessage)
+               {
+                  log.debug(((TextMessage) msg).getText());
+                  counter1.release();
+               }
+            }
+            catch (Exception e)
+            {
+            }
+         }
+      });
+
+      MessageProducer sender = session.createProducer(queue);
+
+      TextMessage message = session.createTextMessage();
+      message.setText("Normal message");
+      sender.send(message, DeliveryMode.NON_PERSISTENT, 4, 0);
+      //sender.send(queue, message, DeliveryMode.NON_PERSISTENT, 4, 0);
+      message.setText("Persistent message");
+      sender.send(message, DeliveryMode.PERSISTENT, 4, 0);
+      //sender.send(queue, message, DeliveryMode.PERSISTENT, 4, 0);
+      message.setText("High Priority Persistent message");
+      sender.send(message, DeliveryMode.PERSISTENT, 10, 0);
+      //sender.send(queue, message, DeliveryMode.PERSISTENT, 10, 0);
+
+      // Wait for the msgs to be received
+      counter1.acquire();
+      log.debug("MessageListener1 received the TMs sent");
+
+      final CountDown counter2 = new CountDown(2);
+      receiver.setMessageListener(new MessageListener()
+      {
+         public void onMessage(Message msg)
+         {
+            Category log = Category.getInstance(getClass().getName());
+            log.debug("ML 2");
+            try
+            {
+               if (msg instanceof TextMessage)
+               {
+                  log.debug(((TextMessage) msg).getText());
+                  counter2.release();
+               }
+            }
+            catch (Exception e)
+            {
+            }
+         }
+      });
+
+      message.setText("Persistent message");
+      sender.send(message, DeliveryMode.PERSISTENT, 4, 0);
+      //sender.send(queue, message, DeliveryMode.PERSISTENT, 4, 0);
+      message.setText("High Priority Persistent message");
+      sender.send(message, DeliveryMode.PERSISTENT, 10, 0);
+      //sender.send(queue, message, DeliveryMode.PERSISTENT, 10, 0);
+
+      // Wait for the msgs to be received
+      counter2.acquire();
+      log.debug("MessageListener2 received the TMs sent");
+
+      receiver.setMessageListener(null);
+
+      message.setText("Persistent message");
+      sender.send(message, DeliveryMode.PERSISTENT, 4, 0);
+      //sender.send(queue, message, DeliveryMode.PERSISTENT, 4, 0);
+      message.setText("High Priority Persistent message");
+      sender.send(message, DeliveryMode.PERSISTENT, 10, 0);
+      //sender.send(queue, message, DeliveryMode.PERSISTENT, 10, 0);
+
+      sender.close();
+      drainQueue();
+      disconnect();
+      getLog().debug("MessageListener test passed");
+   }
+
+   public void testApplicationServerStuff() throws Exception
+   {
+      getLog().debug("Starting testing app server stuff");
+      connect();
+
+      Queue testQueue = (Queue) context.lookup(TEST_QUEUE);
+      final Session session = queueConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+      session.setMessageListener(new MessageListener()
+      {
+         public void onMessage(Message mess)
+         {
+            Category log = Category.getInstance(getClass().getName());
+            log.debug("Processing message");
+            try
+            {
+               if (mess instanceof TextMessage)
+                  log.debug(((TextMessage) mess).getText());
+            }
+            catch (Exception e)
+            {
+               log.error("Error", e);
+            }
+         }
+      });
+
+      MessageProducer sender = session.createProducer(testQueue);
+      sender.send(session.createTextMessage("Hi"));
+      sender.send(session.createTextMessage("There"));
+      sender.send(session.createTextMessage("Guys"));
+      queueConnection.createConnectionConsumer(testQueue, null, new ServerSessionPool()
+      {
+         public ServerSession getServerSession()
+         {
+            Category.getInstance(getClass().getName()).debug("Getting server session.");
+            return new ServerSession()
+            {
+               public Session getSession()
+               {
+                  return session;
+               }
+               public void start()
+               {
+                  Category.getInstance(getClass().getName()).debug("Starting server session.");
+                  session.run();
+               }
+            };
+         }
+      }, 10);
+
+      queueConnection.start();
+
+      try
+      {
+         Thread.sleep(5 * 1000);
+      }
+      catch (Exception e)
+      {
+      }
+
+      disconnect();
+      getLog().debug("Testing app server stuff passed");
+   }
+
+   private void drainMessagesForTopic(MessageConsumer sub) throws JMSException
+   {
+      Message msg = sub.receive(50);
+      int c = 0;
+      while (msg != null)
+      {
+         c++;
+         if (msg instanceof TextMessage)
+            getLog().debug(((TextMessage) msg).getText());
+         msg = sub.receive(50);
+      }
+      getLog().debug("Received " + c + " messages from topic.");
+   }
+
+   public void testTopics() throws Exception
+   {
+      getLog().debug("Starting Topic test");
+      connect();
+
+      TopicConnectionFactory topicFactory = (TopicConnectionFactory) context.lookup(TOPIC_FACTORY);
+      topicConnection = topicFactory.createTopicConnection("john", "needle");
+
+      topicConnection.start();
+
+      //set up some subscribers to the topic
+      Session session = topicConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+      Topic topic = (Topic) context.lookup(TEST_TOPIC);
+
+      TopicSubscriber sub1 = session.createDurableSubscriber(topic, "sub1");
+      MessageConsumer sub2 = session.createConsumer(topic);
+      MessageConsumer sub3 = session.createConsumer(topic);
+
+      //Now a sender
+      MessageProducer sender = session.createProducer(topic);
+
+      //send some messages
+      sender.send(session.createTextMessage("Message 1"));
+      sender.send(session.createTextMessage("Message 2"));
+      sender.send(session.createTextMessage("Message 3"));
+      drainMessagesForTopic(sub1);
+      drainMessagesForTopic(sub2);
+      drainMessagesForTopic(sub3);
+
+      //close some subscribers
+      sub1.close();
+      sub2.close();
+
+      //send some more messages
+      sender.send(session.createTextMessage("Message 4"));
+      sender.send(session.createTextMessage("Message 5"));
+      sender.send(session.createTextMessage("Message 6"));
+
+      //give time for message 4 to be negatively acked (as it will be cause last receive timed out)
+      try
+      {
+         Thread.sleep(5 * 1000);
+      }
+      catch (InterruptedException e)
+      {
+      }
+
+      drainMessagesForTopic(sub3);
+
+      //open subscribers again.
+      sub1 = session.createDurableSubscriber(topic, "sub1");
+      sub2 = session.createConsumer(topic);
+
+      //Send a final message
+      sender.send(session.createTextMessage("Final message"));
+      sender.close();
+
+      drainMessagesForTopic(sub1);
+      drainMessagesForTopic(sub2);
+      drainMessagesForTopic(sub3);
+
+      sub1.close();
+      sub2.close();
+      sub3.close();
+
+      session.unsubscribe("sub1");
+
+      topicConnection.stop();
+      topicConnection.close();
+
+      disconnect();
+      getLog().debug("Topic test passed");
+   }
+
+   /**
+    * Test to seeif the NoLocal feature of topics works.
+    * Messages sended from the same connection should not
+    * be received by Subscribers on the same connection.
+    */
+   public void testTopicNoLocal() throws Exception
+   {
+      getLog().debug("Starting TopicNoLocal test");
+      connect();
+
+      TopicConnectionFactory topicFactory = (TopicConnectionFactory) context.lookup(TOPIC_FACTORY);
+      TopicConnection topicConnection1 = topicFactory.createTopicConnection();
+      topicConnection1.start();
+      TopicConnection topicConnection2 = topicFactory.createTopicConnection();
+      topicConnection2.start();
+
+      // We don't want local messages on this topic.
+      Session session1 = topicConnection1.createSession(false, Session.AUTO_ACKNOWLEDGE);
+      Topic topic = (Topic) context.lookup(TEST_TOPIC);
+      MessageConsumer subscriber1 = session1.createConsumer(topic, null, true);
+      MessageProducer sender1 = session1.createProducer(topic);
+
+      //Now a sender
+      Session session2 = topicConnection2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+      MessageProducer sender2 = session2.createProducer(topic);
+
+      drainMessagesForTopic(subscriber1);
+
+      //send some messages
+      sender1.send(session1.createTextMessage("Local Message"));
+      sender2.send(session2.createTextMessage("Remote Message"));
+
+      // Get the messages, we should get the remote message
+      // but not the local message
+      TextMessage msg1 = (TextMessage) subscriber1.receive(2000);
+      if (msg1 == null)
+      {
+         fail("Did not get any messages");
+      }
+      else
+      {
+         getLog().debug("Got message: " + msg1);
+         if (msg1.getText().equals("Local Message"))
+         {
+            fail("Got a local message");
+         }
+         TextMessage msg2 = (TextMessage) subscriber1.receive(2000);
+         if (msg2 != null)
+         {
+            getLog().debug("Got message: " + msg2);
+            fail("Got an extra message.  msg1:" + msg1 + ", msg2:" + msg2);
+         }
+      }
+
+      topicConnection1.stop();
+      topicConnection1.close();
+      topicConnection2.stop();
+      topicConnection2.close();
+
+      disconnect();
+      getLog().debug("TopicNoLocal test passed");
+   }
+
+   /**
+    * Test to see whether no local works if a message
+    * was created somewhere else.
+    */
+   public void testTopicNoLocalBounce() throws Exception
+   {
+      getLog().debug("Starting TopicNoLocalBounce test");
+      connect();
+
+      TopicConnectionFactory topicFactory = (TopicConnectionFactory) context.lookup(TOPIC_FACTORY);
+      TopicConnection topicConnection1 = topicFactory.createTopicConnection();
+      topicConnection1.start();
+      TopicConnection topicConnection2 = topicFactory.createTopicConnection();
+      topicConnection2.start();
+
+      // Session 1
+      Session session1 = topicConnection1.createSession(false, Session.AUTO_ACKNOWLEDGE);
+      Topic topic = (Topic) context.lookup(TEST_TOPIC);
+      MessageConsumer subscriber1 = session1.createConsumer(topic, null, true);
+      MessageProducer sender1 = session1.createProducer(topic);
+
+      // Session 2
+      Session session2 = topicConnection2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+      MessageConsumer subscriber2 = session2.createConsumer(topic, null, true);
+      MessageProducer sender2 = session2.createProducer(topic);
+
+      drainMessagesForTopic(subscriber1);
+      drainMessagesForTopic(subscriber2);
+
+      //send the message
+      sender1.send(session1.createTextMessage("Message"));
+
+      assertTrue("Subscriber1 should not get a message", subscriber1.receiveNoWait() == null);
+      TextMessage msg = (TextMessage) subscriber2.receive(2000);
+      assertTrue("Subscriber2 should get a message, got " + msg, msg != null && msg.getText().equals("Message"));
+
+      //send it back
+      sender2.send(msg);
+
+      msg = (TextMessage) subscriber1.receive(2000);
+      assertTrue("Subscriber1 should get a message, got " + msg, msg != null && msg.getText().equals("Message"));
+      assertTrue("Subscriber2 should not get a message", subscriber2.receiveNoWait() == null);
+
+      topicConnection1.stop();
+      topicConnection1.close();
+      topicConnection2.stop();
+      topicConnection2.close();
+
+      disconnect();
+      getLog().debug("TopicNoLocalBounce test passed");
+   }
+
+   /**
+    * Test subscribing to a topic with one selector, then changing to another
+    */
+   public void testTopicSelectorChange() throws Exception
+   {
+      getLog().debug("Starting TopicSelectorChange test");
+
+      getLog().debug("Create topic connection");
+      TopicConnectionFactory topicFactory = (TopicConnectionFactory) context.lookup(TOPIC_FACTORY);
+      topicConnection = topicFactory.createTopicConnection("john", "needle");
+      topicConnection.start();
+
+      try
+      {
+         getLog().debug("Retrieving Topic");
+         Topic topic = (Topic) context.lookup(TEST_DURABLE_TOPIC);
+
+         getLog().debug("Creating a send session");
+         Session sendSession = topicConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         MessageProducer sender = sendSession.createProducer(topic);
+
+         getLog().debug("Clearing the topic");
+         Session subSession = topicConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         MessageConsumer subscriber = subSession.createDurableSubscriber(topic, "test");
+         Message message = subscriber.receive(50);
+         while (message != null)
+            message = subscriber.receive(50);
+         subSession.close();
+
+         getLog().debug("Subscribing to topic, looking for Value = 'A'");
+         subSession = topicConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         subscriber = subSession.createDurableSubscriber(topic, "test", "Value = 'A'", false);
+
+         getLog().debug("Send some messages");
+         message = sendSession.createTextMessage("Message1");
+         message.setStringProperty("Value", "A");
+         sender.send(message);
+         message = sendSession.createTextMessage("Message2");
+         message.setStringProperty("Value", "A");
+         sender.send(message);
+         message = sendSession.createTextMessage("Message3");
+         message.setStringProperty("Value", "B");
+         sender.send(message);
+
+         getLog().debug("Retrieving the A messages");
+         message = subscriber.receive(2000);
+         assertTrue("Expected message 1", message != null);
+         assertTrue("Should get an A", message.getStringProperty("Value").equals("A"));
+         message = subscriber.receive(2000);
+         assertTrue("Expected message 2", message != null);
+         assertTrue("Should get a second A", message.getStringProperty("Value").equals("A"));
+         assertTrue("That should be it for A", subscriber.receive(2000) == null);
+
+         getLog().debug("Closing the subscriber without acknowledgement");
+         subSession.close();
+
+         getLog().debug("Subscribing to topic, looking for Value = 'B'");
+         subSession = topicConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         subscriber = subSession.createDurableSubscriber(topic, "test", "Value = 'B'", false);
+
+         getLog().debug("Retrieving the non-existent B messages");
+         assertTrue("B should not be there", subscriber.receive(2000) == null);
+
+         getLog().debug("Closing the subscriber.");
+         subSession.close();
+
+         getLog().debug("Subscribing to topic, looking for those Value = 'A'");
+         subSession = topicConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         subscriber = subSession.createDurableSubscriber(topic, "test", "Value = 'A'", false);
+         assertTrue("Should not be any A the subscription was changed", subscriber.receive(2000) == null);
+         subSession.close();
+
+         getLog().debug("Subscribing to topic, looking for everything");
+         subSession = topicConnection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+         subscriber = subSession.createDurableSubscriber(topic, "test", null, false);
+
+         message = sendSession.createTextMessage("Message4");
+         message.setStringProperty("Value", "A");
+         sender.send(message);
+
+         message = subscriber.receive(2000);
+         assertTrue("Expected message 4", message != null);
+         assertTrue("Should be an A which we don't acknowledge", message.getStringProperty("Value").equals("A"));
+         subSession.close();
+
+         getLog().debug("Subscribing to topic, looking for the Value = 'A'");
+         subSession = topicConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         subscriber = subSession.createDurableSubscriber(topic, "test", "Value = 'A'", false);
+         assertTrue(
+            "Should not be any A, the subscription was changed. Even though the old and new selectors match the message",
+            subscriber.receive(2000) == null);
+         subSession.close();
+
+         getLog().debug("Closing the send session");
+         sendSession.close();
+
+         getLog().debug("Removing the subscription");
+         subSession = topicConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         subSession.unsubscribe("test");
+
+      }
+      finally
+      {
+         getLog().debug("Closing the connection");
+         topicConnection.close();
+      }
+
+      getLog().debug("TopicSelectorChange test passed");
+   }
+
+   /**
+    * Test subscribing to a topic with a null and empty selector
+    */
+   public void testTopicSelectorNullOrEmpty() throws Exception
+   {
+      getLog().debug("Starting TopicSelectorNullOrEmpty test");
+
+      getLog().debug("Create topic connection");
+      TopicConnectionFactory topicFactory = (TopicConnectionFactory) context.lookup(TOPIC_FACTORY);
+      topicConnection = topicFactory.createTopicConnection("john", "needle");
+      topicConnection.start();
+
+      try
+      {
+         getLog().debug("Retrieving Topic");
+         Topic topic = (Topic) context.lookup(TEST_DURABLE_TOPIC);
+
+         getLog().debug("Creating a send session");
+         Session sendSession = topicConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         MessageProducer sender = sendSession.createProducer(topic);
+
+         getLog().debug("Clearing the topic");
+         Session subSession = topicConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         MessageConsumer subscriber = subSession.createDurableSubscriber(topic, "test");
+         TextMessage message = (TextMessage) subscriber.receive(50);
+         while (message != null)
+            message = (TextMessage) subscriber.receive(50);
+         subSession.close();
+
+         getLog().debug("Subscribing to topic, with null selector");
+         subSession = topicConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         subscriber = subSession.createDurableSubscriber(topic, "test", null, false);
+
+         getLog().debug("Send a message");
+         message = sendSession.createTextMessage("Message1");
+         sender.send(message);
+
+         getLog().debug("Retrieving the message");
+         message = (TextMessage) subscriber.receive(2000);
+         assertTrue("Expected message 1", message != null);
+         assertTrue("Should get Message1", message.getText().equals("Message1"));
+         getLog().debug("Closing the subscriber");
+         subSession.close();
+
+         getLog().debug("Subscribing to topic, with an empty selector");
+         subSession = topicConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         subscriber = subSession.createDurableSubscriber(topic, "test", "   ", false);
+
+         getLog().debug("Send a message");
+         message = sendSession.createTextMessage("Message2");
+         sender.send(message);
+
+         getLog().debug("Retrieving the message");
+         message = (TextMessage) subscriber.receive(2000);
+         assertTrue("Expected message 2", message != null);
+         assertTrue("Should get Message2", message.getText().equals("Message2"));
+         getLog().debug("Closing the subscriber");
+
+         getLog().debug("Removing the subscription");
+         subSession = topicConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         subSession.unsubscribe("test");
+         subSession.close();
+
+      }
+      finally
+      {
+         getLog().debug("Closing the connection");
+         topicConnection.close();
+      }
+
+      getLog().debug("TopicSelectorNullOrEmpty test passed");
+   }
+
+   /**
+    * Test sending/receiving an outdated message
+    */
+   public void testSendReceiveOutdated() throws Exception
+   {
+      getLog().debug("Starting SendReceiveOutdated test");
+
+      connect();
+      try
+      {
+         queueConnection.start();
+         drainQueue();
+         queueConnection.stop();
+
+         Session session = queueConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         Queue queue = (Queue) context.lookup(TEST_QUEUE);
+         MessageProducer sender = session.createProducer(queue);
+         MessageConsumer receiver = session.createConsumer(queue);
+
+         // Send a message that has expired
+         TextMessage message = session.createTextMessage("Outdated");
+         sender.send(message, DeliveryMode.PERSISTENT, 4, 1);
+         Thread.sleep(100);
+
+         // Send a message that has not expired
+         message = session.createTextMessage("OK");
+         sender.send(message);
+
+         // Try to receive the message the not expired message
+         queueConnection.start();
+         message = (TextMessage) receiver.receiveNoWait();
+         assertEquals("OK", message.getText());
+
+         // Should be no more
+         assertTrue("Didn't expect anymore messages", receiver.receiveNoWait() == null);
+      }
+      finally
+      {
+         disconnect();
+      }
+
+      getLog().debug("SendReceiveOutdated test passed");
+   }
+
+   public void testSendReceiveExpired() throws Exception
+   {
+      getLog().debug("Starting testSendReceiveExpired test");
+
+      connect();
+      try
+      {
+         queueConnection.start();
+         drainQueue();
+
+         Session session = queueConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         Queue queue = (Queue) context.lookup(TEST_QUEUE);
+         MessageProducer sender = session.createProducer(queue);
+         MessageConsumer receiver = session.createConsumer(queue);
+
+         // Send a message that expires in 5 seconds
+         TextMessage message = session.createTextMessage("5 Second Expiration");
+         sender.send(message, DeliveryMode.PERSISTENT, 4, 5*1000);
+         // Send a message that has not expired
+         message = session.createTextMessage("OK");
+         sender.send(message);
+         // Sleep 6 seconds
+         Thread.sleep(6*1000);
+         // Try to receive the OK message
+         message = (TextMessage) receiver.receiveNoWait();
+         assertEquals("OK", message.getText());
+
+         // Should be no more
+         assertTrue("Didn't expect anymore messages", receiver.receiveNoWait() == null);
+
+         // Send a message that expires in 10 seconds
+         message = session.createTextMessage("10 Second Expiration");
+         sender.send(message, DeliveryMode.PERSISTENT, 4, 10*1000);
+         // Send a message that has not expired
+         message = session.createTextMessage("OK");
+         sender.send(message);
+         // Sleep 1 seconds
+         Thread.sleep(1*1000);
+         // Try to receive the messages
+         message = (TextMessage) receiver.receiveNoWait();
+         assertEquals("10 Second Expiration", message.getText());
+         message = (TextMessage) receiver.receiveNoWait();
+         assertEquals("OK", message.getText());
+
+         // Should be no more
+         assertTrue("Didn't expect anymore messages", receiver.receiveNoWait() == null);
+         
+         // Test that JMSExpiration has no affect
+         message = session.createTextMessage("5 Second Expiration");
+         message.setJMSExpiration(System.currentTimeMillis() + 5*1000);
+         sender.send(message, DeliveryMode.PERSISTENT, 4, 0);
+         // Send a message that has not expired
+         message = session.createTextMessage("OK");
+         sender.send(message);
+         // Sleep 6 seconds
+         Thread.sleep(6*1000);
+         // Try to receive the OK message
+         message = (TextMessage) receiver.receiveNoWait();
+         assertEquals("5 Second Expiration", message.getText());
+         message = (TextMessage) receiver.receiveNoWait();
+         assertEquals("OK", message.getText());
+         assertTrue("Didn't expect anymore messages", receiver.receiveNoWait() == null);
+      }
+      finally
+      {
+         disconnect();
+      }
+   }
+
+   class Synch
+   {
+      boolean waiting = false;
+      String text;
+      public synchronized void doWait(long timeout) throws InterruptedException
+      {
+         waiting = true;
+         this.wait(timeout);
+      }
+      public synchronized void doNotify() throws InterruptedException
+      {
+         while (waiting == false)
+            wait(100);
+         this.notifyAll();
+      }
+      public String getText()
+      {
+         return text;
+      }
+      public void setText(String text)
+      {
+         this.text = text;
+      }
+   }
+
+   /**
+    * Test sending/listening an outdated message
+    */
+   public void testSendListenOutdated() throws Exception
+   {
+      getLog().debug("Starting SendListenOutdated test");
+
+      connect();
+      try
+      {
+         queueConnection.start();
+         drainQueue();
+         queueConnection.stop();
+
+         Session session = queueConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         Queue queue = (Queue) context.lookup(TEST_QUEUE);
+         MessageProducer sender = session.createProducer(queue);
+         MessageConsumer receiver = session.createConsumer(queue);
+
+         // Send a message that has expired
+         TextMessage message = session.createTextMessage("Outdated");
+         sender.send(message, DeliveryMode.PERSISTENT, 4, 1);
+         Thread.sleep(100);
+
+         // Send a message that has not expired
+         message = session.createTextMessage("OK");
+         sender.send(message);
+
+         // Try to receive the message the not expired message
+         final Synch synch = new Synch();
+         MessageListener messagelistener = new MessageListener()
+         {
+            public void onMessage(Message message)
+            {
+               listenOutdated(message, synch);
+            }
+         };
+         receiver.setMessageListener(messagelistener);
+         queueConnection.start();
+
+         synch.doWait(10000);
+         assertEquals("OK", synch.getText());
+      }
+      finally
+      {
+         disconnect();
+      }
+
+      getLog().debug("SendListenOutdated test passed");
+   }
+
+   private void listenOutdated(Message message, Synch synch)
+   {
+      try
+      {
+         synch.setText(((TextMessage) message).getText());
+      }
+      catch (Throwable t)
+      {
+         log.error("Error:", t);
+      }
+      finally
+      {
+         try
+         {
+            synch.doNotify();
+         }
+         catch (Throwable t)
+         {
+            log.error("Error:", t);
+         }
+      }
+   }
+}

Added: trunk/testsuite/src/main/org/jboss/test/jbossmessaging/test/MessageBodyUnitTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/jbossmessaging/test/MessageBodyUnitTestCase.java	2006-10-26 19:15:55 UTC (rev 57857)
+++ trunk/testsuite/src/main/org/jboss/test/jbossmessaging/test/MessageBodyUnitTestCase.java	2006-10-26 19:20:36 UTC (rev 57858)
@@ -0,0 +1,335 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.test.jbossmessaging.test;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.ObjectMessage;
+import javax.jms.Queue;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueReceiver;
+import javax.jms.QueueSender;
+import javax.jms.QueueSession;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.naming.Context;
+
+import org.apache.log4j.Category;
+import org.jboss.test.jbossmessaging.JMSTestCase;
+
+/**
+ * Tests message bodies.
+ *
+ * @author <a href="mailto:richard.achmatowicz at jboss.com">Richard Achmatowicz</a>
+ * @author Loren Rosen (submitted patch)
+ * @author <a href="mailto:jason at planet57.com">Jason Dillon</a>
+ * @version $Revision: 37406 $
+ */
+public class MessageBodyUnitTestCase extends JMSTestCase
+{
+   // Provider specific
+   public static final String QUEUE_FACTORY = "ConnectionFactory";
+   public static final String TEST_QUEUE = "queue/testQueue";
+
+   Context context;
+   QueueConnection queueConnection;
+   QueueSession session;
+   Queue queue;
+
+   QueueReceiver receiver;
+   QueueSender sender;
+
+   Category log;
+
+   public MessageBodyUnitTestCase(String name) throws Exception
+   {
+      super(name);
+      log = getLog();
+   }
+
+   protected void setUp() throws Exception
+   {
+      connect();
+   }
+
+   protected void tearDown() throws Exception
+   {
+      disconnect();
+   }
+
+   protected void connect() throws Exception
+   {
+      log.debug("connecting");
+      if (context == null)
+      {
+         context = getInitialContext();
+      }
+
+      QueueConnectionFactory queueFactory = (QueueConnectionFactory) context.lookup(QUEUE_FACTORY);
+      queueConnection = queueFactory.createQueueConnection();
+      log.debug("connected");
+
+      queueConnection.start();
+      session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+      log.debug("session established");
+
+      queue = (Queue) context.lookup(TEST_QUEUE);
+
+      receiver = session.createReceiver(queue);
+      sender = session.createSender(queue);
+      log.debug("sender established");
+
+      drainQueue();
+      log.debug("end of connect call");
+   }
+
+   protected void disconnect() throws Exception
+   {
+      queueConnection.close();
+   }
+
+   private void drainQueue() throws Exception
+   {
+      log.debug("draining queue");
+
+      Message message = receiver.receive(2000);
+      int c = 0;
+      while (message != null)
+      {
+         message = receiver.receive(2000);
+         c++;
+      }
+
+      if (c != 0)
+         log.debug("Drained " + c + " messages from the queue");
+
+      log.debug("drained queue");
+
+   }
+
+   protected void validate(String payload) throws Exception
+   {
+      log.debug("validating text |" + payload + "|");
+
+      TextMessage outMessage = session.createTextMessage();
+      outMessage.setText(payload);
+      log.debug("sending |" + payload + "|");
+      sender.send(outMessage);
+
+      log.debug("receiving |" + payload + "|");
+      TextMessage inMessage = (TextMessage) receiver.receive();
+      log.debug("received |" + payload + "|");
+      String inPayload = inMessage.getText();
+
+      assertEquals("Message body text test", payload, inPayload);
+      log.debug("validated text " + payload);
+   }
+
+   public void testTextMessageBody() throws Exception
+   {
+      log.debug("testing text");
+
+      validate("ordinary text");
+      validate(" ");
+      validate("");
+      // very long strings, non-printable ASCII strings
+      char c[] = new char[1024 * 32];
+      Arrays.fill(c, 'x');
+      validate(new String(c));
+      Arrays.fill(c, '\u0130'); // I with dot
+      validate(new String(c));
+      Arrays.fill(c, '\u0008');
+      validate(new String(c));
+      log.debug("tested text");
+   }
+
+   protected void validate(java.io.Serializable payload) throws Exception
+   {
+      ObjectMessage outMessage = session.createObjectMessage();
+      outMessage.setObject(payload);
+      sender.send(outMessage);
+
+      ObjectMessage inMessage = (ObjectMessage) receiver.receive();
+      Object inPayload = inMessage.getObject();
+
+      assertEquals("Message body object test", payload, inPayload);
+   }
+
+   public void testObjectMessageBody() throws Exception
+   {
+      log.debug("testing object");
+      validate(new Integer(0));
+      validate(new Integer(1));
+      validate(new Integer(-1));
+      validate(new Integer(Integer.MAX_VALUE));
+      validate(new Integer(Integer.MIN_VALUE));
+      validate(new Integer(-1));
+      validate(new Float(1.0));
+      validate(new Float(0.0));
+      validate(new Float(-1.0));
+      validate(new Float(Float.MAX_VALUE));
+      validate(new Float(Float.MIN_VALUE));
+      validate(new Float(Float.NaN));
+      validate(new Float(Float.POSITIVE_INFINITY));
+      validate(new Float(Float.NEGATIVE_INFINITY));
+      validate(new Float(1.0));
+      HashMap m = new HashMap(); // Fill with serializable stuff
+      m.put("file", new java.io.File("somefile.txt"));
+      m.put("url", new java.net.URL("http://example.net"));
+      validate(m);
+      validate((java.io.Serializable)Collections.nCopies(10000, "Repeat"));
+   }
+
+   /**
+    * Test null properties.
+    */
+   public void testNullProperties() throws Exception
+   {
+      TextMessage message = session.createTextMessage();
+
+      message.setStringProperty("THE_PROP", null);
+      message.setObjectProperty("THE_PROP2", null);
+
+      try
+      {
+        message.setStringProperty("", null);
+        fail("empty string property");
+      }
+      catch (IllegalArgumentException e) {}
+
+      try
+      {
+        message.setStringProperty(null, null);
+        fail("null property");
+      }
+      catch (IllegalArgumentException e) {}
+   }
+
+   public void testInvalidPropertyName() throws Exception
+   {
+      Message message = session.createMessage();
+
+      String[] invalid = new String[]
+      {
+         "invalid-hyphen",
+         "1digitfirst",
+         "NULL",
+         "TRUE",
+         "FALSE",
+         "NOT",
+         "AND",
+         "OR",
+         "BETWEEN",
+         "LIKE",
+         "IN",
+         "IS",
+         "ESCAPE"
+      };
+
+      for (int i = 0; i < invalid.length; ++i)
+      {
+         try
+         {
+            message.setStringProperty(invalid[i], "whatever");
+            fail("expected error for invalid property name " + invalid[i]);
+         }
+         catch (IllegalArgumentException expected)
+         {
+         }
+      }
+
+      String[] valid = new String[]
+      {
+         "identifier",
+         "_",
+         "$",
+         "_xSx",
+         "$x_x",
+         "A1",
+         "null",
+         "true",
+         "false",
+         "not",
+         "and",
+         "or",
+         "between",
+         "like",
+         "in",
+         "is",
+         "escape"
+      };
+
+      for (int i = 0; i < invalid.length; ++i)
+         message.setStringProperty(valid[i], "whatever");
+   }
+
+   /**
+    * Test vendor properties.
+    */
+   public void testVendorProperties() throws Exception
+   {
+      TextMessage message = session.createTextMessage();
+
+      try
+      {
+        message.setStringProperty("JMS_JBOSS_SCHEDULED_DELIVERY", "whenever");
+        fail("invalid type");
+      }
+      catch (JMSException e) {}
+      try
+      {
+        message.setObjectProperty("JMS_JBOSS_SCHEDULED_DELIVERY", "10234");
+        fail("invalid type");
+      }
+      catch (JMSException e) {}
+      try
+      {
+        message.setStringProperty("JMS_JBOSS_REDELIVERY_COUNT", "fruity");
+        fail("invalid type");
+      }
+      catch (JMSException e) {}
+      try
+      {
+        message.setStringProperty("JMS_JBOSS_REDELIVERY_LIMIT", "fruity");
+        fail("invalid type");
+      }
+      catch (JMSException e) {}
+
+      message.setLongProperty("JMS_JBOSS_SCHEDULED_DELIVERY", 10234);
+      message.setIntProperty("JMS_JBOSS_REDELIVERY_COUNT", 123);
+      message.setShortProperty("JMS_JBOSS_REDELIVERY_LIMIT", (short)1);
+   }
+
+   public static junit.framework.Test suite() throws Exception
+   {
+       ClassLoader loader = Thread.currentThread().getContextClassLoader();
+       String resourceName = getJMSResourceRelativePathname("test-destinations-service.xml") ;
+
+       return getDeploySetup(MessageBodyUnitTestCase.class,
+               loader.getResource(resourceName).toString());
+   }
+
+}

Added: trunk/testsuite/src/main/org/jboss/test/jbossmessaging/test/MessageTypesUnitTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/jbossmessaging/test/MessageTypesUnitTestCase.java	2006-10-26 19:15:55 UTC (rev 57857)
+++ trunk/testsuite/src/main/org/jboss/test/jbossmessaging/test/MessageTypesUnitTestCase.java	2006-10-26 19:20:36 UTC (rev 57858)
@@ -0,0 +1,270 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.test.jbossmessaging.test;
+
+import java.util.Arrays;
+import java.math.BigInteger;
+import javax.jms.DeliveryMode;
+import javax.jms.MapMessage;
+import javax.jms.Message;
+import javax.jms.Queue;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueReceiver;
+import javax.jms.QueueSender;
+import javax.jms.QueueSession;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.jms.BytesMessage;
+import javax.jms.ObjectMessage;
+import javax.jms.StreamMessage;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import org.jboss.test.jbossmessaging.JMSTestCase;
+
+/**
+ * Tests of sending/receiving all jms message types to/from a queue
+ * 
+ * @author <a href="mailto:richard.achmatowicz at jboss.com">Richard Achmatowicz</a>
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: 37406 $
+ */
+public class MessageTypesUnitTestCase extends JMSTestCase
+{
+   static String QUEUE_FACTORY = "ConnectionFactory";
+   static String TEST_QUEUE = "queue/testQueue";
+
+   private Context context;
+   private QueueConnection queueConnection;
+   private QueueSession session;
+   private QueueSender sender;
+   private QueueReceiver receiver;
+
+   public MessageTypesUnitTestCase(String name) throws Exception
+   {
+      super(name);
+   }
+
+   public void testMapMessage() throws Exception
+   {
+      log.info("+++ testMapMessage");
+      MapMessage sent = session.createMapMessage();
+      sent.setBoolean("Boolean", true);
+      sent.setByte("Byte", (byte) 1);
+      sent.setBytes("Bytes", "Bytes".getBytes());
+      sent.setChar("Char", 'c');
+      sent.setShort("Short", (short) 31415);
+      sent.setInt("Int", 314159);
+      sent.setLong("Long", 3141592653589793238L);
+      sent.setDouble("Double", 3.1415926535897932384626433832795);
+      sent.setFloat("Float", 3.141f);
+      sent.setObject("Object", "31415926535897932384626433832795");
+      sent.setString("String", "31415926535897932384626433832795");
+
+      MapMessage recv = (MapMessage) sendRecMsg(sent);
+      log.debug("recv: "+recv);
+      assertTrue("Boolean == true", recv.getBoolean("Boolean") == true);
+      assertTrue("Byte == 1", recv.getByte("Byte") == 1);
+      assertTrue("Bytes == Bytes[]",
+         Arrays.equals(recv.getBytes("Bytes"), "Bytes".getBytes()));
+      assertTrue("Char == c", recv.getChar("Char") == 'c');
+      assertTrue("Short == 314159", recv.getShort("Short") == 31415);
+      assertTrue("Int == 314159", recv.getInt("Int") == 314159);
+      assertTrue("Long == 3141592653589793238L",
+         recv.getLong("Long") == 3141592653589793238L);
+      assertTrue("Double == 3.1415926535897932384626433832795",
+         recv.getDouble("Double") == 3.1415926535897932384626433832795);
+      assertTrue("Float == true", recv.getFloat("Float") == 3.141f);
+      assertTrue("Object == 31415926535897932384626433832795",
+         recv.getObject("Object").equals("31415926535897932384626433832795"));
+      assertTrue("String == 31415926535897932384626433832795",
+         recv.getString("String").equals("31415926535897932384626433832795"));
+   }
+   public void testTextMessage() throws Exception
+   {
+      log.info("+++ testTextMessage");
+      String text = "A multiline text msg.\nSecond line.\n";
+      TextMessage sent = session.createTextMessage(text);
+      TextMessage recv = (TextMessage) sendRecMsg(sent);
+      log.debug("recv: "+recv);
+      assertTrue(recv.getText().equals(text));
+   }
+   public void testMessage() throws Exception
+   {
+      log.info("+++ testMessage");
+      Message sent = session.createMessage();
+      sent.setBooleanProperty("Boolean", true);
+      sent.setByteProperty("Byte", (byte) 1);
+      sent.setShortProperty("Short", (short) 31415);
+      sent.setIntProperty("Int", 314159);
+      sent.setLongProperty("Long", 3141592653589793238L);
+      sent.setDoubleProperty("Double", 3.1415926535897932384626433832795);
+      sent.setFloatProperty("Float", 3.141f);
+      sent.setObjectProperty("Object", "31415926535897932384626433832795");
+      sent.setStringProperty("String", "31415926535897932384626433832795");
+
+      Message recv = sendRecMsg(sent);
+      log.debug("recv: "+recv);
+      assertTrue("Boolean == true", recv.getBooleanProperty("Boolean") == true);
+      assertTrue("Byte == 1", recv.getByteProperty("Byte") == 1);
+      assertTrue("Short == 314159", recv.getShortProperty("Short") == 31415);
+      assertTrue("Int == 314159", recv.getIntProperty("Int") == 314159);
+      assertTrue("Long == 3141592653589793238L",
+         recv.getLongProperty("Long") == 3141592653589793238L);
+      assertTrue("Double == 3.1415926535897932384626433832795",
+         recv.getDoubleProperty("Double") == 3.1415926535897932384626433832795);
+      assertTrue("Float == true", recv.getFloatProperty("Float") == 3.141f);
+      assertTrue("Object == 31415926535897932384626433832795",
+         recv.getObjectProperty("Object").equals("31415926535897932384626433832795"));
+      assertTrue("String == 31415926535897932384626433832795",
+         recv.getStringProperty("String").equals("31415926535897932384626433832795"));
+   }
+   public void testBytesMessage() throws Exception
+   {
+      log.info("+++ testBytesMessage");
+      BytesMessage sent = session.createBytesMessage();
+      sent.writeBoolean(true);
+      sent.writeByte((byte) 1);
+      byte[] testBytes = "Bytes".getBytes();
+      sent.writeBytes(testBytes);
+      sent.writeChar('c');
+      sent.writeShort((short) 31415);
+      sent.writeInt(314159);
+      sent.writeLong(3141592653589793238L);
+      sent.writeDouble(3.1415926535897932384626433832795);
+      sent.writeFloat(3.141f);
+      sent.writeObject("31415926535897932384626433832795");
+      sent.writeUTF("31415926535897932384626433832795");
+
+      BytesMessage recv = (BytesMessage) sendRecMsg(sent);
+      log.debug("recv: "+recv);
+      assertTrue("Boolean == true", recv.readBoolean() == true);
+      assertTrue("Byte == 1", recv.readByte() == 1);
+      byte[] bytes = new byte[testBytes.length];
+      recv.readBytes(bytes); 
+      assertTrue("Bytes == Bytes[]",
+         Arrays.equals(bytes, testBytes));
+      assertTrue("Char == c", recv.readChar() == 'c');
+      assertTrue("Short == 314159", recv.readShort() == 31415);
+      assertTrue("Int == 314159", recv.readInt() == 314159);
+      assertTrue("Long == 3141592653589793238L",
+         recv.readLong() == 3141592653589793238L);
+      assertTrue("Double == 3.1415926535897932384626433832795",
+         recv.readDouble() == 3.1415926535897932384626433832795);
+      assertTrue("Float == true", recv.readFloat() == 3.141f);
+      assertTrue("Object == 31415926535897932384626433832795",
+         recv.readUTF().equals("31415926535897932384626433832795"));
+      assertTrue("String == 31415926535897932384626433832795",
+         recv.readUTF().equals("31415926535897932384626433832795"));
+   }
+   public void testObjectMessage() throws Exception
+   {
+      log.info("+++ testObjectMessage");
+      BigInteger data = new BigInteger("31415926535897932384626433832795", 10);
+      ObjectMessage sent = session.createObjectMessage(data);
+      ObjectMessage recv = (ObjectMessage) sendRecMsg(sent);
+      log.debug("recv: "+recv);
+      BigInteger data2 = (BigInteger) recv.getObject();
+      assertTrue("BigInteger == BigInteger2", data2.equals(data));
+   }
+   public void testStreamMessage() throws Exception
+   {
+      log.info("+++ testStreamMessage");
+      StreamMessage sent = session.createStreamMessage();
+      sent.writeBoolean(true);
+      sent.writeByte((byte) 1);
+      byte[] testBytes = "Bytes".getBytes();
+      sent.writeBytes(testBytes);
+      sent.writeChar('c');
+      sent.writeShort((short) 31415);
+      sent.writeInt(314159);
+      sent.writeLong(3141592653589793238L);
+      sent.writeDouble(3.1415926535897932384626433832795);
+      sent.writeFloat(3.141f);
+      sent.writeObject("31415926535897932384626433832795");
+      sent.writeString("31415926535897932384626433832795");
+
+      StreamMessage recv = (StreamMessage) sendRecMsg(sent);
+      log.debug("recv: "+recv);
+      assertTrue("Boolean == true", recv.readBoolean() == true);
+      assertTrue("Byte == 1", recv.readByte() == 1);
+      // Quirky spec behavior requires a read past the end of the byte[] field
+      byte[] bytes = new byte[testBytes.length];
+      recv.readBytes(bytes);
+      assertTrue(recv.readBytes(bytes) < 0);
+      assertTrue("Bytes == Bytes[]",
+         Arrays.equals(bytes, testBytes));
+      char c = recv.readChar();
+      assertTrue("Char == c", c == 'c');
+      assertTrue("Short == 314159", recv.readShort() == 31415);
+      assertTrue("Int == 314159", recv.readInt() == 314159);
+      assertTrue("Long == 3141592653589793238L",
+         recv.readLong() == 3141592653589793238L);
+      assertTrue("Double == 3.1415926535897932384626433832795",
+         recv.readDouble() == 3.1415926535897932384626433832795);
+      assertTrue("Float == true", recv.readFloat() == 3.141f);
+      assertTrue("Object == 31415926535897932384626433832795",
+         recv.readObject().equals("31415926535897932384626433832795"));
+      assertTrue("String == 31415926535897932384626433832795",
+         recv.readString().equals("31415926535897932384626433832795"));
+   }
+
+   protected void setUp() throws Exception
+   {
+      context = new InitialContext();
+      QueueConnectionFactory queueFactory = (QueueConnectionFactory) context.lookup(QUEUE_FACTORY);
+      queueConnection = queueFactory.createQueueConnection();
+      queueConnection.start();
+      session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+      Queue queue = (Queue) context.lookup(TEST_QUEUE);
+      sender = session.createSender(queue);
+      receiver = session.createReceiver(queue);
+
+      log.debug("Connection to jms established.");
+   }
+
+   protected void tearDown() throws Exception
+   {
+      sender.close();
+      receiver.close();
+      session.close();
+      queueConnection.close();
+   }
+
+   private Message sendRecMsg(Message in) throws Exception
+   {
+      sender.send(in, DeliveryMode.NON_PERSISTENT, 4, 0);
+      Message out = receiver.receive(5000);
+      return out;
+   }
+
+   public static junit.framework.Test suite() throws Exception
+   {
+       ClassLoader loader = Thread.currentThread().getContextClassLoader();
+       String resourceName = getJMSResourceRelativePathname("test-destinations-service.xml") ;
+
+       return getDeploySetup(MessageTypesUnitTestCase.class,
+               loader.getResource(resourceName).toString());
+   }
+
+}

Added: trunk/testsuite/src/main/org/jboss/test/jbossmessaging/test/MessagingRefactoringUnitTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/jbossmessaging/test/MessagingRefactoringUnitTestCase.java	2006-10-26 19:15:55 UTC (rev 57857)
+++ trunk/testsuite/src/main/org/jboss/test/jbossmessaging/test/MessagingRefactoringUnitTestCase.java	2006-10-26 19:20:36 UTC (rev 57858)
@@ -0,0 +1,99 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.test.jbossmessaging.test;
+
+
+import javax.jms.Queue;
+import javax.naming.InitialContext;
+
+import org.jboss.logging.Logger;
+
+import org.jboss.test.jbossmessaging.JMSTestCase;
+
+/**
+ * Concurrent delivery tests
+ *
+ * @author <a href="mailto:adrian at jboss.org>Adrian Brock</a>
+ * @version <tt>$Revision: 37406 $</tt>
+ */
+public class MessagingRefactoringUnitTestCase extends JMSTestCase
+{
+   static String QUEUE_NAME = "queue/RAQueue" ;
+   static String TOPIC_NAME = "topic/RATopic" ;
+   static String CONNECTIONFACTORY_NAME = "RAConnectionFactory" ;
+
+   private Logger log = Logger.getLogger(MessagingRefactoringUnitTestCase.class) ;
+
+   public MessagingRefactoringUnitTestCase(String name) throws Exception
+   {
+      super(name);
+   }
+
+    public void testDirectoryName() throws Exception {
+	String name = "Fred" ;
+	String prependName = JMSTestCase.getJMSResourceRelativePathname(name) ;
+	log.info("Resource name = " + prependName) ;
+    } 
+
+   public void testQueueCreation() throws Exception
+   {
+      try
+      {
+	  dumpJNDIContext("/queue") ;
+
+	  // make a call to JMSTestCase method
+	  log.info("Creating Queue " + QUEUE_NAME) ;
+	  createQueue(QUEUE_NAME) ;
+
+	  dumpJNDIContext("/queue") ;
+
+	  // verify that the queue has been created
+          log.info("Looking up Queue " + QUEUE_NAME) ;
+	  InitialContext ic = getInitialContext() ;
+	  Queue q = (Queue) ic.lookup(QUEUE_NAME) ;
+      } catch (Exception e) {
+	  e.printStackTrace() ;
+      }
+   }
+
+   public void testQueueDeletion() throws Exception
+   {
+      try
+      {
+	  dumpJNDIContext("/queue") ;
+
+	  // make a call to JMSTestCase method
+	  log.info("Deleting Queue " + QUEUE_NAME) ;
+	  deleteQueue(QUEUE_NAME) ;
+
+	  dumpJNDIContext("/queue") ;
+
+	  // verify that the queue has been created
+          log.info("Looking up Queue " + QUEUE_NAME) ;
+	  InitialContext ic = getInitialContext() ;
+	  Queue q = (Queue) ic.lookup(QUEUE_NAME) ;
+      } catch (Exception e) {
+	  e.printStackTrace() ;
+      }
+   }
+}
+

Added: trunk/testsuite/src/main/org/jboss/test/jbossmessaging/test/RollBackUnitTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/jbossmessaging/test/RollBackUnitTestCase.java	2006-10-26 19:15:55 UTC (rev 57857)
+++ trunk/testsuite/src/main/org/jboss/test/jbossmessaging/test/RollBackUnitTestCase.java	2006-10-26 19:20:36 UTC (rev 57858)
@@ -0,0 +1,737 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.test.jbossmessaging.test;
+
+import javax.jms.BytesMessage;
+import javax.jms.DeliveryMode;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueReceiver;
+import javax.jms.QueueSender;
+import javax.jms.QueueSession;
+import javax.jms.Session;
+import javax.jms.Topic;
+import javax.jms.TopicConnection;
+import javax.jms.TopicConnectionFactory;
+import javax.jms.TopicPublisher;
+import javax.jms.TopicSession;
+import javax.jms.TopicSubscriber;
+import javax.jms.Queue;
+import javax.naming.Context;
+
+import org.apache.log4j.Category;
+import org.jboss.test.jbossmessaging.JMSTestCase;
+
+/**
+ * Rollback tests
+ *
+ * @author <a href="mailto:richard.achmatowicz at jboss.com">Richard Achmatowicz</a>
+ * @author
+ * @version
+ */
+public class RollBackUnitTestCase extends JMSTestCase
+{
+
+   // Provider specific
+   static String TOPIC_FACTORY = "ConnectionFactory";
+
+   static String QUEUE_FACTORY = "ConnectionFactory";
+
+   static String TEST_QUEUE = "queue/testQueue";
+
+   static String TEST_TOPIC = "topic/testTopic";
+
+   static String TEST_DURABLE_TOPIC = "topic/testDurableTopic";
+
+   static byte[] PAYLOAD = new byte[10];
+
+   static Context context;
+
+   static QueueConnection queueConnection;
+
+   static TopicConnection topicConnection;
+
+   static TopicConnection topicDurableConnection;
+
+   /**
+    * Constructor the test
+    *
+    * @param name           Description of Parameter
+    * @exception Exception  Description of Exception
+    */
+   public RollBackUnitTestCase(String name) throws Exception
+   {
+      super(name);
+   }
+
+   /**
+    * #Description of the Method
+    *
+    * @param persistence    Description of Parameter
+    * @exception Exception  Description of Exception
+    */
+   public void runQueueSendRollBack(final int persistence, final boolean explicit) throws Exception
+   {
+      drainQueue();
+      final int iterationCount = getIterationCount();
+      final Category log = getLog();
+
+      Thread sendThread = new Thread()
+      {
+         public void run()
+         {
+            try
+            {
+               QueueSession session = queueConnection.createQueueSession(true, Session.AUTO_ACKNOWLEDGE);
+               Queue queue = (Queue) context.lookup(TEST_QUEUE);
+
+               QueueSender sender = session.createSender(queue);
+
+               BytesMessage message = session.createBytesMessage();
+               message.writeBytes(PAYLOAD);
+               message.setStringProperty("TEST_NAME", "runQueueSendRollback");
+               message.setIntProperty("TEST_PERSISTENCE", persistence);
+               message.setBooleanProperty("TEST_EXPLICIT", explicit);
+               
+               for (int i = 0; i < iterationCount; i++)
+               {
+                  sender.send(message, persistence, 4, 0);
+               }
+
+               if (explicit)
+                  session.rollback();
+               session.close();
+            }
+            catch (Exception e)
+            {
+               log.error("error", e);
+            }
+         }
+      };
+
+      sendThread.start();
+      sendThread.join();
+      assertTrue("Queue should be empty", drainQueue() == 0);
+   }
+
+   /**
+    * #Description of the Method
+    *
+    * @param persistence    Description of Parameter
+    * @exception Exception  Description of Exception
+    */
+   public void runTopicSendRollBack(final int persistence, final boolean explicit) throws Exception
+   {
+      drainQueue();
+      drainTopic();
+
+      final int iterationCount = getIterationCount();
+      final Category log = getLog();
+
+      Thread sendThread = new Thread()
+      {
+         public void run()
+         {
+            try
+            {
+
+               TopicSession session = topicConnection.createTopicSession(true, Session.AUTO_ACKNOWLEDGE);
+               Topic topic = (Topic) context.lookup(TEST_TOPIC);
+
+               TopicPublisher publisher = session.createPublisher(topic);
+
+               BytesMessage message = session.createBytesMessage();
+               message.writeBytes(PAYLOAD);
+               message.setStringProperty("TEST_NAME", "runTopicSendRollback");
+               message.setIntProperty("TEST_PERSISTENCE", persistence);
+               message.setBooleanProperty("TEST_EXPLICIT", explicit);
+
+               for (int i = 0; i < iterationCount; i++)
+               {
+                  publisher.publish(message, persistence, 4, 0);
+               }
+
+               session.close();
+            }
+            catch (Exception e)
+            {
+               log.error("error", e);
+            }
+         }
+      };
+
+      sendThread.start();
+      sendThread.join();
+      assertTrue("Topic should be empty", drainTopic() == 0);
+   }
+
+   /**
+    * #Description of the Method
+    *
+    * @param persistence    Description of Parameter
+    * @exception Exception  Description of Exception
+    */
+   public void runAsynchQueueReceiveRollBack(final int persistence, final boolean explicit) throws Exception
+   {
+      drainQueue();
+
+      final int iterationCount = getIterationCount();
+      final Category log = getLog();
+
+      Thread sendThread = new Thread()
+      {
+         public void run()
+         {
+            try
+            {
+               QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+               Queue queue = (Queue) context.lookup(TEST_QUEUE);
+
+               QueueSender sender = session.createSender(queue);
+
+               BytesMessage message = session.createBytesMessage();
+               message.writeBytes(PAYLOAD);
+               message.setStringProperty("TEST_NAME", "runAsynchQueueReceiveRollback");
+               message.setIntProperty("TEST_PERSISTENCE", persistence);
+               message.setBooleanProperty("TEST_EXPLICIT", explicit);
+
+               for (int i = 0; i < iterationCount; i++)
+               {
+                  sender.send(message, persistence, 4, 0);
+               }
+
+               session.close();
+            }
+            catch (Exception e)
+            {
+               log.error("error", e);
+            }
+         }
+      };
+
+      QueueSession session = queueConnection.createQueueSession(true, Session.AUTO_ACKNOWLEDGE);
+      Queue queue = (Queue) context.lookup(TEST_QUEUE);
+      QueueReceiver receiver = session.createReceiver(queue);
+
+      MyMessageListener listener = new MyMessageListener(iterationCount, log);
+
+      sendThread.start();
+      receiver.setMessageListener(listener);
+      queueConnection.start();
+      synchronized (listener)
+      {
+         if (listener.i < iterationCount)
+            listener.wait();
+      }
+      receiver.setMessageListener(null);
+
+      if (explicit)
+         session.rollback();
+      session.close();
+
+      queueConnection.stop();
+
+      sendThread.join();
+
+      assertTrue("Queue should be full", drainQueue() == iterationCount);
+
+   }
+
+   /**
+    * #Description of the Method
+    *
+    * @param persistence    Description of Parameter
+    * @exception Exception  Description of Exception
+    */
+   public void runAsynchTopicReceiveRollBack(final int persistence, final boolean explicit) throws Exception
+   {
+      drainQueue();
+      drainTopic();
+
+      final int iterationCount = getIterationCount();
+      final Category log = getLog();
+
+      Thread sendThread = new Thread()
+      {
+         public void run()
+         {
+            try
+            {
+
+               TopicSession session = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+               Topic topic = (Topic) context.lookup(TEST_TOPIC);
+
+               TopicPublisher publisher = session.createPublisher(topic);
+
+               waitForSynchMessage();
+
+               BytesMessage message = session.createBytesMessage();
+               message.writeBytes(PAYLOAD);
+               message.setStringProperty("TEST_NAME", "runAsynchTopicReceiveRollback");
+               message.setIntProperty("TEST_PERSISTENCE", persistence);
+               message.setBooleanProperty("TEST_EXPLICIT", explicit);
+
+               for (int i = 0; i < iterationCount; i++)
+               {
+                  publisher.publish(message, persistence, 4, 0);
+                  log.debug("Published message " + i);
+               }
+
+               session.close();
+            }
+            catch (Exception e)
+            {
+               log.error("error", e);
+            }
+         }
+      };
+
+      TopicSession session = topicConnection.createTopicSession(true, Session.AUTO_ACKNOWLEDGE);
+      Topic topic = (Topic) context.lookup(TEST_TOPIC);
+      TopicSubscriber subscriber = session.createSubscriber(topic);
+
+      MyMessageListener listener = new MyMessageListener(iterationCount, log);
+
+      queueConnection.start();
+      sendThread.start();
+      subscriber.setMessageListener(listener);
+      topicConnection.start();
+      sendSynchMessage();
+      getLog().debug("Waiting for all messages");
+      synchronized (listener)
+      {
+         if (listener.i < iterationCount)
+            listener.wait();
+      }
+      getLog().debug("Got all messages");
+      subscriber.setMessageListener(null);
+
+      if (explicit)
+         session.rollback();
+      session.close();
+
+      sendThread.join();
+      topicConnection.stop();
+      queueConnection.stop();
+      assertTrue("Topic should be empty", drainTopic() == 0);
+   }
+
+   /**
+    * #Description of the Method
+    *
+    * @param persistence    Description of Parameter
+    * @exception Exception  Description of Exception
+    */
+   public void runAsynchDurableTopicReceiveRollBack(final int persistence, final boolean explicit) throws Exception
+   {
+      getLog().debug("====> runAsynchDurableTopicReceiveRollBack persistence=" + persistence + " explicit=" + explicit);
+      drainQueue();
+      drainDurableTopic();
+
+      final int iterationCount = getIterationCount();
+      final Category log = getLog();
+
+      Thread sendThread = new Thread()
+      {
+         public void run()
+         {
+            try
+            {
+
+               TopicSession session = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+               Topic topic = (Topic) context.lookup(TEST_DURABLE_TOPIC);
+
+               TopicPublisher publisher = session.createPublisher(topic);
+
+               waitForSynchMessage();
+
+               BytesMessage message = session.createBytesMessage();
+               message.writeBytes(PAYLOAD);
+               message.setStringProperty("TEST_NAME", "runAsynchDurableTopicReceiveRollback");
+               message.setIntProperty("TEST_PERSISTENCE", persistence);
+               message.setBooleanProperty("TEST_EXPLICIT", explicit);
+
+               for (int i = 0; i < iterationCount; i++)
+               {
+                  publisher.publish(message, persistence, 4, 0);
+                  log.debug("Published message " + i);
+               }
+
+               session.close();
+            }
+            catch (Exception e)
+            {
+               log.error("error", e);
+            }
+         }
+      };
+
+      TopicSession session = topicDurableConnection.createTopicSession(true, Session.AUTO_ACKNOWLEDGE);
+      Topic topic = (Topic) context.lookup(TEST_DURABLE_TOPIC);
+      TopicSubscriber subscriber = session.createDurableSubscriber(topic, "test");
+      try
+      {
+         MyMessageListener listener = new MyMessageListener(iterationCount, log);
+
+         queueConnection.start();
+         sendThread.start();
+         subscriber.setMessageListener(listener);
+         topicDurableConnection.start();
+         sendSynchMessage();
+         getLog().debug("Waiting for all messages");
+         synchronized (listener)
+         {
+            if (listener.i < iterationCount)
+               listener.wait();
+         }
+         getLog().debug("Got all messages");
+         subscriber.setMessageListener(null);
+         subscriber.close();
+
+         if (explicit)
+            session.rollback();
+         session.close();
+
+         sendThread.join();
+         topicDurableConnection.stop();
+         queueConnection.stop();
+         assertTrue("Topic should be full", drainDurableTopic() == iterationCount);
+      }
+      finally
+      {
+         removeDurableSubscription();
+      }
+   }
+
+   /**
+    * A unit test for JUnit
+    *
+    * @exception Exception  Description of Exception
+    */
+   public void testQueueSendRollBack() throws Exception
+   {
+
+      getLog().debug("Starting AsynchQueueSendRollBack test");
+
+      runQueueSendRollBack(DeliveryMode.NON_PERSISTENT, false);
+      runQueueSendRollBack(DeliveryMode.PERSISTENT, false);
+      runQueueSendRollBack(DeliveryMode.NON_PERSISTENT, true);
+      runQueueSendRollBack(DeliveryMode.PERSISTENT, true);
+
+      getLog().debug("AsynchQueueSendRollBack passed");
+   }
+
+   /**
+    * A unit test for JUnit
+    *
+    * @exception Exception  Description of Exception
+    */
+   public void testAsynchQueueReceiveBack() throws Exception
+   {
+
+      getLog().debug("Starting AsynchQueueReceiveRollBack test");
+
+      runAsynchQueueReceiveRollBack(DeliveryMode.NON_PERSISTENT, false);
+      runAsynchQueueReceiveRollBack(DeliveryMode.PERSISTENT, false);
+      runQueueSendRollBack(DeliveryMode.NON_PERSISTENT, true);
+      runQueueSendRollBack(DeliveryMode.PERSISTENT, true);
+
+      getLog().debug("AsynchQueueReceiveRollBack passed");
+   }
+
+   /**
+    * A unit test for JUnit
+    *
+    * @exception Exception  Description of Exception
+    */
+   public void testTopicSendRollBack() throws Exception
+   {
+
+      getLog().debug("Starting AsynchTopicSendRollBack test");
+
+      runTopicSendRollBack(DeliveryMode.NON_PERSISTENT, false);
+      runTopicSendRollBack(DeliveryMode.PERSISTENT, false);
+      runTopicSendRollBack(DeliveryMode.NON_PERSISTENT, true);
+      runTopicSendRollBack(DeliveryMode.PERSISTENT, true);
+
+      getLog().debug("AsynchTopicSendRollBack passed");
+   }
+
+   /**
+    * A unit test for JUnit
+    *
+    * @exception Exception  Description of Exception
+    */
+   public void testAsynchTopicReceiveRollBack() throws Exception
+   {
+
+      getLog().debug("Starting AsynchTopicReceiveRollBack test");
+
+      runAsynchTopicReceiveRollBack(DeliveryMode.NON_PERSISTENT, false);
+      runAsynchTopicReceiveRollBack(DeliveryMode.PERSISTENT, false);
+      runAsynchTopicReceiveRollBack(DeliveryMode.NON_PERSISTENT, true);
+      runAsynchTopicReceiveRollBack(DeliveryMode.PERSISTENT, true);
+
+      getLog().debug("AsynchTopicReceiveRollBack passed");
+   }
+
+   /**
+    * A unit test for JUnit
+    *
+    * @exception Exception  Description of Exception
+    */
+   public void testAsynchDurableTopicReceiveRollBack() throws Exception
+   {
+
+      getLog().debug("Starting AsynchDurableTopicReceiveRollBack test");
+
+      runAsynchDurableTopicReceiveRollBack(DeliveryMode.NON_PERSISTENT, false);
+      runAsynchDurableTopicReceiveRollBack(DeliveryMode.PERSISTENT, false);
+      runAsynchDurableTopicReceiveRollBack(DeliveryMode.NON_PERSISTENT, true);
+      runAsynchDurableTopicReceiveRollBack(DeliveryMode.PERSISTENT, true);
+
+      getLog().debug("AsynchDurableTopicReceiveRollBack passed");
+   }
+
+   /**
+    * A unit test for JUnit
+    *
+    * @exception Exception  Description of Exception
+    */
+   public void removeDurableSubscription() throws Exception
+   {
+
+      TopicSession session = topicDurableConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+      session.unsubscribe("test");
+   }
+
+   /**
+    * The JUnit setup method
+    *
+    * @exception Exception  Description of Exception
+    */
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+      
+      getLog().debug("START TEST " + getName());
+      context = getInitialContext();
+
+      QueueConnectionFactory queueFactory = (QueueConnectionFactory) context.lookup(QUEUE_FACTORY);
+      queueConnection = queueFactory.createQueueConnection();
+
+      TopicConnectionFactory topicFactory = (TopicConnectionFactory) context.lookup(TOPIC_FACTORY);
+      topicConnection = topicFactory.createTopicConnection();
+      topicDurableConnection = topicFactory.createTopicConnection("john", "needle");
+
+      getLog().debug("Connection to JBossMQ established.");
+   }
+   
+   protected void tearDown() throws Exception
+   {
+      try
+      {
+         if (topicDurableConnection != null)
+         {
+            topicDurableConnection.close();
+            topicDurableConnection = null;
+         }
+      }
+      catch (JMSException ignored)
+      {
+      }
+      try
+      {
+         if (topicConnection != null)
+         {
+            topicConnection.close();
+            topicConnection = null;
+         }
+      }
+      catch (JMSException ignored)
+      {
+      }
+      try
+      {
+         if (queueConnection != null)
+         {
+            queueConnection.close();
+            queueConnection = null;
+         }
+      }
+      catch (JMSException ignored)
+      {
+      }
+      super.tearDown();
+   }
+
+   // Emptys out all the messages in a queue
+   private int drainQueue() throws Exception
+   {
+      getLog().debug("Draining Queue");
+      queueConnection.start();
+
+      QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+      Queue queue = (Queue) context.lookup(TEST_QUEUE);
+
+      QueueReceiver receiver = session.createReceiver(queue);
+      Message message = receiver.receive(50);
+      int c = 0;
+      while (message != null)
+      {
+         c++;
+         message = receiver.receive(50);
+      }
+
+      getLog().debug("  Drained " + c + " messages from the queue");
+
+      session.close();
+
+      queueConnection.stop();
+
+      return c;
+   }
+
+   // Emptys out all the messages in a topic
+   private int drainTopic() throws Exception
+   {
+      getLog().debug("Draining Topic");
+      topicConnection.start();
+
+      final TopicSession session = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+      Topic topic = (Topic) context.lookup(TEST_TOPIC);
+      TopicSubscriber subscriber = session.createSubscriber(topic);
+
+      Message message = subscriber.receive(50);
+      int c = 0;
+      while (message != null)
+      {
+         c++;
+         message = subscriber.receive(50);
+      }
+
+      getLog().debug("  Drained " + c + " messages from the topic");
+
+      session.close();
+
+      topicConnection.stop();
+
+      return c;
+   }
+
+   // Emptys out all the messages in a durable topic
+   private int drainDurableTopic() throws Exception
+   {
+      getLog().debug("Draining Durable Topic");
+      topicDurableConnection.start();
+
+      final TopicSession session = topicDurableConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+      Topic topic = (Topic) context.lookup(TEST_DURABLE_TOPIC);
+      TopicSubscriber subscriber = session.createDurableSubscriber(topic, "test");
+
+      Message message = subscriber.receive(50);
+      int c = 0;
+      while (message != null)
+      {
+         c++;
+         message = subscriber.receive(50);
+      }
+
+      getLog().debug("  Drained " + c + " messages from the durable topic");
+
+      session.close();
+
+      topicDurableConnection.stop();
+
+      return c;
+   }
+
+   private void waitForSynchMessage() throws Exception
+   {
+      getLog().debug("Waiting for Synch Message");
+      QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+      Queue queue = (Queue) context.lookup(TEST_QUEUE);
+
+      QueueReceiver receiver = session.createReceiver(queue);
+      receiver.receive();
+      session.close();
+      getLog().debug("Got Synch Message");
+   }
+
+   private void sendSynchMessage() throws Exception
+   {
+      getLog().debug("Sending Synch Message");
+      QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+      Queue queue = (Queue) context.lookup(TEST_QUEUE);
+
+      QueueSender sender = session.createSender(queue);
+
+      Message message = session.createMessage();
+      sender.send(message);
+
+      session.close();
+      getLog().debug("Sent Synch Message");
+   }
+
+   public class MyMessageListener implements MessageListener
+   {
+      public int i = 0;
+
+      public int iterationCount;
+
+      public Category log;
+
+      public MyMessageListener(int iterationCount, Category log)
+      {
+         this.iterationCount = iterationCount;
+         this.log = log;
+      }
+
+      public void onMessage(Message message)
+      {
+         synchronized (this)
+         {
+            i++;
+            log.debug("Got message " + i);
+            if (i >= iterationCount)
+               this.notify();
+         }
+      }
+   }
+
+   public int getIterationCount()
+   {
+      return 5;
+   }
+
+   public static junit.framework.Test suite() throws Exception
+   {
+       ClassLoader loader = Thread.currentThread().getContextClassLoader();
+       String resourceName = getJMSResourceRelativePathname("test-destinations-service.xml") ;
+
+       return getDeploySetup(RollBackUnitTestCase.class,
+               loader.getResource(resourceName).toString());
+   }
+}

Added: trunk/testsuite/src/main/org/jboss/test/jbossmessaging/test/SessionCloseStressTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/jbossmessaging/test/SessionCloseStressTestCase.java	2006-10-26 19:15:55 UTC (rev 57857)
+++ trunk/testsuite/src/main/org/jboss/test/jbossmessaging/test/SessionCloseStressTestCase.java	2006-10-26 19:20:36 UTC (rev 57858)
@@ -0,0 +1,333 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.jbossmessaging.test;
+
+import java.util.Random;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageListener;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueSession;
+import javax.jms.Session;
+import javax.naming.Context;
+
+import junit.framework.Test;
+
+import org.jboss.test.jbossmessaging.JMSTestCase;
+
+/**
+ * Tests for receiving while closing the session
+ *
+ * @author <a href="mailto:richard.achmatowicz at jboss.com">Richard Achmatowicz</a>
+ * @author <a href="mailto:adrian at jboss.org>Adrian Brock</a>
+ * @version <tt>$Revision: 42018 $</tt>
+ */
+public class SessionCloseStressTestCase extends JMSTestCase
+{
+   static String QUEUE_FACTORY = "ConnectionFactory";
+   static String QUEUE = "queue/testQueue";
+
+   QueueConnection queueConnection;
+   Queue queue;
+   
+   public SessionCloseStressTestCase(String name) throws Exception
+   {
+      super(name);
+   }
+
+   public abstract class TestRunnable implements Runnable
+   {
+      public Throwable error = null;
+      
+      public abstract void doRun() throws Exception;
+      
+      public void run()
+      {
+         try
+         {
+            doRun();
+         }
+         catch (Throwable t)
+         {
+            log.error("Error in " + Thread.currentThread(), t);
+            error = t;
+         }
+      }
+   }
+   
+   public class SessionRunnable extends TestRunnable
+   {
+      MessageConsumer consumer;
+      
+      int received = 0;
+      
+      public void doRun() throws Exception
+      {
+         QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+         MessageProducer producer = session.createProducer(queue);
+         for (int i = 0; i < getIterationCount(); ++i)
+         {
+            Message message = session.createTextMessage("" + i);
+            producer.send(message);
+         }
+         producer.close();
+         consumer = session.createConsumer(queue);
+         waitForMessages();
+         session.close();
+      }
+      
+      public synchronized MessageConsumer getConsumer() throws Exception
+      {
+         while (true)
+         {
+            if (consumer != null)
+               return consumer;
+            wait();
+         }
+      }
+      
+      public synchronized void incReceived()
+      {
+         ++received;
+         notifyAll();
+      }
+      
+      public synchronized void waitForMessages() throws Exception
+      {
+         notifyAll();
+         int target = new Random().nextInt(getIterationCount());
+         while (received < target)
+            wait();
+      }
+   }
+   
+   public class ReceiverRunnable extends TestRunnable
+   {
+      SessionRunnable sessionRunnable;
+      
+      public ReceiverRunnable(SessionRunnable sessionRunnable)
+      {
+         this.sessionRunnable = sessionRunnable;
+      }
+      
+      public void doRun() throws Exception
+      {
+         MessageConsumer consumer = sessionRunnable.getConsumer();
+         try
+         {
+            while (true)
+            {
+               consumer.receive();
+               sessionRunnable.incReceived();
+            }
+         }
+         catch (JMSException expected)
+         {
+            if (expected.getMessage().indexOf("closed") == -1)
+               throw expected;
+         }
+      }
+   }
+   
+   public class ReceiverNoWaitRunnable extends TestRunnable
+   {
+      SessionRunnable sessionRunnable;
+      
+      public ReceiverNoWaitRunnable(SessionRunnable sessionRunnable)
+      {
+         this.sessionRunnable = sessionRunnable;
+      }
+      
+      public void doRun() throws Exception
+      {
+         MessageConsumer consumer = sessionRunnable.getConsumer();
+         try
+         {
+            while (true)
+            {
+               if (consumer.receiveNoWait() != null)
+                  sessionRunnable.incReceived();
+            }
+         }
+         catch (JMSException expected)
+         {
+            if (expected.getMessage().indexOf("closed") == -1)
+               throw expected;
+         }
+      }
+   }
+   
+   public class ReceiverMessageListenerRunnable extends TestRunnable implements MessageListener
+   {
+      SessionRunnable sessionRunnable;
+      
+      public ReceiverMessageListenerRunnable(SessionRunnable sessionRunnable)
+      {
+         this.sessionRunnable = sessionRunnable;
+      }
+      
+      public void onMessage(Message message)
+      {
+         sessionRunnable.incReceived();
+      }
+      
+      public void doRun() throws Exception
+      {
+         MessageConsumer consumer = sessionRunnable.getConsumer();
+         try
+         {
+            consumer.setMessageListener(this);
+         }
+         catch (JMSException expected)
+         {
+            if (expected.getMessage().indexOf("closed") == -1)
+               throw expected;
+         }
+      }
+   }
+   
+   public void testSessionCloseCompetesWithReceive() throws Exception
+   {
+      connect();
+      try
+      {
+         for (int i = 0; i < getThreadCount(); ++i)
+         {
+            SessionRunnable sessionRunnable = new SessionRunnable(); 
+            Thread sessionThread = new Thread(sessionRunnable, "Session");
+            Thread consumerThread = new Thread(new ReceiverRunnable(sessionRunnable), "Consumer");
+            consumerThread.start();
+            sessionThread.start();
+            sessionThread.join();
+            consumerThread.join();
+            assertNull(sessionRunnable.error);
+
+            // Drain the queue
+            QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+            MessageConsumer consumer = session.createConsumer(queue);
+            while (consumer.receiveNoWait() != null);
+            session.close();
+         }
+      }
+      finally
+      {
+         disconnect();
+      }
+   }
+   
+   public void testSessionCloseCompetesWithReceiveNoWait() throws Exception
+   {
+      connect();
+      try
+      {
+         for (int i = 0; i < getThreadCount(); ++i)
+         {
+            SessionRunnable sessionRunnable = new SessionRunnable(); 
+            Thread sessionThread = new Thread(sessionRunnable, "Session");
+            Thread consumerThread = new Thread(new ReceiverNoWaitRunnable(sessionRunnable), "Consumer");
+            consumerThread.start();
+            sessionThread.start();
+            sessionThread.join();
+            consumerThread.join();
+            assertNull(sessionRunnable.error);
+
+            // Drain the queue
+            QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+            MessageConsumer consumer = session.createConsumer(queue);
+            while (consumer.receiveNoWait() != null);
+            session.close();
+         }
+      }
+      finally
+      {
+         disconnect();
+      }
+   }
+   
+   public void testSessionCloseCompetesWithMessageListener() throws Exception
+   {
+      connect();
+      try
+      {
+         for (int i = 0; i < getThreadCount(); ++i)
+         {
+            SessionRunnable sessionRunnable = new SessionRunnable(); 
+            Thread sessionThread = new Thread(sessionRunnable, "Session");
+            Thread consumerThread = new Thread(new ReceiverMessageListenerRunnable(sessionRunnable), "Consumer");
+            consumerThread.start();
+            sessionThread.start();
+            sessionThread.join();
+            consumerThread.join();
+            assertNull(sessionRunnable.error);
+
+            // Drain the queue
+            QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+            MessageConsumer consumer = session.createConsumer(queue);
+            while (consumer.receiveNoWait() != null);
+            session.close();
+         }
+      }
+      finally
+      {
+         disconnect();
+      }
+   }
+
+   protected void connect() throws Exception
+   {
+      Context context = getInitialContext();
+      queue = (Queue) context.lookup(QUEUE);
+      QueueConnectionFactory queueFactory = (QueueConnectionFactory) context.lookup(QUEUE_FACTORY);
+      queueConnection = queueFactory.createQueueConnection();
+      queueConnection.start();
+
+      getLog().debug("Connection established.");
+   }
+
+   protected void disconnect()
+   {
+      try
+      {
+         if (queueConnection != null)
+            queueConnection.close();
+      }
+      catch (Exception ignored)
+      {
+      }
+
+      getLog().debug("Connection closed.");
+   }
+
+   public static Test suite() throws Exception
+   {
+       ClassLoader loader = Thread.currentThread().getContextClassLoader();
+       String resourceName = getJMSResourceRelativePathname("tests-destinations-service.xml") ;
+
+       return getDeploySetup(SessionCloseStressTestCase.class,
+               loader.getResource(resourceName).toString());
+   }
+}

Modified: trunk/testsuite/src/resources/jbossmessaging/provider.properties
===================================================================
--- trunk/testsuite/src/resources/jbossmessaging/provider.properties	2006-10-26 19:15:55 UTC (rev 57857)
+++ trunk/testsuite/src/resources/jbossmessaging/provider.properties	2006-10-26 19:20:36 UTC (rev 57858)
@@ -28,8 +28,7 @@
 ##
 
 jms.provider.admin.class = org.jboss.test.jbossmessaging.JBossMessagingAdmin
-#jms.provider.admin.class = org.objectweb.jtests.providers.admin.JoramAdmin
-#jms.provider.admin.class = org.objectweb.jtests.providers.admin.AshnaMQAdmin
-#jms.provider.admin.class = org.objectweb.jtests.providers.admin.FioranoMQAdmin
-#jms.provider.admin.class = org.objectweb.jtests.providers.admin.PramatiAdmin
-#jms.provider.admin.class = org.objectweb.jtests.providers.admin.SwiftMQAdmin
+jms.provider.resources.dir = jbossmessaging
+#jms.provider.admin.class = org.jboss.test.jbossmq.JBossMQAdmin
+#jms.provider.resources.dir = jbossmq
+

Added: trunk/testsuite/src/resources/jbossmessaging/test-destinations-service.xml
===================================================================
--- trunk/testsuite/src/resources/jbossmessaging/test-destinations-service.xml	2006-10-26 19:15:55 UTC (rev 57857)
+++ trunk/testsuite/src/resources/jbossmessaging/test-destinations-service.xml	2006-10-26 19:20:36 UTC (rev 57858)
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<server>
+
+  <loader-repository>jboss.messaging:loader=ScopedLoaderRepository
+    <loader-repository-config>java2ParentDelegation=false</loader-repository-config>
+  </loader-repository>
+
+  <mbean code="org.jboss.jms.server.destination.Topic"
+         name="jboss.messaging.destination:service=Topic,name=testTopic"
+         xmbean-dd="xmdesc/Topic-xmbean.xml">
+     <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+     <attribute name="SecurityConfig">
+        <security>
+           <role name="guest" read="true" write="true"/>
+           <role name="publisher" read="true" write="true" create="false"/>
+           <role name="durpublisher" read="true" write="true" create="true"/>
+        </security>
+     </attribute>
+  </mbean>
+
+  <mbean code="org.jboss.jms.server.destination.Topic"
+         name="jboss.messaging.destination:service=Topic,name=securedTopic"
+         xmbean-dd="xmdesc/Topic-xmbean.xml">
+     <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+     <attribute name="SecurityConfig">
+        <security>
+           <role name="publisher" read="true" write="true" create="false"/>
+        </security>
+     </attribute>
+  </mbean>
+
+  <mbean code="org.jboss.jms.server.destination.Topic"
+         name="jboss.messaging.destination:service=Topic,name=testDurableTopic"
+         xmbean-dd="xmdesc/Topic-xmbean.xml">
+     <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+     <attribute name="SecurityConfig">
+        <security>
+           <role name="guest" read="true" write="true"/>
+           <role name="publisher" read="true" write="true" create="false"/>
+           <role name="durpublisher" read="true" write="true" create="true"/>
+        </security>
+     </attribute>
+  </mbean>
+
+
+  <mbean code="org.jboss.jms.server.destination.Queue"
+         name="jboss.messaging.destination:service=Queue,name=testQueue"
+         xmbean-dd="xmdesc/Queue-xmbean.xml">
+     <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+     <attribute name="SecurityConfig">
+        <security>
+           <role name="guest" read="true" write="true"/>
+           <role name="publisher" read="true" write="true" create="false"/>
+           <role name="noacc" read="false" write="false" create="false"/>
+        </security>
+     </attribute>
+  </mbean>
+
+</server>




More information about the jboss-cvs-commits mailing list