HealthCheckUtils { public static boolean checkHostPort(String connectionString) { String[] hostPort = generateHostPortArray(connectionString); try { createSocket(hostPort); return true; } catch (IOException e) { LOGGER.error("error in connecting to " + hostPort[0] + ":" + hostPort[1], e); } return false; }  static boolean checkHostPort(String connectionString);  }
@Test(expected = IllegalArgumentException.class) public void testInvalidPort() throws Exception { HealthCheckUtils.checkHostPort("localhost:ab12"); }
@Test public void testValidHostPortString() throws Exception { ServerSocket socket = new ServerSocket(8000); HealthCheckUtils.checkHostPort("localhost:8000"); socket.close(); }
@Test(expected = IllegalArgumentException.class) public void testInvalidHost() throws Exception { HealthCheckUtils.checkHostPort("localhost-8000"); }