private ReservationAllocation createReservationAllocation( ReservationId reservationID, int start, int[] alloc, String recurrenceExp) { return createReservationAllocation(reservationID, start, alloc, false, recurrenceExp); }
private ReservationAllocation createReservationAllocation( ReservationId reservationID, int start, int[] alloc, boolean isStep) { return createReservationAllocation(reservationID, start, alloc, isStep, "0"); }
private ReservationAllocation createReservationAllocation( ReservationId reservationID, int start, int[] alloc) { return createReservationAllocation(reservationID, start, alloc, false, "0"); }
private ReservationId submitReservation(Plan plan, long reservationStartTime, long reservationEndTime, long period) { ReservationId reservation = ReservationSystemTestUtil.getNewReservationId(); ReservationAllocation rAllocation = createReservationAllocation( reservation, reservationStartTime, reservationEndTime, String.valueOf(period)); rAllocation.setPeriodicity(period); Assert.assertNull(plan.getReservationById(reservation)); try { plan.addReservation(rAllocation, false); } catch (PlanningException e) { Assert.fail(e.getMessage()); } return reservation; }
@Test public void testUpdateNonExistingReservation() { Plan plan = new InMemoryPlan(queueMetrics, policy, agent, totalCapacity, 1L, resCalc, minAlloc, maxAlloc, planName, replanner, true, context); ReservationId reservationID = ReservationSystemTestUtil.getNewReservationId(); // Try to update a reservation without adding int[] alloc = { 10, 10, 10, 10, 10, 10 }; int start = 100; ReservationAllocation rAllocation = createReservationAllocation(reservationID, start, alloc); Assert.assertNull(plan.getReservationById(reservationID)); try { plan.updateReservation(rAllocation); Assert.fail("Update should fail as it does not exist in the plan"); } catch (IllegalArgumentException e) { Assert.assertTrue(e.getMessage().endsWith("does not exist in the plan")); } catch (PlanningException e) { Assert.fail(e.getMessage()); } Assert.assertNull(plan.getReservationById(reservationID)); }
@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 testGetReservationsAtTime() { 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()); } Set<ReservationAllocation> rAllocations = plan.getReservationsAtTime(rAllocation.getStartTime()); Assert.assertTrue(rAllocations.size() == 1); Assert.assertTrue(rAllocation .compareTo((ReservationAllocation) rAllocations.toArray()[0]) == 0); }
@Test public void testAddEmptyReservation() { Plan plan = new InMemoryPlan(queueMetrics, policy, agent, totalCapacity, 1L, resCalc, minAlloc, maxAlloc, planName, replanner, true, context); ReservationId reservationID = ReservationSystemTestUtil.getNewReservationId(); int[] alloc = {}; 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()); } }
@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); }
int start = 100; ReservationAllocation rAllocation = createReservationAllocation(reservationID, start, alloc); int[] updatedAlloc = { 30, 40, 50 }; rAllocation = createReservationAllocation(reservationID, start, updatedAlloc); rAllocation.getReservationDefinition() .setRecurrenceExpression(String.valueOf(period));
@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); }
int start = 100; ReservationAllocation rAllocation = createReservationAllocation(reservationID, start, alloc);
@Test public void testAddReservationAlreadyExists() { // First add a reservation 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); checkAllocation(plan, alloc, start, 0); // Try to add it again try { plan.addReservation(rAllocation, false); Assert.fail("Add should fail as it already exists"); } catch (IllegalArgumentException e) { Assert.assertTrue(e.getMessage().endsWith("already exists")); } catch (PlanningException e) { Assert.fail(e.getMessage()); } doAssertions(plan, rAllocation); }
@Test public void testAddReservation() { 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); checkAllocation(plan, alloc, start, 0); }
int start = 100; ReservationAllocation rAllocation = createReservationAllocation(reservationID, start, alloc); Assert.assertNull(plan.getReservationById(reservationID)); try {
int start = 100; ReservationAllocation rAllocation = createReservationAllocation(reservationID1, start, alloc1); Assert.assertNull(plan.getReservationById(reservationID1)); try { int[] alloc2 = { 0, 5, 10, 5, 0 }; rAllocation = createReservationAllocation(reservationID2, start, alloc2, true); Assert.assertNull(plan.getReservationById(reservationID2)); try {
int start = 100; ReservationAllocation rAllocation = createReservationAllocation(reservationID, start, alloc); Assert.assertNull(plan.getReservationById(reservationID)); try { int[] updatedAlloc = { 0, 5, 10, 10, 5, 0 }; rAllocation = createReservationAllocation(reservationID, start, updatedAlloc, true); try { plan.updateReservation(rAllocation);
int start = 10; long period = 20; ReservationAllocation rAllocation = createReservationAllocation( reservationID, start, alloc, String.valueOf(period));
int start = 100; ReservationAllocation rAllocation = createReservationAllocation(reservationID, start, alloc, true); Assert.assertNull(plan.getReservationById(reservationID)); try {