Author: borges
Date: 2011-12-07 06:58:59 -0500 (Wed, 07 Dec 2011)
New Revision: 11870
Modified:
trunk/hornetq-core/src/test/java/org/hornetq/tests/util/ServiceTestBase.java
trunk/hornetq-core/src/test/java/org/hornetq/tests/util/UnitTestCase.java
Log:
Move server closing utilities to UnitTestCase
Modified: trunk/hornetq-core/src/test/java/org/hornetq/tests/util/ServiceTestBase.java
===================================================================
---
trunk/hornetq-core/src/test/java/org/hornetq/tests/util/ServiceTestBase.java 2011-12-07
11:58:43 UTC (rev 11869)
+++
trunk/hornetq-core/src/test/java/org/hornetq/tests/util/ServiceTestBase.java 2011-12-07
11:58:59 UTC (rev 11870)
@@ -81,7 +81,6 @@
protected static final String NETTY_CONNECTOR_FACTORY =
NettyConnectorFactory.class.getCanonicalName();
private final Collection<ServerLocator> locators = new
ArrayList<ServerLocator>();
- private final Collection<HornetQServer> servers = new
ArrayList<HornetQServer>();
private final Collection<ClientSessionFactory> sessionFactories = new
ArrayList<ClientSessionFactory>();
private final Collection<ClientSession> clientSessions = new
ArrayList<ClientSession>();
@@ -94,15 +93,6 @@
closeAllServerLocatorsFactories();
- synchronized (servers)
- {
- for (HornetQServer server : servers)
- {
- stopComponent(server);
- }
- servers.clear();
- }
-
super.tearDown();
// checkFreePort(5445);
// checkFreePort(5446);
@@ -114,7 +104,7 @@
}
/**
- *
+ *
*/
protected void closeAllServerLocatorsFactories()
{
@@ -129,7 +119,7 @@
}
/**
- *
+ *
*/
protected void closeAllSessionFactories()
{
@@ -144,7 +134,7 @@
}
/**
- *
+ *
*/
protected void closeAllClientSessions()
{
@@ -405,15 +395,6 @@
}
}
- protected HornetQServer addServer(HornetQServer server)
- {
- synchronized (servers)
- {
- servers.add(server);
- }
- return server;
- }
-
protected ClientSession addClientSession(ClientSession session)
{
synchronized (clientSessions)
@@ -705,15 +686,22 @@
addSessionFactory(sf);
return sf;
}
+
protected void createQueue(final String address, final String queue) throws Exception
{
ServerLocator locator = createInVMNonHALocator();
ClientSessionFactory sf = locator.createSessionFactory();
ClientSession session = sf.createSession();
- session.createQueue(address, queue);
- session.close();
- sf.close();
- locator.close();
+ try
+ {
+ session.createQueue(address, queue);
+ }
+ finally
+ {
+ session.close();
+ sf.close();
+ locator.close();
+ }
}
protected ServerLocator createInVMNonHALocator()
Modified: trunk/hornetq-core/src/test/java/org/hornetq/tests/util/UnitTestCase.java
===================================================================
--- trunk/hornetq-core/src/test/java/org/hornetq/tests/util/UnitTestCase.java 2011-12-07
11:58:43 UTC (rev 11869)
+++ trunk/hornetq-core/src/test/java/org/hornetq/tests/util/UnitTestCase.java 2011-12-07
11:58:59 UTC (rev 11870)
@@ -31,6 +31,7 @@
import java.net.ServerSocket;
import java.nio.ByteBuffer;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -125,6 +126,8 @@
// There is a verification about thread leakages. We only fail a single thread when
this happens
private static Set<Thread> alreadyFailedThread = new HashSet<Thread>();
+ private final Collection<HornetQServer> servers = new
ArrayList<HornetQServer>();
+
private boolean checkThread = true;
protected void disableCheckThread()
@@ -923,6 +926,16 @@
@Override
protected void tearDown() throws Exception
{
+
+ synchronized (servers)
+ {
+ for (HornetQServer server : servers)
+ {
+ stopComponent(server);
+ }
+ servers.clear();
+ }
+
List<ClientSessionFactoryImpl.CloseRunnable> closeRunnables = new
ArrayList<ClientSessionFactoryImpl.CloseRunnable>(ClientSessionFactoryImpl.CLOSE_RUNNABLES);
ArrayList<Exception> exceptions = new ArrayList<Exception>();
try
@@ -1426,6 +1439,14 @@
}
+ protected HornetQServer addServer(HornetQServer server)
+ {
+ synchronized (servers)
+ {
+ servers.add(server);
+ }
+ return server;
+ }
protected static final void stopComponent(HornetQComponent component)
{
if (component == null)
Show replies by date