HDFS-8607. TestFileCorruption doesn't work as expected. (Contributed by Walter Su)

This commit is contained in:
Arpit Agarwal 2015-06-15 10:11:53 -07:00
parent d07f3804b0
commit ea9a9b3d7e
2 changed files with 14 additions and 8 deletions

View File

@ -552,6 +552,9 @@ Release 2.8.0 - UNRELEASED
HDFS-8593. Calculation of effective layout version mishandles comparison to HDFS-8593. Calculation of effective layout version mishandles comparison to
current layout version in storage. (cnauroth) current layout version in storage. (cnauroth)
HDFS-8607. TestFileCorruption doesn't work as expected. (Walter Su via
Arpit Agarwal)
Release 2.7.1 - UNRELEASED Release 2.7.1 - UNRELEASED
INCOMPATIBLE CHANGES INCOMPATIBLE CHANGES

View File

@ -27,8 +27,12 @@ import java.io.DataOutputStream;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.List; import java.util.List;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.DirectoryFileFilter;
import org.apache.commons.io.filefilter.PrefixFileFilter;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.ChecksumException; import org.apache.hadoop.fs.ChecksumException;
import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileSystem;
@ -74,14 +78,13 @@ public class TestFileCorruption {
String bpid = cluster.getNamesystem().getBlockPoolId(); String bpid = cluster.getNamesystem().getBlockPoolId();
File data_dir = MiniDFSCluster.getFinalizedDir(storageDir, bpid); File data_dir = MiniDFSCluster.getFinalizedDir(storageDir, bpid);
assertTrue("data directory does not exist", data_dir.exists()); assertTrue("data directory does not exist", data_dir.exists());
File[] blocks = data_dir.listFiles(); Collection<File> blocks = FileUtils.listFiles(data_dir,
assertTrue("Blocks do not exist in data-dir", (blocks != null) && (blocks.length > 0)); new PrefixFileFilter(Block.BLOCK_FILE_PREFIX),
for (int idx = 0; idx < blocks.length; idx++) { DirectoryFileFilter.DIRECTORY);
if (!blocks[idx].getName().startsWith(Block.BLOCK_FILE_PREFIX)) { assertTrue("Blocks do not exist in data-dir", blocks.size() > 0);
continue; for (File block : blocks) {
} System.out.println("Deliberately removing file " + block.getName());
System.out.println("Deliberately removing file "+blocks[idx].getName()); assertTrue("Cannot remove file.", block.delete());
assertTrue("Cannot remove file.", blocks[idx].delete());
} }
assertTrue("Corrupted replicas not handled properly.", assertTrue("Corrupted replicas not handled properly.",
util.checkFiles(fs, "/srcdat")); util.checkFiles(fs, "/srcdat"));