@Test public void shouldReturnMultiAddress() { ZKAddressParser mock = Mockito.mock(ZKAddressParser.class); String add1 = "192.168.0.1:2182"; String add2 = "192.168.0.2:2183"; String concat = add1 + "," + add2; List<ZKAddress> dummyReturn = new ArrayList<>(1); dummyReturn.add(new ZKAddress(add1)); dummyReturn.add(new ZKAddress(add2)); Mockito.when(mock.validateZkUrl(anyString())).thenReturn(dummyReturn); ZKFormatter formatter = new MesosZKFormatter(mock); String address = formatter.format(""); assertEquals(ZKAddress.ZK_PREFIX + concat + MesosZKFormatter.DEFAULT_MESOS_PATH, address); }
public String format(String zkUrl) { List<ZKAddress> addressList = parser.validateZkUrl(zkUrl); StringBuilder builder = new StringBuilder(); addressList.forEach( add -> builder.append(",").append(add.getAddress()).append(":").append(add.getPort())); builder.deleteCharAt(0); String lastPath = addressList.get(addressList.size() - 1).getZkNode(); if (null == lastPath || lastPath.equals("") || lastPath.equals("/")) { lastPath = DEFAULT_MESOS_PATH; } builder.append(lastPath); builder.insert(0, ZKAddress.ZK_PREFIX); return builder.toString(); }
MesosZKFormatter extends AbstractZKFormatter { public String format(String zkUrl) { List<ZKAddress> addressList = parser.validateZkUrl(zkUrl); StringBuilder builder = new StringBuilder(); addressList.forEach( add -> builder.append(",").append(add.getAddress()).append(":").append(add.getPort())); builder.deleteCharAt(0); String lastPath = addressList.get(addressList.size() - 1).getZkNode(); if (null == lastPath || lastPath.equals("") || lastPath.equals("/")) { lastPath = DEFAULT_MESOS_PATH; } builder.append(lastPath); builder.insert(0, ZKAddress.ZK_PREFIX); return builder.toString(); } }
MesosZKFormatter extends AbstractZKFormatter { public String format(String zkUrl) { List<ZKAddress> addressList = parser.validateZkUrl(zkUrl); StringBuilder builder = new StringBuilder(); addressList.forEach( add -> builder.append(",").append(add.getAddress()).append(":").append(add.getPort())); builder.deleteCharAt(0); String lastPath = addressList.get(addressList.size() - 1).getZkNode(); if (null == lastPath || lastPath.equals("") || lastPath.equals("/")) { lastPath = DEFAULT_MESOS_PATH; } builder.append(lastPath); builder.insert(0, ZKAddress.ZK_PREFIX); return builder.toString(); } MesosZKFormatter(ZKAddressParser parser); }
MesosZKFormatter extends AbstractZKFormatter { public String format(String zkUrl) { List<ZKAddress> addressList = parser.validateZkUrl(zkUrl); StringBuilder builder = new StringBuilder(); addressList.forEach( add -> builder.append(",").append(add.getAddress()).append(":").append(add.getPort())); builder.deleteCharAt(0); String lastPath = addressList.get(addressList.size() - 1).getZkNode(); if (null == lastPath || lastPath.equals("") || lastPath.equals("/")) { lastPath = DEFAULT_MESOS_PATH; } builder.append(lastPath); builder.insert(0, ZKAddress.ZK_PREFIX); return builder.toString(); } MesosZKFormatter(ZKAddressParser parser); String format(String zkUrl); }
MesosZKFormatter extends AbstractZKFormatter { public String format(String zkUrl) { List<ZKAddress> addressList = parser.validateZkUrl(zkUrl); StringBuilder builder = new StringBuilder(); addressList.forEach( add -> builder.append(",").append(add.getAddress()).append(":").append(add.getPort())); builder.deleteCharAt(0); String lastPath = addressList.get(addressList.size() - 1).getZkNode(); if (null == lastPath || lastPath.equals("") || lastPath.equals("/")) { lastPath = DEFAULT_MESOS_PATH; } builder.append(lastPath); builder.insert(0, ZKAddress.ZK_PREFIX); return builder.toString(); } MesosZKFormatter(ZKAddressParser parser); String format(String zkUrl); static final String DEFAULT_MESOS_PATH; }