public void testFailoverFloodTwoServers() throws Exception
{
JBossConnection conn = null;
try
{
conn = (JBossConnection)this.createConnectionOnServer(cf, 1);
Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
Session sessCons = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer cons = sessCons.createConsumer(queue[1]);
MyListener list = new MyListener();
cons.setMessageListener(list);
conn.start();
MessageProducer prod = sessSend.createProducer(queue[1]);
prod.setDeliveryMode(DeliveryMode.PERSISTENT);
int count = 0;
Killer killer = new Killer();
Thread t = new Thread(killer);
t.start();
while (!killer.isDone())
{
TextMessage tm = sessSend.createTextMessage("message " + count);
tm.setIntProperty("cnt", count);
prod.send(tm);
if (count % 100 == 0)
{
log.info("sent " + count + " server id " + conn.getServerID());
}
count++;
//Thread.sleep(5);
}
log.info("done send");
log.info("Waiting to join thread");
t.join(5 * 60 * 60 * 1000);
log.info("joined");
if (killer.failed)
{
fail();
}
//We check that we received all the message
//we allow for duplicates, see http://jira.jboss.org/jira/browse/JBMESSAGING-604
//We are using auto_ack with a listener so duplicates are ok
if (!list.waitFor(count - 1))
{
fail("Timed out waiting for message");
}
conn.close();
conn = null;
count = 0;
Iterator iter = list.msgs.iterator();
while (iter.hasNext())
{
Integer i = (Integer)iter.next();
if (i.intValue() != count)
{
fail("Missing message " + i);
}
count++;
}
if (list.failed)
{
fail();
}
}
catch (Exception e)
{
log.error("Failed", e);
throw e;
}
finally
{
if (conn != null)
{
log.info("closing connection");
try
{
conn.close();
}
catch (Exception ignore)
{
}
log.info("closed connection");