this.routeWithNonClusteredQueues(true);
}
public void testStartTxInternally() throws Throwable
{
PostOffice office1 = null;
try
{
office1 = createClusteredPostOffice(1);
Queue queue1 = new MessagingQueue(1, "queue1", channelIDManager.getID(), ms, pm, true, -1, null, true);
queue1.activate();
boolean added = office1.addBinding(new Binding(new SimpleCondition("condition1"), queue1, false), false);
assertTrue(added);
Queue queue2 = new MessagingQueue(1, "queue2", channelIDManager.getID(), ms, pm, true, -1, null, true);
queue2.activate();
added = office1.addBinding(new Binding(new SimpleCondition("condition1"), queue2, false), false);
assertTrue(added);
Queue queue3 = new MessagingQueue(1, "queue3", channelIDManager.getID(), ms, pm, true, -1, null, true);
queue3.activate();
added = office1.addBinding(new Binding(new SimpleCondition("condition1"), queue3, false), false);
assertTrue(added);
Queue queue4 = new MessagingQueue(1, "queue4", channelIDManager.getID(), ms, pm, true, -1, null, true);
queue4.activate();
added = office1.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, true, null);
MessageReference ref1 = ms.reference(msg1);
RouteResult routed = office1.route(ref1, new SimpleCondition("condition1"), null);
assertTrue(routed.getResult());
Message msg2 = CoreMessageFactory.createCoreMessage(2, true, null);
MessageReference ref2 = ms.reference(msg2);
routed = office1.route(ref2, new SimpleCondition("condition1"), null);
assertTrue(routed.getResult());
Message msg3 = CoreMessageFactory.createCoreMessage(3, true, 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);
assertTrue(msg1 == msgRec1);
Message msgRec2 = (Message)msgs.get(1);
assertTrue(msg2 == msgRec2);
Message msgRec3 = (Message)msgs.get(2);
assertTrue(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);
assertTrue(msg1 == msgRec1);
msgRec2 = (Message)msgs.get(1);
assertTrue(msg2 == msgRec2);
msgRec3 = (Message)msgs.get(2);
assertTrue(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);
assertTrue(msg1 == msgRec1);
msgRec2 = (Message)msgs.get(1);
assertTrue(msg2 == msgRec2);
msgRec3 = (Message)msgs.get(2);
assertTrue(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);
assertTrue(msg1 == msgRec1);
msgRec2 = (Message)msgs.get(1);
assertTrue(msg2 == msgRec2);
msgRec3 = (Message)msgs.get(2);
assertTrue(msg3 == msgRec3);
receiver4.acknowledge(msgRec1, null);
receiver4.acknowledge(msgRec2, null);
receiver4.acknowledge(msgRec3, null);
msgs = queue4.browse(null);
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
}
finally
{
if (office1 != null)
{
office1.removeBinding("queue1", true);
office1.removeBinding("queue2", true);
office1.removeBinding("queue3", true);
office1.removeBinding("queue4", true);
office1.stop();
}
}
}