InMemoryPlan implements Plan { @Override public RLESparseResourceAllocation getAvailableResourceOverTime(String user, ReservationId oldId, long start, long end, long period) throws PlanningException { readLock.lock(); try { if (period == 0) { TreeMap<Long, Resource> totAvailable = new TreeMap<Long, Resource>(); totAvailable.put(start, Resources.clone(totalCapacity)); RLESparseResourceAllocation totRLEAvail = new RLESparseResourceAllocation(totAvailable, resCalc); RLESparseResourceAllocation netAvailable; netAvailable = RLESparseResourceAllocation.merge(resCalc, Resources.clone(totalCapacity), totRLEAvail, rleSparseVector, RLEOperator.subtractTestNonNegative, start, end); netAvailable = RLESparseResourceAllocation.merge(resCalc, Resources.clone(totalCapacity), netAvailable, periodicRle, RLEOperator.subtractTestNonNegative, start, end); ReservationAllocation old = reservationTable.get(oldId); if (old != null) { RLESparseResourceAllocation addBackPrevious = old.getResourcesOverTime(start, end); netAvailable = RLESparseResourceAllocation.merge(resCalc, Resources.clone(totalCapacity), netAvailable, addBackPrevious, RLEOperator.add, start, end); } netAvailable = getSharingPolicy().availableResources(netAvailable, this, user, oldId, start, end); return netAvailable; } else { if (periodicRle.getTimePeriod() % period != 0) { throw new PlanningException("The reservation periodicity (" + period + ") must be" + " an exact divider of the system maxPeriod (" + periodicRle.getTimePeriod() + ")"); } if (period < (end - start)) { throw new PlanningException( "Invalid input: (end - start) = (" + end + " - " + start + ") = " + (end - start) + " > period = " + period); } long numInstInLCM = periodicRle.getTimePeriod() / period; RLESparseResourceAllocation minOverLCM = getAvailableResourceOverTime(user, oldId, start, end, 0); for (int i = 1; i < numInstInLCM; i++) { long rStart = start + i * period; long rEnd = end + i * period; RLESparseResourceAllocation snapShot = getAvailableResourceOverTime(user, oldId, rStart, rEnd, 0); snapShot.shift(-(i * period)); minOverLCM = RLESparseResourceAllocation.merge(resCalc, getTotalCapacity(), minOverLCM, snapShot, RLEOperator.min, start, end); } return minOverLCM; } } finally { readLock.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(expected = PlanningException.class) public void testOutOfRange() throws PlanningException { maxPeriodicity = 100; Plan plan = new InMemoryPlan(queueMetrics, policy, agent, totalCapacity, 1L, resCalc, minAlloc, maxAlloc, planName, replanner, true, maxPeriodicity, context, new UTCClock()); RLESparseResourceAllocation availableBefore = plan.getAvailableResourceOverTime(user, null, 150, 330, 50); }