AbstractZookeeperTransporter implements ZookeeperTransporter { ZookeeperClient fetchAndUpdateZookeeperClientCache(List<String> addressList) { ZookeeperClient zookeeperClient = null; for (String address : addressList) { if ((zookeeperClient = zookeeperClientMap.get(address)) != null && zookeeperClient.isConnected()) { break; } } if (zookeeperClient != null && zookeeperClient.isConnected()) { writeToClientMap(addressList, zookeeperClient); } return zookeeperClient; }  @Override ZookeeperClient connect(URL url);  }
@Test public void testFetchAndUpdateZookeeperClientCache() throws Exception { int zkServerPort2 = NetUtils.getAvailablePort(); TestingServer zkServer2 = new TestingServer(zkServerPort2, true); int zkServerPort3 = NetUtils.getAvailablePort(); TestingServer zkServer3 = new TestingServer(zkServerPort3, true); URL url = URL.valueOf("zookeeper: ZookeeperClient newZookeeperClient = abstractZookeeperTransporter.connect(url); newZookeeperClient.getContent("/dubbo/test"); Assertions.assertEquals(abstractZookeeperTransporter.getZookeeperClientMap().size(), 3); Assertions.assertEquals(abstractZookeeperTransporter.getZookeeperClientMap().get("127.0.0.1:" + zkServerPort), newZookeeperClient); URL url2 = URL.valueOf("zookeeper: checkFetchAndUpdateCacheNotNull(url2); URL url3 = URL.valueOf("zookeeper: checkFetchAndUpdateCacheNotNull(url3); zkServer2.stop(); zkServer3.stop(); }