InMemoryPlan implements Plan { @Override public boolean updateReservation(ReservationAllocation reservation) throws PlanningException { writeLock.lock(); boolean result = false; try { ReservationId resId = reservation.getReservationId(); ReservationAllocation currReservation = getReservationById(resId); if (currReservation == null) { String errMsg = "The specified Reservation with ID " + resId + " does not exist in the plan"; LOG.error(errMsg); throw new IllegalArgumentException(errMsg); } policy.validate(this, reservation); if (!removeReservation(currReservation)) { LOG.error("Unable to replace reservation: {} from plan.", reservation.getReservationId()); return result; } try { result = addReservation(reservation, false); } catch (PlanningException e) { LOG.error("Unable to update reservation: {} from plan due to {}.", reservation.getReservationId(), e.getMessage()); } if (result) { LOG.info("Successfully updated reservation: {} in plan.", reservation.getReservationId()); return result; } else { addReservation(currReservation, false); LOG.info("Rollbacked update reservation: {} from plan.", reservation.getReservationId()); return result; } } finally { writeLock.unlock(); } } InMemoryPlan(QueueMetrics queueMetrics, SharingPolicy policy,
      ReservationAgent agent, Resource totalCapacity, long step,
      ResourceCalculator resCalc, Resource minAlloc, Resource maxAlloc,
      String queueName, Planner replanner, boolean getMoveOnExpiry,
      RMContext rmContext);  InMemoryPlan(QueueMetrics queueMetrics, SharingPolicy policy,
      ReservationAgent agent, Resource totalCapacity, long step,
      ResourceCalculator resCalc, Resource minAlloc, Resource maxAlloc,
      String queueName, Planner replanner, boolean getMoveOnExpiry,
      long maxPeriodicity, RMContext rmContext); @SuppressWarnings("checkstyle:parameternumber")  InMemoryPlan(QueueMetrics queueMetrics, SharingPolicy policy,
      ReservationAgent agent, Resource totalCapacity, long step,
      ResourceCalculator resCalc, Resource minAlloc, Resource maxAlloc,
      String queueName, Planner replanner, boolean getMoveOnExpiry,
      long maxPeriodicty, RMContext rmContext, Clock clock); @Override QueueMetrics getQueueMetrics(); Set<ReservationAllocation> getAllReservations(); @Override boolean addReservation(ReservationAllocation reservation,
      boolean isRecovering); @Override boolean updateReservation(ReservationAllocation reservation); @Override boolean deleteReservation(ReservationId reservationID); @Override void archiveCompletedReservations(long tick); @Override Set<ReservationAllocation> getReservationsAtTime(long tick); @Override long getStep(); @Override SharingPolicy getSharingPolicy(); @Override ReservationAgent getReservationAgent(); @Override RLESparseResourceAllocation getReservationCountForUserOverTime(
      String user, long start, long end); @Override RLESparseResourceAllocation getConsumptionForUserOverTime(String user,
      long start, long end); @Override Resource getTotalCommittedResources(long t); @Override Set<ReservationAllocation> getReservations(ReservationId reservationID,
      ReservationInterval interval); @Override Set<ReservationAllocation> getReservations(ReservationId reservationID,
      ReservationInterval interval, String user); @Override ReservationAllocation getReservationById(ReservationId reservationID); @Override Resource getTotalCapacity(); @Override RLESparseResourceAllocation getAvailableResourceOverTime(String user,
      ReservationId oldId, long start, long end, long period); @Override Resource getMinimumAllocation(); @Override void setTotalCapacity(Resource cap); long getEarliestStartTime(); @Override long getLastEndTime(); @Override ResourceCalculator getResourceCalculator(); @Override String getQueueName(); @Override Resource getMaximumAllocation(); @Override long getMaximumPeriodicity(); String toCumulativeString(); @Override Planner getReplanner(); @Override boolean getMoveOnExpiry(); @Override String toString(); @Override Set<ReservationAllocation> getReservationByUserAtTime(String user,
      long t); @Override RLESparseResourceAllocation getCumulativeLoadOverTime(long start,
      long end);  }
@Test public void testUpdateReservation() { Plan plan = new InMemoryPlan(queueMetrics, policy, agent, totalCapacity, 1L, resCalc, minAlloc, maxAlloc, planName, replanner, true, context); ReservationId reservationID = ReservationSystemTestUtil.getNewReservationId(); int[] alloc = { 10, 10, 10, 10, 10, 10 }; int start = 100; ReservationAllocation rAllocation = createReservationAllocation(reservationID, start, alloc); Assert.assertNull(plan.getReservationById(reservationID)); try { plan.addReservation(rAllocation, false); } catch (PlanningException e) { Assert.fail(e.getMessage()); } doAssertions(plan, rAllocation); RLESparseResourceAllocation userCons = plan.getConsumptionForUserOverTime(user, start, start + alloc.length); for (int i = 0; i < alloc.length; i++) { assertEquals(Resource.newInstance(1024 * (alloc[i]), (alloc[i])), plan.getTotalCommittedResources(start + i)); assertEquals(Resource.newInstance(1024 * (alloc[i]), (alloc[i])), userCons.getCapacityAtTime(start + i)); } start = 110; int[] updatedAlloc = { 0, 5, 10, 10, 5, 0 }; rAllocation = createReservationAllocation(reservationID, start, updatedAlloc, true); try { plan.updateReservation(rAllocation); } catch (PlanningException e) { Assert.fail(e.getMessage()); } doAssertions(plan, rAllocation); userCons = plan.getConsumptionForUserOverTime(user, start, start + updatedAlloc.length); for (int i = 0; i < updatedAlloc.length; i++) { assertEquals(Resource.newInstance(1024 * (updatedAlloc[i] + i), updatedAlloc[i] + i), plan.getTotalCommittedResources(start + i)); assertEquals(Resource.newInstance(1024 * (updatedAlloc[i] + i), updatedAlloc[i] + i), userCons.getCapacityAtTime(start + i)); } }