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));
}
use of com.twitter.heron.spi.packing.PackingPlan in project heron by twitter.
the class HeronMasterDriverTest method scheduleHeronWorkersFailsOnDuplicateRequest.
@Test(expected = HeronMasterDriver.ContainerAllocationException.class)
public void scheduleHeronWorkersFailsOnDuplicateRequest() 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));
PackingPlan.ContainerPlan duplicatePlan = PackingTestUtils.testContainerPlan(1);
Set<PackingPlan.ContainerPlan> toBeAddedContainerPlans = new HashSet<>();
toBeAddedContainerPlans.add(duplicatePlan);
spyDriver.scheduleHeronWorkers(toBeAddedContainerPlans);
}
use of com.twitter.heron.spi.packing.PackingPlan in project heron by twitter.
the class MesosLauncherTest method testLaunch.
@Test
public void testLaunch() throws Exception {
MesosLauncher launcher = Mockito.spy(MesosLauncher.class);
PackingPlan packingPlan = Mockito.mock(PackingPlan.class);
Config config = Mockito.mock(Config.class);
Mockito.doReturn("working-dir").when(config).getStringValue(MesosContext.SCHEDULER_WORKING_DIRECTORY);
Config runtime = Mockito.mock(Config.class);
launcher.initialize(config, runtime);
// Failed to setup working dir
Mockito.doReturn(false).when(launcher).setupWorkingDirectory();
Assert.assertFalse(launcher.launch(packingPlan));
Mockito.doReturn(true).when(launcher).setupWorkingDirectory();
String[] mockCommand = new String[] { "mock", "scheduler", "command" };
Mockito.doReturn(mockCommand).when(launcher).getSchedulerCommand();
// Failed to spwan the process
Mockito.doReturn(null).when(launcher).startScheduler(mockCommand);
Assert.assertFalse(launcher.launch(packingPlan));
// Happy path
Process p = Mockito.mock(Process.class);
Mockito.doReturn(p).when(launcher).startScheduler(mockCommand);
Assert.assertTrue(launcher.launch(packingPlan));
}
Aggregations