Cleanup the tearDown method to ensure we follow on to the super tearDown

where the broker is stopped.
This commit is contained in:
Timothy Bish 2016-05-25 12:15:21 -04:00
parent 3b626c9edc
commit 0757cdcd59
1 changed files with 21 additions and 9 deletions

View File

@ -31,27 +31,38 @@ public abstract class TransportBrokerTestSupport extends BrokerTest {
protected TransportConnector connector;
private ArrayList<StubConnection> connections = new ArrayList<StubConnection>();
@Override
protected void setUp() throws Exception {
super.setUp();
}
@Override
protected BrokerService createBroker() throws Exception {
BrokerService service = super.createBroker();
connector = service.addConnector(getBindLocation());
return service;
}
protected abstract String getBindLocation();
@Override
protected void tearDown() throws Exception {
for (Iterator<StubConnection> iter = connections.iterator(); iter.hasNext();) {
StubConnection connection = iter.next();
connection.stop();
iter.remove();
try {
StubConnection connection = iter.next();
connection.stop();
iter.remove();
} catch (Exception ex) {
}
}
if( connector!=null ) {
connector.stop();
if (connector != null) {
try {
connector.stop();
} catch (Exception ex) {
}
}
super.tearDown();
}
@ -59,12 +70,13 @@ public abstract class TransportBrokerTestSupport extends BrokerTest {
return new URI(getBindLocation());
}
@Override
protected StubConnection createConnection() throws Exception {
URI bindURI = getBindURI();
// Note: on platforms like OS X we cannot bind to the actual hostname, so we
// instead use the original host name (typically localhost) to bind to
// instead use the original host name (typically localhost) to bind to
URI actualURI = connector.getServer().getConnectURI();
URI connectURI = new URI(actualURI.getScheme(), actualURI.getUserInfo(), bindURI.getHost(), actualURI.getPort(), actualURI.getPath(), bindURI
.getQuery(), bindURI.getFragment());