@Test
public void testReturnLocalHostAddressUsingHeuristics() {

	int unusedPort;
	try {
		unusedPort = org.apache.flink.util.NetUtils.getAvailablePort();
	}
	catch (Throwable t) {
		// if this system cannot find an available port,
		// skip this test
		return;
	}
	try {
		// create an unreachable target address
		InetSocketAddress unreachable = new InetSocketAddress("localhost", unusedPort);
		final long start = System.currentTimeMillis();
		InetAddress add = ConnectionUtils.findConnectingAddress(unreachable, 2000, 400);
		// check that it did not take forever
		assertTrue(System.currentTimeMillis() - start < (OperatingSystem.isWindows() ? 30000 : 8000));
		// we should have found a heuristic address
		assertNotNull(add);
		// make sure that we returned the InetAddress.getLocalHost as a heuristic
		assertEquals(InetAddress.getLocalHost(), add);
	}
	catch (Exception e) {
		e.printStackTrace();
		fail(e.getMessage());
	}
}