conn = factory.createConnection(); //connection on server 1
JBossConnection jbc = (JBossConnection)conn;
ClientConnectionDelegate del = (ClientConnectionDelegate)jbc.getDelegate();
ConnectionState state = (ConnectionState)del.getState();
int initialServerID = state.getServerID();
assertEquals(1, initialServerID);
Session sess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
MessageProducer prod = sess.createProducer(queue[1]);
MessageConsumer cons = sess.createConsumer(queue[1]);
final int NUM_MESSAGES = 100;
for (int i = 0; i < NUM_MESSAGES; i++)
{
TextMessage tm = sess.createTextMessage("message:" + i);
prod.send(tm);
}
conn.start();
//Now consume half of the messages but don't ack them these will end up in
//client side toAck list
for (int i = 0; i < NUM_MESSAGES / 2; i++)
{
TextMessage tm = (TextMessage)cons.receive(500);
assertNotNull(tm);
assertEquals("message:" + i, tm.getText());
}
//So now, messages should be in queue[1] on server 1
//So we now kill server 1
//Which should cause transparent failover of connection conn onto server 1
log.info("here we go");
log.info("######");
log.info("###### KILLING (CRASHING) SERVER 1");
log.info("######");
ServerManagement.kill(1);
killed = true;
long sleepTime = 60;
log.info("killed server, now waiting for " + sleepTime + " seconds");
// NOTE: the sleep time needs to be longer than the Remoting connector's lease period
Thread.sleep(sleepTime * 1000);
log.info("done wait");
state = (ConnectionState)del.getState();
int finalServerID = state.getServerID();
log.info("final server id= " + finalServerID);