//condition1
queues[0] = new MessagingQueue(1, "sub1", channelIDManager.getID(), ms, pm, false, -1, null, true);
queues[0].activate();
boolean added = office1.addBinding(new Binding(new SimpleCondition("condition1"), queues[0], false), false);
assertTrue(added);
queues[1] = new MessagingQueue(1, "sub2", channelIDManager.getID(), ms, pm, false, -1, null, true);
queues[1].activate();
added = office1.addBinding(new Binding(new SimpleCondition("condition1"), queues[1], false), false);
assertTrue(added);
queues[2] = new MessagingQueue(2, "sub3", channelIDManager.getID(), ms, pm, false, -1, null, true);
queues[2].activate();
added = office2.addBinding(new Binding(new SimpleCondition("condition1"), queues[2], false), false);
assertTrue(added);
queues[3] = new MessagingQueue(2, "sub4", channelIDManager.getID(), ms, pm, false, -1, null, true);
queues[3].activate();
added = office2.addBinding(new Binding(new SimpleCondition("condition1"), queues[3], false), false);
assertTrue(added);
queues[4] = new MessagingQueue(2, "sub5", channelIDManager.getID(), ms, pm, true, -1, null, true);
queues[4].activate();
added = office2.addBinding(new Binding(new SimpleCondition("condition1"), queues[4], false), false);
assertTrue(added);
queues[5] = new MessagingQueue(1, "sub6", channelIDManager.getID(), ms, pm, false, -1, null, true);
queues[5].activate();
added = office1.addBinding(new Binding(new SimpleCondition("condition1"), queues[5], false), false);
assertTrue(added);
queues[6] = new MessagingQueue(1, "sub7", channelIDManager.getID(), ms, pm, true, -1, null, true);
queues[6].activate();
added = office1.addBinding(new Binding(new SimpleCondition("condition1"), queues[6], false), false);
assertTrue(added);
queues[7] = new MessagingQueue(1, "sub8", channelIDManager.getID(), ms, pm, true, -1, null, true);
queues[7].activate();
added = office1.addBinding(new Binding(new SimpleCondition("condition1"), queues[7], false), false);
assertTrue(added);
//condition2
queues[8] = new MessagingQueue(1, "sub9", channelIDManager.getID(), ms, pm, false, -1, null, true);
queues[8].activate();
added= office1.addBinding(new Binding(new SimpleCondition("condition2"), queues[8], false), false);
assertTrue(added);
queues[9] = new MessagingQueue(1, "sub10", channelIDManager.getID(), ms, pm, false, -1, null, true);
queues[9].activate();
added = office1.addBinding(new Binding(new SimpleCondition("condition2"), queues[9], false), false);
assertTrue(added);
queues[10] = new MessagingQueue(2, "sub11", channelIDManager.getID(), ms, pm, false, -1, null, true);
queues[10].activate();
added = office2.addBinding(new Binding(new SimpleCondition("condition2"), queues[10], false), false);
assertTrue(added);
queues[11] = new MessagingQueue(2, "sub12", channelIDManager.getID(), ms, pm, false, -1, null, true);
queues[11].activate();
added = office2.addBinding(new Binding(new SimpleCondition("condition2"), queues[11], false), false);
assertTrue(added);
queues[12] = new MessagingQueue(2, "sub13", channelIDManager.getID(), ms, pm, true, -1, null, true);
queues[12].activate();
added = office2.addBinding(new Binding(new SimpleCondition("condition2"), queues[12], false), false);
assertTrue(added);
queues[13] = new MessagingQueue(1, "sub14", channelIDManager.getID(), ms, pm, false, -1, null, true);
queues[13].activate();
added = office1.addBinding(new Binding(new SimpleCondition("condition2"), queues[13], false), false);
assertTrue(added);
queues[14] = new MessagingQueue(1, "sub15", channelIDManager.getID(), ms, pm, true, -1, null, true);
queues[14].activate();
added = office1.addBinding(new Binding(new SimpleCondition("condition2"), queues[14], false), false);
assertTrue(added);
queues[15] = new MessagingQueue(1, "sub16", channelIDManager.getID(), ms, pm, true, -1, null, true);
queues[15].activate();
added = office1.addBinding(new Binding(new SimpleCondition("condition2"), queues[15], false), false);
assertTrue(added);
SimpleReceiver[] receivers = new SimpleReceiver[16];
for (int i = 0; i < 16; i++)
{
receivers[i] = new SimpleReceiver("blah" + i, SimpleReceiver.ACCEPTING);
queues[i].getLocalDistributor().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("condition1"), tx);
assertTrue(routed);
routed = office1.route(ref2, new SimpleCondition("condition1"), tx);
assertTrue(routed);
for (int i = 0; i < 16; i++)
{
log.info("i is " + i);
List msgs = receivers[i].getMessages();
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
msgs = queues[i].browse(null);
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
}
log.info("committing");
tx.commit();
log.info("committed");
//Messages are sent asych so may take some finite time to arrive
Thread.sleep(3000);
for (int i = 0; i < 16; i++)
{
if (i >= 8 || (queues[i].getNodeID() == 2 && queues[i].isRecoverable()))
{
//Shouldn't get message
List msgs = receivers[i].getMessages();
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
msgs = queues[i].browse(null);
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
}
else
{
//Should get message
log.info("is is " + i);
log.info("trying with receiver " + receivers[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(null);
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("condition1"), tx);
assertTrue(routed);
routed = office1.route(ref2, new SimpleCondition("condition1"), tx);
assertTrue(routed);
//Messages are sent asych so may take some finite time to arrive
Thread.sleep(3000);
for (int i = 0; i < 16; i++)
{
List msgs = receivers[i].getMessages();
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
msgs = queues[i].browse(null);
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(null);
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 = office2.route(ref1, new SimpleCondition("condition2"), tx);
assertTrue(routed);
routed = office2.route(ref2, new SimpleCondition("condition2"), tx);
assertTrue(routed);
for (int i = 0; i < 16; i++)
{
List msgs = receivers[i].getMessages();
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
msgs = queues[i].browse(null);
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
}
tx.commit();
//Messages are sent asych so may take some finite time to arrive
Thread.sleep(3000);
for (int i = 8; i < 16; i++)
{
if (i < 8 || (queues[i].getNodeID() == 1 && queues[i].isRecoverable()))
{
// Shouldn't get message
List msgs = receivers[i].getMessages();
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
msgs = queues[i].browse(null);
assertNotNull(msgs);
assertTrue(msgs.isEmpty());
}
else
{
// Should get message
log.info("is is " + i);
log.info("trying with receiver " + receivers[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(null);
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("condition1"), tx);
assertTrue(routed);
routed = office1.route(ref2, new SimpleCondition("condition1"), tx);
assertTrue(routed);
for (int i = 0; i < 16; i++)
{
List msgs = receivers[i].getMessages();