try {
Path path = new Path("/dir/file");
DFSTestUtil.createFile(fs, path, 1, (short)1, 0L);
DFSTestUtil.waitReplication(fs, path, (short)1);
FileStatus status = fs.getFileStatus(path);
LocatedBlocksWithMetaInfo blocks = namenode.openAndFetchMetaInfo(
path.toString(), 0, status.getLen());
Assert.assertEquals(1, blocks.getLocatedBlocks().size());
LocatedBlock block = blocks.getLocatedBlocks().get(0);
Assert.assertEquals(1, block.getLocations().length);
DatanodeInfo source = block.getLocations()[0];
Set<DatanodeInfo> excluded = new HashSet<DatanodeInfo>();
for (DatanodeInfo d : datanodes) {
excluded.add(d);
}
excluded.remove(source);
DatanodeInfo target = excluded.iterator().next();
excluded.add(source);
excluded.remove(target);
BlockMover.BlockMoveAction action =
blockMover.new BlockMoveAction(block, source, excluded, 1,
blocks.getDataProtocolVersion(), blocks.getNamespaceID());
LOG.info("Start moving block from " + source + " to " + target);
action.run();
LOG.info("Done moving block");
boolean blockMoved = false;
long startTime = System.currentTimeMillis();
while (!blockMoved && System.currentTimeMillis() - startTime < 60000) {
blocks = namenode.openAndFetchMetaInfo(
path.toString(), 0, status.getLen());
block = blocks.getLocatedBlocks().get(0);
if (block.getLocations().length == 1 &&
block.getLocations()[0].equals((target))) {
blockMoved = true;
break;
}