// create two files with one block each
DFSTestUtil util = new DFSTestUtil("testMaxCorruptFiles", 4, 1, 512);
util.createFiles(fs, "/srcdat2");
// verify that there are no bad blocks.
ClientProtocol namenode = DFSClient.createNamenode(conf);
FileStatus[] badFiles = namenode.getCorruptFiles();
assertTrue("Namenode has " + badFiles.length + " corrupt files. Expecting none.",
badFiles.length == 0);
// Now deliberately remove one block
File data_dir = new File(System.getProperty("test.build.data"),
"dfs/data/data1/current/finalized");
assertTrue("data directory does not exist", data_dir.exists());
File[] blocks = data_dir.listFiles();
assertTrue("Blocks do not exist in data-dir", (blocks != null) && (blocks.length > 0));
for (int idx = 0; idx < blocks.length; idx++) {
if (!blocks[idx].getName().startsWith("blk_")) {
continue;
}
LOG.info("Deliberately removing file "+blocks[idx].getName());
assertTrue("Cannot remove file.", blocks[idx].delete());
}
badFiles = namenode.getCorruptFiles();
while (badFiles.length < 2) {
badFiles = namenode.getCorruptFiles();
Thread.sleep(10000);
}
badFiles = namenode.getCorruptFiles(); // once more since time has passed
LOG.info("Namenode has bad files. " + badFiles.length);
assertTrue("Namenode has " + badFiles.length + " bad files. Expecting 2.",
badFiles.length == 2);
util.cleanup(fs, "/srcdat2");
} finally {