@Test
public void testListenersPreservedWhenHostAdded() throws Exception {
ZkRing ring = ZkRing.create(getZk(), coordinator, ZkPath.append(getRoot(), "ring-group-one"), 1, null, null);
Host h1 = ring.addHost(new PartitionServerAddress("localhost", 1), Collections.emptyList());
MockHostCommandQueueChangeListener l1 = new MockHostCommandQueueChangeListener();
h1.setCommandQueueChangeListener(l1);
final MockHostStateChangeListener l2 = new MockHostStateChangeListener();
h1.setStateChangeListener(l2);
ring.addHost(new PartitionServerAddress("localhost", 2), Collections.emptyList());
h1.setState(HostState.UPDATING);
WaitUntil.orDie(() -> HostState.UPDATING == l2.calledWith);
assertEquals(HostState.UPDATING, l2.calledWith);
h1.enqueueCommand(HostCommand.EXECUTE_UPDATE);
l1.waitForNotification();
assertEquals(h1, l1.calledWith);
}