private ReservationAllocation createReservationAllocation(long startTime, long deadline, long step, int[] alloc, ReservationId id, Resource minAlloc) { Map<ReservationInterval, Resource> allocations = ReservationSystemTestUtil .generateAllocation(startTime, step, alloc); ResourceCalculator rs = mock(ResourceCalculator.class); ReservationDefinition definition = ReservationSystemTestUtil .createSimpleReservationDefinition(startTime, deadline, step); return new InMemoryReservationAllocation(id, definition, "user", ReservationSystemTestUtil.reservationQ, startTime, startTime + step, allocations, rs, minAlloc, false); }
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); }
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); }
@Test(expected = MismatchedUserException.class) public void testUserMismatch() throws IOException, PlanningException { // generate allocation from single tenant that exceed capacity int[] f = generateData(3600, (int) (0.5 * totCont)); ReservationId rid = ReservationSystemTestUtil.getNewReservationId(); plan.addReservation(new InMemoryReservationAllocation(rid, null, "u1", "dedicated", initTime, initTime + f.length, ReservationSystemTestUtil .generateAllocation(initTime, step, f), res, minAlloc)); // trying to update a reservation with a mismatching user plan.updateReservation(new InMemoryReservationAllocation(rid, null, "u2", "dedicated", initTime, initTime + f.length, ReservationSystemTestUtil .generateAllocation(initTime, step, f), res, minAlloc)); }
@Test public void testZeroAlloaction() { ReservationId reservationID = ReservationId.newInstance(rand.nextLong(), rand.nextLong()); int[] alloc = {}; long start = 0; ReservationDefinition rDef = ReservationSystemTestUtil.createSimpleReservationDefinition( start, start + alloc.length + 1, alloc.length); Map<ReservationInterval, Resource> allocations = new HashMap<ReservationInterval, Resource>(); ReservationAllocation rAllocation = new InMemoryReservationAllocation(reservationID, rDef, user, planName, start, start + alloc.length + 1, allocations, resCalc, minAlloc); doAssertions(rAllocation, reservationID, rDef, allocations, (int) start, alloc); Assert.assertFalse(rAllocation.containsGangs()); }
public static InMemoryReservationAllocation toInMemoryAllocation( String planName, ReservationId reservationId, ReservationAllocationStateProto allocationState, Resource minAlloc, ResourceCalculator planResourceCalculator) { ReservationDefinition definition = convertFromProtoFormat( allocationState.getReservationDefinition()); Map<ReservationInterval, Resource> allocations = toAllocations( allocationState.getAllocationRequestsList()); InMemoryReservationAllocation allocation = new InMemoryReservationAllocation(reservationId, definition, allocationState.getUser(), planName, allocationState.getStartTime(), allocationState.getEndTime(), allocations, planResourceCalculator, minAlloc, allocationState.getContainsGangs()); return allocation; }
@Test(expected = PlanningQuotaException.class) public void testFailAvg() throws IOException, PlanningException { // generate an allocation which violates the 25% average single-shot Map<ReservationInterval, ReservationRequest> req = new TreeMap<ReservationInterval, ReservationRequest>(); long win = timeWindow / 2 + 100; int cont = (int) Math.ceil(0.5 * totCont); req.put(new ReservationInterval(initTime, initTime + win), ReservationRequest.newInstance(Resource.newInstance(1024, 1), cont)); assertTrue(plan.toString(), plan.addReservation(new InMemoryReservationAllocation( ReservationSystemTestUtil.getNewReservationId(), null, "u1", "dedicated", initTime, initTime + win, req, res, minAlloc))); }
@Test public void testSimplePass() throws IOException, PlanningException { // generate allocation that simply fit within all constraints int[] f = generateData(3600, (int) Math.ceil(0.2 * totCont)); assertTrue(plan.toString(), plan.addReservation(new InMemoryReservationAllocation( ReservationSystemTestUtil.getNewReservationId(), null, "u1", "dedicated", initTime, initTime + f.length, ReservationSystemTestUtil.generateAllocation(initTime, step, f), res, minAlloc))); }
@Test public void testSingleUserEasyFitPass() throws IOException, PlanningException { // generate allocation that easily fit within resource constraints int[] f = generateData(3600, (int) Math.ceil(0.2 * totCont)); assertTrue(plan.toString(), plan.addReservation(new InMemoryReservationAllocation( ReservationSystemTestUtil.getNewReservationId(), null, "u1", "dedicated", initTime, initTime + f.length, ReservationSystemTestUtil.generateAllocation(initTime, step, f), res, minAlloc))); }
private void prepareBasicPlan() throws PlanningException { // insert in the reservation a couple of controlled reservations, to create // conditions for assignment that are non-empty int[] f = { 10, 10, 20, 20, 20, 10, 10 }; assertTrue(plan.toString(), plan.addReservation(new InMemoryReservationAllocation( ReservationSystemTestUtil.getNewReservationId(), null, "u1", "dedicated", 0L, 0L + f.length * step, ReservationSystemTestUtil .generateAllocation(0, step, f), res, minAlloc))); int[] f2 = { 5, 5, 5, 5, 5, 5, 5 }; Map<ReservationInterval, ReservationRequest> alloc = ReservationSystemTestUtil.generateAllocation(5000, step, f2); assertTrue(plan.toString(), plan.addReservation(new InMemoryReservationAllocation( ReservationSystemTestUtil.getNewReservationId(), null, "u1", "dedicated", 5000, 5000 + f2.length * step, alloc, res, minAlloc))); System.out.println("--------BEFORE AGENT----------"); System.out.println(plan.toString()); System.out.println(plan.toCumulativeString()); }
@Test public void testSimplePass2() throws IOException, PlanningException { // generate allocation from single tenant that exceed avg momentarily but // fit within // max instantanesou int[] f = generateData(3600, (int) Math.ceil(0.69 * totCont)); assertTrue(plan.toString(), plan.addReservation(new InMemoryReservationAllocation( ReservationSystemTestUtil.getNewReservationId(), null, "u1", "dedicated", initTime, initTime + f.length, ReservationSystemTestUtil.generateAllocation(initTime, step, f), res, minAlloc))); }
@Test public void testMultiTenantPass() throws IOException, PlanningException { // generate allocation from multiple tenants that barely fit in tot capacity int[] f = generateData(3600, (int) Math.ceil(0.25 * totCont)); for (int i = 0; i < 4; i++) { assertTrue(plan.toString(), plan.addReservation(new InMemoryReservationAllocation( ReservationSystemTestUtil.getNewReservationId(), null, "u" + i, "dedicated", initTime, initTime + f.length, ReservationSystemTestUtil.generateAllocation(initTime, step, f), res, minAlloc))); } }
@Test(expected = ResourceOverCommitException.class) public void testSingleFail() throws IOException, PlanningException { // generate allocation from single tenant that exceed capacity int[] f = generateData(3600, (int) (1.1 * totCont)); plan.addReservation(new InMemoryReservationAllocation( ReservationSystemTestUtil.getNewReservationId(), null, "u1", "dedicated", initTime, initTime + f.length, ReservationSystemTestUtil .generateAllocation(initTime, step, f), res, minAlloc)); }
@Test(expected = ResourceOverCommitException.class) public void testMultiTenantFail() throws IOException, PlanningException { // generate allocation from multiple tenants that exceed tot capacity int[] f = generateData(3600, (int) Math.ceil(0.25 * totCont)); for (int i = 0; i < 5; i++) { assertTrue(plan.toString(), plan.addReservation(new InMemoryReservationAllocation( ReservationSystemTestUtil.getNewReservationId(), null, "u" + i, "dedicated", initTime, initTime + f.length, ReservationSystemTestUtil.generateAllocation(initTime, step, f), res, minAlloc))); } } }
@Test(expected = PlanningQuotaException.class) public void testInstFail() throws IOException, PlanningException { // generate allocation that exceed the instantaneous cap single-show int[] f = generateData(3600, (int) Math.ceil(0.71 * totCont)); assertTrue(plan.toString(), plan.addReservation(new InMemoryReservationAllocation( ReservationSystemTestUtil.getNewReservationId(), null, "u1", "dedicated", initTime, initTime + f.length, ReservationSystemTestUtil.generateAllocation(initTime, step, f), res, minAlloc))); Assert.fail("should not have accepted this"); }
@Test public void testMultiTenantPass() throws IOException, PlanningException { // generate allocation from multiple tenants that barely fit in tot capacity int[] f = generateData(3600, (int) Math.ceil(0.25 * totCont)); for (int i = 0; i < 4; i++) { assertTrue(plan.toString(), plan.addReservation(new InMemoryReservationAllocation( ReservationSystemTestUtil.getNewReservationId(), null, "u" + i, "dedicated", initTime, initTime + f.length, ReservationSystemTestUtil.generateAllocation(initTime, step, f), res, minAlloc))); } }
@Test(expected = ResourceOverCommitException.class) public void testMultiTenantFail() throws IOException, PlanningException { // generate allocation from multiple tenants that exceed tot capacity int[] f = generateData(3600, (int) Math.ceil(0.25 * totCont)); for (int i = 0; i < 5; i++) { assertTrue(plan.toString(), plan.addReservation(new InMemoryReservationAllocation( ReservationSystemTestUtil.getNewReservationId(), null, "u" + i, "dedicated", initTime, initTime + f.length, ReservationSystemTestUtil.generateAllocation(initTime, step, f), res, minAlloc))); } }
private void addFixedAllocation(long start, long step, int[] f) throws PlanningException { ReservationDefinition rDef = ReservationSystemTestUtil.createSimpleReservationDefinition( start, start + f.length * step, f.length * step); assertTrue(plan.toString(), plan.addReservation(new InMemoryReservationAllocation( ReservationSystemTestUtil.getNewReservationId(), rDef, "user_fixed", "dedicated", start, start + f.length * step, ReservationSystemTestUtil.generateAllocation(start, step, f), res, minAlloc), false)); }
@Test public void testBlocks() { ReservationId reservationID = ReservationId.newInstance(rand.nextLong(), rand.nextLong()); int[] alloc = { 10, 10, 10, 10, 10, 10 }; int start = 100; ReservationDefinition rDef = createSimpleReservationDefinition(start, start + alloc.length + 1, alloc.length); Map<ReservationInterval, ReservationRequest> allocations = generateAllocation(start, alloc, false, false); ReservationAllocation rAllocation = new InMemoryReservationAllocation(reservationID, rDef, user, planName, start, start + alloc.length + 1, allocations, resCalc, minAlloc); doAssertions(rAllocation, reservationID, rDef, allocations, start, alloc); Assert.assertFalse(rAllocation.containsGangs()); for (int i = 0; i < alloc.length; i++) { Assert.assertEquals(Resource.newInstance(1024 * (alloc[i]), (alloc[i])), rAllocation.getResourcesAtTime(start + i)); } }
@Test public void testSingleUserBarelyFitPass() throws IOException, PlanningException { // generate allocation from single tenant that barely fit int[] f = generateData(3600, totCont); assertTrue(plan.toString(), plan.addReservation(new InMemoryReservationAllocation( ReservationSystemTestUtil.getNewReservationId(), null, "u1", "dedicated", initTime, initTime + f.length, ReservationSystemTestUtil.generateAllocation(initTime, step, f), res, minAlloc))); }