added check to stop broker

This commit is contained in:
Andy Taylor 2015-07-31 09:52:46 +01:00
parent 9e761ad8e2
commit 38147ddbe7
5 changed files with 83 additions and 3 deletions

View File

@ -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<Broker, Exception> 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<Broker, Exception> 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;
}
}

View File

@ -71,6 +71,7 @@ public class ActiveMQXAConnectionFactoryTest extends CombinationTestSupport {
broker.stop();
} catch (Throwable ignore) {
}
super.tearDown();
}
public void testCopy() throws URISyntaxException, JMSException {

View File

@ -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) {

View File

@ -59,6 +59,7 @@ public class JmsRedeliveredTest extends TestCase {
connection.close();
connection = null;
}
CombinationTestSupport.checkStopped();
}
/**

View File

@ -80,9 +80,15 @@ public class MessageEvictionTest {
@After
public void tearDown() throws Exception {
if (connection != null)
{
connection.stop();
}
if (broker != null)
{
broker.stop();
}
}
@Test
public void testMessageEvictionMemoryUsageFileCursor() throws Exception {