LocalClusteredQueue queue1 =
new LocalClusteredQueue(office1, 1, "sub1", channelIDManager.getID(), ms, pm,
true, false, -1, null, tr);
Binding binding1 =
office1.bindClusteredQueue(new SimpleCondition("topic1"), queue1);
log.info("Added binding1");
LocalClusteredQueue queue2 =
new LocalClusteredQueue(office1, 1, "sub2", channelIDManager.getID(), ms, pm,
true, false, -1, null, tr);
Binding binding2 =
office1.bindClusteredQueue(new SimpleCondition("topic1"), queue2);
log.info("Added binding2");
// Start another office - make sure it picks up the bindings from the first node
office2 = createClusteredPostOffice(2, "testgroup", sc, ms, pm, tr);
log.info("Created office 2");
Collection bindings = office2.listAllBindingsForCondition(new SimpleCondition("topic1"));
assertNotNull(bindings);
assertEquals(2, bindings.size());
Iterator iter = bindings.iterator();
assertEquivalent(binding1, (Binding)iter.next());
assertEquivalent(binding2, (Binding)iter.next());
// Add another binding on node 2
LocalClusteredQueue queue3 =
new LocalClusteredQueue(office2, 2, "sub3", channelIDManager.getID(), ms, pm,
true, false, -1, null, tr);
Binding binding3 =
office2.bindClusteredQueue(new SimpleCondition("topic1"), queue3);
// Make sure both nodes pick it up
bindings = office1.listAllBindingsForCondition(new SimpleCondition("topic1"));
assertNotNull(bindings);
assertEquals(3, bindings.size());
iter = bindings.iterator();
assertEquivalent(binding1, (Binding)iter.next());
assertEquivalent(binding2, (Binding)iter.next());
assertEquivalent(binding3, (Binding)iter.next());
bindings = office2.listAllBindingsForCondition(new SimpleCondition("topic1"));
assertNotNull(bindings);
assertEquals(3, bindings.size());
iter = bindings.iterator();
assertEquivalent(binding1, (Binding)iter.next());
assertEquivalent(binding2, (Binding)iter.next());
assertEquivalent(binding3, (Binding)iter.next());
// Add another binding on node 1
LocalClusteredQueue queue4 =
new LocalClusteredQueue(office2, 2, "sub4", channelIDManager.getID(), ms, pm,
true, false, -1, null, tr);
Binding binding4 =
office2.bindClusteredQueue(new SimpleCondition("topic1"), queue4);
// Make sure both nodes pick it up
bindings = office1.listAllBindingsForCondition(new SimpleCondition("topic1"));
assertNotNull(bindings);
assertEquals(4, bindings.size());
iter = bindings.iterator();
assertEquivalent(binding1, (Binding)iter.next());
assertEquivalent(binding2, (Binding)iter.next());
assertEquivalent(binding3, (Binding)iter.next());
assertEquivalent(binding4, (Binding)iter.next());
bindings = office2.listAllBindingsForCondition(new SimpleCondition("topic1"));
assertNotNull(bindings);
assertEquals(4, bindings.size());
iter = bindings.iterator();
assertEquivalent(binding1, (Binding)iter.next());
assertEquivalent(binding2, (Binding)iter.next());
assertEquivalent(binding3, (Binding)iter.next());
assertEquivalent(binding4, (Binding)iter.next());
// Unbind binding 1 and binding 2
office1.unbindClusteredQueue("sub1");
office1.unbindClusteredQueue("sub2");
// Make sure bindings are not longer available on either node
bindings = office1.listAllBindingsForCondition(new SimpleCondition("topic1"));
assertNotNull(bindings);
assertEquals(2, bindings.size());
iter = bindings.iterator();
assertEquivalent(binding3, (Binding)iter.next());
assertEquivalent(binding4, (Binding)iter.next());
bindings = office2.listAllBindingsForCondition(new SimpleCondition("topic1"));
assertNotNull(bindings);
assertEquals(2, bindings.size());
iter = bindings.iterator();
assertEquivalent(binding3, (Binding)iter.next());
assertEquivalent(binding4, (Binding)iter.next());
// Add a third office
office3 = createClusteredPostOffice(3, "testgroup", sc, ms, pm, tr);
// Maks sure it picks up the bindings
bindings = office3.listAllBindingsForCondition(new SimpleCondition("topic1"));
assertNotNull(bindings);
assertEquals(2, bindings.size());
iter = bindings.iterator();
assertEquivalent(binding3, (Binding)iter.next());
assertEquivalent(binding4, (Binding)iter.next());
// Add another binding on node 3
LocalClusteredQueue queue5 =
new LocalClusteredQueue(office3, 3, "sub5", channelIDManager.getID(), ms, pm,
true, false, -1, null, tr);
Binding binding5 =
office3.bindClusteredQueue(new SimpleCondition("topic1"), queue5);
// Make sure all nodes pick it up
bindings = office1.listAllBindingsForCondition(new SimpleCondition("topic1"));
assertNotNull(bindings);
assertEquals(3, bindings.size());
iter = bindings.iterator();
assertEquivalent(binding3, (Binding)iter.next());
assertEquivalent(binding4, (Binding)iter.next());
assertEquivalent(binding5, (Binding)iter.next());
bindings = office2.listAllBindingsForCondition(new SimpleCondition("topic1"));
assertNotNull(bindings);
assertEquals(3, bindings.size());
iter = bindings.iterator();
assertEquivalent(binding3, (Binding)iter.next());
assertEquivalent(binding4, (Binding)iter.next());
assertEquivalent(binding5, (Binding)iter.next());
bindings = office3.listAllBindingsForCondition(new SimpleCondition("topic1"));
assertNotNull(bindings);
assertEquals(3, bindings.size());
iter = bindings.iterator();
assertEquivalent(binding3, (Binding)iter.next());
assertEquivalent(binding4, (Binding)iter.next());
assertEquivalent(binding5, (Binding)iter.next());
// Add a durable and a non durable binding on node 1
LocalClusteredQueue queue6 =
new LocalClusteredQueue(office1, 1, "sub6", channelIDManager.getID(), ms, pm,
true, true, -1, null, tr);
Binding binding6 =
office1.bindClusteredQueue(new SimpleCondition("topic1"), queue6);
LocalClusteredQueue queue7 =
new LocalClusteredQueue(office1, 1, "sub7", channelIDManager.getID(), ms, pm,
true, false, -1, null, tr);
Binding binding7 =
office1.bindClusteredQueue(new SimpleCondition("topic1"), queue7);
// Make sure all nodes pick them up
bindings = office1.listAllBindingsForCondition(new SimpleCondition("topic1"));