// create a connection to node 1
conn = createConnectionOnServer(cf, 1);
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"));
//Give time for the NP message to arrive
Thread.sleep(2000);
// register a failover listener
SimpleFailoverListener failoverListener = new SimpleFailoverListener();
((JBossConnection)conn).registerFailoverListener(failoverListener);
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");
}
}
// failover complete
assertEquals(0, getServerId(conn));
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());