### Question:
UnderReplicatedBlocks implements Iterable<Block> { synchronized BlockIterator iterator(int level) { return new BlockIterator(level); } UnderReplicatedBlocks(); synchronized List<List<Block>> chooseUnderReplicatedBlocks(
      int blocksToProcess); @Override synchronized BlockIterator iterator();  }### Answer:
@Test(timeout=60000) public void testSetrepIncWithUnderReplicatedBlocks() throws Exception { Configuration conf = new HdfsConfiguration(); final short REPLICATION_FACTOR = 2; final String FILE_NAME = "/testFile"; final Path FILE_PATH = new Path(FILE_NAME); MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(REPLICATION_FACTOR + 1).build(); try { final FileSystem fs = cluster.getFileSystem(); DFSTestUtil.createFile(fs, FILE_PATH, 1L, REPLICATION_FACTOR, 1L); DFSTestUtil.waitReplication(fs, FILE_PATH, REPLICATION_FACTOR); final BlockManager bm = cluster.getNamesystem().getBlockManager(); ExtendedBlock b = DFSTestUtil.getFirstBlock(fs, FILE_PATH); DatanodeDescriptor dn = bm.blocksMap.getStorages(b.getLocalBlock()) .iterator().next().getDatanodeDescriptor(); bm.addToInvalidates(b.getLocalBlock(), dn); BlockManagerTestUtil.computeAllPendingWork(bm); DataNodeTestUtils.triggerHeartbeat(cluster.getDataNode(dn.getIpcPort())); Thread.sleep(5000); bm.blocksMap.removeNode(b.getLocalBlock(), dn); FsShell shell = new FsShell(conf); assertEquals(0, shell.run(new String[]{ "-setrep", "-w", Integer.toString(1+REPLICATION_FACTOR), FILE_NAME})); } finally { cluster.shutdown(); } }