public static GetNodesToAttributesResponse mergeNodesToAttributesResponse(
      Collection<GetNodesToAttributesResponse> responses) {
    Map<String, Set<NodeAttribute>> attributesMap = new HashMap<>();
    for (GetNodesToAttributesResponse response : responses) {
      if (response != null && response.getNodeToAttributes() != null) {
        attributesMap.putAll(response.getNodeToAttributes());
      }
    }
    return GetNodesToAttributesResponse.newInstance(attributesMap);
  }
@Test
  public void testMergeNodesToAttributesResponse() {
    // normal response1
    NodeAttribute gpu = NodeAttribute.newInstance(NodeAttribute.PREFIX_CENTRALIZED, "GPU",
        NodeAttributeType.STRING, "nvida");
    NodeAttribute os = NodeAttribute.newInstance(NodeAttribute.PREFIX_CENTRALIZED, "OS",
        NodeAttributeType.STRING, "windows64");
    NodeAttribute dist = NodeAttribute.newInstance(NodeAttribute.PREFIX_DISTRIBUTED, "VERSION",
        NodeAttributeType.STRING, "3_0_2");
    Map<String, Set<NodeAttribute>> node1Map = new HashMap<>();
    node1Map.put("node1", ImmutableSet.of(gpu, os, dist));
    GetNodesToAttributesResponse response1 = GetNodesToAttributesResponse.newInstance(node1Map);

    // normal response2
    NodeAttribute docker = NodeAttribute.newInstance(NodeAttribute.PREFIX_DISTRIBUTED, "DOCKER",
        NodeAttributeType.STRING, "docker0");
    Map<String, Set<NodeAttribute>> node2Map = new HashMap<>();
    node2Map.put("node2", ImmutableSet.of(docker));
    GetNodesToAttributesResponse response2 = GetNodesToAttributesResponse.newInstance(node2Map);

    // empty response3
    GetNodesToAttributesResponse response3 =
        GetNodesToAttributesResponse.newInstance(new HashMap<>());

    // null response4
    GetNodesToAttributesResponse response4 = null;

    List<GetNodesToAttributesResponse> responses = new ArrayList<>();
    responses.add(response1);
    responses.add(response2);
    responses.add(response3);
    responses.add(response4);

    GetNodesToAttributesResponse response =
        RouterYarnClientUtils.mergeNodesToAttributesResponse(responses);

    Assert.assertNotNull(response);

    Map<String, Set<NodeAttribute>> hostToAttrs = response.getNodeToAttributes();
    Assert.assertNotNull(hostToAttrs);
    Assert.assertEquals(2, hostToAttrs.size());
    Assert.assertTrue(hostToAttrs.get("node1").contains(dist));
    Assert.assertTrue(hostToAttrs.get("node1").contains(gpu));
    Assert.assertTrue(hostToAttrs.get("node1").contains(os));
    Assert.assertTrue(hostToAttrs.get("node2").contains(docker));
  }