assertEquals(1, ((JBossConnection)conn).getServerID());
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
QueueBrowser browser = session.createBrowser(queue[1]);
Enumeration en = browser.getEnumeration();
assertFalse(en.hasMoreElements());
// send one persistent and one non-persistent message
MessageProducer prod = session.createProducer(queue[1]);
prod.setDeliveryMode(DeliveryMode.PERSISTENT);
prod.send(session.createTextMessage("click"));
prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
prod.send(session.createTextMessage("clack"));
// register a failover listener
SimpleFailoverListener failoverListener = new SimpleFailoverListener();
((JBossConnection)conn).registerFailoverListener(failoverListener);
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(120000);
if (event != null && FailoverEvent.FAILOVER_COMPLETED == event.getType())
{
break;
}
if (event == null)
{
fail("Did not get expected FAILOVER_COMPLETED event");
}
}
// failover complete
log.info("failover completed");
assertEquals(0, ((JBossConnection)conn).getServerID());
en = browser.getEnumeration();
// we expect to only be able to browse the persistent message
assertTrue(en.hasMoreElements());
TextMessage tm = (TextMessage)en.nextElement();
assertEquals("click", tm.getText());