@Test
@SuppressWarnings("unchecked")
public void testIncludeExcludeLists() throws IOException {

  BlockManager bm = mock(BlockManager.class);
  FSNamesystem fsn = mock(FSNamesystem.class);
  Configuration conf = new Configuration();
  HostFileManager hm = new HostFileManager();
  HostFileManager.HostSet includedNodes = new HostFileManager.HostSet();
  HostFileManager.HostSet excludedNodes = new HostFileManager.HostSet();
  includedNodes.add(entry("127.0.0.1:12345"));
  includedNodes.add(entry("localhost:12345"));
  includedNodes.add(entry("127.0.0.1:12345"));
  includedNodes.add(entry("127.0.0.2"));
  excludedNodes.add(entry("127.0.0.1:12346"));
  excludedNodes.add(entry("127.0.30.1:12346"));
  Assert.assertEquals(2, includedNodes.size());
  Assert.assertEquals(2, excludedNodes.size());
  hm.refresh(includedNodes, excludedNodes);
  DatanodeManager dm = new DatanodeManager(bm, fsn, conf);
  Whitebox.setInternalState(dm, "hostFileManager", hm);
  Map<String, DatanodeDescriptor> dnMap = (Map<String,
          DatanodeDescriptor>) Whitebox.getInternalState(dm, "datanodeMap");
  // After the de-duplication, there should be only one DN from the included
  // nodes declared as dead.
  Assert.assertEquals(2, dm.getDatanodeListForReport(HdfsConstants
          .DatanodeReportType.ALL).size());
  Assert.assertEquals(2, dm.getDatanodeListForReport(HdfsConstants
          .DatanodeReportType.DEAD).size());
  dnMap.put("uuid-foo", new DatanodeDescriptor(new DatanodeID("127.0.0.1",
          "localhost", "uuid-foo", 12345, 1020, 1021, 1022)));
  Assert.assertEquals(1, dm.getDatanodeListForReport(HdfsConstants
          .DatanodeReportType.DEAD).size());
  dnMap.put("uuid-bar", new DatanodeDescriptor(new DatanodeID("127.0.0.2",
          "127.0.0.2", "uuid-bar", 12345, 1020, 1021, 1022)));
  Assert.assertEquals(0, dm.getDatanodeListForReport(HdfsConstants
          .DatanodeReportType.DEAD).size());
  DatanodeDescriptor spam = new DatanodeDescriptor(new DatanodeID("127.0.0" +
          ".3", "127.0.0.3", "uuid-spam", 12345, 1020, 1021, 1022));
  DFSTestUtil.setDatanodeDead(spam);
  includedNodes.add(entry("127.0.0.3:12345"));
  dnMap.put("uuid-spam", spam);
  Assert.assertEquals(1, dm.getDatanodeListForReport(HdfsConstants
          .DatanodeReportType.DEAD).size());
  dnMap.remove("uuid-spam");
  Assert.assertEquals(1, dm.getDatanodeListForReport(HdfsConstants
          .DatanodeReportType.DEAD).size());
  excludedNodes.add(entry("127.0.0.3"));
  Assert.assertEquals(0, dm.getDatanodeListForReport(HdfsConstants
          .DatanodeReportType.DEAD).size());
}