[hornetq-commits] JBoss hornetq SVN: r8101 - trunk/tests/src/org/hornetq/tests/integration/jms.

do-not-reply at jboss.org do-not-reply at jboss.org
Wed Oct 14 04:59:08 EDT 2009


Author: jmesnil
Date: 2009-10-14 04:59:08 -0400 (Wed, 14 Oct 2009)
New Revision: 8101

Modified:
   trunk/tests/src/org/hornetq/tests/integration/jms/ManualReconnectionToSingleServerTest.java
Log:
ensure JMS connections are properly closed

Modified: trunk/tests/src/org/hornetq/tests/integration/jms/ManualReconnectionToSingleServerTest.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/integration/jms/ManualReconnectionToSingleServerTest.java	2009-10-13 21:41:29 UTC (rev 8100)
+++ trunk/tests/src/org/hornetq/tests/integration/jms/ManualReconnectionToSingleServerTest.java	2009-10-14 08:59:08 UTC (rev 8101)
@@ -31,6 +31,7 @@
 import static org.hornetq.core.client.impl.ClientSessionFactoryImpl.DEFAULT_SCHEDULED_THREAD_POOL_MAX_SIZE;
 import static org.hornetq.core.client.impl.ClientSessionFactoryImpl.DEFAULT_THREAD_POOL_MAX_SIZE;
 import static org.hornetq.core.client.impl.ClientSessionFactoryImpl.DEFAULT_USE_GLOBAL_POOLS;
+import static org.hornetq.tests.util.RandomUtil.randomString;
 
 import java.util.ArrayList;
 import java.util.Date;
@@ -45,8 +46,8 @@
 import javax.jms.MessageConsumer;
 import javax.jms.MessageListener;
 import javax.jms.MessageProducer;
+import javax.jms.Queue;
 import javax.jms.Session;
-import javax.jms.Topic;
 import javax.naming.Context;
 
 import org.hornetq.core.config.Configuration;
@@ -63,9 +64,6 @@
 import org.hornetq.utils.Pair;
 
 /**
- * Connection tests. Contains all connection tests, except tests relating to closing a connection,
- * which go to ConnectionClosedTest.
- *
  * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
  */
 public class ManualReconnectionToSingleServerTest extends UnitTestCase
@@ -121,7 +119,7 @@
 
    private InVMContext context;
 
-   private final String topicName = "my-topic";
+   private final String queueName = randomString();
 
    // Static --------------------------------------------------------
 
@@ -157,7 +155,7 @@
          {
             killServer();
             Thread.sleep(5000);
-            restartServer();
+            startServer();
             afterRestart = true;
          }
       }
@@ -176,15 +174,7 @@
       log.info("That took " + (end - start));
       
       //Make sure it doesn't pass by just timing out on blocking send
-      assertTrue(end - start < callTimeout);
-      
-      System.gc();
-      System.gc();
-      System.gc();
-      System.gc();
-      
-      Thread.sleep(30000);
-
+      assertTrue(end - start < callTimeout);      
    }
 
    // Package protected ---------------------------------------------
@@ -204,13 +194,7 @@
       server.start();
 
       serverManager = new JMSServerManagerImpl(server);
-      context = new InVMContext();
-      serverManager.setContext(context);
-      serverManager.start();
-      serverManager.activated();
-      
-      serverManager.createTopic(topicName, topicName);
-      registerConnectionFactory();
+      startServer();
    }
 
    @Override
@@ -225,24 +209,27 @@
       connection = null;
 
       super.tearDown();
+      
+      System.gc();
    }
 
    // Private -------------------------------------------------------
 
    // Inner classes -------------------------------------------------
 
-   private void restartServer() throws Exception
+   private void startServer() throws Exception
    {
       serverManager.start();
       serverManager.activated();
       context = new InVMContext();
       serverManager.setContext(context);      
-      serverManager.createTopic(topicName, topicName);
+      serverManager.createQueue(queueName, queueName, null, false);
       registerConnectionFactory();
    }
 
    private void killServer() throws Exception
    {
+      context = null;
       serverManager.stop();
    }
 
@@ -294,7 +281,7 @@
 
    protected void disconnect()
    {
-      log.info("calling disocnnect");
+      log.info("calling disconnect");
       if (connection == null)
       {
          log.info("connection is null");
@@ -319,14 +306,18 @@
    {
       try
       {
+         if (context == null)
+         {
+            return;
+         }
          Context initialContext = context;
-         Topic topic;
+         Queue queue;
          ConnectionFactory cf;
          while (true)
          {            
             try
             {
-               topic = (Topic)initialContext.lookup(topicName);
+               queue = (Queue)initialContext.lookup(queueName);
                cf = (ConnectionFactory)initialContext.lookup("/cf");
                break;
             }
@@ -339,16 +330,26 @@
          connection = cf.createConnection();
          connection.setExceptionListener(exceptionListener);
          session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-         producer = session.createProducer(topic);
+         producer = session.createProducer(queue);
          System.out.println("creating consumer");
-         consumer = session.createConsumer(topic);
+         consumer = session.createConsumer(queue);
          consumer.setMessageListener(listener);
          connection.start();
          System.out.println("started new connection");
       }
       catch (Exception e)
       {
-         e.printStackTrace();
+         if (connection != null)
+         {
+            try
+            {
+               connection.close();
+            }
+            catch (JMSException e1)
+            {
+               e1.printStackTrace();
+            }
+         }
       }
    }
 }



More information about the hornetq-commits mailing list