/** Convert an Object[] to a DatanodeInfo[]. */ private static DatanodeInfo[] toDatanodeInfoArray(final List<?> objects) throws IOException { if (objects == null) { return null; } else if (objects.isEmpty()) { return EMPTY_DATANODE_INFO_ARRAY; } else { final DatanodeInfo[] array = new DatanodeInfo[objects.size()]; int i = 0; for (Object object : objects) { array[i++] = toDatanodeInfo((Map<?, ?>) object); } return array; } }
/** Convert an Object[] to a DatanodeInfo[]. */ private static DatanodeInfo[] toDatanodeInfoArray(final List<?> objects) throws IOException { if (objects == null) { return null; } else if (objects.isEmpty()) { return EMPTY_DATANODE_INFO_ARRAY; } else { final DatanodeInfo[] array = new DatanodeInfo[objects.size()]; int i = 0; for (Object object : objects) { array[i++] = toDatanodeInfo((Map<?, ?>) object); } return array; } }
private void checkDecodeFailure(Map<String, Object> map) { try { JsonUtil.toDatanodeInfo(map); Assert.fail("Exception not thrown against bad input."); } catch (Exception e) { // expected } } }
@Test public void testToDatanodeInfoWithoutSecurePort() throws Exception { Map<String, Object> response = new HashMap<String, Object>(); response.put("ipAddr", "127.0.0.1"); response.put("hostName", "localhost"); response.put("storageID", "fake-id"); response.put("xferPort", 1337l); response.put("infoPort", 1338l); // deliberately don't include an entry for "infoSecurePort" response.put("ipcPort", 1339l); response.put("capacity", 1024l); response.put("dfsUsed", 512l); response.put("remaining", 512l); response.put("blockPoolUsed", 512l); response.put("lastUpdate", 0l); response.put("xceiverCount", 4096l); response.put("networkLocation", "foo.bar.baz"); response.put("adminState", "NORMAL"); response.put("cacheCapacity", 123l); response.put("cacheUsed", 321l); JsonUtil.toDatanodeInfo(response); }
response.put("cacheUsed", 321l); DatanodeInfo di = JsonUtil.toDatanodeInfo(response); Assert.assertEquals(name, di.getXferAddr());