@Test(timeout = 2 * 60 * 1000)
public void testDeadDatanodes() throws Exception {
DFSTestUtil util = new DFSTestUtil("testDeadDatanodes", 1, 1, MAX_FILE_SIZE);
String topDir = "/testDeadDatanodes";
util.createFiles(fs, topDir);
FastCopy fastCopy = new FastCopy(conf);
// Find the locations for the last block of the file.
String filename = util.getFileNames(topDir)[0];
LocatedBlocks lbks = cluster.getNameNode().getBlockLocations(filename, 0,
Long.MAX_VALUE);
assertNotNull(lbks);
LocatedBlock lastBlock = lbks.get(lbks.locatedBlockCount() - 1);
// Shutdown all datanodes that have the last block of the file.
for (DatanodeInfo dnInfo : lastBlock.getLocations()) {
InetSocketAddress addr = new InetSocketAddress(dnInfo.getHost(),
dnInfo.getPort());
for (int i = 0; i < cluster.getDataNodes().size(); i++) {
DataNode dn = cluster.getDataNodes().get(i);
if (dn.getSelfAddr().equals(addr)) {
cluster.shutdownDataNode(i, true);
}
}
}
// Now run FastCopy
try {
for (String fileName : util.getFileNames(topDir)) {
fastCopy.copy(fileName, fileName + "dst", (DistributedFileSystem) fs,
(DistributedFileSystem) fs);
}
} catch (ExecutionException e) {
System.out.println("Expected exception : " + e);
assertEquals(IOException.class, e.getCause().getClass());
return;
} finally {
fastCopy.shutdown();
}
fail("No exception thrown");
}