diff --git a/tests/activemq5-unit-tests/src/main/java/org/apache/activemq/broker/BrokerService.java b/tests/activemq5-unit-tests/src/main/java/org/apache/activemq/broker/BrokerService.java index f2b5b302e1..8ce8fd950b 100644 --- a/tests/activemq5-unit-tests/src/main/java/org/apache/activemq/broker/BrokerService.java +++ b/tests/activemq5-unit-tests/src/main/java/org/apache/activemq/broker/BrokerService.java @@ -27,6 +27,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.WeakHashMap; import javax.management.MalformedObjectNameException; import javax.management.ObjectName; @@ -96,6 +97,8 @@ public class BrokerService implements Service private PolicyMap destinationPolicy; private SystemUsage systemUsage; + public static WeakHashMap map = new WeakHashMap<>(); + static { InputStream in; @@ -135,7 +138,10 @@ public class BrokerService implements Service @Override public void start() throws Exception { + Exception e = new Exception(); + e.fillInStackTrace(); startBroker(startAsync); + map.put(broker, e); } private void startBroker(boolean async) throws Exception @@ -605,7 +611,7 @@ public class BrokerService implements Service public boolean isStopped() { - return broker.isStopped(); + return broker != null ? broker.isStopped() : true; } public void setBrokerId(String brokerId) @@ -744,6 +750,30 @@ public class BrokerService implements Service { return "tcp://localhost:61616"; } + + public static boolean checkStopped() + { + boolean runningBrokers = false; + for (Map.Entry brokerExceptionEntry : map.entrySet()) + { + Broker b = brokerExceptionEntry.getKey(); + if (!b.isStopped()) + { + try + { + b.stop(); + } + catch (Exception e) + { + e.printStackTrace(); + } + brokerExceptionEntry.getValue().printStackTrace(); + runningBrokers = true; + } + } + map.clear(); + return runningBrokers; + } } diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/ActiveMQXAConnectionFactoryTest.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/ActiveMQXAConnectionFactoryTest.java index 4b89851ffb..bafcaa6120 100644 --- a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/ActiveMQXAConnectionFactoryTest.java +++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/ActiveMQXAConnectionFactoryTest.java @@ -71,6 +71,7 @@ public class ActiveMQXAConnectionFactoryTest extends CombinationTestSupport { broker.stop(); } catch (Throwable ignore) { } + super.tearDown(); } public void testCopy() throws URISyntaxException, JMSException { diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/CombinationTestSupport.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/CombinationTestSupport.java index a11505c610..f26a97542c 100644 --- a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/CombinationTestSupport.java +++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/CombinationTestSupport.java @@ -21,6 +21,7 @@ import java.io.IOException; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.Modifier; +import java.net.ServerSocket; import java.security.ProtectionDomain; import java.util.ArrayList; import java.util.Arrays; @@ -35,6 +36,9 @@ import java.util.Map; import junit.framework.Test; import junit.framework.TestSuite; +import org.apache.activemq.artemiswrapper.ArtemisBrokerHelper; +import org.apache.activemq.broker.BrokerService; +import org.apache.activemq.transport.tcp.TcpTransportFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -101,6 +105,44 @@ public abstract class CombinationTestSupport extends AutoFailTestSupport { } } + @Override + protected void tearDown() throws Exception + { + super.tearDown(); + checkStopped(); + } + + public static void checkStopped() throws Exception + { + ArtemisBrokerHelper.stopArtemisBroker(); + boolean notStopped = BrokerService.checkStopped(); + TcpTransportFactory.setBrokerName(null); + if (notStopped) + { + fail("brokers not stopped see exceptions above"); + } + ServerSocket socket = null; + try + { + socket = new ServerSocket(61616); + } + catch (IOException e) + { + fail("61616 port not released"); + } + finally + { + if (socket != null) + try + { + socket.close(); + } + catch (IOException e) + { + } + } + } + @Override public void runBare() throws Throwable { if (combosEvaluated) { diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/JmsRedeliveredTest.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/JmsRedeliveredTest.java index e5d90d681e..8a2cd62576 100644 --- a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/JmsRedeliveredTest.java +++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/JmsRedeliveredTest.java @@ -59,6 +59,7 @@ public class JmsRedeliveredTest extends TestCase { connection.close(); connection = null; } + CombinationTestSupport.checkStopped(); } /** diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/MessageEvictionTest.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/MessageEvictionTest.java index b079070296..efa86a9330 100644 --- a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/MessageEvictionTest.java +++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/MessageEvictionTest.java @@ -80,8 +80,14 @@ public class MessageEvictionTest { @After public void tearDown() throws Exception { - connection.stop(); - broker.stop(); + if (connection != null) + { + connection.stop(); + } + if (broker != null) + { + broker.stop(); + } } @Test