try
{
for (int i = 0; i < ServerManagement.MAX_SERVER_COUNT; i++)
{
Server server = ServerManagement.getServer(i);
if (server != null)
{
oldTimeout = ((Long)server.getAttribute(ServerManagement.getServerPeerObjectName(), "RecoverDeliveriesTimeout")).longValue();
server.setAttribute(ServerManagement.getServerPeerObjectName(), "RecoverDeliveriesTimeout", String.valueOf(timeout));
}
}
ServerManagement.deployQueue("timeoutQueue", 0);
ServerManagement.deployQueue("timeoutQueue", 1);
ServerManagement.deployQueue("timeoutQueue", 2);
Queue timeoutQueue = (Queue)ic[1].lookup("/queue/timeoutQueue");
Session sessSend = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer prod1 = sessSend.createProducer(timeoutQueue);
final int numMessages = 10;
for (int i = 0; i < numMessages; i++)
{
TextMessage tm = sessSend.createTextMessage("message" + i);
prod1.send(tm);
}
Session sess1 = conn1.createSession(false, Session.CLIENT_ACKNOWLEDGE);
MessageConsumer cons1 = sess1.createConsumer(timeoutQueue);
conn1.start();
TextMessage tm = null;
for (int i = 0; i < numMessages; i++)
{
tm = (TextMessage)cons1.receive(2000);
assertNotNull(tm);
assertEquals("message" + i, tm.getText());
}
int failoverNodeId = this.getFailoverNodeForNode(cf, 1);
int recoveryMapSize = ServerManagement.getServer(failoverNodeId).getRecoveryMapSize(timeoutQueue.getQueueName());
assertEquals(0, recoveryMapSize);
Map recoveryArea = ServerManagement.getServer(failoverNodeId).getRecoveryArea(timeoutQueue.getQueueName());
Map ids = (Map)recoveryArea.get(new Integer(1));
assertNotNull(ids);
assertEquals(numMessages, ids.size());
//First turn OFF failover on the connection factory
ServerManagement.kill(1);
log.info("########");
log.info("######## KILLED NODE 1");
log.info("########");
//Failover won't occur on the client
//Let's give it enough time to happen on the server
Thread.sleep(10000);
recoveryMapSize = ServerManagement.getServer(failoverNodeId).getRecoveryMapSize(timeoutQueue.getQueueName());
assertEquals(numMessages, recoveryMapSize);
recoveryArea = ServerManagement.getServer(failoverNodeId).getRecoveryArea(timeoutQueue.getQueueName());
ids = (Map)recoveryArea.get(new Integer(1));
assertNull(ids);
//Now we wait for the timeout period
log.info("Waiting for timeout");
Thread.sleep(timeout + 1000);
log.info("Waited");
recoveryMapSize = ServerManagement.getServer(failoverNodeId).getRecoveryMapSize(timeoutQueue.getQueueName());
assertEquals(0, recoveryMapSize);
recoveryArea = ServerManagement.getServer(failoverNodeId).getRecoveryArea(timeoutQueue.getQueueName());
ids = (Map)recoveryArea.get(new Integer(1));
assertNull(ids);
//Now we should be able to consume the refs again
conn1.close();
log.info("Creating connection");
conn2 = createConnectionOnServer(cf, failoverNodeId);
Session sess2 = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer cons2 = sess2.createConsumer(timeoutQueue);
conn2.start();
Set msgs = new HashSet();
for (int i = 0; i < numMessages; i++)
{
tm = (TextMessage)cons2.receive(2000);
assertNotNull(tm);
log.info("Got message:" + tm.getText());
msgs.add(tm.getText());
}
for (int i = 0; i < numMessages; i++)
{
assertTrue(msgs.contains("message" + i));
}
tm = (TextMessage)cons2.receive(5000);
assertNull(tm);
}
finally
{
if (conn1 != null)
{
conn1.close();
}
if (conn2 != null)
{
conn2.close();
}
((ClientClusteredConnectionFactoryDelegate)cf.getDelegate()).setSupportsFailover(true);
for (int i = 0; i < ServerManagement.MAX_SERVER_COUNT; i++)
{
Server server = ServerManagement.getServer(i);
if (server != null)
{
server.setAttribute(ServerManagement.getServerPeerObjectName(), "RecoverDeliveriesTimeout", String.valueOf(oldTimeout));
}
}
}
}