HostFileManager extends HostConfigManager { @Override public void refresh() throws IOException { refresh(conf.get(DFSConfigKeys.DFS_HOSTS, ""), conf.get(DFSConfigKeys.DFS_HOSTS_EXCLUDE, "")); }  @Override void setConf(Configuration conf); @Override Configuration getConf(); @Override void refresh(); @Override synchronized HostSet getIncludes(); @Override synchronized HostSet getExcludes(); @Override synchronized boolean isIncluded(DatanodeID dn); @Override synchronized boolean isExcluded(DatanodeID dn); @Override synchronized String getUpgradeDomain(final DatanodeID dn); @Override long getMaintenanceExpirationTimeInMS(DatanodeID dn);  }
@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(); HostSet includedNodes = new HostSet(); HostSet excludedNodes = new 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, "hostConfigManager", hm); Map<String, DatanodeDescriptor> dnMap = (Map<String, DatanodeDescriptor>) Whitebox.getInternalState(dm, "datanodeMap"); 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(1, dm.getDatanodeListForReport(HdfsConstants .DatanodeReportType.DEAD).size()); }