queues[i].add(receivers[i]);
}
//First for topic 1
Message msg1 = CoreMessageFactory.createCoreMessage(1, persistent, null);;
MessageReference ref1 = ms.reference(msg1);
Message msg2 = CoreMessageFactory.createCoreMessage(2, persistent, null);;
MessageReference ref2 = ms.reference(msg2);
Transaction tx = tr.createTransaction();
boolean routed = office1.route(ref1, new SimpleCondition("topic1"), tx);
assertTrue(routed);
routed = office1.route(ref2, new SimpleCondition("topic1"), tx);
assertTrue(routed);
for (int i = 0; i < 16; i++)
{
List msgs = receivers[i].getMessages();
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
msgs = queues[i].browse();
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
}
tx.commit();
//Messages are sent asych so may take some finite time to arrive
Thread.sleep(1000);
for (int i = 0; i < 8; i++)
{
List msgs = receivers[i].getMessages();
assertNotNull(msgs);
assertEquals(2, msgs.size());
Message msgRec1 = (Message)msgs.get(0);
assertEquals(msg1.getMessageID(), msgRec1.getMessageID());
Message msgRec2 = (Message)msgs.get(1);
assertEquals(msg2.getMessageID(), msgRec2.getMessageID());
receivers[i].acknowledge(msgRec1, null);
receivers[i].acknowledge(msgRec2, null);
msgs = queues[i].browse();
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
receivers[i].clear();
}
for (int i = 8; i < 16; i++)
{
List msgs = receivers[i].getMessages();
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
msgs = queues[i].browse();
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
}
msg1 = CoreMessageFactory.createCoreMessage(1, persistent, null);;
ref1 = ms.reference(msg1);
msg2 = CoreMessageFactory.createCoreMessage(2, persistent, null);;
ref2 = ms.reference(msg2);
tx = tr.createTransaction();
routed = office1.route(ref1, new SimpleCondition("topic1"), tx);
assertTrue(routed);
routed = office1.route(ref2, new SimpleCondition("topic1"), tx);
assertTrue(routed);
//Messages are sent asych so may take some finite time to arrive
Thread.sleep(1000);
for (int i = 0; i < 16; i++)
{
List msgs = receivers[i].getMessages();
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
msgs = queues[i].browse();
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
}
tx.rollback();
for (int i = 0; i < 16; i++)
{
List msgs = receivers[i].getMessages();
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
msgs = queues[i].browse();
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
}
//Now send some non transactionally
msg1 = CoreMessageFactory.createCoreMessage(1, persistent, null);
ref1 = ms.reference(msg1);
msg2 = CoreMessageFactory.createCoreMessage(2, persistent, null);
ref2 = ms.reference(msg2);
routed = office1.route(ref1, new SimpleCondition("topic1"), null);
assertTrue(routed);
routed = office1.route(ref2, new SimpleCondition("topic1"), null);
assertTrue(routed);
//Messages are sent asych so may take some finite time to arrive
Thread.sleep(1000);
//And acknowledge transactionally
tx = tr.createTransaction();
for (int i = 0; i < 8; i++)
{
List msgs = receivers[i].getMessages();
assertNotNull(msgs);
assertEquals(2, msgs.size());
Message msgRec1 = (Message)msgs.get(0);
assertEquals(msg1.getMessageID(), msgRec1.getMessageID());
Message msgRec2 = (Message)msgs.get(1);
assertEquals(msg2.getMessageID(), msgRec2.getMessageID());
receivers[i].acknowledge(msgRec1, tx);
receivers[i].acknowledge(msgRec2, tx);
int deliveringCount = queues[i].getDeliveringCount();
assertEquals(2, deliveringCount);
receivers[i].clear();
}
for (int i = 8; i < 16; i++)
{
List msgs = receivers[i].getMessages();
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
msgs = queues[i].browse();
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
}
tx.commit();
for (int i = 0; i < 16; i++)
{
List msgs = receivers[i].getMessages();
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
msgs = queues[i].browse();
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
}
// and the rollback
msg1 = CoreMessageFactory.createCoreMessage(1, persistent, null);;
ref1 = ms.reference(msg1);
msg2 = CoreMessageFactory.createCoreMessage(2, persistent, null);;
ref2 = ms.reference(msg2);
routed = office1.route(ref1, new SimpleCondition("topic1"), null);
assertTrue(routed);
routed = office1.route(ref2, new SimpleCondition("topic1"), null);
assertTrue(routed);
Thread.sleep(1000);
tx = tr.createTransaction();
for (int i = 0; i < 8; i++)
{
List msgs = receivers[i].getMessages();
assertNotNull(msgs);
assertEquals(2, msgs.size());
Message msgRec1 = (Message)msgs.get(0);
assertEquals(msg1.getMessageID(), msgRec1.getMessageID());
Message msgRec2 = (Message)msgs.get(1);
assertEquals(msg2.getMessageID(), msgRec2.getMessageID());
receivers[i].acknowledge(msgRec1, tx);
receivers[i].acknowledge(msgRec2, tx);
int deliveringCount = queues[i].getDeliveringCount();
assertEquals(2, deliveringCount);
}
for (int i = 8; i < 16; i++)
{
List msgs = receivers[i].getMessages();
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
msgs = queues[i].browse();
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
}
tx.rollback();
for (int i = 0; i < 8; i++)
{
List msgs = receivers[i].getMessages();
assertNotNull(msgs);
assertEquals(2, msgs.size());
Message msgRec1 = (Message)msgs.get(0);
assertEquals(msg1.getMessageID(), msgRec1.getMessageID());
Message msgRec2 = (Message)msgs.get(1);
assertEquals(msg2.getMessageID(), msgRec2.getMessageID());
int deliveringCount = queues[i].getDeliveringCount();
assertEquals(2, deliveringCount);
receivers[i].acknowledge(msgRec1, null);
receivers[i].acknowledge(msgRec2, null);
receivers[i].clear();
}
for (int i = 8; i < 16; i++)
{
List msgs = receivers[i].getMessages();
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
msgs = queues[i].browse();
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
}
// Now for topic 2
msg1 = CoreMessageFactory.createCoreMessage(1, persistent, null);
ref1 = ms.reference(msg1);
msg2 = CoreMessageFactory.createCoreMessage(2, persistent, null);
ref2 = ms.reference(msg2);
tx = tr.createTransaction();
routed = office1.route(ref1, new SimpleCondition("topic2"), tx);
assertTrue(routed);
routed = office1.route(ref2, new SimpleCondition("topic2"), tx);
assertTrue(routed);
for (int i = 0; i < 16; i++)
{
List msgs = receivers[i].getMessages();
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
msgs = queues[i].browse();
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
}
tx.commit();
//Messages are sent asych so may take some finite time to arrive
Thread.sleep(1000);
for (int i = 0; i < 8; i++)
{
List msgs = receivers[i].getMessages();
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
msgs = queues[i].browse();
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
}
for (int i = 8; i < 16; i++)
{
List msgs = receivers[i].getMessages();
assertNotNull(msgs);
assertEquals(2, msgs.size());
Message msgRec1 = (Message)msgs.get(0);
assertEquals(msg1.getMessageID(), msgRec1.getMessageID());
Message msgRec2 = (Message)msgs.get(1);
assertEquals(msg2.getMessageID(), msgRec2.getMessageID());
receivers[i].acknowledge(msgRec1, null);
receivers[i].acknowledge(msgRec2, null);
msgs = queues[i].browse();
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
receivers[i].clear();
}
msg1 = CoreMessageFactory.createCoreMessage(1, persistent, null);;
ref1 = ms.reference(msg1);
msg2 = CoreMessageFactory.createCoreMessage(2, persistent, null);;
ref2 = ms.reference(msg2);
tx = tr.createTransaction();
routed = office1.route(ref1, new SimpleCondition("topic1"), tx);
assertTrue(routed);
routed = office1.route(ref2, new SimpleCondition("topic1"), tx);
assertTrue(routed);
for (int i = 0; i < 16; i++)
{
List msgs = receivers[i].getMessages();
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
msgs = queues[i].browse();
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
}
tx.rollback();
for (int i = 0; i < 16; i++)
{
List msgs = receivers[i].getMessages();
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
msgs = queues[i].browse();
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
}
//Now send some non transactionally
msg1 = CoreMessageFactory.createCoreMessage(1, persistent, null);
ref1 = ms.reference(msg1);
msg2 = CoreMessageFactory.createCoreMessage(2, persistent, null);
ref2 = ms.reference(msg2);
routed = office1.route(ref1, new SimpleCondition("topic2"), null);
assertTrue(routed);
routed = office1.route(ref2, new SimpleCondition("topic2"), null);
assertTrue(routed);
Thread.sleep(1000);
//And acknowledge transactionally
tx = tr.createTransaction();
for (int i = 0; i < 8; i++)
{
List msgs = receivers[i].getMessages();
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
msgs = queues[i].browse();
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
}
for (int i = 8; i < 16; i++)
{
List msgs = receivers[i].getMessages();
assertNotNull(msgs);
assertEquals(2, msgs.size());
Message msgRec1 = (Message)msgs.get(0);
assertEquals(msg1.getMessageID(), msgRec1.getMessageID());
Message msgRec2 = (Message)msgs.get(1);
assertEquals(msg2.getMessageID(), msgRec2.getMessageID());
receivers[i].acknowledge(msgRec1, tx);
receivers[i].acknowledge(msgRec2, tx);
int deliveringCount = queues[i].getDeliveringCount();
assertEquals(2, deliveringCount);
receivers[i].clear();
}
tx.commit();
for (int i = 0; i < 16; i++)
{
List msgs = receivers[i].getMessages();
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
msgs = queues[i].browse();
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
}
// and the rollback
msg1 = CoreMessageFactory.createCoreMessage(1, persistent, null);;
ref1 = ms.reference(msg1);
msg2 = CoreMessageFactory.createCoreMessage(2, persistent, null);;
ref2 = ms.reference(msg2);
routed = office1.route(ref1, new SimpleCondition("topic2"), null);
assertTrue(routed);
routed = office1.route(ref2, new SimpleCondition("topic2"), null);
assertTrue(routed);
Thread.sleep(1000);
tx = tr.createTransaction();
for (int i = 0; i < 8; i++)
{
List msgs = receivers[i].getMessages();
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
msgs = queues[i].browse();
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
}
for (int i = 8; i < 16; i++)
{
List msgs = receivers[i].getMessages();
assertNotNull(msgs);
assertEquals(2, msgs.size());
Message msgRec1 = (Message)msgs.get(0);
assertEquals(msg1.getMessageID(), msgRec1.getMessageID());
Message msgRec2 = (Message)msgs.get(1);
assertEquals(msg2.getMessageID(), msgRec2.getMessageID());
receivers[i].acknowledge(msgRec1, tx);
receivers[i].acknowledge(msgRec2, tx);
int deliveringCount = queues[i].getDeliveringCount();
assertEquals(2, deliveringCount);
}
tx.rollback();
for (int i = 0; i < 8; i++)
{
List msgs = receivers[i].getMessages();
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
msgs = queues[i].browse();
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
}
for (int i = 8; i < 16; i++)
{
List msgs = receivers[i].getMessages();
assertNotNull(msgs);
assertEquals(2, msgs.size());
Message msgRec1 = (Message)msgs.get(0);
assertEquals(msg1.getMessageID(), msgRec1.getMessageID());
Message msgRec2 = (Message)msgs.get(1);
assertEquals(msg2.getMessageID(), msgRec2.getMessageID());
int deliveringCount = queues[i].getDeliveringCount();
assertEquals(2, deliveringCount);