ZookeeperServerSet implements ServerSet, PathChildrenCacheListener { @Override public Set<InetSocketAddress> getServers() { Set<InetSocketAddress> serverList = new HashSet<InetSocketAddress>(); for (InetSocketAddress address : servers.keySet()) { serverList.add(address); } return serverList; } @AssistedInject  ZookeeperServerSet(@ServicePathCacheFactory PathChildrenCacheFactory childrenCacheFactory,
                            CuratorFramework zkClient,
                            @ServiceReader ZookeeperServerReader reader,
                            @Assisted("serviceName") String serviceName,
                            @Assisted boolean subscribeToUpdates); @Override synchronized void addChangeListener(ChangeListener listener); @Override synchronized void removeChangeListener(ChangeListener listener); @Override void close(); @Override synchronized void childEvent(CuratorFramework client, PathChildrenCacheEvent event); @Override String toString(); @Override Set<InetSocketAddress> getServers();  }
@Test public void testGetServers() throws Exception { InetSocketAddress server1 = new InetSocketAddress("192.168.1.1", 256); InetSocketAddress server2 = new InetSocketAddress("192.168.1.2", 512); ZookeeperServerSet set = new ZookeeperServerSet(mockChildrenCacheFactory, zkClient, serviceReader, "foo", true); CuratorFramework mockZk = mock(CuratorFramework.class); set.childEvent(mockZk, childAddedEvent("/services/foo/node-1", data(server1))); assertTrue(set.getServers().contains(server1)); assertFalse(set.getServers().contains(server2)); set.childEvent(mockZk, childAddedEvent("/services/foo/node-2", data(server2))); assertTrue(set.getServers().contains(server1)); assertTrue(set.getServers().contains(server2)); set.childEvent(mockZk, childRemovedEvent("/services/foo/node-1", data(server1))); assertFalse(set.getServers().contains(server1)); assertTrue(set.getServers().contains(server2)); set.close(); }