public void testDeadDatanodesSameFS() throws Exception {
DFSTestUtil util = new DFSTestUtil("testDeadDatanodesSameFS", 1, 1, MAX_FILE_SIZE);
String topDir = "/testDeadDatanodesSameFS";
FileSystem fs = fileSystems[0];
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(0).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 {
DistributedFileSystem dfs = (DistributedFileSystem) fs;
for (String fileName : util.getFileNames(topDir)) {
fastCopy.copy(fileName, fileName + "dst", dfs, dfs);
assertTrue(fs.exists(new Path(fileName + "dst")));
// assert the hard links.
String[] hardlinks = dfs.getHardLinkedFiles(new Path(fileName));
for (String hardLink : hardlinks) {
assertEquals(hardLink, fileName + "dst");
}
}
} catch (ExecutionException e) {
System.out.println("Expected exception : " + e);
assertEquals(IOException.class, e.getCause().getClass());
return;
} finally {
fastCopy.shutdown();
}
}