HADOOP-6274. Fix TestLocalFSFileContextMainOperations test failure. Contributed by Gary Murry.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@817496 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Suresh Srinivas 2009-09-22 04:12:45 +00:00
parent 277dd0e2a3
commit 373bf85f56
2 changed files with 34 additions and 64 deletions

View File

@ -11,6 +11,8 @@ Trunk (unreleased changes)
OPTIMIZATIONS OPTIMIZATIONS
BUG FIXES BUG FIXES
HADOOP-6274. Fix TestLocalFSFileContextMainOperations test failure. (Gary Murry via suresh).
Release 0.21.0 - Unreleased Release 0.21.0 - Unreleased

View File

@ -267,18 +267,10 @@ public void testListStatus() throws Exception {
paths = fc.listStatus(getTestRootPath("test/hadoop")); paths = fc.listStatus(getTestRootPath("test/hadoop"));
Assert.assertEquals(3, paths.length); Assert.assertEquals(3, paths.length);
Assert.assertTrue(containsPath(getTestRootPath("test/hadoop/a"), paths));
Assert.assertTrue(getTestRootPath("test/hadoop/a").equals(paths[0].getPath()) || Assert.assertTrue(containsPath(getTestRootPath("test/hadoop/b"), paths));
getTestRootPath("test/hadoop/a").equals(paths[1].getPath()) || Assert.assertTrue(containsPath(getTestRootPath("test/hadoop/c"), paths));
getTestRootPath("test/hadoop/a").equals(paths[2].getPath()));
Assert.assertTrue(getTestRootPath("test/hadoop/b").equals(paths[0].getPath()) ||
getTestRootPath("test/hadoop/b").equals(paths[1].getPath()) ||
getTestRootPath("test/hadoop/b").equals(paths[2].getPath()));
Assert.assertTrue(getTestRootPath("test/hadoop/c").equals(paths[0].getPath()) ||
getTestRootPath("test/hadoop/c").equals(paths[1].getPath()) ||
getTestRootPath("test/hadoop/c").equals(paths[2].getPath()));
paths = fc.listStatus(getTestRootPath("test/hadoop/a")); paths = fc.listStatus(getTestRootPath("test/hadoop/a"));
Assert.assertEquals(0, paths.length); Assert.assertEquals(0, paths.length);
} }
@ -315,39 +307,12 @@ public void testListStatusFilterWithSomeMatches() throws Exception {
} }
} }
//should return 2 paths ("/test/hadoop/axa2" and "/test/hadoop/axx2") //should return 2 paths ("/test/hadoop/axa" and "/test/hadoop/axx")
FileStatus[] filteredPaths = fc.util().listStatus(getTestRootPath("test/hadoop"), FileStatus[] filteredPaths = fc.util().listStatus(getTestRootPath("test/hadoop"),
TEST_X_FILTER); TEST_X_FILTER);
Assert.assertEquals(2,filteredPaths.length); Assert.assertEquals(2,filteredPaths.length);
Assert.assertTrue(getTestRootPath(TEST_DIR_AXA).equals(filteredPaths[0].getPath()) || Assert.assertTrue(containsPath(getTestRootPath(TEST_DIR_AXA), filteredPaths));
getTestRootPath(TEST_DIR_AXA).equals(filteredPaths[1].getPath())); Assert.assertTrue(containsPath(getTestRootPath(TEST_DIR_AXX), filteredPaths));
Assert.assertTrue(getTestRootPath(TEST_DIR_AXX).equals(filteredPaths[0].getPath()) ||
getTestRootPath(TEST_DIR_AXX).equals(filteredPaths[1].getPath()));
}
@Test
public void testListStatusFilterWithAnArrayOrPaths() throws Exception {
Path[] testDirs = { getTestRootPath(TEST_DIR_AAA),
getTestRootPath(TEST_DIR_AXA),
getTestRootPath(TEST_DIR_AXX),
getTestRootPath(TEST_DIR_AAA2), };
Path[] targetDirs = { getTestRootPath("test"),
getTestRootPath("test/hadoop"), };
if (fc.exists(testDirs[0]) == false) {
for (Path path : testDirs) {
fc.mkdir(path, FsPermission.getDefault(), true);
}
}
//test using a path[]
FileStatus[] filteredPaths = fc.util().listStatus(targetDirs, TEST_X_FILTER);
Assert.assertEquals(2,filteredPaths.length);
Assert.assertEquals(getTestRootPath(TEST_DIR_AXA),
filteredPaths[0].getPath());
Assert.assertEquals(getTestRootPath(TEST_DIR_AXX),
filteredPaths[1].getPath());
} }
@Test @Test
@ -395,8 +360,8 @@ public void testGlobStatusSomeMatchesInDirectories() throws Exception {
//Should return two items ("/test/hadoop" and "/test/hadoop2") //Should return two items ("/test/hadoop" and "/test/hadoop2")
FileStatus[] paths = fc.util().globStatus(getTestRootPath("test/hadoop*")); FileStatus[] paths = fc.util().globStatus(getTestRootPath("test/hadoop*"));
Assert.assertEquals(2, paths.length); Assert.assertEquals(2, paths.length);
Assert.assertEquals(getTestRootPath("test/hadoop"), paths[0].getPath()); Assert.assertTrue(containsPath(getTestRootPath("test/hadoop"), paths));
Assert.assertEquals(getTestRootPath("test/hadoop2"), paths[1].getPath()); Assert.assertTrue(containsPath(getTestRootPath("test/hadoop2"), paths));
} }
@Test @Test
@ -416,10 +381,10 @@ public void testGlobStatusWithMultipleWildCardMatches() throws Exception {
//"/test/hadoop/axx", and "/test/hadoop2/axx") //"/test/hadoop/axx", and "/test/hadoop2/axx")
FileStatus[] paths = fc.util().globStatus(getTestRootPath("test/hadoop*/*")); FileStatus[] paths = fc.util().globStatus(getTestRootPath("test/hadoop*/*"));
Assert.assertEquals(4, paths.length); Assert.assertEquals(4, paths.length);
Assert.assertEquals(getTestRootPath(TEST_DIR_AAA), paths[0].getPath()); Assert.assertTrue(containsPath(getTestRootPath(TEST_DIR_AAA), paths));
Assert.assertEquals(getTestRootPath(TEST_DIR_AXA), paths[1].getPath()); Assert.assertTrue(containsPath(getTestRootPath(TEST_DIR_AXA), paths));
Assert.assertEquals(getTestRootPath(TEST_DIR_AXX), paths[2].getPath()); Assert.assertTrue(containsPath(getTestRootPath(TEST_DIR_AXX), paths));
Assert.assertEquals(getTestRootPath(TEST_DIR_AAA2), paths[3].getPath()); Assert.assertTrue(containsPath(getTestRootPath(TEST_DIR_AAA2), paths));
} }
@Test @Test
@ -438,8 +403,8 @@ public void testGlobStatusWithMultipleMatchesOfSingleChar() throws Exception {
//Should return only 2 items ("/test/hadoop/axa", "/test/hadoop/axx") //Should return only 2 items ("/test/hadoop/axa", "/test/hadoop/axx")
FileStatus[] paths = fc.util().globStatus(getTestRootPath("test/hadoop/ax?")); FileStatus[] paths = fc.util().globStatus(getTestRootPath("test/hadoop/ax?"));
Assert.assertEquals(2, paths.length); Assert.assertEquals(2, paths.length);
Assert.assertEquals(getTestRootPath(TEST_DIR_AXA), paths[0].getPath()); Assert.assertTrue(containsPath(getTestRootPath(TEST_DIR_AXA), paths));
Assert.assertEquals(getTestRootPath(TEST_DIR_AXX), paths[1].getPath()); Assert.assertTrue(containsPath(getTestRootPath(TEST_DIR_AXX), paths));
} }
@Test @Test
@ -478,12 +443,9 @@ public void testGlobStatusFilterWithSomePathMatchesAndTrivialFilter() throws Exc
FileStatus[] filteredPaths = fc.util().globStatus(getTestRootPath("test/hadoop/*"), FileStatus[] filteredPaths = fc.util().globStatus(getTestRootPath("test/hadoop/*"),
DEFAULT_FILTER); DEFAULT_FILTER);
Assert.assertEquals(3,filteredPaths.length); Assert.assertEquals(3,filteredPaths.length);
Assert.assertEquals(getTestRootPath(TEST_DIR_AAA), Assert.assertTrue(containsPath(getTestRootPath(TEST_DIR_AAA), filteredPaths));
filteredPaths[0].getPath()); Assert.assertTrue(containsPath(getTestRootPath(TEST_DIR_AXA), filteredPaths));
Assert.assertEquals(getTestRootPath(TEST_DIR_AXA), Assert.assertTrue(containsPath(getTestRootPath(TEST_DIR_AXX), filteredPaths));
filteredPaths[1].getPath());
Assert.assertEquals(getTestRootPath(TEST_DIR_AXX),
filteredPaths[2].getPath());
} }
@Test @Test
@ -503,8 +465,9 @@ public void testGlobStatusFilterWithMultipleWildCardMatchesAndTrivialFilter() th
FileStatus[] filteredPaths = fc.util().globStatus(getTestRootPath("test/hadoop/a??"), FileStatus[] filteredPaths = fc.util().globStatus(getTestRootPath("test/hadoop/a??"),
DEFAULT_FILTER); DEFAULT_FILTER);
Assert.assertEquals(3,filteredPaths.length); Assert.assertEquals(3,filteredPaths.length);
Assert.assertEquals(getTestRootPath(TEST_DIR_AAA), filteredPaths[0].getPath()); Assert.assertTrue(containsPath(getTestRootPath(TEST_DIR_AAA), filteredPaths));
Assert.assertEquals(getTestRootPath(TEST_DIR_AXA), filteredPaths[1].getPath()); Assert.assertTrue(containsPath(getTestRootPath(TEST_DIR_AXA), filteredPaths));
Assert.assertTrue(containsPath(getTestRootPath(TEST_DIR_AXX), filteredPaths));
} }
@Test @Test
@ -524,10 +487,8 @@ public void testGlobStatusFilterWithMultiplePathMatchesAndNonTrivialFilter() thr
FileStatus[] filteredPaths = fc.util().globStatus(getTestRootPath("test/hadoop/*"), FileStatus[] filteredPaths = fc.util().globStatus(getTestRootPath("test/hadoop/*"),
TEST_X_FILTER); TEST_X_FILTER);
Assert.assertEquals(2,filteredPaths.length); Assert.assertEquals(2,filteredPaths.length);
Assert.assertEquals(getTestRootPath(TEST_DIR_AXA), Assert.assertTrue(containsPath(getTestRootPath(TEST_DIR_AXA), filteredPaths));
filteredPaths[0].getPath()); Assert.assertTrue(containsPath(getTestRootPath(TEST_DIR_AXX), filteredPaths));
Assert.assertEquals(getTestRootPath(TEST_DIR_AXX),
filteredPaths[1].getPath());
} }
@Test @Test
@ -566,8 +527,8 @@ public void testGlobStatusFilterWithMultiplePathWildcardsAndNonTrivialFilter() t
FileStatus[] filteredPaths = fc.util().globStatus(getTestRootPath("test/hadoop/a??"), FileStatus[] filteredPaths = fc.util().globStatus(getTestRootPath("test/hadoop/a??"),
TEST_X_FILTER); TEST_X_FILTER);
Assert.assertEquals(2,filteredPaths.length); Assert.assertEquals(2,filteredPaths.length);
Assert.assertEquals(getTestRootPath(TEST_DIR_AXA), filteredPaths[0].getPath()); Assert.assertTrue(containsPath(getTestRootPath(TEST_DIR_AXA), filteredPaths));
Assert.assertEquals(getTestRootPath(TEST_DIR_AXX), filteredPaths[1].getPath()); Assert.assertTrue(containsPath(getTestRootPath(TEST_DIR_AXX), filteredPaths));
} }
@Test @Test
@ -969,4 +930,11 @@ private void rename(Path src, Path dst, boolean renameShouldSucceed,
Assert.assertEquals("Source exists", srcExists, fc.exists(src)); Assert.assertEquals("Source exists", srcExists, fc.exists(src));
Assert.assertEquals("Destination exists", dstExists, fc.exists(dst)); Assert.assertEquals("Destination exists", dstExists, fc.exists(dst));
} }
private boolean containsPath(Path path, FileStatus[] filteredPaths) {
for(int i = 0; i < filteredPaths.length; i ++) {
if(getTestRootPath(path.toString()).equals(filteredPaths[i].getPath()))
return true;
}
return false;
}
} }