From do-not-reply at jboss.org Wed Oct 14 04:59:08 2009 Content-Type: multipart/mixed; boundary="===============7141095304318296540==" MIME-Version: 1.0 From: do-not-reply at jboss.org To: hornetq-commits at lists.jboss.org Subject: [hornetq-commits] JBoss hornetq SVN: r8101 - trunk/tests/src/org/hornetq/tests/integration/jms. Date: Wed, 14 Oct 2009 04:59:08 -0400 Message-ID: <200910140859.n9E8x80Y021501@svn01.web.mwc.hst.phx2.redhat.com> --===============7141095304318296540== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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/ManualReconnectionToSi= ngleServerTest.java Log: ensure JMS connections are properly closed Modified: trunk/tests/src/org/hornetq/tests/integration/jms/ManualReconnect= ionToSingleServerTest.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/tests/src/org/hornetq/tests/integration/jms/ManualReconnectionToS= ingleServerTest.java 2009-10-13 21:41:29 UTC (rev 8100) +++ trunk/tests/src/org/hornetq/tests/integration/jms/ManualReconnectionToS= ingleServerTest.java 2009-10-14 08:59:08 UTC (rev 8101) @@ -31,6 +31,7 @@ import static org.hornetq.core.client.impl.ClientSessionFactoryImpl.DEFAUL= T_SCHEDULED_THREAD_POOL_MAX_SIZE; import static org.hornetq.core.client.impl.ClientSessionFactoryImpl.DEFAUL= T_THREAD_POOL_MAX_SIZE; import static org.hornetq.core.client.impl.ClientSessionFactoryImpl.DEFAUL= T_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 Jeff Mesnil */ public class ManualReconnectionToSingleServerTest extends UnitTestCase @@ -121,7 +119,7 @@ = private InVMContext context; = - private final String topicName =3D "my-topic"; + private final String queueName =3D randomString(); = // Static -------------------------------------------------------- = @@ -157,7 +155,7 @@ { killServer(); Thread.sleep(5000); - restartServer(); + startServer(); afterRestart =3D 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 =3D new JMSServerManagerImpl(server); - context =3D new InVMContext(); - serverManager.setContext(context); - serverManager.start(); - serverManager.activated(); - = - serverManager.createTopic(topicName, topicName); - registerConnectionFactory(); + startServer(); } = @Override @@ -225,24 +209,27 @@ connection =3D null; = super.tearDown(); + = + System.gc(); } = // Private ------------------------------------------------------- = // Inner classes ------------------------------------------------- = - private void restartServer() throws Exception + private void startServer() throws Exception { serverManager.start(); serverManager.activated(); context =3D new InVMContext(); serverManager.setContext(context); = - serverManager.createTopic(topicName, topicName); + serverManager.createQueue(queueName, queueName, null, false); registerConnectionFactory(); } = private void killServer() throws Exception { + context =3D null; serverManager.stop(); } = @@ -294,7 +281,7 @@ = protected void disconnect() { - log.info("calling disocnnect"); + log.info("calling disconnect"); if (connection =3D=3D null) { log.info("connection is null"); @@ -319,14 +306,18 @@ { try { + if (context =3D=3D null) + { + return; + } Context initialContext =3D context; - Topic topic; + Queue queue; ConnectionFactory cf; while (true) { = try { - topic =3D (Topic)initialContext.lookup(topicName); + queue =3D (Queue)initialContext.lookup(queueName); cf =3D (ConnectionFactory)initialContext.lookup("/cf"); break; } @@ -339,16 +330,26 @@ connection =3D cf.createConnection(); connection.setExceptionListener(exceptionListener); session =3D connection.createSession(false, Session.AUTO_ACKNOWLE= DGE); - producer =3D session.createProducer(topic); + producer =3D session.createProducer(queue); System.out.println("creating consumer"); - consumer =3D session.createConsumer(topic); + consumer =3D session.createConsumer(queue); consumer.setMessageListener(listener); connection.start(); System.out.println("started new connection"); } catch (Exception e) { - e.printStackTrace(); + if (connection !=3D null) + { + try + { + connection.close(); + } + catch (JMSException e1) + { + e1.printStackTrace(); + } + } } } } --===============7141095304318296540==--