RouterWebServiceUtil { public static NodesInfo deleteDuplicateNodesInfo(ArrayList<NodeInfo> nodes) { NodesInfo nodesInfo = new NodesInfo(); Map<String, NodeInfo> nodesMap = new LinkedHashMap<>(); for (NodeInfo node : nodes) { String nodeId = node.getNodeId(); if (nodesMap.containsKey(nodeId)) { if (nodesMap.get(nodeId).getLastHealthUpdate() < node .getLastHealthUpdate()) { nodesMap.put(node.getNodeId(), node); } } else { nodesMap.put(node.getNodeId(), node); } } nodesInfo.addAll(new ArrayList<NodeInfo>(nodesMap.values())); return nodesInfo; } private  RouterWebServiceUtil(); static Response clientResponseToResponse(ClientResponse r); static void retrieveException(ClientResponse response); static AppsInfo mergeAppsInfo(ArrayList<AppInfo> appsInfo,
      boolean returnPartialResult); static NodesInfo deleteDuplicateNodesInfo(ArrayList<NodeInfo> nodes); static void mergeMetrics(ClusterMetricsInfo metrics,
      ClusterMetricsInfo metricsResponse);  }
@Test public void testDeleteDuplicate4DifferentNodes() { NodesInfo nodes = new NodesInfo(); NodeInfo nodeInfo1 = new NodeInfo(); nodeInfo1.setId(NODE1); nodes.add(nodeInfo1); NodeInfo nodeInfo2 = new NodeInfo(); nodeInfo2.setId(NODE2); nodes.add(nodeInfo2); NodeInfo nodeInfo3 = new NodeInfo(); nodeInfo3.setId(NODE3); nodes.add(nodeInfo3); NodeInfo nodeInfo4 = new NodeInfo(); nodeInfo4.setId(NODE4); nodes.add(nodeInfo4); NodesInfo result = RouterWebServiceUtil.deleteDuplicateNodesInfo(nodes.getNodes()); Assert.assertNotNull(result); Assert.assertEquals(4, result.getNodes().size()); List<String> nodesIds = new ArrayList<String>(); for (NodeInfo node : result.getNodes()) { nodesIds.add(node.getNodeId()); } Assert.assertTrue(nodesIds.contains(NODE1)); Assert.assertTrue(nodesIds.contains(NODE2)); Assert.assertTrue(nodesIds.contains(NODE3)); Assert.assertTrue(nodesIds.contains(NODE4)); }
@Test public void testDeleteDuplicateNodes() { NodesInfo nodes = new NodesInfo(); NodeInfo node1 = new NodeInfo(); node1.setId(NODE1); node1.setLastHealthUpdate(0); nodes.add(node1); NodeInfo node2 = new NodeInfo(); node2.setId(NODE1); node2.setLastHealthUpdate(1); nodes.add(node2); NodeInfo node3 = new NodeInfo(); node3.setId(NODE1); node3.setLastHealthUpdate(2); nodes.add(node3); NodesInfo result = RouterWebServiceUtil.deleteDuplicateNodesInfo(nodes.getNodes()); Assert.assertNotNull(result); Assert.assertEquals(1, result.getNodes().size()); NodeInfo node = result.getNodes().get(0); Assert.assertEquals(NODE1, node.getNodeId()); Assert.assertEquals(2, node.getLastHealthUpdate()); }