public virtual 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 = new int[] { 10, 10, 10, 10, 10, 10 }; int start = 100; IDictionary <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 ); NUnit.Framework.Assert.IsNull(plan.GetReservationById(reservationID)); try { plan.UpdateReservation(rAllocation); NUnit.Framework.Assert.Fail("Update should fail as it does not exist in the plan" ); } catch (ArgumentException e) { NUnit.Framework.Assert.IsTrue(e.Message.EndsWith("does not exist in the plan")); } catch (PlanningException e) { NUnit.Framework.Assert.Fail(e.Message); } NUnit.Framework.Assert.IsNull(plan.GetReservationById(reservationID)); }
/// <exception cref="System.IO.IOException"/> /// <exception cref="Org.Apache.Hadoop.Yarn.Server.Resourcemanager.Reservation.Exceptions.PlanningException /// "/> public virtual void TestUserMismatch() { // 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)); }
public virtual void TestUpdateReservation() { Plan plan = new InMemoryPlan(queueMetrics, policy, agent, totalCapacity, 1L, resCalc , minAlloc, maxAlloc, planName, replanner, true); ReservationId reservationID = ReservationSystemTestUtil.GetNewReservationId(); // First add a reservation int[] alloc = new int[] { 10, 10, 10, 10, 10, 10 }; int start = 100; IDictionary <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 ); NUnit.Framework.Assert.IsNull(plan.GetReservationById(reservationID)); try { plan.AddReservation(rAllocation); } catch (PlanningException e) { NUnit.Framework.Assert.Fail(e.Message); } DoAssertions(plan, rAllocation); for (int i = 0; i < alloc.Length; i++) { NUnit.Framework.Assert.AreEqual(Org.Apache.Hadoop.Yarn.Api.Records.Resource.NewInstance (1024 * (alloc[i]), (alloc[i])), plan.GetTotalCommittedResources(start + i)); NUnit.Framework.Assert.AreEqual(Org.Apache.Hadoop.Yarn.Api.Records.Resource.NewInstance (1024 * (alloc[i]), (alloc[i])), plan.GetConsumptionForUser(user, start + i)); } // Now update it start = 110; int[] updatedAlloc = new int[] { 0, 5, 10, 10, 5, 0 }; allocations = GenerateAllocation(start, updatedAlloc, true); rDef = CreateSimpleReservationDefinition(start, start + updatedAlloc.Length, updatedAlloc .Length, allocations.Values); rAllocation = new InMemoryReservationAllocation(reservationID, rDef, user, planName , start, start + updatedAlloc.Length, allocations, resCalc, minAlloc); try { plan.UpdateReservation(rAllocation); } catch (PlanningException e) { NUnit.Framework.Assert.Fail(e.Message); } DoAssertions(plan, rAllocation); for (int i_1 = 0; i_1 < updatedAlloc.Length; i_1++) { NUnit.Framework.Assert.AreEqual(Org.Apache.Hadoop.Yarn.Api.Records.Resource.NewInstance (1024 * (updatedAlloc[i_1] + i_1), updatedAlloc[i_1] + i_1), plan.GetTotalCommittedResources (start + i_1)); NUnit.Framework.Assert.AreEqual(Org.Apache.Hadoop.Yarn.Api.Records.Resource.NewInstance (1024 * (updatedAlloc[i_1] + i_1), updatedAlloc[i_1] + i_1), plan.GetConsumptionForUser (user, start + i_1)); } }