Exemple #1
0
        public virtual void TestSteps()
        {
            ResourceCalculator resCalc = new DefaultResourceCalculator();

            Org.Apache.Hadoop.Yarn.Api.Records.Resource minAlloc = Org.Apache.Hadoop.Yarn.Api.Records.Resource
                                                                   .NewInstance(1, 1);
            RLESparseResourceAllocation rleSparseVector = new RLESparseResourceAllocation(resCalc
                                                                                          , minAlloc);

            int[] alloc = new int[] { 10, 10, 10, 10, 10, 10 };
            int   start = 100;
            ICollection <KeyValuePair <ReservationInterval, ReservationRequest> > inputs = GenerateAllocation
                                                                                               (start, alloc, true);

            foreach (KeyValuePair <ReservationInterval, ReservationRequest> ip in inputs)
            {
                rleSparseVector.AddInterval(ip.Key, ip.Value);
            }
            Log.Info(rleSparseVector.ToString());
            NUnit.Framework.Assert.IsFalse(rleSparseVector.IsEmpty());
            NUnit.Framework.Assert.AreEqual(Org.Apache.Hadoop.Yarn.Api.Records.Resource.NewInstance
                                                (0, 0), rleSparseVector.GetCapacityAtTime(99));
            NUnit.Framework.Assert.AreEqual(Org.Apache.Hadoop.Yarn.Api.Records.Resource.NewInstance
                                                (0, 0), rleSparseVector.GetCapacityAtTime(start + alloc.Length + 1));
            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)), rleSparseVector.GetCapacityAtTime(start
                                                                                                                               + i));
            }
            NUnit.Framework.Assert.AreEqual(Org.Apache.Hadoop.Yarn.Api.Records.Resource.NewInstance
                                                (0, 0), rleSparseVector.GetCapacityAtTime(start + alloc.Length + 2));
            foreach (KeyValuePair <ReservationInterval, ReservationRequest> ip_1 in inputs)
            {
                rleSparseVector.RemoveInterval(ip_1.Key, ip_1.Value);
            }
            Log.Info(rleSparseVector.ToString());
            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), rleSparseVector.GetCapacityAtTime(start + i_1));
            }
            NUnit.Framework.Assert.IsTrue(rleSparseVector.IsEmpty());
        }
Exemple #2
0
        public virtual void TestZeroAlloaction()
        {
            ResourceCalculator resCalc = new DefaultResourceCalculator();

            Org.Apache.Hadoop.Yarn.Api.Records.Resource minAlloc = Org.Apache.Hadoop.Yarn.Api.Records.Resource
                                                                   .NewInstance(1, 1);
            RLESparseResourceAllocation rleSparseVector = new RLESparseResourceAllocation(resCalc
                                                                                          , minAlloc);

            rleSparseVector.AddInterval(new ReservationInterval(0, long.MaxValue), ReservationRequest
                                        .NewInstance(Org.Apache.Hadoop.Yarn.Api.Records.Resource.NewInstance(0, 0), (0))
                                        );
            Log.Info(rleSparseVector.ToString());
            NUnit.Framework.Assert.AreEqual(Org.Apache.Hadoop.Yarn.Api.Records.Resource.NewInstance
                                                (0, 0), rleSparseVector.GetCapacityAtTime(new Random().NextLong()));
            NUnit.Framework.Assert.IsTrue(rleSparseVector.IsEmpty());
        }
Exemple #3
0
        private void DecrementAllocation(ReservationAllocation reservation)
        {
            System.Diagnostics.Debug.Assert((readWriteLock.IsWriteLockedByCurrentThread()));
            IDictionary <ReservationInterval, ReservationRequest> allocationRequests = reservation
                                                                                       .GetAllocationRequests();
            string user = reservation.GetUser();
            RLESparseResourceAllocation resAlloc = userResourceAlloc[user];

            foreach (KeyValuePair <ReservationInterval, ReservationRequest> r in allocationRequests)
            {
                resAlloc.RemoveInterval(r.Key, r.Value);
                rleSparseVector.RemoveInterval(r.Key, r.Value);
            }
            if (resAlloc.IsEmpty())
            {
                Sharpen.Collections.Remove(userResourceAlloc, user);
            }
        }