@Test
public void testNodeLocalAllocation() throws Exception {

  ResourceBlacklistRequest blacklistRequest =
      ResourceBlacklistRequest.newInstance(
          new ArrayList<>(), new ArrayList<>());
  List<ResourceRequest> reqs =
      Arrays.asList(
          ResourceRequest.newBuilder().allocationRequestId(1)
              .priority(PRIORITY_NORMAL)
              .resourceName(ResourceRequest.ANY)
              .capability(CAPABILITY_1GB)
              .relaxLocality(true)
              .executionType(ExecutionType.OPPORTUNISTIC).build(),
          ResourceRequest.newBuilder().allocationRequestId(2)
              .priority(PRIORITY_NORMAL)
              .resourceName("/r1")
              .capability(CAPABILITY_1GB)
              .relaxLocality(true)
              .executionType(ExecutionType.OPPORTUNISTIC).build(),
          ResourceRequest.newBuilder().allocationRequestId(2)
              .priority(PRIORITY_NORMAL)
              .resourceName("h1")
              .capability(CAPABILITY_1GB)
              .relaxLocality(true)
              .executionType(ExecutionType.OPPORTUNISTIC).build(),
          ResourceRequest.newBuilder().allocationRequestId(2)
              .priority(PRIORITY_NORMAL)
              .resourceName(ResourceRequest.ANY)
              .capability(CAPABILITY_1GB)
              .relaxLocality(true)
              .executionType(ExecutionType.OPPORTUNISTIC).build(),
          ResourceRequest.newBuilder().allocationRequestId(3)
              .priority(PRIORITY_NORMAL)
              .resourceName("/r1")
              .capability(CAPABILITY_1GB)
              .relaxLocality(true)
              .executionType(ExecutionType.OPPORTUNISTIC).build(),
          ResourceRequest.newBuilder().allocationRequestId(3)
              .priority(PRIORITY_NORMAL)
              .resourceName("h1")
              .capability(CAPABILITY_1GB)
              .relaxLocality(true)
              .executionType(ExecutionType.OPPORTUNISTIC).build(),
          ResourceRequest.newBuilder().allocationRequestId(3)
              .priority(PRIORITY_NORMAL)
              .resourceName(ResourceRequest.ANY)
              .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("h1", 1234), "h1:1234", "/r1"),
          RemoteNode.newInstance(
              NodeId.newInstance("h2", 1234), "h2:1234", "/r1"),
          RemoteNode.newInstance(
              NodeId.newInstance("h3", 1234), "h3:1234", "/r1")));
  List<Container> containers = allocator.allocateContainers(
      blacklistRequest, reqs, appAttId, oppCntxt, 1L, "luser");
  LOG.info("Containers: {}", containers);
  // all 3 containers should be allocated.
  Assert.assertEquals(3, containers.size());
  // container with allocation id 2 and 3 should be allocated on node h1
  for (Container c : containers) {
    if (c.getAllocationRequestId() == 2 || c.getAllocationRequestId() == 3) {
      Assert.assertEquals("h1:1234", c.getNodeHttpAddress());
    }
  }
}