@Test
public void testSchedulingRequestValidation() {

  // Valid
  assertValidSchedulingRequest(SchedulingRequest.newBuilder().executionType(
      ExecutionTypeRequest.newInstance(ExecutionType.GUARANTEED))
      .allocationRequestId(10L).priority(Priority.newInstance(1))
      .placementConstraintExpression(PlacementConstraints
          .targetNotIn(PlacementConstraints.NODE,
              PlacementConstraints.PlacementTargets
                  .allocationTag("mapper", "reducer"),
              PlacementConstraints.PlacementTargets.nodePartition(""))
          .build()).resourceSizing(
          ResourceSizing.newInstance(1, Resource.newInstance(1024, 1)))
      .build());
  Assert.assertEquals("", allocator.getTargetNodePartition());
  // Valid (with partition)
  assertValidSchedulingRequest(SchedulingRequest.newBuilder().executionType(
      ExecutionTypeRequest.newInstance(ExecutionType.GUARANTEED))
      .allocationRequestId(10L).priority(Priority.newInstance(1))
      .placementConstraintExpression(PlacementConstraints
          .targetNotIn(PlacementConstraints.NODE,
              PlacementConstraints.PlacementTargets
                  .allocationTag("mapper", "reducer"),
              PlacementConstraints.PlacementTargets.nodePartition("x"))
          .build()).resourceSizing(
          ResourceSizing.newInstance(1, Resource.newInstance(1024, 1)))
      .build());
  Assert.assertEquals("x", allocator.getTargetNodePartition());
  // Valid (without specifying node partition)
  assertValidSchedulingRequest(SchedulingRequest.newBuilder().executionType(
      ExecutionTypeRequest.newInstance(ExecutionType.GUARANTEED))
      .allocationRequestId(10L).priority(Priority.newInstance(1))
      .placementConstraintExpression(PlacementConstraints
          .targetNotIn(PlacementConstraints.NODE,
              PlacementConstraints.PlacementTargets
                  .allocationTag("mapper", "reducer")).build())
      .resourceSizing(
          ResourceSizing.newInstance(1, Resource.newInstance(1024, 1)))
      .build());
  // Node partition is unspecified, use the default node label expression y
  Assert.assertEquals("y", allocator.getTargetNodePartition());
  // Valid (with application Id target)
  assertValidSchedulingRequest(SchedulingRequest.newBuilder().executionType(
      ExecutionTypeRequest.newInstance(ExecutionType.GUARANTEED))
      .allocationRequestId(10L).priority(Priority.newInstance(1))
      .placementConstraintExpression(PlacementConstraints
          .targetNotIn(PlacementConstraints.NODE,
              PlacementConstraints.PlacementTargets
                  .allocationTag("mapper", "reducer")).build())
      .resourceSizing(
          ResourceSizing.newInstance(1, Resource.newInstance(1024, 1)))
      .build());
  // Allocation tags should not include application Id
  Assert.assertEquals("y", allocator.getTargetNodePartition());
  // Invalid (without sizing)
  assertInvalidSchedulingRequest(SchedulingRequest.newBuilder().executionType(
      ExecutionTypeRequest.newInstance(ExecutionType.GUARANTEED))
      .allocationRequestId(10L).priority(Priority.newInstance(1))
      .placementConstraintExpression(PlacementConstraints
          .targetNotIn(PlacementConstraints.NODE,
              PlacementConstraints.PlacementTargets
                  .allocationTag("mapper", "reducer")).build())
      .build(), true);
  // Invalid (without target tags)
  assertInvalidSchedulingRequest(SchedulingRequest.newBuilder().executionType(
      ExecutionTypeRequest.newInstance(ExecutionType.GUARANTEED))
      .allocationRequestId(10L).priority(Priority.newInstance(1))
      .placementConstraintExpression(PlacementConstraints
          .targetNotIn(PlacementConstraints.NODE).build())
      .build(), true);
  // Invalid (not GUARANTEED)
  assertInvalidSchedulingRequest(SchedulingRequest.newBuilder().executionType(
      ExecutionTypeRequest.newInstance(ExecutionType.OPPORTUNISTIC))
      .allocationRequestId(10L).priority(Priority.newInstance(1))
      .placementConstraintExpression(PlacementConstraints
          .targetNotIn(PlacementConstraints.NODE,
              PlacementConstraints.PlacementTargets
                  .allocationTag("mapper", "reducer"),
              PlacementConstraints.PlacementTargets.nodePartition(""))
          .build()).resourceSizing(
          ResourceSizing.newInstance(1, Resource.newInstance(1024, 1)))
      .build(), true);
}