office5 = (DefaultClusteredPostOffice)
createClusteredPostOffice(5, "testgroup", 10000, 10000, new DefaultMessagePullPolicy(),
sc, ms, pm, tr);
LocalClusteredQueue queue1 =
new LocalClusteredQueue(office1, 1, "queue1", channelIDManager.getID(), ms, pm,
true, recoverable, -1, null, tr);
office1.bindClusteredQueue(new SimpleCondition("queue1"), queue1);
LocalClusteredQueue queue2 =
new LocalClusteredQueue(office2, 2, "queue1", channelIDManager.getID(), ms, pm,
true, recoverable, -1, null, tr);
office2.bindClusteredQueue(new SimpleCondition("queue1"), queue2);
LocalClusteredQueue queue3 =
new LocalClusteredQueue(office3, 3, "queue1", channelIDManager.getID(), ms, pm,
true, recoverable, -1, null, tr);
office3.bindClusteredQueue(new SimpleCondition("queue1"), queue3);
LocalClusteredQueue queue4 =
new LocalClusteredQueue(office4, 4, "queue1", channelIDManager.getID(), ms, pm,
true, recoverable, -1, null, tr);
office4.bindClusteredQueue(new SimpleCondition("queue1"), queue4);
LocalClusteredQueue queue5 =
new LocalClusteredQueue(office5, 5, "queue1", channelIDManager.getID(), ms, pm,
true, recoverable, -1, null, tr);
office5.bindClusteredQueue(new SimpleCondition("queue1"), queue5);
final int NUM_MESSAGES = 100;
this.sendMessages("queue1", persistent, office1, NUM_MESSAGES, null);
this.sendMessages("queue1", persistent, office2, NUM_MESSAGES, null);
this.sendMessages("queue1", persistent, office3, NUM_MESSAGES, null);
this.sendMessages("queue1", persistent, office4, NUM_MESSAGES, null);
this.sendMessages("queue1", persistent, office5, NUM_MESSAGES, null);
Thread.sleep(2000);
// Check the sizes
log.trace("Here are the sizes 1:");
log.trace("queue1, refs:" + queue1.memoryRefCount() + " dels:" + queue1.getDeliveringCount());
log.trace("queue2, refs:" + queue2.memoryRefCount() + " dels:" + queue2.getDeliveringCount());
log.trace("queue3, refs:" + queue3.memoryRefCount() + " dels:" + queue3.getDeliveringCount());
log.trace("queue4, refs:" + queue4.memoryRefCount() + " dels:" + queue4.getDeliveringCount());
log.trace("queue5, refs:" + queue5.memoryRefCount() + " dels:" + queue5.getDeliveringCount());
assertEquals(NUM_MESSAGES, queue1.memoryRefCount());
assertEquals(0, queue1.getDeliveringCount());
assertEquals(NUM_MESSAGES, queue2.memoryRefCount());
assertEquals(0, queue2.getDeliveringCount());
assertEquals(NUM_MESSAGES, queue3.memoryRefCount());
assertEquals(0, queue3.getDeliveringCount());
assertEquals(NUM_MESSAGES, queue4.memoryRefCount());
assertEquals(0, queue4.getDeliveringCount());
assertEquals(NUM_MESSAGES, queue5.memoryRefCount());
assertEquals(0, queue5.getDeliveringCount());
assertTrue(office1.getHoldingTransactions().isEmpty());
assertTrue(office2.getHoldingTransactions().isEmpty());
assertTrue(office3.getHoldingTransactions().isEmpty());
assertTrue(office4.getHoldingTransactions().isEmpty());
assertTrue(office5.getHoldingTransactions().isEmpty());
SimpleReceiver receiver1 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING_TO_MAX);
queue1.add(receiver1);
SimpleReceiver receiver2 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING_TO_MAX);
queue2.add(receiver2);
SimpleReceiver receiver3 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING_TO_MAX);
queue3.add(receiver3);
SimpleReceiver receiver4 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING_TO_MAX);
queue4.add(receiver4);
SimpleReceiver receiver5 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING_TO_MAX);
queue5.add(receiver5);
receiver1.setMaxRefs(5);
queue1.deliver();
readOK = receiver1.waitForHandleInvocations(5, 20000);
assertTrue(readOK);
Thread.sleep(1000);
assertEquals(NUM_MESSAGES - 5, queue1.memoryRefCount());
assertEquals(5, queue1.getDeliveringCount());
acknowledgeAll(receiver1);
assertEquals(0, queue1.getDeliveringCount());
receiver1.setMaxRefs(0);
receiver2.setMaxRefs(10);
queue2.deliver();
readOK = receiver2.waitForHandleInvocations(10, 20000);
assertTrue(readOK);
Thread.sleep(1000);
assertEquals(NUM_MESSAGES - 10, queue2.memoryRefCount());
assertEquals(10, queue2.getDeliveringCount());
acknowledgeAll(receiver2);
receiver2.setMaxRefs(0);
receiver3.setMaxRefs(15);
queue3.deliver();
readOK = receiver3.waitForHandleInvocations(15, 20000);
Thread.sleep(1000);
assertEquals(NUM_MESSAGES - 15, queue3.memoryRefCount());
assertEquals(15, queue3.getDeliveringCount());
acknowledgeAll(receiver3);
receiver3.setMaxRefs(0);
receiver4.setMaxRefs(20);
queue4.deliver();
readOK = receiver4.waitForHandleInvocations(20, 20000);
assertTrue(readOK);
Thread.sleep(1000);
assertEquals(NUM_MESSAGES - 20, queue4.memoryRefCount());
assertEquals(20, queue4.getDeliveringCount());
acknowledgeAll(receiver4);
receiver4.setMaxRefs(0);
receiver5.setMaxRefs(25);
queue5.deliver();
readOK = receiver5.waitForHandleInvocations(25, 20000);
assertTrue(readOK);
Thread.sleep(1000);
assertEquals(NUM_MESSAGES - 25, queue5.memoryRefCount());
assertEquals(25, queue5.getDeliveringCount());
acknowledgeAll(receiver5);
receiver5.setMaxRefs(0);
assertTrue(office1.getHoldingTransactions().isEmpty());
assertTrue(office2.getHoldingTransactions().isEmpty());
assertTrue(office3.getHoldingTransactions().isEmpty());
assertTrue(office4.getHoldingTransactions().isEmpty());
assertTrue(office5.getHoldingTransactions().isEmpty());
log.trace("Here are the sizes 2:");
log.trace("queue1, refs:" + queue1.memoryRefCount() + " dels:" + queue1.getDeliveringCount());
log.trace("queue2, refs:" + queue2.memoryRefCount() + " dels:" + queue2.getDeliveringCount());
log.trace("queue3, refs:" + queue3.memoryRefCount() + " dels:" + queue3.getDeliveringCount());
log.trace("queue4, refs:" + queue4.memoryRefCount() + " dels:" + queue4.getDeliveringCount());
log.trace("queue5, refs:" + queue5.memoryRefCount() + " dels:" + queue5.getDeliveringCount());
// Consume the rest from queue 5
receiver5.setMaxRefs(NUM_MESSAGES - 25);
queue5.deliver();
readOK = receiver5.waitForHandleInvocations(NUM_MESSAGES - 25, 20000);
assertTrue(readOK);
Thread.sleep(2000);
log.trace("receiver5 msgs:" + receiver5.getMessages().size());
log.trace("Here are the sizes 3:");
log.trace("queue1, refs:" + queue1.memoryRefCount() + " dels:" + queue1.getDeliveringCount());
log.trace("queue2, refs:" + queue2.memoryRefCount() + " dels:" + queue2.getDeliveringCount());
log.trace("queue3, refs:" + queue3.memoryRefCount() + " dels:" + queue3.getDeliveringCount());
log.trace("queue4, refs:" + queue4.memoryRefCount() + " dels:" + queue4.getDeliveringCount());
log.trace("queue5, refs:" + queue5.memoryRefCount() + " dels:" + queue5.getDeliveringCount());
// This will result in an extra one being pulled from queue1 - we cannot avoid this. This
// is because the channel does not know that the receiver is full unless it tries with a
// ref so it needs to retrieve one
// http://jira.jboss.org/jira/browse/JBMESSAGING-901
assertEquals(NUM_MESSAGES - 6, queue1.memoryRefCount()); // <- expected:<94> but was:<93>
assertEquals(0, queue1.getDeliveringCount());
assertEquals(NUM_MESSAGES - 10, queue2.memoryRefCount());
assertEquals(0, queue2.getDeliveringCount());
assertEquals(NUM_MESSAGES - 15, queue3.memoryRefCount());
assertEquals(0, queue3.getDeliveringCount());
assertEquals(NUM_MESSAGES - 20, queue4.memoryRefCount());
assertEquals(0, queue4.getDeliveringCount());
assertEquals(1, queue5.memoryRefCount());
assertEquals(NUM_MESSAGES - 25, queue5.getDeliveringCount());
acknowledgeAll(receiver5);
assertEquals(0, queue5.getDeliveringCount());
receiver5.setMaxRefs(0);
assertTrue(office1.getHoldingTransactions().isEmpty());
assertTrue(office2.getHoldingTransactions().isEmpty());
assertTrue(office3.getHoldingTransactions().isEmpty());
assertTrue(office4.getHoldingTransactions().isEmpty());
assertTrue(office5.getHoldingTransactions().isEmpty());
// Now consume 5 more from queue5, they should come from queue1 which has the most messages
log.trace("Consume 5 more from queue 5");
receiver5.setMaxRefs(5);
queue5.deliver();
readOK = receiver5.waitForHandleInvocations(5, 20000);
assertTrue(readOK);
Thread.sleep(4000);
log.trace("Here are the sizes 4:");
log.trace("queue1, refs:" + queue1.memoryRefCount() + " dels:" + queue1.getDeliveringCount());
log.trace("queue2, refs:" + queue2.memoryRefCount() + " dels:" + queue2.getDeliveringCount());
log.trace("queue3, refs:" + queue3.memoryRefCount() + " dels:" + queue3.getDeliveringCount());
log.trace("queue4, refs:" + queue4.memoryRefCount() + " dels:" + queue4.getDeliveringCount());
log.trace("queue5, refs:" + queue5.memoryRefCount() + " dels:" + queue5.getDeliveringCount());
assertEquals(NUM_MESSAGES - 11, queue1.memoryRefCount()); // <-- expected:<89> but was:<88>
assertEquals(0, queue1.getDeliveringCount());
assertEquals(NUM_MESSAGES - 10, queue2.memoryRefCount());
assertEquals(0, queue2.getDeliveringCount());
assertEquals(NUM_MESSAGES - 15, queue3.memoryRefCount());
assertEquals(0, queue3.getDeliveringCount());
assertEquals(NUM_MESSAGES - 20, queue4.memoryRefCount());
assertEquals(0, queue4.getDeliveringCount());
assertEquals(1, queue5.memoryRefCount());
assertEquals(5, queue5.getDeliveringCount());
acknowledgeAll(receiver5);
assertEquals(0, queue5.getDeliveringCount());
receiver1.setMaxRefs(0);
assertTrue(office1.getHoldingTransactions().isEmpty());
assertTrue(office2.getHoldingTransactions().isEmpty());
assertTrue(office3.getHoldingTransactions().isEmpty());
assertTrue(office4.getHoldingTransactions().isEmpty());
assertTrue(office5.getHoldingTransactions().isEmpty());
// Consume 1 more - should pull one from queue2
receiver5.setMaxRefs(1);
queue5.deliver();
readOK = receiver5.waitForHandleInvocations(1, 20000);
assertTrue(readOK);
Thread.sleep(2000);
log.trace("Here are the sizes 5:");
log.trace("queue1, refs:" + queue1.memoryRefCount() + " dels:" + queue1.getDeliveringCount());
log.trace("queue2, refs:" + queue2.memoryRefCount() + " dels:" + queue2.getDeliveringCount());
log.trace("queue3, refs:" + queue3.memoryRefCount() + " dels:" + queue3.getDeliveringCount());
log.trace("queue4, refs:" + queue4.memoryRefCount() + " dels:" + queue4.getDeliveringCount());
log.trace("queue5, refs:" + queue5.memoryRefCount() + " dels:" + queue5.getDeliveringCount());
assertEquals(NUM_MESSAGES - 11, queue1.memoryRefCount());
assertEquals(0, queue1.getDeliveringCount());
assertEquals(NUM_MESSAGES - 11, queue2.memoryRefCount());
assertEquals(0, queue2.getDeliveringCount());
assertEquals(NUM_MESSAGES - 15, queue3.memoryRefCount());
assertEquals(0, queue3.getDeliveringCount());
assertEquals(NUM_MESSAGES - 20, queue4.memoryRefCount());
assertEquals(0, queue4.getDeliveringCount());
assertEquals(1, queue5.memoryRefCount());
assertEquals(1, queue5.getDeliveringCount());
acknowledgeAll(receiver5);
assertEquals(0, queue5.getDeliveringCount());
receiver5.setMaxRefs(0);
assertTrue(office1.getHoldingTransactions().isEmpty());
assertTrue(office2.getHoldingTransactions().isEmpty());
assertTrue(office3.getHoldingTransactions().isEmpty());
assertTrue(office4.getHoldingTransactions().isEmpty());
assertTrue(office5.getHoldingTransactions().isEmpty());
// From queue 4 consume everything else
int num = NUM_MESSAGES - 15 + NUM_MESSAGES - 20 + NUM_MESSAGES - 11 + NUM_MESSAGES - 11 + 1;
receiver4.setMaxRefs(num);
queue4.deliver();
readOK = receiver4.waitForHandleInvocations(num, 20000);
assertTrue(readOK);
Thread.sleep(2000);
log.trace("Here are the sizes 6:");
log.trace("queue1, refs:" + queue1.memoryRefCount() + " dels:" + queue1.getDeliveringCount());
log.trace("queue2, refs:" + queue2.memoryRefCount() + " dels:" + queue2.getDeliveringCount());
log.trace("queue3, refs:" + queue3.memoryRefCount() + " dels:" + queue3.getDeliveringCount());
log.trace("queue4, refs:" + queue4.memoryRefCount() + " dels:" + queue4.getDeliveringCount());
log.trace("queue5, refs:" + queue5.memoryRefCount() + " dels:" + queue5.getDeliveringCount());
assertEquals(0, queue1.memoryRefCount());
assertEquals(0, queue1.getDeliveringCount());
assertEquals(0, queue2.memoryRefCount());
assertEquals(0, queue2.getDeliveringCount());
assertEquals(0, queue3.memoryRefCount()); // <- sometimes, there is still 1 message left in this queue
assertEquals(0, queue3.getDeliveringCount());
assertEquals(0, queue4.memoryRefCount());
assertEquals(NUM_MESSAGES - 15 + NUM_MESSAGES - 20 + NUM_MESSAGES - 11 + NUM_MESSAGES - 11 + 1, queue4.getDeliveringCount());
assertEquals(0, queue5.memoryRefCount());
assertEquals(0, queue5.getDeliveringCount());
acknowledgeAll(receiver4);
assertEquals(0, queue4.getDeliveringCount());