conn.setClientID("testClient");
conn.start();
try
{
JBossSession session = (JBossSession) conn.createSession(true, Session.SESSION_TRANSACTED);
ClientSessionDelegate clientSessionDelegate = (ClientSessionDelegate) session.getDelegate();
SessionState sessionState = (SessionState) clientSessionDelegate.getState();
MessageConsumer consumerHA = session.createDurableSubscriber((Topic) destination, "T1");
MessageProducer producer = session.createProducer(destination);
Message message = session.createTextMessage("Hello Before");
producer.send(message);
session.commit();
receiveMessage("consumerHA", consumerHA, true, false);
session.commit();
//if (true) return;
Object txID = sessionState.getCurrentTxId();
producer.send(session.createTextMessage("Hello again before failover"));
ClientConnectionDelegate delegate = (ClientConnectionDelegate) conn.getDelegate();
JMSRemotingConnection originalRemoting = delegate.getRemotingConnection();
ServerManagement.kill(1);
// 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");
}
}
// if failover happened, this object was replaced
assertNotSame(originalRemoting, delegate.getRemotingConnection());
message = session.createTextMessage("Hello After");
producer.send(message);
assertEquals(txID, sessionState.getCurrentTxId());
session.commit();
receiveMessage("consumerHA", consumerHA, true, false);
receiveMessage("consumerHA", consumerHA, true, false);
receiveMessage("consumerHA", consumerHA, true, true);
session.commit();
consumerHA.close();
session.unsubscribe("T1");
}
finally
{
if (conn!=null)
{