{
try
{
startHornetQServer(acceptorFactory);
JMSServerControl control = createManagementControl();
Assert.assertEquals(0, server.getConnectionCount());
Assert.assertEquals(0, control.listRemoteAddresses().length);
ConnectionFactory cf = JMSUtil.createFactory(connectorFactory,
JMSServerControl2Test.CONNECTION_TTL,
JMSServerControl2Test.PING_PERIOD);
Connection connection = cf.createConnection();
Assert.assertEquals(1, server.getConnectionCount());
String[] remoteAddresses = control.listRemoteAddresses();
Assert.assertEquals(1, remoteAddresses.length);
String remoteAddress = remoteAddresses[0];
final CountDownLatch exceptionLatch = new CountDownLatch(1);
connection.setExceptionListener(new ExceptionListener()
{
public void onException(final JMSException e)
{
exceptionLatch.countDown();
}
});
Assert.assertTrue(control.closeConnectionsForAddress(remoteAddress));
boolean gotException = exceptionLatch.await(2 * JMSServerControl2Test.CONNECTION_TTL, TimeUnit.MILLISECONDS);
Assert.assertTrue("did not received the expected JMSException", gotException);
remoteAddresses = control.listRemoteAddresses();
Assert.assertEquals("got " + Arrays.asList(remoteAddresses), 0, remoteAddresses.length);
Assert.assertEquals(0, server.getConnectionCount());
connection.close();
}