Author: borges
Date: 2011-11-10 06:07:46 -0500 (Thu, 10 Nov 2011)
New Revision: 11684
Modified:
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/client/ProducerFlowControlTest.java
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/client/SessionCreateConsumerTest.java
Log:
Improve clean to make sure everything gets closed.
Modified:
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/client/ProducerFlowControlTest.java
===================================================================
---
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/client/ProducerFlowControlTest.java 2011-11-10
11:07:28 UTC (rev 11683)
+++
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/client/ProducerFlowControlTest.java 2011-11-10
11:07:46 UTC (rev 11684)
@@ -43,7 +43,7 @@
import org.hornetq.tests.util.UnitTestCase;
/**
- *
+ *
* A ProducerFlowControlTest
*
* @author <a href="mailto:tim.fox@jboss.com">Tim Fox</a> fox
@@ -55,6 +55,12 @@
private ServerLocator locator;
+ private ClientSessionFactory sf;
+
+ private ClientSession session;
+
+ private HornetQServer server;
+
protected boolean isNetty()
{
return false;
@@ -70,7 +76,12 @@
@Override
protected void tearDown() throws Exception
{
- locator.close();
+ stopComponent(server);
+ if (sf != null)
+ {
+ sf.close();
+ }
+ closeServerLocator(locator);
super.tearDown();
}
@@ -207,7 +218,7 @@
{
final SimpleString address = new SimpleString("testaddress");
- HornetQServer server = createServer(realFiles, isNetty());
+ server = createServer(realFiles, isNetty());
AddressSettings addressSettings = new AddressSettings();
addressSettings.setMaxSizeBytes(maxSize);
@@ -219,10 +230,7 @@
server.start();
waitForServer(server);
- try
- {
-
- locator.setProducerWindowSize(producerWindowSize);
+ locator.setProducerWindowSize(producerWindowSize);
locator.setConsumerWindowSize(consumerWindowSize);
locator.setAckBatchSize(ackBatchSize);
@@ -231,8 +239,8 @@
locator.setMinLargeMessageSize(minLargeMessageSize);
}
- ClientSessionFactory sf = locator.createSessionFactory();
- ClientSession session = sf.createSession(false, true, true, true);
+ sf = locator.createSessionFactory();
+ session = sf.createSession(false, true, true, true);
session.start();
@@ -346,22 +354,13 @@
double rate = 1000 * (double)numMessages / (end - start);
ProducerFlowControlTest.log.info("rate is " + rate + " msgs /
sec");
-
- session.close();
-
- sf.close();
- }
- finally
- {
- server.stop();
- }
}
public void testClosingSessionUnblocksBlockedProducer() throws Exception
{
final SimpleString address = new SimpleString("testaddress");
- HornetQServer server = createServer(false, isNetty());
+ server = createServer(false, isNetty());
AddressSettings addressSettings = new AddressSettings();
addressSettings.setMaxSizeBytes(1024);
@@ -373,15 +372,12 @@
server.start();
waitForServer(server);
- try
- {
-
locator.setProducerWindowSize(1024);
locator.setConsumerWindowSize(1024);
locator.setAckBatchSize(1024);
- ClientSessionFactory sf = locator.createSessionFactory();
- final ClientSession session = sf.createSession(false, true, true, true);
+ sf = locator.createSessionFactory();
+ session = sf.createSession(false, true, true, true);
final SimpleString queueName = new SimpleString("testqueue");
@@ -423,18 +419,13 @@
Assert.assertTrue(closed.get());
t.join();
- }
- finally
- {
- server.stop();
- }
}
public void testFlowControlMessageNotRouted() throws Exception
{
final SimpleString address = new SimpleString("testaddress");
- HornetQServer server = createServer(false, isNetty());
+ server = createServer(false, isNetty());
AddressSettings addressSettings = new AddressSettings();
addressSettings.setMaxSizeBytes(1024);
@@ -446,16 +437,13 @@
server.start();
waitForServer(server);
- try
- {
-
locator.setProducerWindowSize(1024);
locator.setConsumerWindowSize(1024);
locator.setAckBatchSize(1024);
- ClientSessionFactory sf = locator.createSessionFactory();
+ sf = locator.createSessionFactory();
- final ClientSession session = sf.createSession(false, true, true, true);
+ session = sf.createSession(false, true, true, true);
ClientProducer producer = session.createProducer(address);
@@ -471,30 +459,20 @@
producer.send(message);
}
-
- session.close();
- }
- finally
- {
- server.stop();
- }
}
// Not technically a flow control test, but what the hell
public void testMultipleConsumers() throws Exception
{
- HornetQServer server = createServer(false, isNetty());
+ server = createServer(false, isNetty());
server.start();
waitForServer(server);
- try
- {
+ sf = locator.createSessionFactory();
- ClientSessionFactory sf = locator.createSessionFactory();
+ session = sf.createSession(false, true, true, true);
- final ClientSession session = sf.createSession(false, true, true, true);
-
session.createQueue("address", "queue1", null, false);
session.createQueue("address", "queue2", null, false);
session.createQueue("address", "queue3", null, false);
@@ -546,29 +524,19 @@
Assert.assertNotNull(msg);
}
-
- session.close();
- }
- finally
- {
- server.stop();
- }
}
public void testProducerCreditsCaching1() throws Exception
{
- HornetQServer server = createServer(false, isNetty());
+ server = createServer(false, isNetty());
server.start();
waitForServer(server);
- try
- {
+ sf = locator.createSessionFactory();
- ClientSessionFactory sf = locator.createSessionFactory();
+ session = sf.createSession(false, true, true, true);
- final ClientSession session = sf.createSession(false, true, true, true);
-
session.createQueue("address", "queue1", null, false);
ClientProducerCredits credits = null;
@@ -590,29 +558,18 @@
Assert.assertEquals(0,
((ClientSessionInternal)session).getProducerCreditManager()
.unReferencedCreditsSize());
}
-
- session.close();
- }
- finally
- {
- server.stop();
- }
}
public void testProducerCreditsCaching2() throws Exception
{
- HornetQServer server = createServer(false, isNetty());
+ server = createServer(false, isNetty());
server.start();
waitForServer(server);
+ sf = locator.createSessionFactory();
- try
- {
+ session = sf.createSession(false, true, true, true);
- ClientSessionFactory sf = locator.createSessionFactory();
-
- final ClientSession session = sf.createSession(false, true, true, true);
-
session.createQueue("address", "queue1", null, false);
ClientProducerCredits credits = null;
@@ -636,29 +593,19 @@
Assert.assertEquals(1,
((ClientSessionInternal)session).getProducerCreditManager()
.unReferencedCreditsSize());
}
-
- session.close();
- }
- finally
- {
- server.stop();
- }
}
public void testProducerCreditsCaching3() throws Exception
{
- HornetQServer server = createServer(false, isNetty());
+ server = createServer(false, isNetty());
server.start();
waitForServer(server);
- try
- {
+ sf = locator.createSessionFactory();
- ClientSessionFactory sf = locator.createSessionFactory();
+ session = sf.createSession(false, true, true, true);
- final ClientSession session = sf.createSession(false, true, true, true);
-
session.createQueue("address", "queue1", null, false);
ClientProducerCredits credits = null;
@@ -680,29 +627,18 @@
Assert.assertEquals(0,
((ClientSessionInternal)session).getProducerCreditManager()
.unReferencedCreditsSize());
}
-
- session.close();
- }
- finally
- {
- server.stop();
- }
}
public void testProducerCreditsCaching4() throws Exception
{
- HornetQServer server = createServer(false, isNetty());
+ server = createServer(false, isNetty());
server.start();
waitForServer(server);
+ sf = locator.createSessionFactory();
- try
- {
+ session = sf.createSession(false, true, true, true);
- ClientSessionFactory sf = locator.createSessionFactory();
-
- final ClientSession session = sf.createSession(false, true, true, true);
-
session.createQueue("address", "queue1", null, false);
ClientProducerCredits credits = null;
@@ -726,29 +662,19 @@
Assert.assertEquals(i + 1,
((ClientSessionInternal)session).getProducerCreditManager()
.unReferencedCreditsSize());
}
-
- session.close();
- }
- finally
- {
- server.stop();
- }
}
public void testProducerCreditsCaching5() throws Exception
{
- HornetQServer server = createServer(false, isNetty());
+ server = createServer(false, isNetty());
server.start();
waitForServer(server);
- try
- {
+ sf = locator.createSessionFactory();
- ClientSessionFactory sf = locator.createSessionFactory();
+ session = sf.createSession(false, true, true, true);
- final ClientSession session = sf.createSession(false, true, true, true);
-
session.createQueue("address", "queue1", null, false);
ClientProducerCredits credits = null;
@@ -800,29 +726,18 @@
Assert.assertEquals(0,
((ClientSessionInternal)session).getProducerCreditManager()
.unReferencedCreditsSize());
}
-
- session.close();
- }
- finally
- {
- server.stop();
- }
}
public void testProducerCreditsCaching6() throws Exception
{
- HornetQServer server = createServer(false, isNetty());
+ server = createServer(false, isNetty());
server.start();
waitForServer(server);
+ sf = locator.createSessionFactory();
- try
- {
+ session = sf.createSession(false, true, true, true);
- ClientSessionFactory sf = locator.createSessionFactory();
-
- final ClientSession session = sf.createSession(false, true, true, true);
-
session.createQueue("address", "queue1", null, false);
for (int i = 0; i <
ClientProducerCreditManagerImpl.MAX_UNREFERENCED_CREDITS_CACHE_SIZE; i++)
@@ -835,30 +750,19 @@
Assert.assertEquals(1,
((ClientSessionInternal)session).getProducerCreditManager()
.unReferencedCreditsSize());
}
-
- session.close();
- }
- finally
- {
- server.stop();
- }
-
}
public void testProducerCreditsCaching7() throws Exception
{
- HornetQServer server = createServer(false, isNetty());
+ server = createServer(false, isNetty());
server.start();
waitForServer(server);
- try
- {
+ sf = locator.createSessionFactory();
- ClientSessionFactory sf = locator.createSessionFactory();
+ session = sf.createSession(false, true, true, true);
- final ClientSession session = sf.createSession(false, true, true, true);
-
session.createQueue("address", "queue1", null, false);
for (int i = 0; i <
ClientProducerCreditManagerImpl.MAX_UNREFERENCED_CREDITS_CACHE_SIZE; i++)
@@ -895,29 +799,19 @@
Assert.assertEquals(ClientProducerCreditManagerImpl.MAX_UNREFERENCED_CREDITS_CACHE_SIZE,
((ClientSessionInternal)session).getProducerCreditManager().unReferencedCreditsSize());
}
-
- session.close();
- }
- finally
- {
- server.stop();
- }
}
public void testProducerCreditsRefCounting() throws Exception
{
- HornetQServer server = createServer(false, isNetty());
+ server = createServer(false, isNetty());
server.start();
waitForServer(server);
- try
- {
+ sf = locator.createSessionFactory();
- ClientSessionFactory sf = locator.createSessionFactory();
+ session = sf.createSession(false, true, true, true);
- final ClientSession session = sf.createSession(false, true, true, true);
-
session.createQueue("address", "queue1", null, false);
ClientProducer prod1 = session.createProducer("address");
@@ -946,13 +840,6 @@
Assert.assertEquals(1,
((ClientSessionInternal)session).getProducerCreditManager().creditsMapSize());
Assert.assertEquals(1,
((ClientSessionInternal)session).getProducerCreditManager().unReferencedCreditsSize());
-
- session.close();
- }
- finally
- {
- server.stop();
- }
}
}
Modified:
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/client/SessionCreateConsumerTest.java
===================================================================
---
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/client/SessionCreateConsumerTest.java 2011-11-10
11:07:28 UTC (rev 11683)
+++
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/client/SessionCreateConsumerTest.java 2011-11-10
11:07:46 UTC (rev 11684)
@@ -30,56 +30,52 @@
private final String queueName = "ClientSessionCreateConsumerTestQ";
private ServerLocator locator;
+ private HornetQServer service;
+ private ClientSessionInternal clientSession;
+ private ClientSessionFactory cf;
@Override
protected void setUp() throws Exception
{
locator = createInVMNonHALocator();
-
- super.setUp();
+ super.setUp();
+
+ service = createServer(false);
+ service.start();
+ locator.setProducerMaxRate(99);
+ locator.setBlockOnNonDurableSend(true);
+ locator.setBlockOnNonDurableSend(true);
+ cf = locator.createSessionFactory();
+ clientSession = (ClientSessionInternal)cf.createSession(false, true, true);
}
@Override
protected void tearDown() throws Exception
{
- locator.close();
-
- super.tearDown();
+ stopComponent(service);
+ try
+ {
+ if (clientSession != null)
+ clientSession.close();
+ if (cf != null)
+ cf.close();
+ }
+ finally
+ {
+ closeServerLocator(locator);
+ super.tearDown();
+ }
}
public void testCreateConsumer() throws Exception
{
- HornetQServer service = createServer(false);
- try
- {
- service.start();
- locator.setProducerMaxRate(99);
- locator.setBlockOnNonDurableSend(true);
- locator.setBlockOnNonDurableSend(true);
- ClientSessionFactory cf = locator.createSessionFactory();
- ClientSessionInternal clientSession =
(ClientSessionInternal)cf.createSession(false, true, true);
clientSession.createQueue(queueName, queueName, false);
ClientConsumer consumer = clientSession.createConsumer(queueName);
Assert.assertNotNull(consumer);
- clientSession.close();
- }
- finally
- {
- service.stop();
- }
}
public void testCreateConsumerNoQ() throws Exception
{
- HornetQServer service = createServer(false);
- try
- {
- service.start();
- locator.setProducerMaxRate(99);
- locator.setBlockOnNonDurableSend(true);
- locator.setBlockOnNonDurableSend(true);
- ClientSessionFactory cf = locator.createSessionFactory();
- ClientSessionInternal clientSession =
(ClientSessionInternal)cf.createSession(false, true, true);
try
{
clientSession.createConsumer(queueName);
@@ -89,47 +85,17 @@
{
Assert.assertEquals(e.getCode(), HornetQException.QUEUE_DOES_NOT_EXIST);
}
- clientSession.close();
- }
- finally
- {
- service.stop();
- }
}
public void testCreateConsumerWithFilter() throws Exception
{
- HornetQServer service = createServer(false);
- try
- {
- service.start();
- locator.setProducerMaxRate(99);
- locator.setBlockOnNonDurableSend(true);
- locator.setBlockOnNonDurableSend(true);
- ClientSessionFactory cf = locator.createSessionFactory();
- ClientSessionInternal clientSession =
(ClientSessionInternal)cf.createSession(false, true, true);
clientSession.createQueue(queueName, queueName, false);
ClientConsumer consumer = clientSession.createConsumer(queueName,
"foo=bar");
Assert.assertNotNull(consumer);
- clientSession.close();
- }
- finally
- {
- service.stop();
- }
}
public void testCreateConsumerWithInvalidFilter() throws Exception
{
- HornetQServer service = createServer(false);
- try
- {
- service.start();
- locator.setProducerMaxRate(99);
- locator.setBlockOnNonDurableSend(true);
- locator.setBlockOnNonDurableSend(true);
- ClientSessionFactory cf = locator.createSessionFactory();
- ClientSessionInternal clientSession =
(ClientSessionInternal)cf.createSession(false, true, true);
clientSession.createQueue(queueName, queueName, false);
try
{
@@ -140,56 +106,20 @@
{
Assert.assertEquals(e.getCode(),
HornetQException.INVALID_FILTER_EXPRESSION);
}
- clientSession.close();
- }
- finally
- {
- service.stop();
- }
}
public void testCreateConsumerWithBrowseOnly() throws Exception
{
- HornetQServer service = createServer(false);
- try
- {
- service.start();
- locator.setProducerMaxRate(99);
- locator.setBlockOnNonDurableSend(true);
- locator.setBlockOnNonDurableSend(true);
- ClientSessionFactory cf = locator.createSessionFactory();
- ClientSessionInternal clientSession =
(ClientSessionInternal)cf.createSession(false, true, true);
clientSession.createQueue(queueName, queueName, false);
ClientConsumer consumer = clientSession.createConsumer(queueName, null, true);
Assert.assertNotNull(consumer);
- clientSession.close();
- }
- finally
- {
- service.stop();
- }
}
public void testCreateConsumerWithOverrides() throws Exception
{
- HornetQServer service = createServer(false);
- try
- {
- service.start();
- locator.setProducerMaxRate(99);
- locator.setBlockOnNonDurableSend(true);
- locator.setBlockOnNonDurableSend(true);
- ClientSessionFactory cf = locator.createSessionFactory();
- ClientSessionInternal clientSession =
(ClientSessionInternal)cf.createSession(false, true, true);
clientSession.createQueue(queueName, queueName, false);
ClientConsumer consumer = clientSession.createConsumer(queueName, null, 100,
100, false);
Assert.assertNotNull(consumer);
- clientSession.close();
- }
- finally
- {
- service.stop();
- }
}
}