Ejemplo n.º 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());
        }
Ejemplo n.º 2
0
 public virtual string ToCumulativeString()
 {
     readLock.Lock();
     try
     {
         return(rleSparseVector.ToString());
     }
     finally
     {
         readLock.Unlock();
     }
 }
Ejemplo n.º 3
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());
        }
        public override string ToString()
        {
            StringBuilder sBuf = new StringBuilder();

            sBuf.Append(GetReservationId()).Append(" user:"******" startTime: "
                                                                                      ).Append(GetStartTime()).Append(" endTime: ").Append(GetEndTime()).Append(" alloc:["
                                                                                                                                                                ).Append(resourcesOverTime.ToString()).Append("] ");
            return(sBuf.ToString());
        }