ConnectionState state = (ConnectionState)del.getState();
ResourceManager rm = state.getResourceManager();
// Create a session
JBossSession sess1 = (JBossSession)conn.createXASession();
DummyListener listener = new DummyListener();
sess1.setMessageListener(listener);
conn.start();
MessagingXAResource res1 = (MessagingXAResource)sess1.getXAResource();
tm.begin();
Transaction trans = tm.getTransaction();
trans.enlistResource(res1);
trans.delistResource(res1, XAResource.TMSUCCESS);
MessageProducer p = sess1.createProducer(queue1);
MessageConsumer cons = sess1.createConsumer(queue1);
conn.start();
// send 10 messages
for (int i = 0; i < 10; i++)
{
TextMessage message = sess1.createTextMessage("delistedwork" + i);
p.send(message);
}
// now receive 5
for (int i = 0; i < 5; i++)
{
TextMessage textMessage = (TextMessage)cons.receive();
assertEquals("delistedwork" + i, textMessage.getText());
}
// once we enlist ensure that the 5 acks are merged ok, the first timne we do this there is nothing to merge in
// the global tx
// so all acks are just copied
trans.enlistResource(res1);
SessionState sstate = (SessionState)((DelegateSupport)sess1.getDelegate()).getState();
ClientTransaction clientTransaction = rm.getTx(sstate.getCurrentTxId());
assertEquals("to many session states", clientTransaction.getSessionStates().size(), 1);
ClientTransaction.SessionTxState sessionTxState = (ClientTransaction.SessionTxState)clientTransaction.getSessionStates()
.get(0);
assertEquals("wrong number of acks", 5, sessionTxState.getAcks().size());