DatanodeManager { public void sortLocatedBlocks(final String targethost, final List<LocatedBlock> locatedblocks) { Node client = getDatanodeByHost(targethost); if (client == null) { List<String> hosts = new ArrayList<> (1); hosts.add(targethost); List<String> resolvedHosts = dnsToSwitchMapping.resolve(hosts); if (resolvedHosts != null && !resolvedHosts.isEmpty()) { String rName = resolvedHosts.get(0); if (rName != null) { client = new NodeBase(rName + NodeBase.PATH_SEPARATOR_STR + targethost); } } else { LOG.error("Node Resolution failed. Please make sure that rack " + "awareness scripts are functional."); } } Comparator<DatanodeInfo> comparator = avoidStaleDataNodesForRead ? new DFSUtil.DecomStaleComparator(staleInterval) : DFSUtil.DECOM_COMPARATOR; for (LocatedBlock b : locatedblocks) { DatanodeInfo[] di = b.getLocations(); Arrays.sort(di, comparator); int lastActiveIndex = di.length - 1; while (lastActiveIndex > 0 && isInactive(di[lastActiveIndex])) { --lastActiveIndex; } int activeLen = lastActiveIndex + 1; networktopology.sortByDistance(client, b.getLocations(), activeLen); b.updateCachedStorageInfo(); } } DatanodeManager(final BlockManager blockManager, final Namesystem namesystem,
      final Configuration conf); NetworkTopology getNetworkTopology(); @VisibleForTesting DecommissionManager getDecomManager(); @VisibleForTesting void setHeartbeatExpireInterval(long expiryMs); @VisibleForTesting FSClusterStats getFSClusterStats(); DatanodeStatistics getDatanodeStatistics(); void sortLocatedBlocks(final String targethost,
      final List<LocatedBlock> locatedblocks); DatanodeDescriptor getDatanodeByHost(final String host); DatanodeDescriptor getDatanodeByXferAddr(String host, int xferPort); Host2NodesMap getHost2DatanodeMap(); 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(); List<DatanodeDescriptor> getDecommissioningNodes(); boolean shouldAvoidStaleDataNodesForWrite(); long getBlocksPerPostponedMisreplicatedBlocksRescan(); 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); void setBalancerBandwidth(long bandwidth); void markAllDatanodesStale(); void clearPendingQueues(); void resetLastCachingDirectiveSentTime(); @Override String toString(); void clearPendingCachingCommands(); void setShouldSendCachingCommands(boolean shouldSendCachingCommands);  }
@Test public void testSortLocatedBlocks() throws IOException, URISyntaxException { HelperFunction(null); }