@Test
public void testHasPendingResourceRequest() throws Exception {

  ApplicationAttemptId attemptId = createAppAttemptId(0, 0);
  Queue queue = createQueue("test", null);
  RMContext rmContext = mock(RMContext.class);
  when(rmContext.getEpoch()).thenReturn(3L);
  when(rmContext.getYarnConfiguration()).thenReturn(conf);
  SchedulerApplicationAttempt app = new SchedulerApplicationAttempt(
      attemptId, "user", queue, queue.getAbstractUsersManager(), rmContext);
  Priority priority = Priority.newInstance(1);
  List<ResourceRequest> requests = new ArrayList<>(2);
  Resource unit = Resource.newInstance(1L, 1);
  // Add a request for a container with a node label
  requests.add(ResourceRequest.newInstance(priority, ResourceRequest.ANY,
      unit, 1, false, "label1"));
  // Add a request for a container without a node label
  requests.add(ResourceRequest.newInstance(priority, ResourceRequest.ANY,
      unit, 1, false, ""));
  // Add unique allocation IDs so that the requests aren't considered
  // duplicates
  requests.get(0).setAllocationRequestId(0L);
  requests.get(1).setAllocationRequestId(1L);
  app.updateResourceRequests(requests);
  assertTrue("Reported no pending resource requests for no label when "
      + "resource requests for no label are pending (exclusive partitions)",
      app.hasPendingResourceRequest("",
          SchedulingMode.RESPECT_PARTITION_EXCLUSIVITY));
  assertTrue("Reported no pending resource requests for label with pending "
      + "resource requests (exclusive partitions)",
      app.hasPendingResourceRequest("label1",
          SchedulingMode.RESPECT_PARTITION_EXCLUSIVITY));
  assertFalse("Reported pending resource requests for label with no pending "
      + "resource requests (exclusive partitions)",
      app.hasPendingResourceRequest("label2",
          SchedulingMode.RESPECT_PARTITION_EXCLUSIVITY));
  assertTrue("Reported no pending resource requests for no label when "
      + "resource requests for no label are pending (relaxed partitions)",
      app.hasPendingResourceRequest("",
          SchedulingMode.IGNORE_PARTITION_EXCLUSIVITY));
  assertTrue("Reported no pending resource requests for label with pending "
      + "resource requests (relaxed partitions)",
      app.hasPendingResourceRequest("label1",
          SchedulingMode.IGNORE_PARTITION_EXCLUSIVITY));
  assertTrue("Reported no pending resource requests for label with no "
      + "pending resource requests (relaxed partitions)",
      app.hasPendingResourceRequest("label2",
          SchedulingMode.IGNORE_PARTITION_EXCLUSIVITY));
}