|
@@ -489,13 +489,20 @@ public class TestNetUtils {
|
|
return addr;
|
|
return addr;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
private void
|
|
private void
|
|
- verifyInetAddress(InetAddress addr, String host, String ip) {
|
|
|
|
|
|
+ verifyInetAddress(InetAddress addr, String host, String... ips) {
|
|
assertNotNull(addr);
|
|
assertNotNull(addr);
|
|
assertEquals(host, addr.getHostName());
|
|
assertEquals(host, addr.getHostName());
|
|
- assertEquals(ip, addr.getHostAddress());
|
|
|
|
|
|
+
|
|
|
|
+ boolean found = false;
|
|
|
|
+ for (String ip:ips) {
|
|
|
|
+ found |= ip.equals(addr.getHostAddress());
|
|
|
|
+ }
|
|
|
|
+ assertTrue("Expected addr.getHostAddress["+addr.getHostAddress()+"] to be one of " + StringUtils.join(ips, ","), found);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+
|
|
@Test
|
|
@Test
|
|
public void testResolverUnqualified() {
|
|
public void testResolverUnqualified() {
|
|
String host = "host";
|
|
String host = "host";
|
|
@@ -525,12 +532,16 @@ public class TestNetUtils {
|
|
}
|
|
}
|
|
|
|
|
|
// localhost
|
|
// localhost
|
|
-
|
|
|
|
|
|
+
|
|
@Test
|
|
@Test
|
|
public void testResolverLoopback() {
|
|
public void testResolverLoopback() {
|
|
String host = "Localhost";
|
|
String host = "Localhost";
|
|
InetAddress addr = verifyResolve(host); // no lookup should occur
|
|
InetAddress addr = verifyResolve(host); // no lookup should occur
|
|
- verifyInetAddress(addr, "Localhost", "127.0.0.1");
|
|
|
|
|
|
+ verifyInetAddress(addr,
|
|
|
|
+ "Localhost",
|
|
|
|
+ "127.0.0.1",
|
|
|
|
+ IPV6_LOOPBACK_LONG_STRING,
|
|
|
|
+ IPV6_LOOPBACK_SHORT_STRING);
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
@@ -637,10 +648,14 @@ public class TestNetUtils {
|
|
// when ipaddress is normalized, same address is expected in return
|
|
// when ipaddress is normalized, same address is expected in return
|
|
assertEquals(summary, hosts.get(0), normalizedHosts.get(0));
|
|
assertEquals(summary, hosts.get(0), normalizedHosts.get(0));
|
|
// for normalizing a resolvable hostname, resolved ipaddress is expected in return
|
|
// for normalizing a resolvable hostname, resolved ipaddress is expected in return
|
|
|
|
+
|
|
assertFalse("Element 1 equal "+ summary,
|
|
assertFalse("Element 1 equal "+ summary,
|
|
normalizedHosts.get(1).equals(hosts.get(1)));
|
|
normalizedHosts.get(1).equals(hosts.get(1)));
|
|
- assertEquals(summary, hosts.get(0), normalizedHosts.get(1));
|
|
|
|
- // this address HADOOP-8372: when normalizing a valid resolvable hostname start with numeric,
|
|
|
|
|
|
+ assertTrue("Should get the localhost address back",
|
|
|
|
+ normalizedHosts.get(1).equals(hosts.get(0)) ||
|
|
|
|
+ normalizedHosts.get(1).equals(IPV6_LOOPBACK_LONG_STRING));
|
|
|
|
+ // this address HADOOP-8372: when normalizing a valid resolvable hostname start with numeric,
|
|
|
|
+
|
|
// its ipaddress is expected to return
|
|
// its ipaddress is expected to return
|
|
assertFalse("Element 2 equal " + summary,
|
|
assertFalse("Element 2 equal " + summary,
|
|
normalizedHosts.get(2).equals(hosts.get(2)));
|
|
normalizedHosts.get(2).equals(hosts.get(2)));
|
|
@@ -690,7 +705,9 @@ public class TestNetUtils {
|
|
|
|
|
|
InetSocketAddress addr = NetUtils.createSocketAddr(defaultAddr);
|
|
InetSocketAddress addr = NetUtils.createSocketAddr(defaultAddr);
|
|
conf.setSocketAddr("myAddress", addr);
|
|
conf.setSocketAddr("myAddress", addr);
|
|
- assertEquals(defaultAddr.trim(), NetUtils.getHostPortString(addr));
|
|
|
|
|
|
+ assertTrue(
|
|
|
|
+ "Trim should have been called on ipv6 hostname",
|
|
|
|
+ defaultAddr.trim().equalsIgnoreCase(NetUtils.getHostPortString(addr)));
|
|
}
|
|
}
|
|
|
|
|
|
private <T> void assertBetterArrayEquals(T[] expect, T[]got) {
|
|
private <T> void assertBetterArrayEquals(T[] expect, T[]got) {
|