Host2NodesMap { DatanodeDescriptor getDatanodeByHost(String ipAddr) { if (ipAddr == null) { return null; } hostmapLock.readLock().lock(); try { DatanodeDescriptor[] nodes = map.get(ipAddr); if (nodes == null) { return null; } if (nodes.length == 1) { return nodes[0]; } return nodes[DFSUtil.getRandom().nextInt(nodes.length)]; } finally { hostmapLock.readLock().unlock(); } }  DatanodeDescriptor getDatanodeByXferAddr(String ipAddr, int xferPort); @Override String toString();  }
@Test public void testGetDatanodeByHost() throws Exception { assertEquals(map.getDatanodeByHost("1.1.1.1"), dataNodes[0]); assertEquals(map.getDatanodeByHost("2.2.2.2"), dataNodes[1]); DatanodeDescriptor node = map.getDatanodeByHost("3.3.3.3"); assertTrue(node == dataNodes[2] || node == dataNodes[3]); assertNull(map.getDatanodeByHost("4.4.4.4")); }