slfan1989 commented on code in PR #8877:
URL: https://github.com/apache/hadoop/pull/8877#discussion_r4461570861


##########
hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeRpcServer.java:
##########
@@ -84,6 +90,39 @@ public void testNamenodeRpcBindAny() throws IOException {
     }
   }
 
+  @Test
+  public void testAdvertisedAddress() throws IOException {
+    for (boolean useIp : new boolean[] {true, false}) {
+      SecurityUtil.setTokenServiceUseIp(useIp);
+      try {
+        // The reverse name of a literal is advertised only if it resolves 
back to it.
+        for (String literal : new String[] {"127.0.0.1", "[::1]"}) {
+          InetSocketAddress configured = NetUtils.createSocketAddr(literal + 
":0");
+          InetSocketAddress advertised =
+              NameNodeRpcServer.getAdvertisedAddress(configured, 8020);
+          assertEquals(8020, advertised.getPort());
+          assertEquals(configured.getAddress(), advertised.getAddress());
+          assertEquals(configured.getAddress(),
+              InetAddress.getByName(advertised.getHostName()));
+        }
+        assertEquals("localhost", NameNodeRpcServer.getAdvertisedAddress(

Review Comment:
   Could we avoid hard-coding "localhost" here? 
   With dual-stack localhost and `java.net.preferIPv6Addresses=true`, the 
helper correctly retains `127.0.0.1`, but this assertion fails. It also fails 
when the canonical name is `localhost.localdomain`.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to