HADOOP-6188. TestTrash uses java.io.File api but not hadoop FileSystem api. Contributed by Boris Shkolnik

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@803296 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Tsz-wo Sze 2009-08-11 21:03:50 +00:00
parent d70dd1a2df
commit 38a84a6c98
2 changed files with 25 additions and 14 deletions

View File

@ -914,6 +914,9 @@ Trunk (unreleased changes)
HADOOP-6177. FSInputChecker.getPos() would return position greater
than the file size. (Hong Tang via hairong)
HADOOP-6188. TestTrash uses java.io.File api but not hadoop FileSystem api.
(Boris Shkolnik via szetszwo)
Release 0.20.1 - Unreleased
INCOMPATIBLE CHANGES

View File

@ -61,18 +61,22 @@ public class TestTrash extends TestCase {
// counts how many instances of the file are in the Trash
// they all are in format fileName*
protected static int countSameDeletedFiles(FileSystem fs, final File trashDir,
final String fileName) throws IOException {
System.out.println("Counting " + fileName + " in " + trashDir.getAbsolutePath());
String [] res = trashDir.list(
new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.startsWith(fileName);
}
}
);
protected static int countSameDeletedFiles(FileSystem fs,
Path trashDir, Path fileName) throws IOException {
return res.length;
final String prefix = fileName.getName();
System.out.println("Counting " + fileName + " in " + trashDir.toString());
// filter that matches all the files that start with fileName*
PathFilter pf = new PathFilter() {
public boolean accept(Path file) {
return file.getName().startsWith(prefix);
}
};
// run the filter
FileStatus [] fss = fs.listStatus(trashDir, pf);
return fss==null? 0 : fss.length;
}
// check that the specified file is not in Trash
@ -358,10 +362,14 @@ public class TestTrash extends TestCase {
assertTrue(val==0);
}
// current trash directory
File trashCurrent = new File(trashRoot.toUri().getPath() + myFile.getParent().toUri().getPath());
Path trashDir = new Path(trashRoot.toUri().getPath() + myFile.getParent().toUri().getPath());
int count = countSameDeletedFiles(fs, trashCurrent, myFile.getName());
System.out.println("counted " + count + " files " + myFile.getName() + "* in " + trashCurrent);
System.out.println("Deleting same myFile: myFile.parent=" + myFile.getParent().toUri().getPath() +
"; trashroot="+trashRoot.toUri().getPath() +
"; trashDir=" + trashDir.toUri().getPath());
int count = countSameDeletedFiles(fs, trashDir, myFile);
System.out.println("counted " + count + " files " + myFile.getName() + "* in " + trashDir);
assertTrue(count==num_runs);
}