@Test (timeout = 30000)
public void testValidateResourceRequest() {

  Resource maxResource = Resources.createResource(
      YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_MB,
      YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_VCORES);
  // zero memory
  try {
    Resource resource = Resources.createResource(
        0,
        YarnConfiguration.DEFAULT_RM_SCHEDULER_MINIMUM_ALLOCATION_VCORES);
    ResourceRequest resReq = BuilderUtils.newResourceRequest(
        mock(Priority.class), ResourceRequest.ANY, resource, 1);
    SchedulerUtils.validateResourceRequest(resReq, maxResource);
  } catch (InvalidResourceRequestException e) {
    fail("Zero memory should be accepted");
  }
  // zero vcores
  try {
    Resource resource = Resources.createResource(
        YarnConfiguration.DEFAULT_RM_SCHEDULER_MINIMUM_ALLOCATION_MB,
        0);
    ResourceRequest resReq = BuilderUtils.newResourceRequest(
        mock(Priority.class), ResourceRequest.ANY, resource, 1);
    SchedulerUtils.validateResourceRequest(resReq, maxResource);
  } catch (InvalidResourceRequestException e) {
    fail("Zero vcores should be accepted");
  }
  // max memory
  try {
    Resource resource = Resources.createResource(
        YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_MB,
        YarnConfiguration.DEFAULT_RM_SCHEDULER_MINIMUM_ALLOCATION_VCORES);
    ResourceRequest resReq = BuilderUtils.newResourceRequest(
        mock(Priority.class), ResourceRequest.ANY, resource, 1);
    SchedulerUtils.validateResourceRequest(resReq, maxResource);
  } catch (InvalidResourceRequestException e) {
    fail("Max memory should be accepted");
  }
  // max vcores
  try {
    Resource resource = Resources.createResource(
        YarnConfiguration.DEFAULT_RM_SCHEDULER_MINIMUM_ALLOCATION_MB,
        YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_VCORES);
    ResourceRequest resReq = BuilderUtils.newResourceRequest(
        mock(Priority.class), ResourceRequest.ANY, resource, 1);
    SchedulerUtils.validateResourceRequest(resReq, maxResource);
  } catch (InvalidResourceRequestException e) {
    fail("Max vcores should not be accepted");
  }
  // negative memory
  try {
    Resource resource = Resources.createResource(
        -1,
        YarnConfiguration.DEFAULT_RM_SCHEDULER_MINIMUM_ALLOCATION_VCORES);
    ResourceRequest resReq = BuilderUtils.newResourceRequest(
        mock(Priority.class), ResourceRequest.ANY, resource, 1);
    SchedulerUtils.validateResourceRequest(resReq, maxResource);
    fail("Negative memory should not be accepted");
  } catch (InvalidResourceRequestException e) {
    // expected
  }
  // negative vcores
  try {
    Resource resource = Resources.createResource(
        YarnConfiguration.DEFAULT_RM_SCHEDULER_MINIMUM_ALLOCATION_MB,
        -1);
    ResourceRequest resReq = BuilderUtils.newResourceRequest(
        mock(Priority.class), ResourceRequest.ANY, resource, 1);
    SchedulerUtils.validateResourceRequest(resReq, maxResource);
    fail("Negative vcores should not be accepted");
  } catch (InvalidResourceRequestException e) {
    // expected
  }
  // more than max memory
  try {
    Resource resource = Resources.createResource(
        YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_MB + 1,
        YarnConfiguration.DEFAULT_RM_SCHEDULER_MINIMUM_ALLOCATION_VCORES);
    ResourceRequest resReq = BuilderUtils.newResourceRequest(
        mock(Priority.class), ResourceRequest.ANY, resource, 1);
    SchedulerUtils.validateResourceRequest(resReq, maxResource);
    fail("More than max memory should not be accepted");
  } catch (InvalidResourceRequestException e) {
    // expected
  }
  // more than max vcores
  try {
    Resource resource = Resources.createResource(
        YarnConfiguration.DEFAULT_RM_SCHEDULER_MINIMUM_ALLOCATION_MB,
        YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_VCORES
        + 1);
    ResourceRequest resReq = BuilderUtils.newResourceRequest(
        mock(Priority.class), ResourceRequest.ANY, resource, 1);
    SchedulerUtils.validateResourceRequest(resReq, maxResource);
    fail("More than max vcores should not be accepted");
  } catch (InvalidResourceRequestException e) {
    // expected
  }
}