Author: borges
Date: 2011-12-05 09:44:39 -0500 (Mon, 05 Dec 2011)
New Revision: 11834
Modified:
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/client/JMSMessageCounterTest.java
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/client/ConnectionTest.java
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/client/CreateQueueTest.java
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/client/ExpiryMessageTest.java
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/client/MessageTest.java
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/client/PreACKJMSTest.java
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/client/ReceiveNoWaitTest.java
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/client/TextMessageTest.java
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/connection/CloseConnectionFactoryOnGCest.java
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/connection/CloseConnectionOnGCTest.java
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/consumer/ConsumerTest.java
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/divert/DivertAndACKClientTest.java
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/largemessage/JMSLargeMessageTest.java
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/util/JMSTestBase.java
Log:
Move closing of resources to tearDown()
Modified:
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/client/JMSMessageCounterTest.java
===================================================================
---
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/client/JMSMessageCounterTest.java 2011-12-05
14:25:39 UTC (rev 11833)
+++
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/client/JMSMessageCounterTest.java 2011-12-05
14:44:39 UTC (rev 11834)
@@ -30,59 +30,45 @@
public class JMSMessageCounterTest extends JMSTestBase
{
+ @Override
protected boolean usePersistence()
{
return true;
}
-
+
public void testMessageCounter() throws Exception
{
-
- try
- {
Connection conn = cf.createConnection();
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
+
Queue queue = createQueue(true, "Test");
-
+
MessageProducer producer = sess.createProducer(queue);
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
-
+
final int numMessages = 100;
-
+
for (int i = 0; i < numMessages; i++)
{
TextMessage mess = sess.createTextMessage("msg" + i);
producer.send(mess);
}
-
+
conn.close();
-
+
JMSQueueControl control =
(JMSQueueControl)server.getManagementService().getResource(ResourceNames.JMS_QUEUE +
queue.getQueueName());
assertNotNull(control);
-
+
System.out.println(control.listMessageCounterAsHTML());
-
+
jmsServer.stop();
-
+
restartServer();
-
+
control =
(JMSQueueControl)server.getManagementService().getResource(ResourceNames.JMS_QUEUE +
queue.getQueueName());
assertNotNull(control);
-
- System.out.println(control.listMessageCounterAsHTML());
- }
- catch (Exception e)
- {
- e.printStackTrace();
- throw e;
- }
- finally
- {
- jmsServer.stop();
- }
-
+ System.out.println(control.listMessageCounterAsHTML());
}
}
Modified:
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/client/ConnectionTest.java
===================================================================
---
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/client/ConnectionTest.java 2011-12-05
14:25:39 UTC (rev 11833)
+++
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/client/ConnectionTest.java 2011-12-05
14:44:39 UTC (rev 11834)
@@ -13,7 +13,6 @@
package org.hornetq.tests.integration.jms.client;
-import javax.jms.Connection;
import javax.jms.Session;
import javax.jms.XAConnection;
import javax.jms.XASession;
@@ -30,47 +29,23 @@
public class ConnectionTest extends JMSTestBase
{
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- // Public --------------------------------------------------------
-
-
public void testGetSetConnectionFactory() throws Exception
{
- Connection conn = cf.createConnection();
-
+ conn = cf.createConnection();
+
conn.getClientID();
-
+
conn.setClientID("somethingElse");
- conn.close();
}
-
+
public void testXAInstanceof() throws Exception
{
- Connection conn = cf.createConnection();
-
+ conn = cf.createConnection();
+
assertFalse(conn instanceof XAConnection);
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
+
assertFalse(sess instanceof XASession);
-
- conn.close();
}
-
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-
}
Modified:
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/client/CreateQueueTest.java
===================================================================
---
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/client/CreateQueueTest.java 2011-12-05
14:25:39 UTC (rev 11833)
+++
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/client/CreateQueueTest.java 2011-12-05
14:44:39 UTC (rev 11834)
@@ -13,7 +13,6 @@
package org.hornetq.tests.integration.jms.client;
-import javax.jms.Connection;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Queue;
@@ -25,7 +24,7 @@
import org.hornetq.tests.util.JMSTestBase;
/**
- *
+ *
* A CreateQueueTest
*
* @author <a href="mailto:tim.fox@jboss.com">Tim Fox</a>
@@ -48,157 +47,101 @@
public void testCreateQueueTempQueue() throws Exception
{
- Connection conn = cf.createConnection();
+ conn = cf.createConnection();
- try
- {
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
+
Queue tempQueue = session.createTemporaryQueue();
-
+
String tempQueueName = tempQueue.getQueueName();
-
+
assertFalse(tempQueueName.startsWith(HornetQDestination.JMS_QUEUE_ADDRESS_PREFIX));
-
+
Queue replyQueue = session.createQueue(tempQueueName);
-
+
MessageProducer producer = session.createProducer(replyQueue);
-
+
producer.send(session.createMessage());
-
+
MessageConsumer consumer= session.createConsumer(replyQueue);
-
+
conn.start();
-
+
assertNotNull(consumer.receive(10000));
-
- }
- finally
- {
- try
- {
- conn.close();
- }
- catch (Throwable igonred)
- {
- }
- }
- }
-
+ }
+
public void testCreateQueue() throws Exception
{
- Connection conn = cf.createConnection();
+ conn = cf.createConnection();
+ Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- try
- {
- Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
Queue queue = createQueue("TestQueue");
-
+
String queueName = queue.getQueueName();
-
+
log.info("queue name is " + queueName);
-
+
assertFalse(queueName.startsWith(HornetQDestination.JMS_QUEUE_ADDRESS_PREFIX));
-
+
Queue replyQueue = session.createQueue(queueName);
-
+
MessageProducer producer = session.createProducer(replyQueue);
-
+
producer.send(session.createMessage());
-
+
MessageConsumer consumer= session.createConsumer(replyQueue);
-
+
conn.start();
-
+
assertNotNull(consumer.receive(10000));
-
- }
- finally
- {
- try
- {
- conn.close();
}
- catch (Throwable igonred)
- {
- }
- }
- }
-
+
public void testCreateTopic() throws Exception
{
- Connection conn = cf.createConnection();
-
- try
- {
- Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
+ conn = cf.createConnection();
+
+ Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
Topic topic = createTopic("TestTopic");
-
+
String topicName = topic.getTopicName();
-
+
assertFalse(topicName.startsWith(HornetQDestination.JMS_TOPIC_ADDRESS_PREFIX));
-
+
Topic replyTopic = session.createTopic(topicName);
-
+
MessageConsumer consumer= session.createConsumer(replyTopic);
-
+
conn.start();
-
+
MessageProducer producer = session.createProducer(replyTopic);
-
+
producer.send(session.createMessage());
-
- assertNotNull(consumer.receive(10000));
- }
- finally
- {
- try
- {
- conn.close();
+
+ assertNotNull(consumer.receive(10000));
}
- catch (Throwable igonred)
- {
- }
- }
- }
-
+
public void testCreateTopicTempTopic() throws Exception
{
- Connection conn = cf.createConnection();
-
- try
- {
+ conn = cf.createConnection();
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
+
Topic tempTopic = session.createTemporaryTopic();
-
+
String tempTopicName = tempTopic.getTopicName();
-
+
assertFalse(tempTopicName.startsWith(HornetQDestination.JMS_TOPIC_ADDRESS_PREFIX));
-
+
Topic replyTopic = session.createTopic(tempTopicName);
-
+
MessageConsumer consumer= session.createConsumer(replyTopic);
-
+
conn.start();
-
+
MessageProducer producer = session.createProducer(replyTopic);
-
+
producer.send(session.createMessage());
-
- assertNotNull(consumer.receive(10000));
- }
- finally
- {
- try
- {
- conn.close();
+
+ assertNotNull(consumer.receive(10000));
}
- catch (Throwable igonred)
- {
- }
- }
- }
}
Modified:
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/client/ExpiryMessageTest.java
===================================================================
---
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/client/ExpiryMessageTest.java 2011-12-05
14:25:39 UTC (rev 11833)
+++
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/client/ExpiryMessageTest.java 2011-12-05
14:44:39 UTC (rev 11834)
@@ -25,7 +25,7 @@
import org.hornetq.tests.util.JMSTestBase;
/**
- *
+ *
* A MessageTest
*
* @author <a href="mailto:tim.fox@jboss.com">Tim Fox</a>
@@ -48,60 +48,60 @@
protected Configuration createDefaultConfig(boolean netty)
{
Configuration conf = super.createDefaultConfig(netty);
-
+
conf.setMessageExpiryScanPeriod(1000);
-
+
return conf;
}
-
+
public void testSendTopicNoSubscription() throws Exception
{
-
+
Topic topic = createTopic("test-topic");
TopicControl control = ManagementControlHelper.createTopicControl(topic,
mbeanServer);
-
+
System.out.println("size = " + control.getMessageCount());
-
+
Connection conn2 = cf.createConnection();
-
+
conn2.setClientID("client1");
-
+
Session sess2 = conn2.createSession(true, Session.SESSION_TRANSACTED);
-
+
sess2.createDurableSubscriber(topic, "client-sub1");
sess2.createDurableSubscriber(topic, "client-sub2");
-
+
conn2.close();
- Connection conn = cf.createConnection();
+ conn = cf.createConnection();
Session sess = conn.createSession(true, Session.SESSION_TRANSACTED);
MessageProducer prod = sess.createProducer(topic);
prod.setTimeToLive(1000);
-
+
for (int i = 0 ; i < 100; i++)
{
TextMessage txt = sess.createTextMessage("txt");
prod.send(txt);
}
-
+
sess.commit();
-
+
conn.close();
// minimal time needed
Thread.sleep(2000);
-
+
long timeout = System.currentTimeMillis() + 10000;
-
+
// We will wait some time, but we will wait as minimal as possible
while (control.getMessageCount() != 0 && System.currentTimeMillis() >
timeout)
{
Thread.sleep(100);
}
-
+
assertEquals(0, control.getMessageCount());
-
-
+
+
}
// Package protected ---------------------------------------------
Modified:
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/client/MessageTest.java
===================================================================
---
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/client/MessageTest.java 2011-12-05
14:25:39 UTC (rev 11833)
+++
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/client/MessageTest.java 2011-12-05
14:44:39 UTC (rev 11834)
@@ -28,7 +28,7 @@
import org.hornetq.tests.util.JMSTestBase;
/**
- *
+ *
* A MessageTest
*
* @author <a href="mailto:tim.fox@jboss.com">Tim Fox</a>
@@ -64,8 +64,6 @@
Queue queue = createQueue("testQueue");
- try
- {
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer prod = sess.createProducer(queue);
@@ -75,7 +73,7 @@
conn.start();
StreamMessage msg = sess.createStreamMessage();
-
+
msg.writeInt(1);
msg.writeInt(2);
msg.writeInt(3);
@@ -88,137 +86,124 @@
assertEquals(1, received.readObject());
assertEquals(2, received.readObject());
assertEquals(3, received.readObject());
-
+
try
{
received.readObject();
-
+
fail("Should throw exception");
}
catch (MessageEOFException e)
{
//Ok
}
-
+
try
{
received.readBoolean();
-
+
fail("Should throw exception");
}
catch (MessageEOFException e)
{
//Ok
}
-
+
try
{
received.readByte();
-
+
fail("Should throw exception");
}
catch (MessageEOFException e)
{
//Ok
}
-
+
try
{
received.readChar();
-
+
fail("Should throw exception");
}
catch (MessageEOFException e)
{
//Ok
}
-
+
try
{
received.readDouble();
-
+
fail("Should throw exception");
}
catch (MessageEOFException e)
{
//Ok
}
-
+
try
{
received.readFloat();
-
+
fail("Should throw exception");
}
catch (MessageEOFException e)
{
//Ok
}
-
+
try
{
received.readInt();
-
+
fail("Should throw exception");
}
catch (MessageEOFException e)
{
//Ok
}
-
+
try
{
received.readLong();
-
+
fail("Should throw exception");
}
catch (MessageEOFException e)
{
//Ok
}
-
+
try
{
received.readShort();
-
+
fail("Should throw exception");
}
catch (MessageEOFException e)
{
//Ok
}
-
+
try
{
received.readString();
-
+
fail("Should throw exception");
}
catch (MessageEOFException e)
{
//Ok
- }
- }
- finally
- {
- try
- {
- conn.close();
}
- catch (Throwable igonred)
- {
- }
- }
}
-
+
public void testNullProperties() throws Exception
{
- Connection conn = cf.createConnection();
+ conn = cf.createConnection();
Queue queue = createQueue("testQueue");
- try
- {
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer prod = sess.createProducer(queue);
@@ -228,21 +213,21 @@
conn.start();
Message msg = sess.createMessage();
-
+
msg.setStringProperty("Test", "SomeValue");
-
+
assertEquals("SomeValue", msg.getStringProperty("Test"));
-
+
msg.setStringProperty("Test", null);
-
+
assertEquals(null, msg.getStringProperty("Test"));
msg.setObjectProperty(MessageTest.propName1, null);
-
+
msg.setStringProperty(MessageTest.propName2, null);
-
+
msg.getStringProperty(MessageTest.propName1);
-
+
msg.setStringProperty("Test", null);
Message received = sendAndConsumeMessage(msg, prod, cons);
@@ -250,18 +235,7 @@
Assert.assertNotNull(received);
checkProperties(received);
- }
- finally
- {
- try
- {
- conn.close();
}
- catch (Throwable igonred)
- {
- }
- }
- }
// Package protected ---------------------------------------------
Modified:
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/client/PreACKJMSTest.java
===================================================================
---
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/client/PreACKJMSTest.java 2011-12-05
14:25:39 UTC (rev 11833)
+++
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/client/PreACKJMSTest.java 2011-12-05
14:44:39 UTC (rev 11834)
@@ -15,9 +15,7 @@
import java.util.ArrayList;
import java.util.List;
-import java.util.Random;
-import javax.jms.Connection;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Queue;
@@ -26,13 +24,10 @@
import junit.framework.Assert;
-import org.hornetq.api.core.Pair;
import org.hornetq.api.core.TransportConfiguration;
import org.hornetq.api.core.client.HornetQClient;
import org.hornetq.api.jms.JMSFactoryType;
-import org.hornetq.core.server.HornetQServer;
import org.hornetq.tests.util.JMSTestBase;
-import org.hornetq.tests.util.RandomUtil;
/**
* A PreACKJMSTest
@@ -73,9 +68,7 @@
public void internalTestPreACK(final int sessionType) throws Exception
{
- Connection conn = cf.createConnection();
- try
- {
+ conn = cf.createConnection();
Session sess = conn.createSession(false, sessionType);
MessageProducer prod = sess.createProducer(queue);
@@ -107,25 +100,11 @@
msg2 = (TextMessage)cons.receiveNoWait();
Assert.assertNull("ConnectionFactory is on PreACK mode, the message
shouldn't be received", msg2);
- }
- finally
- {
- try
- {
- conn.close();
- }
- catch (Throwable igonred)
- {
- }
- }
-
}
public void disabled_testPreACKTransactional() throws Exception
{
- Connection conn = cf.createConnection();
- try
- {
+ conn = cf.createConnection();
Session sess = conn.createSession(true, Session.SESSION_TRANSACTED);
MessageProducer prod = sess.createProducer(queue);
@@ -161,18 +140,6 @@
msg2 = (TextMessage)cons.receive(10);
Assert.assertNotNull("ConnectionFactory is on PreACK mode but it is
transacted", msg2);
- }
- finally
- {
- try
- {
- conn.close();
- }
- catch (Throwable igonred)
- {
- }
- }
-
}
// Package protected ---------------------------------------------
@@ -201,7 +168,7 @@
double retryIntervalMultiplier = 1.0;
int reconnectAttempts = -1;
int callTimeout = 30000;
-
+
ArrayList<String> connectors = registerConnectors(server, connectorConfigs);
jmsServer.createConnectionFactory("ManualReconnectionToSingleServerTest",
Modified:
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/client/ReceiveNoWaitTest.java
===================================================================
---
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/client/ReceiveNoWaitTest.java 2011-12-05
14:25:39 UTC (rev 11833)
+++
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/client/ReceiveNoWaitTest.java 2011-12-05
14:44:39 UTC (rev 11834)
@@ -21,7 +21,6 @@
import javax.jms.Session;
import javax.jms.TextMessage;
-import org.hornetq.core.logging.Logger;
import org.hornetq.tests.util.JMSTestBase;
/**
@@ -34,10 +33,9 @@
*/
public class ReceiveNoWaitTest extends JMSTestBase
{
- private static final Logger log = Logger.getLogger(ReceiveNoWaitTest.class);
-
private Queue queue;
+ @Override
protected void setUp() throws Exception
{
super.setUp();
@@ -45,6 +43,7 @@
queue = createQueue("TestQueue");
}
+ @Override
protected void tearDown() throws Exception
{
jmsServer.destroyQueue("TestQueue");
Modified:
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/client/TextMessageTest.java
===================================================================
---
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/client/TextMessageTest.java 2011-12-05
14:25:39 UTC (rev 11833)
+++
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/client/TextMessageTest.java 2011-12-05
14:44:39 UTC (rev 11834)
@@ -15,7 +15,6 @@
import java.util.List;
-import javax.jms.Connection;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Queue;
@@ -31,7 +30,7 @@
import org.hornetq.tests.util.RandomUtil;
/**
- *
+ *
* A TextMessageTest
*
* @author Tim Fox
@@ -55,10 +54,8 @@
public void testSendReceiveNullBody() throws Exception
{
- Connection conn = cf.createConnection();
+ conn = cf.createConnection();
- try
- {
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer prod = sess.createProducer(queue);
@@ -85,18 +82,6 @@
TextMessage received3 = (TextMessage)cons.receive(1000);
Assert.assertNotNull(received3);
Assert.assertNull(received3.getText());
- }
- finally
- {
- try
- {
- conn.close();
- }
- catch (Throwable igonred)
- {
- }
- }
-
}
public void testSendReceiveWithBody0() throws Exception
@@ -141,10 +126,7 @@
private void testSendReceiveWithBody(final int bodyLength) throws Exception
{
- Connection conn = cf.createConnection();
-
- try
- {
+ conn = cf.createConnection();
char[] chrs = new char[bodyLength];
for (int i = 0; i < bodyLength; i++)
@@ -173,7 +155,7 @@
TextMessage received2 = (TextMessage)cons.receive(1000);
Assert.assertNotNull(received2);
Assert.assertEquals(str, received2.getText());
-
+
assertEquals(str, msg2.getText());
// Now resend it
@@ -190,19 +172,6 @@
TextMessage received4 = (TextMessage)cons.receive(1000);
Assert.assertNotNull(received4);
assertEquals(str, received4.getText());
-
- }
- finally
- {
- try
- {
- conn.close();
- }
- catch (Throwable igonred)
- {
- }
- }
-
}
// Package protected ---------------------------------------------
@@ -267,9 +236,4 @@
null,
jndiBindings);
}
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-
}
Modified:
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/connection/CloseConnectionFactoryOnGCest.java
===================================================================
---
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/connection/CloseConnectionFactoryOnGCest.java 2011-12-05
14:25:39 UTC (rev 11833)
+++
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/connection/CloseConnectionFactoryOnGCest.java 2011-12-05
14:44:39 UTC (rev 11834)
@@ -12,28 +12,19 @@
*/
package org.hornetq.tests.integration.jms.connection;
-import java.io.BufferedReader;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.io.PrintStream;
-import java.io.StringReader;
import java.util.concurrent.atomic.AtomicInteger;
import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
import org.hornetq.api.core.TransportConfiguration;
import org.hornetq.api.jms.HornetQJMSClient;
import org.hornetq.api.jms.JMSFactoryType;
import org.hornetq.core.client.impl.ServerLocatorImpl;
-import org.hornetq.core.logging.Logger;
import org.hornetq.jms.client.HornetQConnectionFactory;
import org.hornetq.tests.util.JMSTestBase;
/**
- *
+ *
* A CloseConnectionOnGCTest
*
* @author <a href="mailto:tim.fox@jboss.com">Tim Fox</a>
@@ -42,20 +33,7 @@
*/
public class CloseConnectionFactoryOnGCest extends JMSTestBase
{
- private static final Logger log =
Logger.getLogger(CloseConnectionFactoryOnGCest.class);
- @Override
- protected void setUp() throws Exception
- {
- super.setUp();
- }
-
- @Override
- protected void tearDown() throws Exception
- {
- super.tearDown();
- }
-
public void testCloseCFOnGC() throws Exception
{
Modified:
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/connection/CloseConnectionOnGCTest.java
===================================================================
---
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/connection/CloseConnectionOnGCTest.java 2011-12-05
14:25:39 UTC (rev 11833)
+++
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/connection/CloseConnectionOnGCTest.java 2011-12-05
14:44:39 UTC (rev 11834)
@@ -23,17 +23,16 @@
import junit.framework.Assert;
import org.hornetq.api.core.TransportConfiguration;
-import org.hornetq.jms.client.HornetQConnectionFactory;
import org.hornetq.api.jms.HornetQJMSClient;
import org.hornetq.api.jms.JMSFactoryType;
-import org.hornetq.core.logging.Logger;
import org.hornetq.core.remoting.CloseListener;
+import org.hornetq.jms.client.HornetQConnectionFactory;
import org.hornetq.spi.core.protocol.RemotingConnection;
import org.hornetq.tests.util.JMSTestBase;
import org.hornetq.tests.util.UnitTestCase;
/**
- *
+ *
* A CloseConnectionOnGCTest
*
* @author <a href="mailto:tim.fox@jboss.com">Tim Fox</a>
@@ -42,8 +41,6 @@
*/
public class CloseConnectionOnGCTest extends JMSTestBase
{
- private static final Logger log = Logger.getLogger(CloseConnectionOnGCTest.class);
-
private HornetQConnectionFactory cf;
@Override
@@ -51,15 +48,17 @@
{
super.setUp();
- cf = (HornetQConnectionFactory)
HornetQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new
TransportConfiguration("org.hornetq.core.remoting.impl.invm.InVMConnectorFactory"));
+ cf = HornetQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new
TransportConfiguration("org.hornetq.core.remoting.impl.invm.InVMConnectorFactory"));
cf.setBlockOnDurableSend(true);
cf.setPreAcknowledge(true);
+
}
@Override
protected void tearDown() throws Exception
{
- cf = null;
+ if (cf != null)
+ cf.close();
super.tearDown();
}
Modified:
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/consumer/ConsumerTest.java
===================================================================
---
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/consumer/ConsumerTest.java 2011-12-05
14:25:39 UTC (rev 11833)
+++
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/consumer/ConsumerTest.java 2011-12-05
14:44:39 UTC (rev 11834)
@@ -12,7 +12,6 @@
*/
package org.hornetq.tests.integration.jms.consumer;
-import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.JMSException;
import javax.jms.Message;
@@ -65,7 +64,7 @@
public void testPreCommitAcks() throws Exception
{
- Connection conn = cf.createConnection();
+ conn = cf.createConnection();
Session session = conn.createSession(false, HornetQJMSConstants.PRE_ACKNOWLEDGE);
jBossQueue = HornetQJMSClient.createQueue(ConsumerTest.Q_NAME);
MessageProducer producer = session.createProducer(jBossQueue);
@@ -86,13 +85,12 @@
SimpleString queueName = new
SimpleString(HornetQDestination.JMS_QUEUE_ADDRESS_PREFIX + ConsumerTest.Q_NAME);
Assert.assertEquals(0,
((Queue)server.getPostOffice().getBinding(queueName).getBindable()).getDeliveringCount());
Assert.assertEquals(0,
((Queue)server.getPostOffice().getBinding(queueName).getBindable()).getMessageCount());
- conn.close();
}
public void testPreCommitAcksSetOnConnectionFactory() throws Exception
{
((HornetQConnectionFactory)cf).setPreAcknowledge(true);
- Connection conn = cf.createConnection();
+ conn = cf.createConnection();
Session session = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
jBossQueue = HornetQJMSClient.createQueue(ConsumerTest.Q_NAME);
@@ -115,14 +113,13 @@
SimpleString queueName = new
SimpleString(HornetQDestination.JMS_QUEUE_ADDRESS_PREFIX + ConsumerTest.Q_NAME);
Assert.assertEquals(0,
((Queue)server.getPostOffice().getBinding(queueName).getBindable()).getDeliveringCount());
Assert.assertEquals(0,
((Queue)server.getPostOffice().getBinding(queueName).getBindable()).getMessageCount());
- conn.close();
}
public void testPreCommitAcksWithMessageExpiry() throws Exception
{
ConsumerTest.log.info("starting test");
- Connection conn = cf.createConnection();
+ conn = cf.createConnection();
Session session = conn.createSession(false, HornetQJMSConstants.PRE_ACKNOWLEDGE);
jBossQueue = HornetQJMSClient.createQueue(ConsumerTest.Q_NAME);
MessageProducer producer = session.createProducer(jBossQueue);
@@ -146,13 +143,12 @@
// point
// which can cause delivering count to flip to 1
- conn.close();
}
public void testPreCommitAcksWithMessageExpirySetOnConnectionFactory() throws
Exception
{
((HornetQConnectionFactory)cf).setPreAcknowledge(true);
- Connection conn = cf.createConnection();
+ conn = cf.createConnection();
Session session = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
jBossQueue = HornetQJMSClient.createQueue(ConsumerTest.Q_NAME);
MessageProducer producer = session.createProducer(jBossQueue);
@@ -174,13 +170,11 @@
// Asserting delivering count is zero is bogus since messages might still be being
delivered and expired at this
// point
// which can cause delivering count to flip to 1
-
- conn.close();
}
public void testClearExceptionListener() throws Exception
{
- Connection conn = cf.createConnection();
+ conn = cf.createConnection();
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
jBossQueue = HornetQJMSClient.createQueue(ConsumerTest.Q_NAME);
MessageConsumer consumer = session.createConsumer(jBossQueue);
@@ -193,13 +187,11 @@
consumer.setMessageListener(null);
consumer.receiveNoWait();
-
- conn.close();
}
public void testCantReceiveWhenListenerIsSet() throws Exception
{
- Connection conn = cf.createConnection();
+ conn = cf.createConnection();
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
jBossQueue = HornetQJMSClient.createQueue(ConsumerTest.Q_NAME);
MessageConsumer consumer = session.createConsumer(jBossQueue);
@@ -219,7 +211,5 @@
{
// Ok
}
-
- conn.close();
}
}
Modified:
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/divert/DivertAndACKClientTest.java
===================================================================
---
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/divert/DivertAndACKClientTest.java 2011-12-05
14:25:39 UTC (rev 11833)
+++
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/divert/DivertAndACKClientTest.java 2011-12-05
14:44:39 UTC (rev 11834)
@@ -16,7 +16,6 @@
import java.util.ArrayList;
import java.util.List;
-import javax.jms.Connection;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Queue;
@@ -25,7 +24,6 @@
import junit.framework.Assert;
-import org.hornetq.api.core.Pair;
import org.hornetq.api.core.TransportConfiguration;
import org.hornetq.api.core.client.HornetQClient;
import org.hornetq.api.jms.JMSFactoryType;
@@ -35,7 +33,7 @@
/**
* A DivertAndACKClientTest
- *
+ *
*
https://jira.jboss.org/jira/browse/HORNETQ-165
*
* @author <mailto:clebert.suconic@jboss.org">Clebert Suconic</a>
@@ -60,22 +58,20 @@
Queue queueSource = createQueue("Source");
Queue queueTarget = createQueue("Dest");
- Connection connection = cf.createConnection();
- Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ conn = cf.createConnection();
+ Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
final MessageProducer producer = session.createProducer(queueSource);
final TextMessage message = session.createTextMessage("message text");
producer.send(message);
- connection.start();
+ conn.start();
final MessageConsumer consumer = session.createConsumer(queueTarget);
TextMessage receivedMessage = (TextMessage)consumer.receive(1000);
Assert.assertNotNull(receivedMessage);
-
- connection.close();
}
public void testClientACK() throws Exception
@@ -83,22 +79,20 @@
Queue queueSource = createQueue("Source");
Queue queueTarget = createQueue("Dest");
- Connection connection = cf.createConnection();
- Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+ conn = cf.createConnection();
+ Session session = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
final MessageProducer producer = session.createProducer(queueSource);
final TextMessage message = session.createTextMessage("message text");
producer.send(message);
- connection.start();
+ conn.start();
final MessageConsumer consumer = session.createConsumer(queueTarget);
TextMessage receivedMessage = (TextMessage)consumer.receive(1000);
Assert.assertNotNull(receivedMessage);
receivedMessage.acknowledge();
-
- connection.close();
}
// Package protected ---------------------------------------------
Modified:
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/largemessage/JMSLargeMessageTest.java
===================================================================
---
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/largemessage/JMSLargeMessageTest.java 2011-12-05
14:25:39 UTC (rev 11833)
+++
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/jms/largemessage/JMSLargeMessageTest.java 2011-12-05
14:44:39 UTC (rev 11834)
@@ -20,7 +20,6 @@
import java.util.concurrent.atomic.AtomicLong;
import javax.jms.BytesMessage;
-import javax.jms.Connection;
import javax.jms.JMSException;
import javax.jms.MessageConsumer;
import javax.jms.MessageNotWriteableException;
@@ -33,7 +32,6 @@
import org.hornetq.tests.util.JMSTestBase;
import org.hornetq.tests.util.UnitTestCase;
-import org.hornetq.utils.UUID;
import org.hornetq.utils.UUIDGenerator;
/**
@@ -79,10 +77,7 @@
public void testSimpleLargeMessage() throws Exception
{
- Connection conn = null;
- try
- {
conn = cf.createConnection();
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
@@ -122,24 +117,10 @@
}
Assert.assertNotNull(rm);
-
- }
- finally
- {
- if (conn != null)
- {
- conn.close();
- }
- }
-
}
public void testSimpleLargeMessage2() throws Exception
{
- Connection conn = null;
-
- try
- {
conn = cf.createConnection();
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
@@ -176,26 +157,12 @@
}
Assert.assertNotNull(rm);
-
- }
- finally
- {
- if (conn != null)
- {
- conn.close();
- }
- }
-
}
public void testExceptionsOnSettingNonStreaming() throws Exception
{
- Connection conn = null;
+ conn = cf.createConnection();
- try
- {
- conn = cf.createConnection();
-
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
TextMessage msg = session.createTextMessage();
@@ -249,26 +216,13 @@
Assert.assertNotNull(rm);
}
- finally
- {
- if (conn != null)
- {
- conn.close();
- }
- }
- }
-
public void testWaitOnOutputStream() throws Exception
{
int msgSize = 1024 * 1024;
- Connection conn = null;
+ conn = cf.createConnection();
- try
- {
- conn = cf.createConnection();
-
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer prod = session.createProducer(queue1);
@@ -330,49 +284,36 @@
Assert.assertEquals(0, numberOfErrors.get());
}
- finally
- {
- if (conn != null)
- {
- conn.close();
- }
- }
- }
-
public void testHugeString() throws Exception
{
int msgSize = 1024 * 1024;
- Connection conn = null;
+ conn = cf.createConnection();
- try
- {
- conn = cf.createConnection();
-
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer prod = session.createProducer(queue1);
TextMessage m = session.createTextMessage();
-
+
StringBuffer buffer = new StringBuffer();
while(buffer.length() < msgSize)
{
buffer.append(UUIDGenerator.getInstance().generateStringUUID());
}
-
+
final String originalString = buffer.toString();
-
+
m.setText(originalString);
-
+
buffer = null;
prod.send(m);
conn.close();
-
+
validateNoFilesOnLargeDir(1);
conn = cf.createConnection();
@@ -388,16 +329,7 @@
String str = rm.getText();
assertEquals(originalString, str);
-
- }
- finally
- {
- if (conn != null)
- {
- conn.close();
- }
- }
-
+ conn.close();
validateNoFilesOnLargeDir(0);
}
Modified:
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/util/JMSTestBase.java
===================================================================
---
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/util/JMSTestBase.java 2011-12-05
14:25:39 UTC (rev 11833)
+++
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/util/JMSTestBase.java 2011-12-05
14:44:39 UTC (rev 11834)
@@ -16,6 +16,7 @@
import java.util.ArrayList;
import java.util.List;
+import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Queue;
import javax.jms.Topic;
@@ -49,6 +50,7 @@
protected MBeanServer mbeanServer;
protected ConnectionFactory cf;
+ protected Connection conn;
protected InVMContext context;
@@ -127,7 +129,7 @@
conf.getConnectorConfigurations().put("invm", new
TransportConfiguration(INVM_CONNECTOR_FACTORY));
server = HornetQServers.newHornetQServer(conf, mbeanServer, usePersistence());
-
+ addServer(server);
jmsServer = new JMSServerManagerImpl(server);
context = new InVMContext();
jmsServer.setContext(context);
@@ -164,13 +166,17 @@
@Override
protected void tearDown() throws Exception
{
-
+ try
+ {
+ if (conn != null)
+ conn.close();
+ }
+ catch (Exception e)
+ {
+ // no-op
+ }
+ context.close();
jmsServer.stop();
-
- server.stop();
-
- context.close();
-
server = null;
jmsServer = null;