assertEquals(1, locations.locatedBlockCount());
LocatedBlock locatedblock = locations.getLocatedBlocks().get(0);
int nsId = cluster.getNameNode().getNamespaceID();
for(DatanodeInfo datanodeinfo: locatedblock.getLocations()) {
DataNode datanode = cluster.getDataNode(datanodeinfo.ipcPort);
FSDataset dataset = (FSDataset)datanode.data;
Block b = dataset.getStoredBlock(nsId, locatedblock.getBlock().getBlockId());
Block newBlock = new Block(b);
newBlock.setGenerationStamp(6661);
dataset.updateBlock(nsId, b, newBlock);
Block newBlock1 = new Block(b);
newBlock1.setGenerationStamp(6662);
boolean hitException = false;
try {
dataset.updateBlock(nsId, b, newBlock1);
} catch (IOException e) {
hitException = true;
}
TestCase.assertTrue("Shouldn't allow update block when generation doesn't match", hitException);
dataset.updateBlock(nsId, newBlock, newBlock1);
}
} finally {
IOUtils.closeStream(dfs);
cluster.shutdown();
}