AbstractZookeeperTransporter implements ZookeeperTransporter { @Override public ZookeeperClient connect(URL url) { ZookeeperClient zookeeperClient; List<String> addressList = getURLBackupAddress(url); if ((zookeeperClient = fetchAndUpdateZookeeperClientCache(addressList)) != null && zookeeperClient.isConnected()) { logger.info("find valid zookeeper client from the cache for address: " + url); return zookeeperClient; } synchronized (zookeeperClientMap) { if ((zookeeperClient = fetchAndUpdateZookeeperClientCache(addressList)) != null && zookeeperClient.isConnected()) { logger.info("find valid zookeeper client from the cache for address: " + url); return zookeeperClient; } zookeeperClient = createZookeeperClient(url); logger.info("No valid zookeeper client found from cache, therefore create a new client for url. " + url); writeToClientMap(addressList, zookeeperClient); } return zookeeperClient; }  @Override ZookeeperClient connect(URL url);  }
@Test public void testSameHostWithDifferentUser() throws Exception { int zkPort1 = NetUtils.getAvailablePort(); int zkPort2 = NetUtils.getAvailablePort(); try (TestingServer zkServer1 = new TestingServer(zkPort1, true)) { try (TestingServer zkServer2 = new TestingServer(zkPort2, true)) { URL url1 = URL.valueOf("zookeeper: URL url2 = URL.valueOf("zookeeper: ZookeeperClient client1 = abstractZookeeperTransporter.connect(url1); ZookeeperClient client2 = abstractZookeeperTransporter.connect(url2); assertThat(client1, not(client2)); } } }