DatanodeManager { public NetworkTopology getNetworkTopology() { return networktopology; } DatanodeManager(final BlockManager blockManager, final Namesystem namesystem,
      final Configuration conf); NetworkTopology getNetworkTopology(); @VisibleForTesting DatanodeAdminManager getDatanodeAdminManager(); HostConfigManager getHostConfigManager(); @VisibleForTesting void setHeartbeatExpireInterval(long expiryMs); @VisibleForTesting FSClusterStats getFSClusterStats(); @VisibleForTesting int getBlockInvalidateLimit(); DatanodeStatistics getDatanodeStatistics(); void sortLocatedBlocks(final String targetHost,
      final List<LocatedBlock> locatedBlocks); DatanodeDescriptor getDatanodeByHost(final String host); DatanodeDescriptor getDatanodeByXferAddr(String host, int xferPort); Set<DatanodeDescriptor> getDatanodes(); Host2NodesMap getHost2DatanodeMap(); DatanodeDescriptor getDatanode(final String datanodeUuid); DatanodeDescriptor getDatanode(DatanodeID nodeID); DatanodeStorageInfo[] getDatanodeStorageInfos(
      DatanodeID[] datanodeID, String[] storageIDs,
      String format, Object... args); void removeDatanode(final DatanodeID node); HashMap<String, Integer> getDatanodesSoftwareVersions(); List<String> resolveNetworkLocation(List<String> names); void registerDatanode(DatanodeRegistration nodeReg); void refreshNodes(final Configuration conf); int getNumLiveDataNodes(); int getNumDeadDataNodes(); int getNumOfDataNodes(); List<DatanodeDescriptor> getDecommissioningNodes(); List<DatanodeDescriptor> getEnteringMaintenanceNodes(); boolean shouldAvoidStaleDataNodesForWrite(); long getBlocksPerPostponedMisreplicatedBlocksRescan(); long getHeartbeatInterval(); long getHeartbeatRecheckInterval(); int getNumStaleNodes(); int getNumStaleStorages(); void fetchDatanodes(final List<DatanodeDescriptor> live, 
      final List<DatanodeDescriptor> dead, final boolean removeDecommissionNode); List<DatanodeDescriptor> getDatanodeListForReport(
      final DatanodeReportType type); DatanodeCommand[] handleHeartbeat(DatanodeRegistration nodeReg,
      StorageReport[] reports, final String blockPoolId,
      long cacheCapacity, long cacheUsed, int xceiverCount, 
      int maxTransfers, int failedVolumes,
      VolumeFailureSummary volumeFailureSummary,
      @Nonnull SlowPeerReports slowPeers,
      @Nonnull SlowDiskReports slowDisks); void handleLifeline(DatanodeRegistration nodeReg,
      StorageReport[] reports, String blockPoolId, long cacheCapacity,
      long cacheUsed, int xceiverCount, int maxTransfers, int failedVolumes,
      VolumeFailureSummary volumeFailureSummary); void setBalancerBandwidth(long bandwidth); void markAllDatanodesStale(); void clearPendingQueues(); void resetLastCachingDirectiveSentTime(); @Override String toString(); void clearPendingCachingCommands(); void setShouldSendCachingCommands(boolean shouldSendCachingCommands); void setHeartbeatInterval(long intervalSeconds); void setHeartbeatRecheckInterval(int recheckInterval); String getSlowPeersReport(); @VisibleForTesting SlowDiskTracker getSlowDiskTracker(); String getSlowDisksReport(); DatanodeStorageReport[] getDatanodeStorageReport(
      DatanodeReportType type);  }
@Test public void testNetworkTopologyInstantiation() throws Exception { Configuration conf1 = new HdfsConfiguration(); FSNamesystem fsn = Mockito.mock(FSNamesystem.class); DatanodeManager dm1 = mockDatanodeManager(fsn, conf1); assertEquals(DFSNetworkTopology.class, dm1.getNetworkTopology().getClass()); Configuration conf2 = new HdfsConfiguration(); conf2.setBoolean(DFSConfigKeys.DFS_USE_DFS_NETWORK_TOPOLOGY_KEY, false); DatanodeManager dm2 = mockDatanodeManager(fsn, conf2); assertEquals(NetworkTopology.class, dm2.getNetworkTopology() .getClass()); Configuration conf3 = new HdfsConfiguration(); conf3.setClass(CommonConfigurationKeysPublic.NET_TOPOLOGY_IMPL_KEY, MockDfsNetworkTopology.class, NetworkTopology.class); conf3.setBoolean(DFSConfigKeys.DFS_USE_DFS_NETWORK_TOPOLOGY_KEY, false); DatanodeManager dm3 = mockDatanodeManager(fsn, conf3); assertEquals(MockDfsNetworkTopology.class, dm3.getNetworkTopology() .getClass()); Configuration conf4 = new HdfsConfiguration(); conf4.setClass(DFSConfigKeys.DFS_NET_TOPOLOGY_IMPL_KEY, MockDfsNetworkTopology.class, NetworkTopology.class); conf4.setBoolean(DFSConfigKeys.DFS_USE_DFS_NETWORK_TOPOLOGY_KEY, true); DatanodeManager dm4 = mockDatanodeManager(fsn, conf4); assertEquals(MockDfsNetworkTopology.class, dm4.getNetworkTopology() .getClass()); }