瀏覽代碼

HADOOP-3450. Add tests to Local Directory Allocator for asserting their URI-returning capability. Contributed by Sho Shimauchi. (harsh)

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1355789 13f79535-47bb-0310-9956-ffa450edef68
Harsh J 13 年之前
父節點
當前提交
511da1096a

+ 3 - 0
hadoop-common-project/hadoop-common/CHANGES.txt

@@ -222,6 +222,9 @@ Branch-2 ( Unreleased changes )
     from CommonConfigurationKeys.java (not used, deprecated)
     (Sho Shimauchi via harsh)
 
+    HADOOP-3450. Add tests to Local Directory Allocator for
+    asserting their URI-returning capability (Sho Shimauchi via harsh)
+
   BUG FIXES
 
     HADOOP-8372. NetUtils.normalizeHostName() incorrectly handles hostname

+ 33 - 4
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestLocalDirAllocator.java

@@ -72,8 +72,11 @@ public class TestLocalDirAllocator {
       System.exit(-1);
     }
 
+    // absolute path in test environment
+    // /home/testuser/src/hadoop-common-project/hadoop-common/build/test/temp
     ABSOLUTE_DIR_ROOT = new Path(localFs.getWorkingDirectory(),
         BUFFER_DIR_ROOT).toUri().getPath();
+    // file:/home/testuser/src/hadoop-common-project/hadoop-common/build/test/temp
     QUALIFIED_DIR_ROOT = new Path(localFs.getWorkingDirectory(),
         BUFFER_DIR_ROOT).toUri().toString();
   }
@@ -145,7 +148,7 @@ public class TestLocalDirAllocator {
    * @throws Exception
    */
   @Test
-  public void test1() throws Exception {
+  public void testROBufferDirAndRWBufferDir() throws Exception {
     if (isWindows) return;
     String dir1 = buildBufferDir(ROOT, 1);
     String dir2 = buildBufferDir(ROOT, 2);
@@ -164,7 +167,7 @@ public class TestLocalDirAllocator {
    * Check if tmp dirs are allocated in a round-robin
    */
   @Test
-  public void test2() throws Exception {
+  public void testDirsNotExist() throws Exception {
     if (isWindows) return;
     String dir2 = buildBufferDir(ROOT, 2);
     String dir3 = buildBufferDir(ROOT, 3);
@@ -190,7 +193,7 @@ public class TestLocalDirAllocator {
    * @throws Exception
    */
   @Test
-  public void test3() throws Exception {
+  public void testRWBufferDirBecomesRO() throws Exception {
     if (isWindows) return;
     String dir3 = buildBufferDir(ROOT, 3);
     String dir4 = buildBufferDir(ROOT, 4);
@@ -228,7 +231,7 @@ public class TestLocalDirAllocator {
    */
   static final int TRIALS = 100;
   @Test
-  public void test4() throws Exception {
+  public void testCreateManyFiles() throws Exception {
     if (isWindows) return;
     String dir5 = buildBufferDir(ROOT, 5);
     String dir6 = buildBufferDir(ROOT, 6);
@@ -311,4 +314,30 @@ public class TestLocalDirAllocator {
       rmBufferDirs();
     }
   }
+
+  /**
+   * Test getLocalPathToRead() returns correct filename and "file" schema.
+   *
+   * @throws IOException
+   */
+  @Test
+  public void testGetLocalPathToRead() throws IOException {
+    if (isWindows)
+      return;
+    String dir = buildBufferDir(ROOT, 0);
+    try {
+      conf.set(CONTEXT, dir);
+      assertTrue(localFs.mkdirs(new Path(dir)));
+      File f1 = dirAllocator.createTmpFileForWrite(FILENAME, SMALL_FILE_SIZE,
+          conf);
+      Path p1 = dirAllocator.getLocalPathToRead(f1.getName(), conf);
+      assertEquals(f1.getName(), p1.getName());
+      assertEquals("file", p1.getFileSystem(conf).getUri().getScheme());
+    } finally {
+      Shell.execCommand(new String[] { "chmod", "u+w", BUFFER_DIR_ROOT });
+      rmBufferDirs();
+    }
+
+  }
+
 }