use of com.twitter.heron.spi.packing.PackingPlan in project heron by twitter.
the class ResourceCompliantRRPackingTest method removeFirstContainer.
/**
* Test the scenario where the scaling down is requested and the first container is removed
*/
@Test
public void removeFirstContainer() throws Exception {
int spoutScalingDown = -3;
int boltScalingDown = -3;
/* The packing plan consists of two containers. The first one contains 2 spouts and 2 bolts
the second one contains 2 spouts and 1 bolt. During scaling we remove 3 spouts and 3 bolts
and thus the first container is removed.
*/
Map<String, Integer> componentChanges = new HashMap<>();
//leave 1 spout
componentChanges.put(SPOUT_NAME, spoutScalingDown);
//leave 1 bolt
componentChanges.put(BOLT_NAME, boltScalingDown);
int numContainersBeforeRepack = 2;
PackingPlan newPackingPlan = doDefaultScalingTest(componentChanges, numContainersBeforeRepack);
Assert.assertEquals(1, newPackingPlan.getContainers().size());
Assert.assertEquals((Integer) (totalInstances + spoutScalingDown + boltScalingDown), newPackingPlan.getInstanceCount());
AssertPacking.assertNumInstances(newPackingPlan.getContainers(), BOLT_NAME, 0);
AssertPacking.assertNumInstances(newPackingPlan.getContainers(), SPOUT_NAME, 1);
}
use of com.twitter.heron.spi.packing.PackingPlan in project heron by twitter.
the class PackingTestUtils method testProtoPackingPlan.
public static PackingPlans.PackingPlan testProtoPackingPlan(String topologyName, IPacking packing) {
PackingPlan plan = testPackingPlan(topologyName, packing);
PackingPlanProtoSerializer serializer = new PackingPlanProtoSerializer();
return serializer.toProto(plan);
}
use of com.twitter.heron.spi.packing.PackingPlan in project heron by twitter.
the class SlurmSchedulerTest method testOnSchedule.
/**
* Test the schedule method
* @throws Exception
*/
@Test
public void testOnSchedule() throws Exception {
SlurmController controller = Mockito.mock(SlurmController.class);
Mockito.doReturn(controller).when(scheduler).getController();
Config config = createRunnerConfig();
Config runtime = Mockito.mock(Config.class);
PowerMockito.spy(SlurmContext.class);
PowerMockito.doReturn(WORKING_DIRECTORY).when(SlurmContext.class, "workingDirectory", config);
scheduler.initialize(config, runtime);
// Fail to schedule due to null PackingPlan
Assert.assertFalse(scheduler.onSchedule(null));
PackingPlan plan = new PackingPlan(PACKING_PLAN_ID, new HashSet<PackingPlan.ContainerPlan>());
Assert.assertTrue(plan.getContainers().isEmpty());
// Fail to schedule due to PackingPlan is empty
Assert.assertFalse(scheduler.onSchedule(plan));
// Construct valid PackingPlan
Set<PackingPlan.ContainerPlan> containers = new HashSet<>();
containers.add(Mockito.mock(PackingPlan.ContainerPlan.class));
PackingPlan validPlan = new PackingPlan(PACKING_PLAN_ID, containers);
// Failed to create job via controller
Mockito.doReturn(false).when(controller).createJob(Mockito.anyString(), Mockito.anyString(), Matchers.any(String[].class), Mockito.anyString(), Mockito.anyInt());
Assert.assertFalse(scheduler.onSchedule(validPlan));
Mockito.verify(controller).createJob(Mockito.eq(SLURM_PATH), Mockito.anyString(), Matchers.any(String[].class), Mockito.anyString(), Mockito.anyInt());
// Happy path
Mockito.doReturn(true).when(controller).createJob(Mockito.anyString(), Mockito.anyString(), Matchers.any(String[].class), Mockito.anyString(), Mockito.anyInt());
Assert.assertTrue(scheduler.onSchedule(validPlan));
Mockito.verify(controller, Mockito.times(2)).createJob(Mockito.anyString(), Mockito.anyString(), Matchers.any(String[].class), Mockito.anyString(), Mockito.anyInt());
}
use of com.twitter.heron.spi.packing.PackingPlan in project heron by twitter.
the class HeronMasterDriverTest method killWorkersTerminatesSpecificContainers.
@Test
public void killWorkersTerminatesSpecificContainers() throws Exception {
int numContainers = 5;
Set<PackingPlan.ContainerPlan> containers = new HashSet<>();
for (int id = 0; id < numContainers; id++) {
containers.add(PackingTestUtils.testContainerPlan(id));
}
PackingPlan packingPlan = new PackingPlan("packing", containers);
spyDriver.scheduleHeronWorkers(packingPlan);
for (int id = 0; id < numContainers; id++) {
verify(spyDriver, times(1)).requestContainerForWorker(eq(id), anyHeronWorker());
assertTrue(spyDriver.lookupByContainerPlan(id).isPresent());
}
verify(mockRequestor, times(numContainers)).submit(any(EvaluatorRequest.class));
AllocatedEvaluator[] mockEvaluators = createApplicationWithContainers(numContainers);
Set<PackingPlan.ContainerPlan> containersTobeDeleted = new HashSet<>();
containersTobeDeleted.add(PackingTestUtils.testContainerPlan(2));
containersTobeDeleted.add(PackingTestUtils.testContainerPlan(3));
spyDriver.killWorkers(containersTobeDeleted);
for (int id = 0; id < numContainers; id++) {
if (id == 2 || id == 3) {
verify(mockEvaluators[id], times(1)).close();
assertFalse(spyDriver.lookupByContainerPlan(id).isPresent());
assertFalse(spyDriver.lookupByEvaluatorId("e" + id).isPresent());
continue;
}
verify(mockEvaluators[id], never()).close();
assertTrue(spyDriver.lookupByContainerPlan(id).isPresent());
assertTrue(spyDriver.lookupByEvaluatorId("e" + id).isPresent());
}
}
use of com.twitter.heron.spi.packing.PackingPlan in project heron by twitter.
the class HeronMasterDriverTest method scheduleHeronWorkersAddsContainers.
@Test
public void scheduleHeronWorkersAddsContainers() throws Exception {
PackingPlan packingPlan = PackingTestUtils.testPackingPlan("test", new RoundRobinPacking());
spyDriver.scheduleHeronWorkers(packingPlan);
verify(spyDriver, times(1)).requestContainerForWorker(eq(1), anyHeronWorker());
verify(mockRequestor, times(1)).submit(any(EvaluatorRequest.class));
Set<PackingPlan.ContainerPlan> toBeAddedContainerPlans = new HashSet<>();
toBeAddedContainerPlans.add(PackingTestUtils.testContainerPlan(2));
toBeAddedContainerPlans.add(PackingTestUtils.testContainerPlan(3));
spyDriver.scheduleHeronWorkers(toBeAddedContainerPlans);
verify(spyDriver, times(1)).requestContainerForWorker(eq(2), anyHeronWorker());
verify(spyDriver, times(1)).requestContainerForWorker(eq(3), anyHeronWorker());
verify(mockRequestor, times(3)).submit(any(EvaluatorRequest.class));
}
Aggregations