LocalClusteredQueue queue3 =
new LocalClusteredQueue(office3, 3, "queue3", channelIDManager.getID(), ms, pm,
true, true, -1, null, tr);
office3.bindClusteredQueue(new SimpleCondition("topic1"), queue3);
SimpleReceiver receiver1 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);
queue1.add(receiver1);
SimpleReceiver receiver2 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);
queue2.add(receiver2);
SimpleReceiver receiver3 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);
queue3.add(receiver3);
//This will make it fail after casting but before persisting the message in the db
office1.setFail(true, false, false);
Transaction tx = tr.createTransaction();
final int NUM_MESSAGES = 10;
for (int i = 0; i < NUM_MESSAGES; i++)
{
Message msg = CoreMessageFactory.createCoreMessage(i, true, null);
MessageReference ref = ms.reference(msg);
office1.route(ref, new SimpleCondition("topic1"), tx);
}
Thread.sleep(1000);
List msgs = receiver1.getMessages();
assertTrue(msgs.isEmpty());
msgs = receiver2.getMessages();
assertTrue(msgs.isEmpty());
msgs = receiver3.getMessages();
assertTrue(msgs.isEmpty());
try
{
//An exception should be thrown
tx.commit();
fail();
}
catch (TransactionException e)
{
//Ok
}
Thread.sleep(1000);
msgs = receiver1.getMessages();
assertTrue(msgs.isEmpty());
msgs = receiver2.getMessages();
assertTrue(msgs.isEmpty());
msgs = receiver3.getMessages();
assertTrue(msgs.isEmpty());
//Nodes 2 and 3 should have a held tx
assertTrue(office1.getHoldingTransactions().isEmpty());
assertEquals(1, office2.getHoldingTransactions().size());
assertEquals(1, office3.getHoldingTransactions().size());
//We now kill the office - this should make the other offices do their transaction check
office1.stop();
Thread.sleep(1000);
//This should result in the held txs being rolled back
assertTrue(office1.getHoldingTransactions().isEmpty());
assertTrue(office2.getHoldingTransactions().isEmpty());
assertTrue(office3.getHoldingTransactions().isEmpty());
//The tx should be removed from the holding area and nothing should be received
//remember node1 has now crashed so no point checking receiver1
msgs = receiver2.getMessages();
assertTrue(msgs.isEmpty());
msgs = receiver3.getMessages();
assertTrue(msgs.isEmpty());
}
finally
{