@Test
public void testLotsOfContainersRackLocalAllocation()
    throws Exception {

  ResourceBlacklistRequest blacklistRequest =
      ResourceBlacklistRequest.newInstance(
          new ArrayList<>(), new ArrayList<>());
  List<ResourceRequest> reqs = new ArrayList<>();
  for (int i = 0; i < 100; i++) {
    reqs.add(ResourceRequest.newBuilder().allocationRequestId(i + 1)
        .priority(PRIORITY_NORMAL)
        .resourceName("*")
        .capability(CAPABILITY_1GB)
        .relaxLocality(true)
        .executionType(ExecutionType.OPPORTUNISTIC).build());
    reqs.add(ResourceRequest.newBuilder().allocationRequestId(i + 1)
        .priority(PRIORITY_NORMAL)
        .resourceName("h1")
        .capability(CAPABILITY_1GB)
        .relaxLocality(true)
        .executionType(ExecutionType.OPPORTUNISTIC).build());
    reqs.add(ResourceRequest.newBuilder().allocationRequestId(i + 1)
        .priority(PRIORITY_NORMAL)
        .resourceName("/r1")
        .capability(CAPABILITY_1GB)
        .relaxLocality(true)
        .executionType(ExecutionType.OPPORTUNISTIC).build());
  }
  ApplicationAttemptId appAttId = ApplicationAttemptId.newInstance(
      ApplicationId.newInstance(0L, 1), 1);
  oppCntxt.updateNodeList(
      Arrays.asList(
          RemoteNode.newInstance(
              NodeId.newInstance("h3", 1234), "h3:1234", "/r2"),
          RemoteNode.newInstance(
              NodeId.newInstance("h2", 1234), "h2:1234", "/r1"),
          RemoteNode.newInstance(
              NodeId.newInstance("h5", 1234), "h5:1234", "/r1"),
          RemoteNode.newInstance(
              NodeId.newInstance("h4", 1234), "h4:1234", "/r2")));
  List<Container> containers = new ArrayList<>();
  for (int i = 0; i < 25; i++) {
    containers.addAll(allocator.allocateContainers(
        blacklistRequest, reqs, appAttId, oppCntxt, 1L, "luser"));
  }
  Assert.assertEquals(100, containers.size());
}