hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From szets...@apache.org
Subject svn commit: r1413970 - in /hadoop/common/branches/branch-1-win: ./ CHANGES.txt src/core/org/apache/hadoop/net/NetUtils.java src/test/org/apache/hadoop/net/TestNetUtils.java
Date Tue, 27 Nov 2012 01:55:29 GMT
Author: szetszwo
Date: Tue Nov 27 01:55:27 2012
New Revision: 1413970

URL: http://svn.apache.org/viewvc?rev=1413970&view=rev
Log:
svn merge -c 1413969 from branch-1 for HADOOP-9095. Backport HADOOP-8372: NetUtils.normalizeHostName()
incorrectly handles hostname starting with a numeric character.

Modified:
    hadoop/common/branches/branch-1-win/   (props changed)
    hadoop/common/branches/branch-1-win/CHANGES.txt   (contents, props changed)
    hadoop/common/branches/branch-1-win/src/core/org/apache/hadoop/net/NetUtils.java
    hadoop/common/branches/branch-1-win/src/test/org/apache/hadoop/net/TestNetUtils.java

Propchange: hadoop/common/branches/branch-1-win/
------------------------------------------------------------------------------
  Merged /hadoop/common/branches/branch-1:r1413969

Modified: hadoop/common/branches/branch-1-win/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1-win/CHANGES.txt?rev=1413970&r1=1413969&r2=1413970&view=diff
==============================================================================
--- hadoop/common/branches/branch-1-win/CHANGES.txt (original)
+++ hadoop/common/branches/branch-1-win/CHANGES.txt Tue Nov 27 01:55:27 2012
@@ -33,6 +33,10 @@ Release 1.2.0 - unreleased
     HADOOP-9036. Fix racy test case TestSinkQueue (Backport HADOOP-7292).
     (Luke Lu backport by suresh)
 
+    HADOOP-9095. Backport HADOOP-8372: NetUtils.normalizeHostName() incorrectly
+    handles hostname starting with a numeric character.  (Jing Zhao via
+    szetszwo)
+
 Release 1.1.1 - Unreleased
 
   INCOMPATIBLE CHANGES

Propchange: hadoop/common/branches/branch-1-win/CHANGES.txt
------------------------------------------------------------------------------
  Merged /hadoop/common/branches/branch-1/CHANGES.txt:r1413969

Modified: hadoop/common/branches/branch-1-win/src/core/org/apache/hadoop/net/NetUtils.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1-win/src/core/org/apache/hadoop/net/NetUtils.java?rev=1413970&r1=1413969&r2=1413970&view=diff
==============================================================================
--- hadoop/common/branches/branch-1-win/src/core/org/apache/hadoop/net/NetUtils.java (original)
+++ hadoop/common/branches/branch-1-win/src/core/org/apache/hadoop/net/NetUtils.java Tue Nov
27 01:55:27 2012
@@ -514,15 +514,11 @@ public class NetUtils {
    * @return its IP address in the string format
    */
   public static String normalizeHostName(String name) {
-    if (Character.digit(name.charAt(0), 10) != -1) { //FIXME 
+    try {
+      InetAddress ipAddress = InetAddress.getByName(name);
+      return ipAddress.getHostAddress();
+    } catch (UnknownHostException e) {
       return name;
-    } else {
-      try {
-        InetAddress ipAddress = InetAddress.getByName(name);
-        return ipAddress.getHostAddress();
-      } catch (UnknownHostException e) {
-        return name;
-      }
     }
   }
   

Modified: hadoop/common/branches/branch-1-win/src/test/org/apache/hadoop/net/TestNetUtils.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1-win/src/test/org/apache/hadoop/net/TestNetUtils.java?rev=1413970&r1=1413969&r2=1413970&view=diff
==============================================================================
--- hadoop/common/branches/branch-1-win/src/test/org/apache/hadoop/net/TestNetUtils.java (original)
+++ hadoop/common/branches/branch-1-win/src/test/org/apache/hadoop/net/TestNetUtils.java Tue
Nov 27 01:55:27 2012
@@ -18,6 +18,7 @@
 package org.apache.hadoop.net;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
@@ -30,6 +31,8 @@ import java.net.Socket;
 import java.net.SocketException;
 import java.net.URI;
 import java.net.UnknownHostException;
+import java.util.Arrays;
+import java.util.List;
 
 import org.apache.commons.lang.StringUtils;
 import org.apache.hadoop.conf.Configuration;
@@ -321,4 +324,26 @@ public class TestNetUtils {
     String gotStr = StringUtils.join(got, ", ");
     assertEquals(expectStr, gotStr);
   }
+  
+  /**
+   * Test for {@link NetUtils#normalizeHostNames
+
+   */
+  @Test
+  public void testNormalizeHostName() {
+    List<String> hosts = Arrays.asList(new String[] { "127.0.0.1", "localhost",
+        "3w.org", "UnknownHost" });
+    List<String> normalizedHosts = NetUtils.normalizeHostNames(hosts);
+    // when ipaddress is normalized, same address is expected in return
+    assertEquals(normalizedHosts.get(0), hosts.get(0));
+    // for normalizing a resolvable hostname, resolved ipaddress is expected in
+    // return
+    assertFalse(normalizedHosts.get(1).equals(hosts.get(1)));
+    assertEquals(normalizedHosts.get(1), hosts.get(0));
+    // when normalizing a valid resolvable hostname start with numeric,
+    // its ipaddress is expected to return
+    assertFalse(normalizedHosts.get(2).equals(hosts.get(2)));
+    // return the same hostname after normalizing a irresolvable hostname.
+    assertEquals(normalizedHosts.get(3), hosts.get(3));
+  }
 }
\ No newline at end of file



Mime
View raw message