From d8409ef981a4c4683f95d0f6560c1fa71dc57aa3 Mon Sep 17 00:00:00 2001 From: Harsh J Date: Sat, 30 Jun 2012 18:53:00 +0000 Subject: [PATCH] Backport of HADOOP-3450. svn merge -c 1355789 from trunk. (harsh) git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1355791 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop-common/CHANGES.txt | 3 ++ .../hadoop/fs/TestLocalDirAllocator.java | 37 +++++++++++++++++-- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index e37e120fb88..19890d2bc74 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -54,6 +54,9 @@ Release 2.0.1-alpha - UNRELEASED 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 diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestLocalDirAllocator.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestLocalDirAllocator.java index da5f65d7347..ad319709bfa 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestLocalDirAllocator.java +++ b/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(); + } + + } + }