@Test public void testGetReservationsWithNoReservation() { Plan plan = new InMemoryPlan(queueMetrics, policy, agent, totalCapacity, 1L, resCalc, minAlloc, maxAlloc, planName, replanner, true, context); // Verify that get reservation returns no entries if no queries are made. ReservationInterval interval = new ReservationInterval(0, Long.MAX_VALUE); Set<ReservationAllocation> rAllocations = plan.getReservations(null, interval, ""); Assert.assertTrue(rAllocations.size() == 0); }
private void testPositiveGetRecurringReservationsHelper(long reservationStart, long reservationEnd, long searchStart, long searchEnd, long cycles, long period, int periodMultiplier) { maxPeriodicity = period * periodMultiplier; Plan plan = new InMemoryPlan(queueMetrics, policy, agent, totalCapacity, 1L, resCalc, minAlloc, maxAlloc, planName, replanner, true, maxPeriodicity, context, new UTCClock()); ReservationId reservationID = submitReservation(plan, reservationStart, reservationEnd, period); for (int i = 0; i < cycles; i++) { long searchStepIncrease = i * period; Set<ReservationAllocation> alloc = plan.getReservations(null, new ReservationInterval(searchStart + searchStepIncrease, searchEnd + searchStepIncrease)); assertEquals(1, alloc.size()); assertEquals(reservationID, alloc.iterator().next().getReservationId()); } }
private void testNegativeGetRecurringReservationsHelper(long reservationStart, long reservationEnd, long searchStart, long searchEnd, long cycles, long period, int periodMultiplier) { maxPeriodicity = period * periodMultiplier; Plan plan = new InMemoryPlan(queueMetrics, policy, agent, totalCapacity, 1L, resCalc, minAlloc, maxAlloc, planName, replanner, true, maxPeriodicity, context, new UTCClock()); submitReservation(plan, reservationStart, reservationEnd, period); for (int i = 0; i < cycles; i++) { long searchStepIncrease = i * period; Set<ReservationAllocation> alloc = plan.getReservations(null, new ReservationInterval(searchStart + searchStepIncrease, searchEnd + searchStepIncrease)); assertEquals(0, alloc.size()); } }
reservations = plan.getReservations(reservationId, new ReservationInterval( startTime, endTime));
@Test public void testGetReservationsById() { 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()); } // Verify that get by reservation id works. Set<ReservationAllocation> rAllocations = plan.getReservations(reservationID, null, ""); Assert.assertTrue(rAllocations.size() == 1); Assert.assertTrue(rAllocation .compareTo((ReservationAllocation) rAllocations.toArray()[0]) == 0); // Verify that get by reservation id works even when time range // and user is invalid. ReservationInterval interval = new ReservationInterval(0, 0); rAllocations = plan.getReservations(reservationID, interval, "invalid"); Assert.assertTrue(rAllocations.size() == 1); Assert.assertTrue(rAllocation .compareTo((ReservationAllocation) rAllocations.toArray()[0]) == 0); }
rAllocation.getStartTime(), rAllocation.getEndTime()); Set<ReservationAllocation> rAllocations = plan.getReservations(null, interval, ""); Assert.assertTrue(rAllocations.size() == 1); Assert.assertTrue(rAllocation rAllocation.getStartTime() + duration * (long) 0.3, rAllocation.getEndTime() - duration * (long) 0.3); rAllocations = plan.getReservations(null, interval, ""); Assert.assertTrue(rAllocations.size() == 1); Assert.assertTrue(rAllocation rAllocations = plan.getReservations(null, interval, ""); Assert.assertTrue(rAllocations.size() == 1); Assert.assertTrue(rAllocation rAllocations = plan.getReservations(null, interval, ""); Assert.assertTrue(rAllocations.size() == 0); rAllocations = plan.getReservations(null, interval, ""); Assert.assertTrue(rAllocations.size() == 0);
@Test public void testGetReservationsWithNoInput() { 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()); } // Verify that getReservations defaults to getting all reservations if no // reservationID, time interval, and user is provided, Set<ReservationAllocation> rAllocations = plan.getReservations(null, null, ""); Assert.assertTrue(rAllocations.size() == 1); Assert.assertTrue(rAllocation .compareTo((ReservationAllocation) rAllocations.toArray()[0]) == 0); }
@Test public void testGetReservationsByInvalidId() { 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()); } // If reservationId is null, then nothing is returned. ReservationId invalidReservationID = ReservationSystemTestUtil.getNewReservationId(); Set<ReservationAllocation> rAllocations = plan.getReservations(invalidReservationID, null, ""); Assert.assertTrue(rAllocations.size() == 0); }