public static GetAttributesToNodesResponse mergeAttributesToNodesResponse(
      Collection<GetAttributesToNodesResponse> responses) {
    Map<NodeAttributeKey, List<NodeToAttributeValue>> nodeAttributeMap = new HashMap<>();
    for (GetAttributesToNodesResponse response : responses) {
      if (response != null && response.getAttributesToNodes() != null) {
        nodeAttributeMap.putAll(response.getAttributesToNodes());
      }
    }
    return GetAttributesToNodesResponse.newInstance(nodeAttributeMap);
  }
@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();

    NodeAttributeKey gpuKey = gpu.getAttributeKey();
    Assert.assertEquals(attributeValue1.toString(), attrs.get(gpuKey).get(0).toString());

    NodeAttributeKey dockerKey = docker.getAttributeKey();
    Assert.assertEquals(attributeValue2.toString(), attrs.get(dockerKey).get(0).toString());
  }