AbstractZookeeperTransporter implements ZookeeperTransporter { List<String> getURLBackupAddress(URL url) { List<String> addressList = new ArrayList<String>(); addressList.add(url.getAddress()); addressList.addAll(url.getParameter(RemotingConstants.BACKUP_KEY, Collections.EMPTY_LIST)); String authPrefix = null; if (StringUtils.isNotEmpty(url.getUsername())) { StringBuilder buf = new StringBuilder(); buf.append(url.getUsername()); if (StringUtils.isNotEmpty(url.getPassword())) { buf.append(":"); buf.append(url.getPassword()); } buf.append("@"); authPrefix = buf.toString(); } if (StringUtils.isNotEmpty(authPrefix)) { List<String> authedAddressList = new ArrayList<>(addressList.size()); for (String addr : addressList) { authedAddressList.add(authPrefix + addr); } return authedAddressList; } return addressList; }  @Override ZookeeperClient connect(URL url);  }
@Test public void testGetURLBackupAddress() { URL url = URL.valueOf("zookeeper: List<String> stringList = abstractZookeeperTransporter.getURLBackupAddress(url); Assertions.assertEquals(stringList.size(), 2); Assertions.assertEquals(stringList.get(0), "127.0.0.1:" + zkServerPort); Assertions.assertEquals(stringList.get(1), "127.0.0.1:9099"); }
@Test public void testGetURLBackupAddressNoBack() { URL url = URL.valueOf("zookeeper: List<String> stringList = abstractZookeeperTransporter.getURLBackupAddress(url); Assertions.assertEquals(stringList.size(), 1); Assertions.assertEquals(stringList.get(0), "127.0.0.1:" + zkServerPort); }