### Question:
BKRegistrationNameResolver extends NameResolver { @Override public synchronized void start(Listener listener) { checkState(null == this.listener, "Resolver already started"); this.listener = Objects.requireNonNull(listener, "Listener is null"); ClientConfiguration conf = new ClientConfiguration(); conf.setMetadataServiceUri(serviceURI.toString()); try { clientDriver.initialize(conf, executor, NullStatsLogger.INSTANCE, Optional.empty()); } catch (MetadataException e) { throw new RuntimeException("Failed to initialize registration client driver at " + serviceURI, e); } resolve(); } BKRegistrationNameResolver(MetadataClientDriver clientDriver,
                               URI serviceURI); @Override String getServiceAuthority(); @Override synchronized void start(Listener listener); @Override void shutdown();  }### Answer:
@Test public void testNameResolver() throws Exception { int numServers = 3; Set<SocketAddress> addressSet = new HashSet<>(); for (int i = 0; i < numServers; i++) { InetSocketAddress address = new InetSocketAddress("127.0.0.1", 3181 + i); addressSet.add(address); bookieDriver.getRegistrationManager().registerBookie( BookieId.parse("127.0.0.1:" + (3181 + i)), false, BookieServiceInfo.EMPTY ); } LinkedBlockingQueue<List<EquivalentAddressGroup>> notifications = new LinkedBlockingQueue<>(); @Cleanup("shutdown") NameResolver resolver = resolverProvider.newNameResolver(serviceUri, Attributes.EMPTY); resolver.start(new Listener() { @Override public void onAddresses(List<EquivalentAddressGroup> servers, Attributes attributes) { notifications.add(servers); } @Override public void onError(Status error) { } }); List<EquivalentAddressGroup> groups = notifications.take(); assertEquals(numServers, groups.size()); Set<SocketAddress> receivedSet = groups.stream() .map(group -> group.getAddresses().get(0)) .collect(Collectors.toSet()); assertEquals(addressSet, receivedSet); for (int i = numServers; i < 2 * numServers; i++) { InetSocketAddress address = new InetSocketAddress("127.0.0.1", 3181 + i); addressSet.add(address); bookieDriver.getRegistrationManager().registerBookie( BookieId.parse("127.0.0.1:" + (3181 + i)), false, BookieServiceInfo.EMPTY ); } List<EquivalentAddressGroup> notification = notifications.take(); while (notification.size() < 2 * numServers) { notification = notifications.take(); } assertEquals(2 * numServers, notification.size()); receivedSet = notification.stream() .map(group -> group.getAddresses().get(0)) .collect(Collectors.toSet()); assertEquals(addressSet, receivedSet); }