public virtual void TestNormalizeRequestWithDominantResourceCalculator() { ResourceCalculator resourceCalculator = new DominantResourceCalculator(); Org.Apache.Hadoop.Yarn.Api.Records.Resource minResource = Resources.CreateResource (1024, 1); Org.Apache.Hadoop.Yarn.Api.Records.Resource maxResource = Resources.CreateResource (10240, 10); Org.Apache.Hadoop.Yarn.Api.Records.Resource clusterResource = Resources.CreateResource (10 * 1024, 10); ResourceRequest ask = new ResourceRequestPBImpl(); // case negative memory/vcores ask.SetCapability(Resources.CreateResource(-1024, -1)); SchedulerUtils.NormalizeRequest(ask, resourceCalculator, clusterResource, minResource , maxResource); NUnit.Framework.Assert.AreEqual(minResource, ask.GetCapability()); // case zero memory/vcores ask.SetCapability(Resources.CreateResource(0, 0)); SchedulerUtils.NormalizeRequest(ask, resourceCalculator, clusterResource, minResource , maxResource); NUnit.Framework.Assert.AreEqual(minResource, ask.GetCapability()); NUnit.Framework.Assert.AreEqual(1, ask.GetCapability().GetVirtualCores()); NUnit.Framework.Assert.AreEqual(1024, ask.GetCapability().GetMemory()); // case non-zero memory & zero cores ask.SetCapability(Resources.CreateResource(1536, 0)); SchedulerUtils.NormalizeRequest(ask, resourceCalculator, clusterResource, minResource , maxResource); NUnit.Framework.Assert.AreEqual(Resources.CreateResource(2048, 1), ask.GetCapability ()); NUnit.Framework.Assert.AreEqual(1, ask.GetCapability().GetVirtualCores()); NUnit.Framework.Assert.AreEqual(2048, ask.GetCapability().GetMemory()); }
public virtual void TestNormalizeRequest() { ResourceCalculator resourceCalculator = new DefaultResourceCalculator(); int minMemory = 1024; int maxMemory = 8192; Org.Apache.Hadoop.Yarn.Api.Records.Resource minResource = Resources.CreateResource (minMemory, 0); Org.Apache.Hadoop.Yarn.Api.Records.Resource maxResource = Resources.CreateResource (maxMemory, 0); ResourceRequest ask = new ResourceRequestPBImpl(); // case negative memory ask.SetCapability(Resources.CreateResource(-1024)); SchedulerUtils.NormalizeRequest(ask, resourceCalculator, null, minResource, maxResource ); NUnit.Framework.Assert.AreEqual(minMemory, ask.GetCapability().GetMemory()); // case zero memory ask.SetCapability(Resources.CreateResource(0)); SchedulerUtils.NormalizeRequest(ask, resourceCalculator, null, minResource, maxResource ); NUnit.Framework.Assert.AreEqual(minMemory, ask.GetCapability().GetMemory()); // case memory is a multiple of minMemory ask.SetCapability(Resources.CreateResource(2 * minMemory)); SchedulerUtils.NormalizeRequest(ask, resourceCalculator, null, minResource, maxResource ); NUnit.Framework.Assert.AreEqual(2 * minMemory, ask.GetCapability().GetMemory()); // case memory is not a multiple of minMemory ask.SetCapability(Resources.CreateResource(minMemory + 10)); SchedulerUtils.NormalizeRequest(ask, resourceCalculator, null, minResource, maxResource ); NUnit.Framework.Assert.AreEqual(2 * minMemory, ask.GetCapability().GetMemory()); // case memory is equal to max allowed ask.SetCapability(Resources.CreateResource(maxMemory)); SchedulerUtils.NormalizeRequest(ask, resourceCalculator, null, minResource, maxResource ); NUnit.Framework.Assert.AreEqual(maxMemory, ask.GetCapability().GetMemory()); // case memory is just less than max ask.SetCapability(Resources.CreateResource(maxMemory - 10)); SchedulerUtils.NormalizeRequest(ask, resourceCalculator, null, minResource, maxResource ); NUnit.Framework.Assert.AreEqual(maxMemory, ask.GetCapability().GetMemory()); // max is not a multiple of min maxResource = Resources.CreateResource(maxMemory - 10, 0); ask.SetCapability(Resources.CreateResource(maxMemory - 100)); // multiple of minMemory > maxMemory, then reduce to maxMemory SchedulerUtils.NormalizeRequest(ask, resourceCalculator, null, minResource, maxResource ); NUnit.Framework.Assert.AreEqual(maxResource.GetMemory(), ask.GetCapability().GetMemory ()); // ask is more than max maxResource = Resources.CreateResource(maxMemory, 0); ask.SetCapability(Resources.CreateResource(maxMemory + 100)); SchedulerUtils.NormalizeRequest(ask, resourceCalculator, null, minResource, maxResource ); NUnit.Framework.Assert.AreEqual(maxResource.GetMemory(), ask.GetCapability().GetMemory ()); }