datanodes[i] = cluster.getDataNode(datanodeinfos[i].getIpcPort());
assertTrue(datanodes[i] != null);
}
//verify BlockMetaDataInfo
Block lastblock = locatedblock.getBlock();
DataNode.LOG.info("newblocks=" + lastblock);
for(int i = 0; i < REPLICATION_NUM; i++) {
checkMetaInfo(lastblock, idps[i]);
}
//setup random block sizes
int lastblocksize = ORG_FILE_SIZE % BLOCK_SIZE;
Integer[] newblocksizes = new Integer[REPLICATION_NUM];
for(int i = 0; i < REPLICATION_NUM; i++) {
newblocksizes[i] = AppendTestUtil.nextInt(lastblocksize);
}
if (forceOneBlockToZero) {
newblocksizes[0] = 0;
}
DataNode.LOG.info("newblocksizes = " + Arrays.asList(newblocksizes));
//update blocks with random block sizes
Block[] newblocks = new Block[REPLICATION_NUM];
for(int i = 0; i < REPLICATION_NUM; i++) {
DataNode dn = datanodes[i];
FSDatasetTestUtil.truncateBlock(dn, lastblock, newblocksizes[i]);
newblocks[i] = new Block(lastblock.getBlockId(), newblocksizes[i],
lastblock.getGenerationStamp());
checkMetaInfo(newblocks[i], idps[i]);
}
DataNode.LOG.info("dfs.dfs.clientName=" + dfs.dfs.clientName);
cluster.getNameNode().append(filestr, dfs.dfs.clientName);
//block synchronization
final int primarydatanodeindex = AppendTestUtil.nextInt(datanodes.length);
DataNode.LOG.info("primarydatanodeindex =" + primarydatanodeindex);
DataNode primary = datanodes[primarydatanodeindex];
DataNode.LOG.info("primary.dnRegistration=" + primary.dnRegistration);
primary.recoverBlocks(new Block[]{lastblock}, new DatanodeInfo[][]{datanodeinfos}).join();
BlockMetaDataInfo[] updatedmetainfo = new BlockMetaDataInfo[REPLICATION_NUM];
int minsize = min(newblocksizes);
long currentGS = cluster.getNameNode().namesystem.getGenerationStamp();
lastblock.setGenerationStamp(currentGS);
for(int i = 0; i < REPLICATION_NUM; i++) {
updatedmetainfo[i] = idps[i].getBlockMetaDataInfo(lastblock);
assertEquals(lastblock.getBlockId(), updatedmetainfo[i].getBlockId());
assertEquals(minsize, updatedmetainfo[i].getNumBytes());
assertEquals(currentGS, updatedmetainfo[i].getGenerationStamp());
}
}
finally {