PagingFilteredQueue queue1 =
new PagingFilteredQueue("queue1", channelIDManager.getID(), ms, pm, true, false,
-1, null);
postOffice.bindQueue(new SimpleCondition("topic1"), queue1);
PagingFilteredQueue queue2 =
new PagingFilteredQueue("queue2", channelIDManager.getID(), ms, pm, true, true,
-1, null);
postOffice.bindQueue(new SimpleCondition("topic1"), queue2);
SimpleReceiver receiver1 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);;
queue1.add(receiver1);
SimpleReceiver receiver2 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);;
queue2.add(receiver2);
assertTrue(queue1.isActive());
assertTrue(queue2.isActive());
Message msg1 = CoreMessageFactory.createCoreMessage(1, persistentMessage, null);
MessageReference ref1 = ms.reference(msg1);
Message msg2 = CoreMessageFactory.createCoreMessage(2, persistentMessage, null);
MessageReference ref2 = ms.reference(msg2);
Transaction tx = tr.createTransaction();
boolean routed = postOffice.route(ref1, new SimpleCondition("topic1"), tx);
assertTrue(routed);
routed = postOffice.route(ref2, new SimpleCondition("topic1"), tx);
assertTrue(routed);
List msgs = queue1.browse();
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
msgs = queue2.browse();
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
tx.commit();
msgs = receiver1.getMessages();
assertNotNull(msgs);
assertEquals(2, msgs.size());
Message msgRec1 = (Message)msgs.get(0);
Message msgRec2 = (Message)msgs.get(1);
assertTrue(msgRec1 == msg1);
assertTrue(msgRec2 == msg2);
msgs = receiver2.getMessages();
assertNotNull(msgs);
assertEquals(2, msgs.size());
msgRec1 = (Message)msgs.get(0);
msgRec2 = (Message)msgs.get(1);
assertTrue(msgRec1 == msg1);
assertTrue(msgRec2 == msg2);
//Acknowledge non transactionally
receiver1.acknowledge(msgRec1, null);
receiver1.acknowledge(msgRec2, null);
receiver2.acknowledge(msgRec1, null);
receiver2.acknowledge(msgRec2, null);
msgs = queue1.browse();
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
receiver1.clear();
msgs = queue2.browse();
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
receiver2.clear();
Message msg3 = CoreMessageFactory.createCoreMessage(3, persistentMessage, null);
MessageReference ref3 = ms.reference(msg3);
Message msg4 = CoreMessageFactory.createCoreMessage(4, persistentMessage, null);
MessageReference ref4 = ms.reference(msg4);
tx = tr.createTransaction();
routed = postOffice.route(ref3, new SimpleCondition("topic1"), tx);
assertTrue(routed);
routed = postOffice.route(ref4, new SimpleCondition("topic1"), tx);
assertTrue(routed);
msgs = queue1.browse();
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
msgs = queue2.browse();
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
tx.rollback();
msgs = receiver1.getMessages();
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
receiver1.clear();
msgs = receiver2.getMessages();
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
receiver2.clear();
Message msg5 = CoreMessageFactory.createCoreMessage(5, persistentMessage, null);
MessageReference ref5 = ms.reference(msg5);
Message msg6 = CoreMessageFactory.createCoreMessage(6, persistentMessage, null);
MessageReference ref6 = ms.reference(msg6);
routed = postOffice.route(ref5, new SimpleCondition("topic1"), null);
assertTrue(routed);
routed = postOffice.route(ref6, new SimpleCondition("topic1"), null);
assertTrue(routed);
msgs = receiver1.getMessages();
assertNotNull(msgs);
assertEquals(2, msgs.size());
msgRec1 = (Message)msgs.get(0);
msgRec2 = (Message)msgs.get(1);
assertTrue(msgRec1 == msg5);
assertTrue(msgRec2 == msg6);
msgs = receiver2.getMessages();
assertNotNull(msgs);
assertEquals(2, msgs.size());
msgRec1 = (Message)msgs.get(0);
msgRec2 = (Message)msgs.get(1);
assertTrue(msgRec1 == msg5);
assertTrue(msgRec2 == msg6);
//Acknowledge transactionally
tx = tr.createTransaction();
receiver1.acknowledge(msgRec1, tx);
receiver1.acknowledge(msgRec2, tx);
receiver2.acknowledge(msgRec1, tx);
receiver2.acknowledge(msgRec2, tx);
int deliveringCount = queue1.getDeliveringCount();
assertEquals(2, deliveringCount);
deliveringCount = queue2.getDeliveringCount();
assertEquals(2, deliveringCount);
tx.commit();
msgs = queue1.browse();
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
receiver1.clear();
msgs = queue2.browse();
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
receiver2.clear();
Message msg7 = CoreMessageFactory.createCoreMessage(7, persistentMessage, null);
MessageReference ref7 = ms.reference(msg7);
Message msg8 = CoreMessageFactory.createCoreMessage(8, persistentMessage, null);
MessageReference ref8 = ms.reference(msg8);
routed = postOffice.route(ref7, new SimpleCondition("topic1"), null);
assertTrue(routed);
routed = postOffice.route(ref8, new SimpleCondition("topic1"), null);
assertTrue(routed);
msgs = receiver1.getMessages();
assertNotNull(msgs);
assertEquals(2, msgs.size());