public static GetAllResourceTypeInfoResponse mergeResourceTypes(
      Collection<GetAllResourceTypeInfoResponse> responses) {
    GetAllResourceTypeInfoResponse resourceTypeInfoResponse =
        Records.newRecord(GetAllResourceTypeInfoResponse.class);
    Set<ResourceTypeInfo> resourceTypeInfoSet = new HashSet<>();
    for (GetAllResourceTypeInfoResponse response : responses) {
      if (response != null && response.getResourceTypeInfo() != null) {
        resourceTypeInfoSet.addAll(response.getResourceTypeInfo());
      }
    }
    resourceTypeInfoResponse.setResourceTypeInfo(
        new ArrayList<>(resourceTypeInfoSet));
    return resourceTypeInfoResponse;
  }
@Test
  public void testMergeResourceTypes() {

    ResourceTypeInfo resourceTypeInfo1 = ResourceTypeInfo.newInstance("vcores");
    ResourceTypeInfo resourceTypeInfo2 = ResourceTypeInfo.newInstance("gpu");
    ResourceTypeInfo resourceTypeInfo3 = ResourceTypeInfo.newInstance("memory-mb");

    List<ResourceTypeInfo> resourceTypeInfoList1 = new ArrayList<>();
    resourceTypeInfoList1.add(resourceTypeInfo1);
    resourceTypeInfoList1.add(resourceTypeInfo3);

    List<ResourceTypeInfo> resourceTypeInfoList2 = new ArrayList<>();
    resourceTypeInfoList2.add(resourceTypeInfo3);
    resourceTypeInfoList2.add(resourceTypeInfo2);

    // normal response
    GetAllResourceTypeInfoResponse response1 =
        Records.newRecord(GetAllResourceTypeInfoResponse.class);
    response1.setResourceTypeInfo(resourceTypeInfoList1);

    GetAllResourceTypeInfoResponse response2 =
        Records.newRecord(GetAllResourceTypeInfoResponse.class);
    response2.setResourceTypeInfo(resourceTypeInfoList2);

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

    // null response
    GetAllResourceTypeInfoResponse response4 = null;

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

    // expected response
    List<ResourceTypeInfo> expectedResponse = new ArrayList<>();
    expectedResponse.add(resourceTypeInfo1);
    expectedResponse.add(resourceTypeInfo2);
    expectedResponse.add(resourceTypeInfo3);
    GetAllResourceTypeInfoResponse response =
        RouterYarnClientUtils.mergeResourceTypes(responses);
    Assert.assertTrue(CollectionUtils.isEqualCollection(expectedResponse,
        response.getResourceTypeInfo()));
  }