Пример #1
0
        public virtual void TestAddReservation()
        {
            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, 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));
            }
        }
Пример #2
0
        public virtual void TestArchiveCompletedReservations()
        {
            Plan plan = new InMemoryPlan(queueMetrics, policy, agent, totalCapacity, 1L, resCalc
                                         , minAlloc, maxAlloc, planName, replanner, true);
            ReservationId reservationID1 = ReservationSystemTestUtil.GetNewReservationId();

            // First add a reservation
            int[] alloc1 = new int[] { 10, 10, 10, 10, 10, 10 };
            int   start  = 100;
            IDictionary <ReservationInterval, ReservationRequest> allocations1 = GenerateAllocation
                                                                                     (start, alloc1, false);
            ReservationDefinition rDef1 = CreateSimpleReservationDefinition(start, start + alloc1
                                                                            .Length, alloc1.Length, allocations1.Values);
            ReservationAllocation rAllocation = new InMemoryReservationAllocation(reservationID1
                                                                                  , rDef1, user, planName, start, start + alloc1.Length, allocations1, resCalc, minAlloc
                                                                                  );

            NUnit.Framework.Assert.IsNull(plan.GetReservationById(reservationID1));
            try
            {
                plan.AddReservation(rAllocation);
            }
            catch (PlanningException e)
            {
                NUnit.Framework.Assert.Fail(e.Message);
            }
            DoAssertions(plan, rAllocation);
            for (int i = 0; i < alloc1.Length; i++)
            {
                NUnit.Framework.Assert.AreEqual(Org.Apache.Hadoop.Yarn.Api.Records.Resource.NewInstance
                                                    (1024 * (alloc1[i]), (alloc1[i])), plan.GetTotalCommittedResources(start + i));
                NUnit.Framework.Assert.AreEqual(Org.Apache.Hadoop.Yarn.Api.Records.Resource.NewInstance
                                                    (1024 * (alloc1[i]), (alloc1[i])), plan.GetConsumptionForUser(user, start + i));
            }
            // Now add another one
            ReservationId reservationID2 = ReservationSystemTestUtil.GetNewReservationId();

            int[] alloc2 = new int[] { 0, 5, 10, 5, 0 };
            IDictionary <ReservationInterval, ReservationRequest> allocations2 = GenerateAllocation
                                                                                     (start, alloc2, true);
            ReservationDefinition rDef2 = CreateSimpleReservationDefinition(start, start + alloc2
                                                                            .Length, alloc2.Length, allocations2.Values);

            rAllocation = new InMemoryReservationAllocation(reservationID2, rDef2, user, planName
                                                            , start, start + alloc2.Length, allocations2, resCalc, minAlloc);
            NUnit.Framework.Assert.IsNull(plan.GetReservationById(reservationID2));
            try
            {
                plan.AddReservation(rAllocation);
            }
            catch (PlanningException e)
            {
                NUnit.Framework.Assert.Fail(e.Message);
            }
            NUnit.Framework.Assert.IsNotNull(plan.GetReservationById(reservationID2));
            for (int i_1 = 0; i_1 < alloc2.Length; i_1++)
            {
                NUnit.Framework.Assert.AreEqual(Org.Apache.Hadoop.Yarn.Api.Records.Resource.NewInstance
                                                    (1024 * (alloc1[i_1] + alloc2[i_1] + i_1), alloc1[i_1] + alloc2[i_1] + i_1), plan
                                                .GetTotalCommittedResources(start + i_1));
                NUnit.Framework.Assert.AreEqual(Org.Apache.Hadoop.Yarn.Api.Records.Resource.NewInstance
                                                    (1024 * (alloc1[i_1] + alloc2[i_1] + i_1), alloc1[i_1] + alloc2[i_1] + i_1), plan
                                                .GetConsumptionForUser(user, start + i_1));
            }
            // Now archive completed reservations
            Org.Mockito.Mockito.When(clock.GetTime()).ThenReturn(106L);
            Org.Mockito.Mockito.When(policy.GetValidWindow()).ThenReturn(1L);
            try
            {
                // will only remove 2nd reservation as only that has fallen out of the
                // archival window
                plan.ArchiveCompletedReservations(clock.GetTime());
            }
            catch (PlanningException e)
            {
                NUnit.Framework.Assert.Fail(e.Message);
            }
            NUnit.Framework.Assert.IsNotNull(plan.GetReservationById(reservationID1));
            NUnit.Framework.Assert.IsNull(plan.GetReservationById(reservationID2));
            for (int i_2 = 0; i_2 < alloc1.Length; i_2++)
            {
                NUnit.Framework.Assert.AreEqual(Org.Apache.Hadoop.Yarn.Api.Records.Resource.NewInstance
                                                    (1024 * (alloc1[i_2]), (alloc1[i_2])), plan.GetTotalCommittedResources(start + i_2
                                                                                                                           ));
                NUnit.Framework.Assert.AreEqual(Org.Apache.Hadoop.Yarn.Api.Records.Resource.NewInstance
                                                    (1024 * (alloc1[i_2]), (alloc1[i_2])), plan.GetConsumptionForUser(user, start +
                                                                                                                      i_2));
            }
            Org.Mockito.Mockito.When(clock.GetTime()).ThenReturn(107L);
            try
            {
                // will remove 1st reservation also as it has fallen out of the archival
                // window
                plan.ArchiveCompletedReservations(clock.GetTime());
            }
            catch (PlanningException e)
            {
                NUnit.Framework.Assert.Fail(e.Message);
            }
            NUnit.Framework.Assert.IsNull(plan.GetReservationById(reservationID1));
            for (int i_3 = 0; i_3 < alloc1.Length; i_3++)
            {
                NUnit.Framework.Assert.AreEqual(Org.Apache.Hadoop.Yarn.Api.Records.Resource.NewInstance
                                                    (0, 0), plan.GetTotalCommittedResources(start + i_3));
                NUnit.Framework.Assert.AreEqual(Org.Apache.Hadoop.Yarn.Api.Records.Resource.NewInstance
                                                    (0, 0), plan.GetConsumptionForUser(user, start + i_3));
            }
        }