Curator implements AutoCloseable { static String createConnectionSpecForLocalhost(ConfigserverConfig config) { String thisServer = HostName.getLocalhost(); for (int i = 0; i < config.zookeeperserver().size(); i++) { ConfigserverConfig.Zookeeperserver server = config.zookeeperserver(i); if (thisServer.equals(server.hostname())) { return String.format("%s:%d", server.hostname(), server.port()); } } throw new IllegalArgumentException("Unable to create connect string to localhost: " + "There is no localhost server specified in config: " + config); } @Inject  Curator(ConfigserverConfig configserverConfig, VespaZooKeeperServer server);   Curator(ConfigserverConfig configserverConfig, Optional<File> clientConfigFile); private  Curator(String connectionSpec, String zooKeeperEnsembleConnectionSpec, Optional<File> clientConfigFile); protected  Curator(String connectionSpec,
                      String zooKeeperEnsembleConnectionSpec,
                      Function<RetryPolicy, CuratorFramework> curatorFactory); private  Curator(String connectionSpec,
                    String zooKeeperEnsembleConnectionSpec,
                    Function<RetryPolicy, CuratorFramework> curatorFactory,
                    RetryPolicy retryPolicy); static Curator create(String connectionSpec); static Curator create(String connectionSpec, Optional<File> clientConfigFile); String connectionSpec(); DistributedAtomicLong createAtomicCounter(String path); InterProcessLock createMutex(String lockPath); CompletionWaiter getCompletionWaiter(Path waiterPath, int numMembers, String id); CompletionWaiter createCompletionWaiter(Path parentPath, String waiterNode, int numMembers, String id); DirectoryCache createDirectoryCache(String path, boolean cacheData, boolean dataIsCompressed, ExecutorService executorService); FileCache createFileCache(String path, boolean dataIsCompressed); boolean exists(Path path); void set(Path path, byte[] data); boolean create(Path path); void createAtomically(Path... paths); void delete(Path path); List<String> getChildren(Path path); Optional<byte[]> getData(Path path); Optional<Stat> getStat(Path path); Lock lock(Path path, Duration timeout); CuratorFramework framework(); @Override void close(); String zooKeeperEnsembleConnectionSpec(); int zooKeeperEnsembleCount();  }
@Test public void localhost_affinity() { String localhostHostName = "myhost"; int localhostPort = 123; ConfigserverConfig.Builder builder = new ConfigserverConfig.Builder(); builder.zookeeperserver(createZKBuilder(localhostHostName, localhostPort)); builder.zookeeperserver(createZKBuilder("otherhost", 345)); ConfigserverConfig config = new ConfigserverConfig(builder); HostName.setHostNameForTestingOnly(localhostHostName); String localhostSpec = localhostHostName + ":" + localhostPort; assertEquals(localhostSpec, Curator.createConnectionSpecForLocalhost(config)); }