Buggy code:
@ RunWith ( Arquillian . class ) @ RunAsClient 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" ; public static ModelControllerClient modelControllerClient ; private ExecutorService executor = Executors . newSingleThreadExecutor ( ) ; private static String QUEUE_SEND = "queue//sendMessage" ; private static String QUEUE_REPLY = "queue//replyMessage" ; @ ArquillianResource Deployer deployer ; @ 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 ( ) { } @ BeforeClass public static void init ( ) throws Exception { } @ AfterClass public static void clearUp ( ) throws Exception { } private InitialContext getInitialContext ( ) throws NamingException { } private static void createQueue ( ModelControllerClient modelClient , String queueName ) throws Exception { } private static void destroyQueue ( ModelControllerClient modelClient , String queueName ) throws Exception { } 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 > ( ) ; connectionParams . put ( HOST_PROP_NAME , "localhost" ) ; connectionParams . put ( PORT_PROP_NAME , 5445 ) ; TransportConfiguration transportConfiguration = new TransportConfiguration ( NettyConnectorFactory . class . getName ( ) , connectionParams ) ; ConnectionFactory cf = ( ( ConnectionFactory ) ( HornetQJMSClient . createConnectionFactoryWithoutHA ( CF , transportConfiguration ) ) ) ; <START_BUG> connection = cf . createConnection ( ) ; <END_BUG> 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 = 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 , SendMessagesTestCase . modelControllerClient ) ; 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 = ( ( 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 ( ( executor ) != null ) { executor . shutdown ( ) ; } deployer . undeploy ( "mdb" ) ; } } private Callable < Void > undeployTask ( ) { } }

Fix:
connection = cf . createConnection ( "guest" , "guest" ) ;