use of org.apache.myriad.scheduler.offer.OfferBuilder in project incubator-myriad by apache.
the class TestResourceOfferContainer method testResouceOfferContainerForNMWithRole.
@Test
public void testResouceOfferContainerForNMWithRole() {
Protos.Offer offer = new OfferBuilder("test.com").addScalarResource("cpus", 2.0).addScalarResource("mem", 8000).addScalarResource("cpus", "test", 4.0).addScalarResource("mem", "test", 32000.0).addRangeResource("ports", 3500, 3600).addRangeResource("ports", "test", 1500, 1600).build();
Map<String, Long> ports = new HashMap<>(4);
ports.put("test1.address", 0L);
ports.put("test2.address", 0L);
ports.put("test3.address", 1500L);
ports.put("test4.port", 3502L);
ServiceResourceProfile profile1 = new ExtendedResourceProfile(new NMProfile("small", 2L, 8000L), .2, 1024.0, ports);
ResourceOfferContainer roc = new ResourceOfferContainer(offer, profile1, "test");
assertTrue(roc.getHostName().equals("test.com"));
assertTrue("Should be satisfied if offer contains request", roc.satisfies(profile1));
ServiceResourceProfile profile2 = new ExtendedResourceProfile(new NMProfile("tooMuchCpu", 7L, 8000L), .2, 1024.0, ports);
roc = new ResourceOfferContainer(offer, profile2, "test");
assertFalse("Should be unsatisfied if too much cpu requested", roc.satisfies(profile2));
ServiceResourceProfile profile3 = new ExtendedResourceProfile(new NMProfile("tooMuchMem", 3L, 50000L), .2, 1024.0, ports);
roc = new ResourceOfferContainer(offer, profile3, "test");
assertFalse("Should be unsatisfied if too much memory requested", roc.satisfies(profile3));
ports.put("test.bad.address", 32000L);
ServiceResourceProfile profile4 = new ExtendedResourceProfile(new NMProfile("portOutOfRange", 3L, 50000L), .2, 1024.0, ports);
roc = new ResourceOfferContainer(offer, profile4, "test");
assertFalse("Should be unsatisfied if port not in range", roc.satisfies(profile4));
List<Protos.Resource> resources = roc.consumeCpus(4.5);
assertTrue("Resource List should be of size to when requesting 4.1 cpus", (resources.size() == 2));
assertTrue("Cpus should be decreased", roc.getCpus() <= 1.5);
List<Protos.Resource> resources1 = roc.consumeCpus(1.5);
assertTrue("Resource List should be of size 1", resources1.size() == 1);
assertTrue("All cpu resources should be consumed", roc.getCpus() <= 0.0);
}
Aggregations