Buggy code:
@ RunWith ( Arquillian . class ) @ RunAsClient @ ServerSetup ( SendMessagesTestCase . SendMessagesTestCaseSetup . class ) public class SendMessagesTestCase { private static final Logger log = Logger . getLogger ( SendMessagesTestCase . class ) ; private static final String MBEAN = "mbean-containerstart" ; private static final String SINGLETON = "single-containerstart" ; private static ExecutorService executor = Executors . newSingleThreadExecutor ( ) ; private static String QUEUE_SEND = "queue//sendMessage" ; private static String QUEUE_REPLY = "queue//replyMessage" ; @ ContainerResource private ManagementClient managementClient ; static class SendMessagesTestCaseSetup extends AbstractMgmtServerSetupTask { @ Override protected void doSetup ( final ManagementClient managementClient ) throws Exception { } @ Override public void tearDown ( final ManagementClient managementClient ) throws Exception { } private void createQueue ( String queueName ) throws Exception { } private void destroyQueue ( String queueName ) throws Exception { } } @ ArquillianResource private Deployer deployer ; @ ArquillianResource @ OperateOnDeployment ( "test" ) private InitialContext initialContext ; @ AfterClass public static void afterClass ( ) { } @ Deployment ( name = "singleton" , order = 1 , testable = false , managed = true ) public static Archive < ? > deploymentMbean ( ) { } @ Deployment ( name = "mdb" , order = 2 , testable = false , managed = false ) public static Archive < ? > deploymentMdb ( ) { } @ Deployment ( name = "test" , order = 3 , managed = true , testable = true ) public static Archive < ? > deploymentTest ( ) { } private static ModelNode getQueueAddr ( String name ) { } public static void applyUpdate ( ModelNode update , final ModelControllerClient client ) throws Exception { } private int awaitSingleton ( String where ) throws Exception { } private static void sendMessage ( Session session , MessageProducer sender , Queue replyQueue , String txt ) throws JMSException { } @ Test public void testShutdown ( ) throws Exception { Session session = null ; MessageProducer sender = null ; MessageConsumer receiver = null ; Connection connection = null ; try { deployer . deploy ( "mdb" ) ; Queue queue = new HornetQQueue ( SendMessagesTestCase . QUEUE_SEND ) ; Queue replyQueue = new HornetQQueue ( SendMessagesTestCase . QUEUE_REPLY ) ; Map < String , Object > connectionParams = new HashMap < String , Object > ( ) ; <START_BUG> connectionParams . put ( HOST_PROP_NAME , "localhost" ) ; <END_BUG> connectionParams . put ( PORT_PROP_NAME , 5445 ) ; TransportConfiguration transportConfiguration = new TransportConfiguration ( NettyConnectorFactory . class . getName ( ) , connectionParams ) ; ConnectionFactory cf = ( ( ConnectionFactory ) ( HornetQJMSClient . createConnectionFactoryWithoutHA ( CF , transportConfiguration ) ) ) ; connection = cf . createConnection ( "guest" , "guest" ) ; connection . start ( ) ; session = connection . createSession ( false , AUTO_ACKNOWLEDGE ) ; sender = session . createProducer ( queue ) ; receiver = session . createConsumer ( replyQueue ) ; SortedSet < String > expected = new TreeSet < String > ( ) ; SendMessagesTestCase . sendMessage ( session , sender , replyQueue , "await" ) ; expected . add ( "Reply:<seq2seq4repair_space>await" ) ; int awaitInt = awaitSingleton ( "first<seq2seq4repair_space>test" ) ; SendMessagesTestCase . log . debug ( ( "testsuite:<seq2seq4repair_space>awaitSingleton()<seq2seq4repair_space>returned:<seq2seq4repair_space>" + awaitInt ) ) ; Future < ? > undeployed = SendMessagesTestCase . executor . submit ( undeployTask ( ) ) ; Thread . sleep ( 1000 ) ; for ( int i = 0 ; i < 50 ; i ++ ) { String msg = ( "Do<seq2seq4repair_space>not<seq2seq4repair_space>lose!<seq2seq4repair_space>(" + i ) + ")" ; SendMessagesTestCase . sendMessage ( session , sender , replyQueue , msg ) ; expected . add ( ( "Reply:<seq2seq4repair_space>" + msg ) ) ; } awaitInt = awaitSingleton ( "second<seq2seq4repair_space>test" ) ; SendMessagesTestCase . log . debug ( ( "testsuite:<seq2seq4repair_space>awaitSingleton()2<seq2seq4repair_space>returned::<seq2seq4repair_space>" + awaitInt ) ) ; undeployed . get ( 10 , TimeUnit . SECONDS ) ; final ModelNode deployAddr = new ModelNode ( ) ; deployAddr . get ( OP_ADDR ) . add ( "deployment" , ( ( SendMessagesTestCase . MBEAN ) + ".jar" ) ) ; deployAddr . get ( OP ) . set ( "deploy" ) ; SendMessagesTestCase . applyUpdate ( deployAddr , managementClient . getControllerClient ( ) ) ; for ( int i = 0 ; i < 10 ; i ++ ) { String msg = ( "Some<seq2seq4repair_space>more<seq2seq4repair_space>(" + i ) + ")" ; SendMessagesTestCase . sendMessage ( session , sender , replyQueue , msg ) ; expected . add ( ( "Reply:<seq2seq4repair_space>" + msg ) ) ; } SendMessagesTestCase . log . debug ( "Some<seq2seq4repair_space>more<seq2seq4repair_space>messages<seq2seq4repair_space>sent" ) ; SortedSet < String > received = new TreeSet < String > ( ) ; for ( int i = 0 ; i < ( ( 1 + 50 ) + 10 ) ; i ++ ) { Message msg = receiver . receive ( TimeUnit . SECONDS . toMillis ( 10 ) ) ; Assert . assertNotNull ( msg ) ; String text = ( ( javax . jms . TextMessage ) ( msg ) ) . getText ( ) ; received . add ( text ) ; SendMessagesTestCase . log . info ( ( ( i + ":<seq2seq4repair_space>" ) + text ) ) ; } Assert . assertEquals ( expected , received ) ; connection . stop ( ) ; } finally { if ( connection != null ) { connection . close ( ) ; } if ( session != null ) { session . close ( ) ; } if ( sender != null ) { sender . close ( ) ; } if ( receiver != null ) { receiver . close ( ) ; } if ( ( SendMessagesTestCase . executor ) != null ) { SendMessagesTestCase . executor . shutdown ( ) ; } deployer . undeploy ( "mdb" ) ; } } private Callable < Void > undeployTask ( ) { } }

Fix:
connectionParams . put ( HOST_PROP_NAME , managementClient . getMgmtAddress ( ) ) ;