ReservationInputValidator { public Plan validateReservationDeleteRequest( ReservationSystem reservationSystem, ReservationDeleteRequest request) throws YarnException { return validateReservation(reservationSystem, request.getReservationId(), AuditConstants.DELETE_RESERVATION_REQUEST); } ReservationInputValidator(Clock clock); Plan validateReservationSubmissionRequest(
      ReservationSystem reservationSystem, ReservationSubmissionRequest request,
      ReservationId reservationId); Plan validateReservationUpdateRequest(
      ReservationSystem reservationSystem, ReservationUpdateRequest request); Plan validateReservationListRequest(
      ReservationSystem reservationSystem, ReservationListRequest request); Plan validateReservationDeleteRequest(
      ReservationSystem reservationSystem, ReservationDeleteRequest request);  }
@Test public void testDeleteReservationNormal() { ReservationDeleteRequest request = new ReservationDeleteRequestPBImpl(); ReservationId reservationID = ReservationSystemTestUtil.getNewReservationId(); request.setReservationId(reservationID); ReservationAllocation reservation = mock(ReservationAllocation.class); when(plan.getReservationById(reservationID)).thenReturn(reservation); Plan plan = null; try { plan = rrValidator.validateReservationDeleteRequest(rSystem, request); } catch (YarnException e) { Assert.fail(e.getMessage()); } Assert.assertNotNull(plan); }
@Test public void testDeleteReservationNoID() { ReservationDeleteRequest request = new ReservationDeleteRequestPBImpl(); Plan plan = null; try { plan = rrValidator.validateReservationDeleteRequest(rSystem, request); Assert.fail(); } catch (YarnException e) { Assert.assertNull(plan); String message = e.getMessage(); Assert .assertTrue(message .startsWith("Missing reservation id. Please try again by specifying a reservation id.")); LOG.info(message); } }
@Test public void testDeleteReservationDoesnotExist() { ReservationDeleteRequest request = new ReservationDeleteRequestPBImpl(); ReservationId rId = ReservationSystemTestUtil.getNewReservationId(); request.setReservationId(rId); when(rSystem.getQueueForReservation(rId)).thenReturn(null); Plan plan = null; try { plan = rrValidator.validateReservationDeleteRequest(rSystem, request); Assert.fail(); } catch (YarnException e) { Assert.assertNull(plan); String message = e.getMessage(); Assert .assertTrue(message.equals(MessageFormat .format( "The specified reservation with ID: {0} is unknown. Please try again with a valid reservation.", rId))); LOG.info(message); } }
@Test public void testDeleteReservationInvalidPlan() { ReservationDeleteRequest request = new ReservationDeleteRequestPBImpl(); ReservationId reservationID = ReservationSystemTestUtil.getNewReservationId(); request.setReservationId(reservationID); when(rSystem.getPlan(PLAN_NAME)).thenReturn(null); Plan plan = null; try { plan = rrValidator.validateReservationDeleteRequest(rSystem, request); Assert.fail(); } catch (YarnException e) { Assert.assertNull(plan); String message = e.getMessage(); Assert .assertTrue(message .endsWith(" is not associated with any valid plan. Please try again with a valid reservation.")); LOG.info(message); } }