// Private -------------------------------------------------------
private void route(boolean persistentMessage) throws Throwable
{
PostOffice postOffice = null;
try
{
postOffice = createNonClusteredPostOffice();
Condition condition1 = new SimpleCondition("topic1");
MessagingQueue queue1 = new MessagingQueue(1, "queue1", channelIDManager.getID(), ms, pm, false, -1, null, false);
queue1.activate();
postOffice.addBinding(new Binding(condition1, queue1, false), false);
MessagingQueue queue2 = new MessagingQueue(1, "queue2", channelIDManager.getID(), ms, pm, false, -1, null, false);
queue2.activate();
postOffice.addBinding(new Binding(condition1, queue2, false), false);
MessagingQueue queue3 = new MessagingQueue(1, "queue3", channelIDManager.getID(), ms, pm, false, -1, null, false);
queue3.activate();
postOffice.addBinding(new Binding(condition1, queue3, false), false);
MessagingQueue queue4 = new MessagingQueue(1, "queue4", channelIDManager.getID(), ms, pm, true, -1, null, false);
queue4.activate();
Condition condition2 = new SimpleCondition("topic2");
postOffice.addBinding(new Binding(condition2, queue4, false), false);
MessagingQueue queue5 = new MessagingQueue(1, "queue5", channelIDManager.getID(), ms, pm, true, -1, null, false);
queue5.activate();
postOffice.addBinding(new Binding(condition2, queue5, false), false);
MessagingQueue queue6 = new MessagingQueue(1, "queue6", channelIDManager.getID(), ms, pm, true, -1, null, false);
queue6.activate();
postOffice.addBinding(new Binding(condition2, queue6, false), false);
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);
SimpleReceiver receiver5 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);;
queue5.getLocalDistributor().add(receiver5);
SimpleReceiver receiver6 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);;
queue6.getLocalDistributor().add(receiver6);
assertTrue(queue1.isActive());
assertTrue(queue2.isActive());
assertTrue(queue3.isActive());
assertTrue(queue4.isActive());
assertTrue(queue5.isActive());
assertTrue(queue6.isActive());
Message msg1 = CoreMessageFactory.createCoreMessage(1, persistentMessage, null);
MessageReference ref1 = ms.reference(msg1);
RouteResult routed = postOffice.route(ref1, condition1, null);
assertTrue(routed.getResult());
List msgs = receiver1.getMessages();
assertNotNull(msgs);
assertEquals(1, msgs.size());
Message msgRec = (Message)msgs.get(0);
assertTrue(msg1 == msgRec);
receiver1.acknowledge(msgRec, null);
msgs = queue1.browse(null);
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
msgs = receiver2.getMessages();
assertNotNull(msgs);
assertEquals(1, msgs.size());
msgRec = (Message)msgs.get(0);
assertTrue(msg1 == msgRec);
receiver2.acknowledge(msgRec, null);
msgs = queue2.browse(null);
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
msgs = receiver3.getMessages();
assertNotNull(msgs);
assertEquals(1, msgs.size());
msgRec = (Message)msgs.get(0);
assertTrue(msg1 == msgRec);
receiver3.acknowledge(msgRec, null);
msgs = queue3.browse(null);
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
msgs = receiver4.getMessages();
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
msgs = receiver5.getMessages();
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
msgs = receiver6.getMessages();
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
receiver1.clear();
receiver2.clear();
receiver3.clear();
Message msg2 = CoreMessageFactory.createCoreMessage(2, persistentMessage, null);
MessageReference ref2 = ms.reference(msg2);
routed = postOffice.route(ref2, condition2, null);
assertTrue(routed.getResult());
msgs = receiver4.getMessages();
assertNotNull(msgs);
assertEquals(1, msgs.size());
msgRec = (Message)msgs.get(0);
assertTrue(msg2 == msgRec);
receiver4.acknowledge(msgRec, null);
msgs = queue4.browse(null);
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
msgs = receiver5.getMessages();
assertNotNull(msgs);
assertEquals(1, msgs.size());
msgRec = (Message)msgs.get(0);
assertTrue(msg2 == msgRec);
receiver5.acknowledge(msgRec, null);
msgs = queue5.browse(null);
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
msgs = receiver6.getMessages();
assertNotNull(msgs);
assertEquals(1, msgs.size());
msgRec = (Message)msgs.get(0);
assertTrue(msg2 == msgRec);
receiver6.acknowledge(msgRec, null);
msgs = queue6.browse(null);
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
msgs = receiver1.getMessages();
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
msgs = receiver2.getMessages();
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
msgs = receiver3.getMessages();
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
postOffice.removeBinding("queue1", false);
postOffice.removeBinding("queue2", false);
postOffice.removeBinding("queue3", false);
postOffice.removeBinding("queue4", false);
postOffice.removeBinding("queue5", false);
postOffice.removeBinding("queue6", false);
}
finally
{
if (postOffice != null)
{
postOffice.stop();
}
}
}