浏览代码

HADOOP-13605. Clean up FileSystem javadocs, logging; improve diagnostics on FS load. Contributed by Steve Loughran

Mingliang Liu 8 年之前
父节点
当前提交
860d49aa6a

文件差异内容过多而无法显示
+ 333 - 198
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java


+ 1 - 1
hadoop-common-project/hadoop-common/src/site/markdown/filesystem/filesystem.md

@@ -419,7 +419,7 @@ If the filesystem is not location aware, it SHOULD return
         BlockLocation(["localhost:9866"] ,
                   ["localhost"],
                   ["/default/localhost"]
-                   0, F.getLen())
+                   0, f.getLen())
        ] ;
 
 

+ 14 - 26
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestDefaultUri.java

@@ -21,14 +21,14 @@ import static org.apache.hadoop.fs.FileSystem.FS_DEFAULT_NAME_KEY;
 import static org.hamcrest.CoreMatchers.instanceOf;
 import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertThat;
-import static org.junit.Assert.fail;
 
 import java.io.IOException;
 import java.net.URI;
 
 import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.test.GenericTestUtils;
+
 import org.junit.Test;
+import static org.apache.hadoop.test.LambdaTestUtils.*;
 
 /**
  * Test default URI related APIs in {@link FileSystem}.
@@ -69,15 +69,12 @@ public class TestDefaultUri {
   }
 
   @Test
-  public void tetGetDefaultUriNoSchemeTrailingSlash() {
+  public void tetGetDefaultUriNoSchemeTrailingSlash() throws Exception {
     conf.set(FS_DEFAULT_NAME_KEY, "nn_host/");
-    try {
-      FileSystem.getDefaultUri(conf);
-      fail("Expect IAE: No scheme in default FS");
-    } catch (IllegalArgumentException e) {
-      GenericTestUtils.assertExceptionContains(
-          "No scheme in default FS", e);
-    }
+    intercept(IllegalArgumentException.class,
+        "No scheme in default FS",
+        () -> FileSystem.getDefaultUri(conf));
+
   }
 
   @Test
@@ -88,28 +85,19 @@ public class TestDefaultUri {
   }
 
   @Test
-  public void tetFsGetNoScheme() throws IOException {
+  public void tetFsGetNoScheme() throws Exception {
     // Bare host name or address indicates hdfs scheme
     conf.set(FS_DEFAULT_NAME_KEY, "nn_host");
-    try {
-      FileSystem.get(conf);
-      fail("Expect IOE: No FileSystem for scheme: hdfs");
-    } catch (IOException e) {
-      GenericTestUtils.assertExceptionContains(
-          "No FileSystem for scheme: hdfs", e);
-    }
+    intercept(UnsupportedFileSystemException.class, "hdfs",
+        () -> FileSystem.get(conf));
   }
 
   @Test
-  public void tetFsGetNoSchemeTrailingSlash() throws IOException {
+  public void tetFsGetNoSchemeTrailingSlash() throws Exception {
     // Bare host name or address with trailing slash is invalid
     conf.set(FS_DEFAULT_NAME_KEY, "nn_host/");
-    try {
-      FileSystem.get(conf);
-      fail("Expect IAE: No scheme in default FS");
-    } catch (IllegalArgumentException e) {
-      GenericTestUtils.assertExceptionContains(
-          "No scheme in default FS", e);
-    }
+    intercept(IllegalArgumentException.class,
+        "No scheme in default FS",
+        () -> FileSystem.get(conf));
   }
 }

+ 3 - 5
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFileSystemCaching.java

@@ -95,16 +95,14 @@ public class TestFileSystemCaching {
     try {
       fs = FileSystem.get(URI.create("//host"), conf);
       fail("got fs with auth but no scheme");
-    } catch (Exception e) {
-      assertEquals("No FileSystem for scheme: null", e.getMessage());
+    } catch (UnsupportedFileSystemException e) {
     }
-    
+
     // no scheme, different auth
     try {
       fs = FileSystem.get(URI.create("//host2"), conf);
       fail("got fs with auth but no scheme");
-    } catch (Exception e) {
-      assertEquals("No FileSystem for scheme: null", e.getMessage());
+    } catch (UnsupportedFileSystemException e) {
     }
   }
   

部分文件因为文件数量过多而无法显示