public void setInitializedReplQueues(boolean v) {
    this.initializedReplQueues = v;
  }
@Test
  public void testBlockReportAfterDataNodeRestart() throws Exception {
    Configuration conf = new HdfsConfiguration();
    try (MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf)
           .numDataNodes(3).storagesPerDatanode(1).build()) {
      cluster.waitActive();
      BlockManager blockManager = cluster.getNamesystem().getBlockManager();
      DistributedFileSystem fs = cluster.getFileSystem();
      final Path filePath = new Path("/tmp.txt");
      final long fileLen = 1L;
      DFSTestUtil.createFile(fs, filePath, fileLen, (short) 3, 1L);
      DFSTestUtil.waitForReplication(fs, filePath, (short) 3, 60000);
      ArrayList<DataNode> datanodes = cluster.getDataNodes();
      assertEquals(datanodes.size(), 3);

      // Stop RedundancyMonitor.
      blockManager.setInitializedReplQueues(false);

      // Delete the replica on the first datanode.
      DataNode dn = datanodes.get(0);
      int dnIpcPort = dn.getIpcPort();
      File dnDir = dn.getFSDataset().getVolumeList().get(0).getCurrentDir();
      String[] children = FileUtil.list(dnDir);
      for (String s : children) {
        if (!s.equals("VERSION")) {
          FileUtil.fullyDeleteContents(new File(dnDir, s));
        }
      }

      // The number of replicas is still 3 because the datanode has not sent
      // a new block report.
      FileStatus stat = fs.getFileStatus(filePath);
      BlockLocation[] locs = fs.getFileBlockLocations(stat, 0, stat.getLen());
      assertEquals(3, locs[0].getHosts().length);

      // Restart the first datanode.
      cluster.restartDataNode(0, true);

      // Wait for the block report to be processed.
      cluster.waitDatanodeFullyStarted(cluster.getDataNode(dnIpcPort), 10000);
      cluster.waitFirstBRCompleted(0, 10000);

      // The replica num should be 2.
      locs = fs.getFileBlockLocations(stat, 0, stat.getLen());
      assertEquals(2, locs[0].getHosts().length);
    }
  }