示例#1
0
        public virtual void TestDeleteReservation()
        {
            // First add a reservation
            Plan plan = new InMemoryPlan(queueMetrics, policy, agent, totalCapacity, 1L, resCalc
                                         , minAlloc, maxAlloc, planName, replanner, true);
            ReservationId reservationID = ReservationSystemTestUtil.GetNewReservationId();

            int[] alloc = new int[] { 10, 10, 10, 10, 10, 10 };
            int   start = 100;
            IDictionary <ReservationInterval, ReservationRequest> allocations = GenerateAllocation
                                                                                    (start, alloc, true);
            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] + i), (alloc[i] + i)), plan.GetTotalCommittedResources(start +
                                                                                                                             i));
                NUnit.Framework.Assert.AreEqual(Org.Apache.Hadoop.Yarn.Api.Records.Resource.NewInstance
                                                    (1024 * (alloc[i] + i), (alloc[i] + i)), plan.GetConsumptionForUser(user, start
                                                                                                                        + i));
            }
            // Now delete it
            try
            {
                plan.DeleteReservation(reservationID);
            }
            catch (PlanningException e)
            {
                NUnit.Framework.Assert.Fail(e.Message);
            }
            NUnit.Framework.Assert.IsNull(plan.GetReservationById(reservationID));
            for (int i_1 = 0; i_1 < alloc.Length; i_1++)
            {
                NUnit.Framework.Assert.AreEqual(Org.Apache.Hadoop.Yarn.Api.Records.Resource.NewInstance
                                                    (0, 0), plan.GetTotalCommittedResources(start + i_1));
                NUnit.Framework.Assert.AreEqual(Org.Apache.Hadoop.Yarn.Api.Records.Resource.NewInstance
                                                    (0, 0), plan.GetConsumptionForUser(user, start + i_1));
            }
        }
示例#2
0
        public virtual void TestDeleteNonExistingReservation()
        {
            Plan plan = new InMemoryPlan(queueMetrics, policy, agent, totalCapacity, 1L, resCalc
                                         , minAlloc, maxAlloc, planName, replanner, true);
            ReservationId reservationID = ReservationSystemTestUtil.GetNewReservationId();

            // Try to delete a reservation without adding
            NUnit.Framework.Assert.IsNull(plan.GetReservationById(reservationID));
            try
            {
                plan.DeleteReservation(reservationID);
                NUnit.Framework.Assert.Fail("Delete 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));
        }