Author: borges
Date: 2011-09-23 08:21:30 -0400 (Fri, 23 Sep 2011)
New Revision: 11400
Modified:
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/client/DeadLetterAddressTest.java
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/client/SessionCloseOnGCTest.java
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/client/SessionCloseTest.java
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/client/SessionFactoryTest.java
trunk/tests/unit-tests/src/test/java/org/hornetq/tests/unit/util/LinkedListTest.java
Log:
Don't leave stuff open after running the test
Modified:
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/client/DeadLetterAddressTest.java
===================================================================
---
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/client/DeadLetterAddressTest.java 2011-09-23
03:24:21 UTC (rev 11399)
+++
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/client/DeadLetterAddressTest.java 2011-09-23
12:21:30 UTC (rev 11400)
@@ -149,10 +149,10 @@
class TestHandler implements MessageHandler
{
- private CountDownLatch latch;
+ private final CountDownLatch latch;
int count = 0;
- private ClientSession clientSession;
+ private final ClientSession clientSession;
public TestHandler(CountDownLatch latch, ClientSession clientSession)
{
@@ -251,10 +251,12 @@
SimpleString dlq = new SimpleString("DLQ1");
clientSession.createQueue(dla, dlq, null, false);
clientSession.createQueue(qName, qName, null, false);
- ServerLocator locator = HornetQClient.createServerLocatorWithoutHA(new
TransportConfiguration(UnitTestCase.INVM_CONNECTOR_FACTORY));
- ClientSessionFactory sessionFactory = locator.createSessionFactory();
+ final ServerLocator locator = HornetQClient.createServerLocatorWithoutHA(new
TransportConfiguration(UnitTestCase.INVM_CONNECTOR_FACTORY));
+ final ClientSessionFactory sessionFactory = locator.createSessionFactory();
ClientSession sendSession = sessionFactory.createSession(false, true, true);
- ClientProducer producer = sendSession.createProducer(qName);
+ try
+ {
+ ClientProducer producer = sendSession.createProducer(qName);
Map<String, Long> origIds = new HashMap<String, Long>();
for (int i = 0; i < NUM_MESSAGES; i++)
@@ -320,7 +322,10 @@
}
sendSession.close();
-
+ } finally {
+ sessionFactory.close();
+ locator.close();
+ }
}
public void testDeadlLetterAddressWithDefaultAddressSettings() throws Exception
Modified:
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/client/SessionCloseOnGCTest.java
===================================================================
---
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/client/SessionCloseOnGCTest.java 2011-09-23
03:24:21 UTC (rev 11399)
+++
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/client/SessionCloseOnGCTest.java 2011-09-23
12:21:30 UTC (rev 11400)
@@ -26,7 +26,7 @@
import org.hornetq.tests.util.UnitTestCase;
/**
- *
+ *
* A SessionCloseOnGCTest
*
* @author <mailto:clebert.suconic@jboss.org">Clebert Suconic</a>
@@ -57,7 +57,7 @@
protected void tearDown() throws Exception
{
//locator.close();
-
+
server.stop();
server = null;
@@ -269,12 +269,13 @@
public void testCloseOneSessionOnGC() throws Exception
{
- ClientSessionFactoryImpl sf = (ClientSessionFactoryImpl)
locator.createSessionFactory();
+ final ClientSessionFactoryImpl sf =
(ClientSessionFactoryImpl)locator.createSessionFactory();
- ClientSession session = sf.createSession(false, true, true);
+ try
+ {
+ ClientSession session = sf.createSession(false, true, true);
+ WeakReference<ClientSession> wses = new
WeakReference<ClientSession>(session);
- WeakReference<ClientSession> wses = new
WeakReference<ClientSession>(session);
-
Assert.assertEquals(1, server.getRemotingService().getConnections().size());
session = null;
@@ -284,12 +285,18 @@
Assert.assertEquals(0, sf.numSessions());
Assert.assertEquals(1, sf.numConnections());
Assert.assertEquals(1, server.getRemotingService().getConnections().size());
+ }
+ finally
+ {
+ sf.close();
+ }
}
public void testCloseSeveralSessionOnGC() throws Exception
{
- ClientSessionFactoryImpl sf = (ClientSessionFactoryImpl)
locator.createSessionFactory();
-
+ final ClientSessionFactoryImpl sf =
(ClientSessionFactoryImpl)locator.createSessionFactory();
+ try
+ {
ClientSession session1 = sf.createSession(false, true, true);
ClientSession session2 = sf.createSession(false, true, true);
ClientSession session3 = sf.createSession(false, true, true);
@@ -309,6 +316,11 @@
Assert.assertEquals(0, sf.numSessions());
Assert.assertEquals(1, sf.numConnections());
Assert.assertEquals(1, server.getRemotingService().getConnections().size());
+
+ }
+ finally
+ {
+ sf.close();
+ }
}
-
}
Modified:
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/client/SessionCloseTest.java
===================================================================
---
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/client/SessionCloseTest.java 2011-09-23
03:24:21 UTC (rev 11399)
+++
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/client/SessionCloseTest.java 2011-09-23
12:21:30 UTC (rev 11400)
@@ -21,11 +21,14 @@
import org.hornetq.api.core.HornetQException;
import org.hornetq.api.core.SimpleString;
import org.hornetq.api.core.TransportConfiguration;
-import org.hornetq.api.core.client.*;
+import org.hornetq.api.core.client.ClientConsumer;
+import org.hornetq.api.core.client.ClientProducer;
+import org.hornetq.api.core.client.ClientSession;
+import org.hornetq.api.core.client.ClientSessionFactory;
+import org.hornetq.api.core.client.HornetQClient;
+import org.hornetq.api.core.client.ServerLocator;
import org.hornetq.core.config.Configuration;
-import org.hornetq.core.config.impl.ConfigurationImpl;
import org.hornetq.core.remoting.impl.invm.InVMAcceptorFactory;
-import org.hornetq.core.remoting.impl.invm.InVMConnectorFactory;
import org.hornetq.core.server.HornetQServer;
import org.hornetq.core.server.HornetQServers;
import org.hornetq.tests.util.RandomUtil;
@@ -49,6 +52,8 @@
private ClientSessionFactory sf;
+ private ServerLocator locator;
+
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
@@ -252,7 +257,9 @@
server.start();
- ServerLocator locator = HornetQClient.createServerLocatorWithoutHA(new
TransportConfiguration(UnitTestCase.INVM_CONNECTOR_FACTORY));
+ locator =
+ HornetQClient.createServerLocatorWithoutHA(new TransportConfiguration(
+
UnitTestCase.INVM_CONNECTOR_FACTORY));
sf = locator.createSessionFactory();
}
@@ -270,8 +277,13 @@
server.stop();
}
+ if (locator != null)
+ {
+ locator.close();
+ }
+
+ locator = null;
sf = null;
-
server = null;
super.tearDown();
Modified:
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/client/SessionFactoryTest.java
===================================================================
---
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/client/SessionFactoryTest.java 2011-09-23
03:24:21 UTC (rev 11399)
+++
trunk/tests/integration-tests/src/test/java/org/hornetq/tests/integration/client/SessionFactoryTest.java 2011-09-23
12:21:30 UTC (rev 11400)
@@ -38,7 +38,7 @@
import org.hornetq.tests.util.ServiceTestBase;
/**
- *
+ *
* A ClientSessionFactoryTest
*
* @author <a href="mailto:andy.taylor@jboss.org">Andy Taylor</a>
@@ -50,7 +50,7 @@
{
private static final Logger log = Logger.getLogger(SessionFactoryTest.class);
- private DiscoveryGroupConfiguration groupConfiguration = new
DiscoveryGroupConfiguration(getUDPDiscoveryAddress(), getUDPDiscoveryPort());
+ private final DiscoveryGroupConfiguration groupConfiguration = new
DiscoveryGroupConfiguration(getUDPDiscoveryAddress(), getUDPDiscoveryPort());
private HornetQServer liveService;
@@ -101,16 +101,22 @@
Assert.assertNotNull(csi);
csi.close();
-
+
locator.close();
}
public void testCloseUnusedClientSessionFactoryWithoutGlobalPools() throws Exception
{
ServerLocator locator = HornetQClient.createServerLocatorWithoutHA(liveTC);
-
- ClientSessionFactory csf = locator.createSessionFactory();
- csf.close();
+ try
+ {
+ ClientSessionFactory csf = locator.createSessionFactory();
+ csf.close();
+ }
+ finally
+ {
+ locator.close();
+ }
}
public void testDiscoveryConstructor() throws Exception
@@ -141,15 +147,15 @@
HornetQClient.DEFAULT_RETRY_INTERVAL,
HornetQClient.DEFAULT_RETRY_INTERVAL_MULTIPLIER,
HornetQClient.DEFAULT_RECONNECT_ATTEMPTS);
-
+
ClientSessionFactory cf = locator.createSessionFactory();
ClientSession session = cf.createSession(false, true, true);
Assert.assertNotNull(session);
session.close();
testSettersThrowException(cf);
-
+
cf.close();
-
+
locator.close();
}
@@ -182,13 +188,13 @@
HornetQClient.DEFAULT_RETRY_INTERVAL,
HornetQClient.DEFAULT_RETRY_INTERVAL_MULTIPLIER,
HornetQClient.DEFAULT_RECONNECT_ATTEMPTS);
-
+
ClientSessionFactory cf = locator.createSessionFactory();
ClientSession session = cf.createSession(false, true, true);
Assert.assertNotNull(session);
session.close();
testSettersThrowException(cf);
-
+
cf.close();
}
Modified:
trunk/tests/unit-tests/src/test/java/org/hornetq/tests/unit/util/LinkedListTest.java
===================================================================
---
trunk/tests/unit-tests/src/test/java/org/hornetq/tests/unit/util/LinkedListTest.java 2011-09-23
03:24:21 UTC (rev 11399)
+++
trunk/tests/unit-tests/src/test/java/org/hornetq/tests/unit/util/LinkedListTest.java 2011-09-23
12:21:30 UTC (rev 11400)
@@ -57,6 +57,7 @@
payload = new byte[10 * 1024];
}
+ @Override
protected void finalize() throws Exception
{
count.decrementAndGet();
@@ -112,10 +113,8 @@
assertEquals(1000, count.get());
- int removed = 0;
while (iter.hasNext())
{
- System.out.println("removed " + (removed++));
iter.next();
iter.remove();
}