// get data node
DataNode datanode = cluster.getDataNode(nodes[0].getIpcPort());
assertTrue(datanode != null);
// verifies checksum file is of length 0
LocatedBlockWithMetaInfo locatedblock = TestInterDatanodeProtocol
.getLastLocatedBlock(dfs.dfs.namenode, filestr);
Block lastblock = locatedblock.getBlock();
DataNode.LOG.info("newblocks=" + lastblock);
BlockPathInfo blockPathInfo = datanode.getBlockPathInfo(lastblock);
String blockPath = blockPathInfo.getBlockPath();
String metaPath = blockPathInfo.getMetaPath();
File f = new File(blockPath);
File meta = new File(metaPath);
assertEquals(0, f.length());
// set the checksum file to 0
meta.delete();
DataOutputStream outs = new DataOutputStream(new FileOutputStream(
metaPath, false));
outs.close();
// issue recovery and makit e sure it succeeds.
int numTries = 500;
for (int idxTry = 0; idxTry < numTries; idxTry++) {
boolean success = dfs.recoverLease(filepath);
if (success) {
break;
} else if (idxTry == numTries - 1) {
TestCase.fail("Recovery lease failed");
} else {
Thread.sleep(10);
}
}
// make sure the meta file is still empty
locatedblock = TestInterDatanodeProtocol.getLastLocatedBlock(
dfs.dfs.namenode, filestr);
Block newBlock = locatedblock.getBlock();
blockPathInfo = datanode.getBlockPathInfo(newBlock);
assertEquals(0, blockPathInfo.getNumBytes());
metaPath = blockPathInfo.getMetaPath();
meta = new File(metaPath);
assertEquals(0, meta.length());