hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1179471 - in /hadoop/common/branches/branch-0.20-security: CHANGES.txt src/hdfs/org/apache/hadoop/hdfs/server/namenode/NameNode.java src/test/org/apache/hadoop/hdfs/TestDefaultNameNodePort.java
Date Wed, 05 Oct 2011 23:19:54 GMT
Author: mattf
Date: Wed Oct  5 23:19:54 2011
New Revision: 1179471

URL: http://svn.apache.org/viewvc?rev=1179471&view=rev
Log:
HDFS-2358. NPE when the default filesystem's uri has no authority. Contributed by Daryn Sharp.

Modified:
    hadoop/common/branches/branch-0.20-security/CHANGES.txt
    hadoop/common/branches/branch-0.20-security/src/hdfs/org/apache/hadoop/hdfs/server/namenode/NameNode.java
    hadoop/common/branches/branch-0.20-security/src/test/org/apache/hadoop/hdfs/TestDefaultNameNodePort.java

Modified: hadoop/common/branches/branch-0.20-security/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20-security/CHANGES.txt?rev=1179471&r1=1179470&r2=1179471&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.20-security/CHANGES.txt (original)
+++ hadoop/common/branches/branch-0.20-security/CHANGES.txt Wed Oct  5 23:19:54 2011
@@ -91,6 +91,9 @@ Release 0.20.205.0 - unreleased
 
   BUG FIXES
 
+    HDFS-2358. NPE when the default filesystem's uri has no authority.
+    (Daryn Sharp via mattf)
+
     MAPREDUCE-3112. Calling hadoop cli inside mapreduce job leads to errors.
     (Eric Yang via mattf)
 

Modified: hadoop/common/branches/branch-0.20-security/src/hdfs/org/apache/hadoop/hdfs/server/namenode/NameNode.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20-security/src/hdfs/org/apache/hadoop/hdfs/server/namenode/NameNode.java?rev=1179471&r1=1179470&r2=1179471&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.20-security/src/hdfs/org/apache/hadoop/hdfs/server/namenode/NameNode.java
(original)
+++ hadoop/common/branches/branch-0.20-security/src/hdfs/org/apache/hadoop/hdfs/server/namenode/NameNode.java
Wed Oct  5 23:19:54 2011
@@ -223,7 +223,7 @@ public class NameNode implements ClientP
   }
 
   public static InetSocketAddress getAddress(Configuration conf) {
-    return getAddress(FileSystem.getDefaultUri(conf).getAuthority());
+    return getAddress(FileSystem.getDefaultUri(conf).toString());
   }
 
   public static URI getUri(InetSocketAddress namenode) {

Modified: hadoop/common/branches/branch-0.20-security/src/test/org/apache/hadoop/hdfs/TestDefaultNameNodePort.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20-security/src/test/org/apache/hadoop/hdfs/TestDefaultNameNodePort.java?rev=1179471&r1=1179470&r2=1179471&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.20-security/src/test/org/apache/hadoop/hdfs/TestDefaultNameNodePort.java
(original)
+++ hadoop/common/branches/branch-0.20-security/src/test/org/apache/hadoop/hdfs/TestDefaultNameNodePort.java
Wed Oct  5 23:19:54 2011
@@ -17,7 +17,9 @@
  */
 package org.apache.hadoop.hdfs;
 
-import junit.framework.TestCase;
+import org.junit.*;
+import static org.junit.Assert.*;
+
 import java.io.*;
 import java.net.*;
 import java.util.*;
@@ -27,8 +29,8 @@ import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.hdfs.server.namenode.NameNode;
 
 /** Test NameNode port defaulting code. */
-public class TestDefaultNameNodePort extends TestCase {
-
+public class TestDefaultNameNodePort {
+  @Test
   public void testGetAddressFromString() throws Exception {
     assertEquals(NameNode.getAddress("foo").getPort(),
                  NameNode.DEFAULT_PORT);
@@ -40,6 +42,7 @@ public class TestDefaultNameNodePort ext
                  555);
   }
 
+  @Test
   public void testGetAddressFromConf() throws Exception {
     Configuration conf = new Configuration();
     FileSystem.setDefaultUri(conf, "hdfs://foo/");
@@ -57,4 +60,36 @@ public class TestDefaultNameNodePort ext
                                                        NameNode.DEFAULT_PORT)),
                  URI.create("hdfs://foo"));
   }
+
+  @Test
+  public void testSlashAddress() throws Exception {
+    verifyBadAuthAddress("/junk");
+  } 
+
+  @Test
+  public void testSlashSlashAddress() throws Exception {
+    verifyBadAuthAddress("//junk");
+  } 
+
+  @Test
+  public void testNoAuthAddress() throws Exception {
+    // this is actually the default value if the default fs isn't configured!
+    verifyBadAuthAddress("file:///");
+  } 
+
+  public void verifyBadAuthAddress(String noAuth) throws Exception {
+    Configuration conf = new Configuration();
+    FileSystem.setDefaultUri(conf, noAuth);
+    try {
+      InetSocketAddress addr = NameNode.getAddress(conf);
+      // this will show what we got back in case the test fails
+      assertEquals(null, addr);
+    } catch (IllegalArgumentException e) {
+      assertEquals(
+          "Does not contain a valid host:port authority: " + noAuth,
+          e.getMessage());
+    }
+  } 
+
+
 }



Mime
View raw message