office1 = createClusteredPostOffice(1);
office2 = createClusteredPostOffice(2);
office3 = createClusteredPostOffice(3);
office4 = createClusteredPostOffice(4);
Queue queue1 = new MessagingQueue(1, "queue1", channelIDManager.getID(), ms, pm, false, -1, null, true);
queue1.activate();
boolean added = office1.addBinding(new Binding(new SimpleCondition("condition1"), queue1, false), false);
assertTrue(added);
Queue queue2 = new MessagingQueue(2, "queue2", channelIDManager.getID(), ms, pm, false, -1, null, true);
queue2.activate();
added = office2.addBinding(new Binding(new SimpleCondition("condition1"), queue2, false), false);
assertTrue(added);
Queue queue3 = new MessagingQueue(3, "queue3", channelIDManager.getID(), ms, pm, false, -1, null, true);
queue3.activate();
added = office3.addBinding(new Binding(new SimpleCondition("condition1"), queue3, false), false);
assertTrue(added);
Queue queue4 = new MessagingQueue(4, "queue4", channelIDManager.getID(), ms, pm, false, -1, null, true);
queue4.activate();
added = office4.addBinding(new Binding(new SimpleCondition("condition1"), queue4, false), false);
assertTrue(added);
SimpleReceiver receiver1 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);
queue1.getLocalDistributor().add(receiver1);
SimpleReceiver receiver2 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);
queue2.getLocalDistributor().add(receiver2);
SimpleReceiver receiver3 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);
queue3.getLocalDistributor().add(receiver3);
SimpleReceiver receiver4 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);
queue4.getLocalDistributor().add(receiver4);
Message msg1 = CoreMessageFactory.createCoreMessage(1, persistentMessage, null);
MessageReference ref1 = ms.reference(msg1);
RouteResult routed = office1.route(ref1, new SimpleCondition("condition1"), null);
assertTrue(routed.getResult());
Message msg2 = CoreMessageFactory.createCoreMessage(2, persistentMessage, null);
MessageReference ref2 = ms.reference(msg2);
routed = office1.route(ref2, new SimpleCondition("condition1"), null);
assertTrue(routed.getResult());
Message msg3 = CoreMessageFactory.createCoreMessage(3, persistentMessage, null);
MessageReference ref3 = ms.reference(msg3);
routed = office1.route(ref3, new SimpleCondition("condition1"), null);
assertTrue(routed.getResult());
Thread.sleep(3000);
List msgs = receiver1.getMessages();
assertNotNull(msgs);
assertEquals(3, msgs.size());
Message msgRec1 = (Message)msgs.get(0);
assertEquals(msg1, msgRec1);
Message msgRec2 = (Message)msgs.get(1);
assertEquals(msg2, msgRec2);
Message msgRec3 = (Message)msgs.get(2);
assertEquals(msg3, msgRec3);
receiver1.acknowledge(msgRec1, null);
receiver1.acknowledge(msgRec2, null);
receiver1.acknowledge(msgRec3, null);
msgs = queue1.browse(null);
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
msgs = receiver2.getMessages();
assertNotNull(msgs);
assertEquals(3, msgs.size());
msgRec1 = (Message)msgs.get(0);
assertEquals(msg1, msgRec1);
msgRec2 = (Message)msgs.get(1);
assertEquals(msg2, msgRec2);
msgRec3 = (Message)msgs.get(2);
assertEquals(msg3, msgRec3);
receiver2.acknowledge(msgRec1, null);
receiver2.acknowledge(msgRec2, null);
receiver2.acknowledge(msgRec3, null);
msgs = queue2.browse(null);
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
msgs = receiver3.getMessages();
assertNotNull(msgs);
assertEquals(3, msgs.size());
msgRec1 = (Message)msgs.get(0);
assertEquals(msg1, msgRec1);
msgRec2 = (Message)msgs.get(1);
assertEquals(msg2, msgRec2);
msgRec3 = (Message)msgs.get(2);
assertEquals(msg3, msgRec3);
receiver3.acknowledge(msgRec1, null);
receiver3.acknowledge(msgRec2, null);
receiver3.acknowledge(msgRec3, null);
msgs = queue3.browse(null);
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
msgs = receiver4.getMessages();
assertNotNull(msgs);
assertEquals(3, msgs.size());
msgRec1 = (Message)msgs.get(0);
assertEquals(msg1, msgRec1);
msgRec2 = (Message)msgs.get(1);
assertEquals(msg2, msgRec2);
msgRec3 = (Message)msgs.get(2);
assertEquals(msg3, msgRec3);
receiver4.acknowledge(msgRec1, null);
receiver4.acknowledge(msgRec2, null);
receiver4.acknowledge(msgRec3, null);
msgs = queue4.browse(null);
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
}
finally
{