listener1.expectChangeSet(1);
listener2.expectChangeSet(0); // shutdown
listener3.expectChangeSet(0); // shutdown
// Send changeSet to one of the buses ...
ChangeSet changeSet = new TestChangeSet("ws1");
bus1.notify(changeSet);
// Wait for the observers to be notified ...
listener1.assertExpectedEventsCount();
listener2.assertExpectedEventsCount();
listener3.assertExpectedEventsCount();
// Now verify that all of the observers received the notification ...
assertThat(listener1.getObservedChangeSet().size(), is(1));
assertThat(listener2.getObservedChangeSet().size(), is(0));
assertThat(listener3.getObservedChangeSet().size(), is(0));
assertThat(listener1.getObservedChangeSet().get(0), is(changeSet));
// ------------------------------------
// Create a second bus ...
// ------------------------------------
ClusteredChangeBus bus2 = startNewBus();
bus2.register(listener2);
// ------------------------------------
// Send a change from the first bus ...
// ------------------------------------
// Set the observers to expect one event ...
listener1.expectChangeSet(1);
listener2.expectChangeSet(1);
listener3.expectChangeSet(0); // shutdown
// Send changeSet to one of the buses ...
changeSet = new TestChangeSet("ws1");
bus1.notify(changeSet);
// Wait for the observers to be notified ...
listener1.assertExpectedEventsCount();
listener2.assertExpectedEventsCount();
listener3.assertExpectedEventsCount();
// Now verify that all of the observers received the notification ...
assertThat(listener1.getObservedChangeSet().size(), is(1));
assertThat(listener2.getObservedChangeSet().size(), is(1));
assertThat(listener3.getObservedChangeSet().size(), is(0));
assertThat(listener1.getObservedChangeSet().get(0), is(changeSet));
assertThat(listener2.getObservedChangeSet().get(0), is(changeSet));
// ------------------------------------
// Send a change from the second bus ...
// ------------------------------------
// Set the observers to expect one event ...
listener1.expectChangeSet(1);
listener2.expectChangeSet(1);
listener3.expectChangeSet(0); // shutdown
// Send changeSet to one of the buses ...
changeSet = new TestChangeSet("ws2");
bus2.notify(changeSet);
// Wait for the observers to be notified ...
listener1.assertExpectedEventsCount();
listener2.assertExpectedEventsCount();
listener3.assertExpectedEventsCount();
// Now verify that all of the observers received the notification ...
assertThat(listener1.getObservedChangeSet().size(), is(1));
assertThat(listener2.getObservedChangeSet().size(), is(1));
assertThat(listener3.getObservedChangeSet().size(), is(0));
assertThat(listener1.getObservedChangeSet().get(0), is(changeSet));
assertThat(listener2.getObservedChangeSet().get(0), is(changeSet));
// ------------------------------------
// Create a third bus ...
// ------------------------------------
ClusteredChangeBus bus3 = startNewBus();
bus3.register(listener3);
// ------------------------------------
// Send a change from the first bus ...
// ------------------------------------
// Set the observers to expect one event ...
listener1.expectChangeSet(1);
listener2.expectChangeSet(1);
listener3.expectChangeSet(1);
// Send changeSet to one of the buses ...
changeSet = new TestChangeSet("ws1");
bus1.notify(changeSet);
// Wait for the observers to be notified ...
listener1.assertExpectedEventsCount();
listener2.assertExpectedEventsCount();
listener3.assertExpectedEventsCount();
// Now verify that all of the observers received the notification ...
assertThat(listener1.getObservedChangeSet().size(), is(1));
assertThat(listener2.getObservedChangeSet().size(), is(1));
assertThat(listener3.getObservedChangeSet().size(), is(1));
assertThat(listener1.getObservedChangeSet().get(0), is(changeSet));
assertThat(listener2.getObservedChangeSet().get(0), is(changeSet));
assertThat(listener3.getObservedChangeSet().get(0), is(changeSet));
// -------------------------------------
// Send a change from the second bus ...
// -------------------------------------
// Set the observers to expect one event ...
listener1.expectChangeSet(1);
listener2.expectChangeSet(1);
listener3.expectChangeSet(1);
// Send changeSet to one of the buses ...
ChangeSet changeSet2 = new TestChangeSet("ws2");
bus2.notify(changeSet2);
// Wait for the observers to be notified ...
listener1.assertExpectedEventsCount();
listener2.assertExpectedEventsCount();
listener3.assertExpectedEventsCount();
// Now verify that all of the observers received the notification ...
assertThat(listener1.getObservedChangeSet().size(), is(1));
assertThat(listener2.getObservedChangeSet().size(), is(1));
assertThat(listener3.getObservedChangeSet().size(), is(1));
assertThat(listener1.getObservedChangeSet().get(0), is(changeSet2));
assertThat(listener2.getObservedChangeSet().get(0), is(changeSet2));
assertThat(listener3.getObservedChangeSet().get(0), is(changeSet2));
// ------------------------------------
// Send a change from the third bus ...
// ------------------------------------
// Set the observers to expect one event ...
listener1.expectChangeSet(1);
listener2.expectChangeSet(1);
listener3.expectChangeSet(1);
// Send changeSet to one of the buses ...
ChangeSet changeSet3 = new TestChangeSet("ws3");
bus3.notify(changeSet3);
// Wait for the observers to be notified ...
listener1.assertExpectedEventsCount();
listener2.assertExpectedEventsCount();