//https://issues.jboss.org/browse/JBMESSAGING-1889
public void testConnectionConsumerXAFailover() throws Exception
{
XAConnection xaConn = null;
JBossConnection conn = null;
JBossConnectionConsumer cc = null;
XAConnectionFactory xaCF = (XAConnectionFactory)cf;
try
{
conn = (JBossConnection)createConnectionOnServer(cf, 1);
xaConn = createXAConnectionOnServer(xaCF, 1);
MockServerSessionPool2 sessionPool = new MockServerSessionPool2(xaConn);
cc = new JBossConnectionConsumer(conn.getDelegate(),
(JBossDestination)queue[1],
null,
null,
sessionPool,
5);
conn.start();
//Send a message
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer prod = sess.createProducer(queue[1]);
TextMessage sent1 = sess.createTextMessage("plop1");
prod.send(sent1);
sessionPool.waitToFailover();
// register a failover listener
SimpleFailoverListener failoverListener = new SimpleFailoverListener();
((JBossConnection)conn).registerFailoverListener(failoverListener);
SimpleFailoverListener failoverListener2 = new SimpleFailoverListener();
((JBossConnection)xaConn).registerFailoverListener(failoverListener2);
log.debug("killing node 1 ....");
ServerManagement.kill(1);
log.info("########");
log.info("######## KILLED NODE 1");
log.info("########");
// wait for the client-side failover to complete
while(true)
{
FailoverEvent event = failoverListener.getEvent(30000);
if (event != null && FailoverEvent.FAILOVER_COMPLETED == event.getType())
{
break;
}
if (event == null)
{
fail("Did not get expected FAILOVER_COMPLETED event");
}
}
while(true)
{
FailoverEvent event = failoverListener2.getEvent(30000);
if (event != null && FailoverEvent.FAILOVER_COMPLETED == event.getType())
{
break;
}
if (event == null)
{
fail("Did not get expected FAILOVER_COMPLETED event on xaConn");
}
}
// failover complete
log.info("failover completed");
sessionPool.failoverComplete();
Thread.sleep(5000);
int n = sessionPool.getReceivedMessage();
//either this should fail or the message is left on the queue. both valid.
assertTrue(n == 1);
}
finally
{
if (conn != null)
{
conn.close();
}
if (xaConn != null)
{
xaConn.close();
}