public static GetResourceProfileResponse mergeClusterResourceProfileResponse(
      Collection<GetResourceProfileResponse> responses) {
    GetResourceProfileResponse profileResponse =
        Records.newRecord(GetResourceProfileResponse.class);
    Resource resource = Resource.newInstance(0, 0);
    for (GetResourceProfileResponse response : responses) {
      if (response != null && response.getResource() != null) {
        Resource responseResource = response.getResource();
        resource = Resources.add(resource, responseResource);
      }
    }
    profileResponse.setResource(resource);
    return profileResponse;
  }
@Test
  public void testMergeResourceProfile() {
    // normal response1
    Resource resource1 = Resource.newInstance(1024, 1);
    GetResourceProfileResponse response1 =
        Records.newRecord(GetResourceProfileResponse.class);
    response1.setResource(resource1);

    // normal response2
    Resource resource2 = Resource.newInstance(2048, 2);
    GetResourceProfileResponse response2 =
        Records.newRecord(GetResourceProfileResponse.class);
    response2.setResource(resource2);

    // empty response
    GetResourceProfileResponse response3 =
        Records.newRecord(GetResourceProfileResponse.class);

    // null response
    GetResourceProfileResponse response4 = null;

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

    GetResourceProfileResponse response =
        RouterYarnClientUtils.mergeClusterResourceProfileResponse(responses);
    Resource resource = response.getResource();
    Assert.assertEquals(3, resource.getVirtualCores());
    Assert.assertEquals(3072, resource.getMemorySize());
  }