slfan1989 commented on code in PR #4610:
URL: https://github.com/apache/hadoop/pull/4610#discussion_r928007827


##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/clientrm/TestRouterYarnClientUtils.java:
##########
@@ -610,4 +617,100 @@ public void testMergeResourceProfile() {
     Assert.assertEquals(3, resource.getVirtualCores());
     Assert.assertEquals(3072, resource.getMemorySize());
   }
+
+  @Test
+  public void testMergeAttributesToNodesResponse() {
+    // normal response1
+    NodeAttribute gpu = 
NodeAttribute.newInstance(NodeAttribute.PREFIX_CENTRALIZED, "GPU",
+        NodeAttributeType.STRING, "nvidia");
+    Map<NodeAttributeKey, List<NodeToAttributeValue>> map1 = new HashMap<>();
+    List<NodeToAttributeValue> lists1 = new ArrayList<>();
+    NodeToAttributeValue attributeValue1 = 
NodeToAttributeValue.newInstance("node1", gpu.getAttributeValue());
+    lists1.add(attributeValue1);
+    map1.put(gpu.getAttributeKey(), lists1);
+    GetAttributesToNodesResponse response1 = 
GetAttributesToNodesResponse.newInstance(map1);
+
+    // normal response2
+    NodeAttribute docker = 
NodeAttribute.newInstance(NodeAttribute.PREFIX_DISTRIBUTED, "DOCKER",
+        NodeAttributeType.STRING, "docker0");
+    Map<NodeAttributeKey, List<NodeToAttributeValue>> map2 = new HashMap<>();
+    List<NodeToAttributeValue> lists2 = new ArrayList<>();
+    NodeToAttributeValue attributeValue2 = 
NodeToAttributeValue.newInstance("node2", docker.getAttributeValue());
+    lists2.add(attributeValue2);
+    map2.put(docker.getAttributeKey(), lists2);
+    GetAttributesToNodesResponse response2 = 
GetAttributesToNodesResponse.newInstance(map2);
+
+    // empty response3
+    GetAttributesToNodesResponse response3 = 
GetAttributesToNodesResponse.newInstance(new HashMap<>());
+
+    // null response4
+    GetAttributesToNodesResponse response4 = null;
+
+    List<GetAttributesToNodesResponse> responses = new ArrayList<>();
+    responses.add(response1);
+    responses.add(response2);
+    responses.add(response3);
+    responses.add(response4);
+
+    GetAttributesToNodesResponse response =
+        RouterYarnClientUtils.mergeAttributesToNodesResponse(responses);
+
+    Assert.assertNotNull(response);
+    Assert.assertEquals(2, response.getAttributesToNodes().size());
+
+    Map<NodeAttributeKey, List<NodeToAttributeValue>> attrs = 
response.getAttributesToNodes();
+    Assert.assertTrue(findHostnameAndValInMapping("node2", "docker0",
+        attrs.get(docker.getAttributeKey())));
+  }
+
+  @Test
+  public void testMergeClusterNodeAttributesResponse() {
+    // normal response1
+    NodeAttributeInfo nodeAttributeInfo1 =
+        NodeAttributeInfo.newInstance(NodeAttributeKey.newInstance("GPU"), 
NodeAttributeType.STRING);
+    Set<NodeAttributeInfo> attributes1 = new HashSet<>();
+    attributes1.add(nodeAttributeInfo1);
+    GetClusterNodeAttributesResponse response1 = 
GetClusterNodeAttributesResponse.newInstance(attributes1);
+
+    // normal response2
+    NodeAttributeInfo nodeAttributeInfo2 =
+        NodeAttributeInfo.newInstance(NodeAttributeKey.newInstance("CPU"), 
NodeAttributeType.STRING);
+    Set<NodeAttributeInfo> attributes2 = new HashSet<>();
+    attributes2.add(nodeAttributeInfo2);
+    GetClusterNodeAttributesResponse response2 = 
GetClusterNodeAttributesResponse.newInstance(attributes2);
+
+    // empty response3
+    GetClusterNodeAttributesResponse response3 = 
GetClusterNodeAttributesResponse.newInstance(new HashSet<>());
+
+    // null response4
+    GetClusterNodeAttributesResponse response4 = null;
+
+    List<GetClusterNodeAttributesResponse> responses = new ArrayList<>();
+    responses.add(response1);
+    responses.add(response2);
+    responses.add(response3);
+    responses.add(response4);
+
+    GetClusterNodeAttributesResponse response =
+        RouterYarnClientUtils.mergeClusterNodeAttributesResponse(responses);
+
+    Assert.assertNotNull(response);
+
+    Set<NodeAttributeInfo> nodeAttributeInfos = response.getNodeAttributes();
+    Assert.assertEquals(2, nodeAttributeInfos.size());
+
+    Object[] objectArr = nodeAttributeInfos.toArray();

Review Comment:
   I will refactor this code to use the methods provided by Set directly.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to