@Test
public void testSplitAllocateRequest() throws Exception {

  // Test a complex List<ResourceRequest> is split correctly
  initializePolicy();
  addHomeSubClusterAsActive();
  FederationPoliciesTestUtil.initializePolicyContext(
      getFederationPolicyContext(), getPolicy(), getPolicyInfo(),
      getActiveSubclusters(), new Configuration());
  List<ResourceRequest> resourceRequests = createComplexRequest();
  Map<SubClusterId, List<ResourceRequest>> response =
      ((FederationAMRMProxyPolicy) getPolicy()).splitResourceRequests(
          resourceRequests, new HashSet<SubClusterId>());
  validateSplit(response, resourceRequests);
  prettyPrintRequests(response);
  // we expect 7 entries for home subcluster (2 for request-id 4, 3 for
  // request-id 5, and a part of the broadcast of request-id 2
  checkExpectedAllocation(response, getHomeSubCluster().getId(), 7, 29);
  // for subcluster0 we expect 10 entries, 3 from request-id 0, and 3 from
  // request-id 3, 3 entries from request-id 5, as well as part of the
  // request-id 2 broadast
  checkExpectedAllocation(response, "subcluster0", 10, 32);
  // we expect 5 entries for subcluster1 (4 from request-id 1, and part
  // of the broadcast of request-id 2
  checkExpectedAllocation(response, "subcluster1", 5, 26);
  // sub-cluster 2 should contain 3 entries from request-id 1 and 1 from the
  // broadcast of request-id 2, and no request-id 0
  checkExpectedAllocation(response, "subcluster2", 4, 23);
  // subcluster id 3, 4 should not appear (due to weights or active/inactive)
  checkExpectedAllocation(response, "subcluster3", -1, -1);
  checkExpectedAllocation(response, "subcluster4", -1, -1);
  // subcluster5 should get only part of the request-id 2 broadcast
  checkExpectedAllocation(response, "subcluster5", 1, 20);
  // Check the total number of container asks in all RR
  checkTotalContainerAllocation(response, 130);
  // check that the allocations that show up are what expected
  for (ResourceRequest rr : response.get(getHomeSubCluster())) {
    Assert.assertTrue(
        rr.getAllocationRequestId() == 2L || rr.getAllocationRequestId() == 4L
            || rr.getAllocationRequestId() == 5L);
  }
  List<ResourceRequest> rrs =
      response.get(SubClusterId.newInstance("subcluster0"));
  for (ResourceRequest rr : rrs) {
    Assert.assertTrue(rr.getAllocationRequestId() != 1L);
    Assert.assertTrue(rr.getAllocationRequestId() != 4L);
  }
  for (ResourceRequest rr : response
      .get(SubClusterId.newInstance("subcluster1"))) {
    Assert.assertTrue(rr.getAllocationRequestId() == 1L
        || rr.getAllocationRequestId() == 2L);
  }
  for (ResourceRequest rr : response
      .get(SubClusterId.newInstance("subcluster2"))) {
    Assert.assertTrue(rr.getAllocationRequestId() == 1L
        || rr.getAllocationRequestId() == 2L);
  }
  for (ResourceRequest rr : response
      .get(SubClusterId.newInstance("subcluster5"))) {
    Assert.assertTrue(rr.getAllocationRequestId() == 2);
    Assert.assertTrue(rr.getRelaxLocality());
  }
}