// we need to disable exception listener otherwise it will clear up the connection itself
ObjectName remoteConnectorName = ServiceContainer.REMOTING_OBJECT_NAME;
ConnectionManager cm = localServer.getServerPeer().getConnectionManager();
localServer.getServerPeer().getServer().
invoke(remoteConnectorName,
"removeConnectionListener",
new Object[] {cm},
new String[] {"org.jboss.remoting.ConnectionListener"});
InitialContext ic = new InitialContext(InVMInitialContextFactory.getJNDIEnvironment());
ConnectionFactory cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
Queue queue = (Queue)ic.lookup("/queue/Queue");
CreateHangingConsumerCommand command = new CreateHangingConsumerCommand(cf, queue);
String remotingSessionId = (String)remoteServer.executeCommand(command);
remoteServer.kill();
// we have removed the exception listener so the server side resouces shouldn't be cleared up
log.info("sleeping for 1 min ...");
Thread.sleep(60000);
assertTrue(cm.containsRemotingSession(remotingSessionId));
// Now we send a message which should prompt delivery to the dead consumer causing
// an exception which should cause connection cleanup
Connection conn = cf.createConnection();
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer prod = sess.createProducer(queue);
// sending just one message should be enough to trigger the failure and client smacking
prod.send(sess.createMessage());
log.info("sleeping for 45 secs ...");
Thread.sleep(45000);
assertFalse(cm.containsRemotingSession(remotingSessionId));
// make sure the message is still in queue
conn = cf.createConnection();
conn.start();