private ReservationAllocation createReservationAllocation( ReservationId reservationID, int start, int[] alloc, boolean isStep, String recurrenceExp) { Map<ReservationInterval, ReservationRequest> allocations = generateAllocation(start, alloc, isStep); ReservationDefinition rDef = createSimpleReservationDefinition(start, start + alloc.length, alloc.length, allocations.values(), recurrenceExp); Map<ReservationInterval, Resource> allocs = ReservationSystemUtil.toResources(allocations); return new InMemoryReservationAllocation(reservationID, rDef, user, planName, start, start + alloc.length, allocs, resCalc, minAlloc); }
private ReservationAllocation createReservationAllocation( ReservationId reservationID, int start, int[] alloc, String recurrenceExp) { return createReservationAllocation(reservationID, start, alloc, false, recurrenceExp); }
@Test public void testNegativeGetReservationSearchIntervalCloseToStartTime() { // Reservation duration is 10 minutes long reservationStart = Timestamp.valueOf("2050-12-03 10:37:37").getTime(); long reservationEnd = Timestamp.valueOf("2050-12-03 10:47:37").getTime(); // Search interval does not fit within the reservation but is close to // the start time. long searchStart = Timestamp.valueOf("2050-12-03 11:30:37").getTime(); long searchEnd = Timestamp.valueOf("2050-12-03 11:35:37").getTime(); // 60 minute period in milliseconds. long period = 60 * 60 * 1000; testNegativeGetRecurringReservationsHelper(reservationStart, reservationEnd, searchStart, searchEnd, 100, period, 10); }
int start = 100; Map<ReservationInterval, ReservationRequest> allocations = generateAllocation(start, alloc, false); ReservationDefinition rDef = createSimpleReservationDefinition(start, start + alloc.length, alloc.length, allocations.values()); ReservationAllocation rAllocation = Assert.fail(e.getMessage()); doAssertions(plan, rAllocation); for (int i = 0; i < alloc.length; i++) { Assert.assertEquals(Resource.newInstance(1024 * (alloc[i]), (alloc[i])), 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 { Assert.fail(e.getMessage()); doAssertions(plan, rAllocation); int[] updatedAlloc = { 0, 5, 10, 10, 5, 0 }; rAllocation = createReservationAllocation(reservationID, start, updatedAlloc, true); try { plan.updateReservation(rAllocation); Assert.fail(e.getMessage()); doAssertions(plan, rAllocation);
private ReservationAllocation createReservationAllocation( ReservationId reservationID, long startTime, long endTime, String period) { ReservationInterval interval = new ReservationInterval(startTime, endTime); List<ReservationRequest> request = new ArrayList<>(); request.add(ReservationRequest.newInstance(minAlloc, 1, 1, endTime - startTime)); ReservationDefinition rDef = createSimpleReservationDefinition(startTime, endTime, endTime - startTime, request, period); Map<ReservationInterval, Resource> allocations = new HashMap<>(); allocations.put(interval, minAlloc); return new InMemoryReservationAllocation(reservationID, rDef, user, planName, startTime, endTime, allocations, resCalc, minAlloc); }
@Test public void testGetReservationReservationStartTimeOverlap() { // Reservation duration is 10 minutes long reservationStart = Timestamp.valueOf("2050-12-03 10:37:37").getTime(); long reservationEnd = Timestamp.valueOf("2050-12-03 10:47:37").getTime(); // Search interval fits the starting portion of the reservation. long searchStart = Timestamp.valueOf("2050-12-03 11:36:37").getTime(); long searchEnd = Timestamp.valueOf("2050-12-03 11:38:37").getTime(); // 60 minute period in milliseconds. long period = 60 * 60 * 1000; testPositiveGetRecurringReservationsHelper(reservationStart, reservationEnd, searchStart, searchEnd, 100, period, 10); }
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()); } }
int start = 100; Map<ReservationInterval, ReservationRequest> allocations = generateAllocation(start, alloc, false); ReservationDefinition rDef = createSimpleReservationDefinition(start, start + alloc.length, alloc.length, allocations.values()); ReservationAllocation rAllocation = Assert.fail(e.getMessage()); doAssertions(plan, rAllocation); for (int i = 0; i < alloc.length; i++) { Assert.assertEquals(Resource.newInstance(1024 * (alloc[i]), (alloc[i])),
int start = 100; ReservationAllocation rAllocation = createReservationAllocation(reservationID, start, alloc); doAssertions(plan, rAllocation); checkAllocation(plan, alloc, start, period); int[] updatedAlloc = { 30, 40, 50 }; rAllocation = createReservationAllocation(reservationID, start, updatedAlloc); rAllocation.getReservationDefinition() .setRecurrenceExpression(String.valueOf(period)); Assert.fail(e.getMessage()); doAssertions(plan, rAllocation); checkAllocation(plan, updatedAlloc, start, period);
int start = 100; ReservationAllocation rAllocation = createReservationAllocation(reservationID, start, alloc, true); Assert.assertNull(plan.getReservationById(reservationID)); try { Assert.fail(e.getMessage()); doAssertions(plan, rAllocation);
@Test public void testAddEmptyReservation() { Plan plan = new InMemoryPlan(queueMetrics, policy, agent, totalCapacity, 1L, resCalc, minAlloc, maxAlloc, planName, replanner, true); ReservationId reservationID = ReservationSystemTestUtil.getNewReservationId(); int[] alloc = {}; int start = 100; Map<ReservationInterval, ReservationRequest> allocations = new HashMap<ReservationInterval, ReservationRequest>(); ReservationDefinition rDef = createSimpleReservationDefinition(start, start + alloc.length, alloc.length, allocations.values()); ReservationAllocation rAllocation = new InMemoryReservationAllocation(reservationID, rDef, user, planName, start, start + alloc.length, allocations, resCalc, minAlloc); Assert.assertNull(plan.getReservationById(reservationID)); try { plan.addReservation(rAllocation); } catch (PlanningException e) { Assert.fail(e.getMessage()); } }
@Test public void testGetReservationReservationEndTimeOverlap() { // Reservation duration is 10 minutes long reservationStart = Timestamp.valueOf("2050-12-03 10:37:37").getTime(); long reservationEnd = Timestamp.valueOf("2050-12-03 10:47:37").getTime(); // Search interval fits the ending portion of the reservation. long searchStart = Timestamp.valueOf("2050-12-03 11:46:37").getTime(); long searchEnd = Timestamp.valueOf("2050-12-03 11:48:37").getTime(); // 60 minute period in milliseconds. long period = 60 * 60 * 1000; testPositiveGetRecurringReservationsHelper(reservationStart, reservationEnd, searchStart, searchEnd, 100, period, 10); }
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()); } }
int start = 100; Map<ReservationInterval, ReservationRequest> allocations = generateAllocation(start, alloc, false); ReservationDefinition rDef = createSimpleReservationDefinition(start, start + alloc.length, alloc.length, allocations.values()); ReservationAllocation rAllocation = Assert.fail(e.getMessage()); doAssertions(plan, rAllocation); for (int i = 0; i < alloc.length; i++) { Assert.assertEquals(Resource.newInstance(1024 * (alloc[i]), (alloc[i])), allocations = generateAllocation(start, updatedAlloc, true); rDef = createSimpleReservationDefinition(start, start + updatedAlloc.length, updatedAlloc.length, allocations.values()); rAllocation = Assert.fail(e.getMessage()); doAssertions(plan, rAllocation); for (int i = 0; i < updatedAlloc.length; i++) { Assert.assertEquals(
@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 testUpdateNonExistingReservation() { Plan plan = new InMemoryPlan(queueMetrics, policy, agent, totalCapacity, 1L, resCalc, minAlloc, maxAlloc, planName, replanner, true); ReservationId reservationID = ReservationSystemTestUtil.getNewReservationId(); // Try to update a reservation without adding int[] alloc = { 10, 10, 10, 10, 10, 10 }; int start = 100; Map<ReservationInterval, ReservationRequest> allocations = generateAllocation(start, alloc, false); ReservationDefinition rDef = createSimpleReservationDefinition(start, start + alloc.length, alloc.length, allocations.values()); ReservationAllocation rAllocation = new InMemoryReservationAllocation(reservationID, rDef, user, planName, start, start + alloc.length, allocations, resCalc, minAlloc); 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)); }
private ReservationAllocation createReservationAllocation( ReservationId reservationID, int start, int[] alloc, boolean isStep) { return createReservationAllocation(reservationID, start, alloc, isStep, "0"); }
@Test public void testGetReservationReservationFitWithinSearchInterval() { // Reservation duration is 10 minutes long reservationStart = Timestamp.valueOf("2050-12-03 10:37:37").getTime(); long reservationEnd = Timestamp.valueOf("2050-12-03 10:47:37").getTime(); // Search interval fits the entire reservation but is smaller than the // period. long searchStart = Timestamp.valueOf("2050-12-03 10:36:37").getTime(); long searchEnd = Timestamp.valueOf("2050-12-03 10:48:37").getTime(); // 20 minute period in milliseconds. long period = 20 * 60 * 1000; testPositiveGetRecurringReservationsHelper(reservationStart, reservationEnd, searchStart, searchEnd, 100, period, 10); }