use of org.apache.heron.spi.packing.PackingPlan in project heron by twitter.
the class NomadSchedulerTest method testOnSchedule.
@Test
public void testOnSchedule() throws Exception {
PowerMockito.mockStatic(NomadScheduler.class);
Mockito.doReturn(new LinkedList<>()).when(scheduler).getJobs(Mockito.any(PackingPlan.class));
scheduler.initialize(this.mockConfig, this.mockRuntime);
// Fail to schedule due to null PackingPlan
Assert.assertFalse(scheduler.onSchedule(null));
PackingPlan pplan = new PackingPlan(PACKING_PLAN_ID, new HashSet<>());
Assert.assertTrue(pplan.getContainers().isEmpty());
// Fail to schedule due to PackingPlan is empty
Assert.assertFalse(scheduler.onSchedule(pplan));
Set<PackingPlan.ContainerPlan> containers = new HashSet<>();
containers.add(Mockito.mock(PackingPlan.ContainerPlan.class));
PackingPlan validPlan = new PackingPlan(PACKING_PLAN_ID, containers);
// Fail to submit due to client failure
Job[] jobs = { new Job(), new Job(), new Job() };
List<Job> jobList = Arrays.asList(jobs);
Mockito.doReturn(jobList).when(scheduler).getJobs(validPlan);
PowerMockito.doThrow(new RuntimeException()).when(NomadScheduler.class, "startJobs", Mockito.any(NomadApiClient.class), anyVararg());
Assert.assertFalse(scheduler.onSchedule(validPlan));
// Succeed
Mockito.doReturn(jobList).when(scheduler).getJobs(validPlan);
PowerMockito.doNothing().when(NomadScheduler.class, "startJobs", Mockito.any(NomadApiClient.class), anyVararg());
Assert.assertTrue(scheduler.onSchedule(validPlan));
}
use of org.apache.heron.spi.packing.PackingPlan in project heron by twitter.
the class SlurmLauncherTest method testLaunch.
/**
* Test slurm scheduler launcher
*/
@Test
public void testLaunch() throws Exception {
Config config = createRunnerConfig();
Config runtime = Mockito.mock(Config.class);
PackingPlan packingPlan = Mockito.mock(PackingPlan.class);
PackingPlan plan = new PackingPlan("plan.id", new HashSet<PackingPlan.ContainerPlan>());
PowerMockito.spy(SlurmContext.class);
PowerMockito.doReturn(WORKING_DIRECTORY).when(SlurmContext.class, "workingDirectory", config);
LauncherUtils mockLauncherUtils = Mockito.mock(LauncherUtils.class);
PowerMockito.spy(LauncherUtils.class);
PowerMockito.doReturn(mockLauncherUtils).when(LauncherUtils.class, "getInstance");
SlurmLauncher slurmLauncher = Mockito.spy(new SlurmLauncher());
slurmLauncher.initialize(config, runtime);
SlurmScheduler slurmScheduler = Mockito.spy(new SlurmScheduler());
PowerMockito.doReturn(true).when(slurmScheduler).onSchedule(plan);
// Failed to download
Mockito.doReturn(false).when(slurmLauncher).setupWorkingDirectory();
Assert.assertFalse(slurmLauncher.launch(packingPlan));
Mockito.verify(slurmLauncher).setupWorkingDirectory();
// Failed to schedule
Mockito.when(mockLauncherUtils.onScheduleAsLibrary(Mockito.any(Config.class), Mockito.any(Config.class), Mockito.any(IScheduler.class), Mockito.any(PackingPlan.class))).thenReturn(false);
PowerMockito.doReturn(true).when(slurmLauncher).setupWorkingDirectory();
Assert.assertFalse(slurmLauncher.launch(Mockito.mock(PackingPlan.class)));
Mockito.verify(mockLauncherUtils).onScheduleAsLibrary(Mockito.any(Config.class), Mockito.any(Config.class), Mockito.any(IScheduler.class), Mockito.any(PackingPlan.class));
// happy path
Mockito.when(mockLauncherUtils.onScheduleAsLibrary(Mockito.any(Config.class), Mockito.any(Config.class), Mockito.any(IScheduler.class), Mockito.any(PackingPlan.class))).thenReturn(true);
Assert.assertTrue(slurmLauncher.launch(Mockito.mock(PackingPlan.class)));
Mockito.verify(slurmLauncher, Mockito.times(3)).launch(Mockito.any(PackingPlan.class));
Mockito.verify(mockLauncherUtils, Mockito.times(2)).onScheduleAsLibrary(Mockito.any(Config.class), Mockito.any(Config.class), Mockito.any(IScheduler.class), Mockito.any(PackingPlan.class));
slurmLauncher.close();
}
use of org.apache.heron.spi.packing.PackingPlan in project heron by twitter.
the class KubernetesSchedulerTest method testOnSchedule.
@Test
public void testOnSchedule() throws Exception {
KubernetesController controller = Mockito.mock(KubernetesController.class);
Mockito.doReturn(controller).when(scheduler).getController();
scheduler.initialize(config, mockRuntime);
// Fail to schedule due to null PackingPlan
Assert.assertFalse(scheduler.onSchedule(null));
PackingPlan pplan = new PackingPlan(PACKING_PLAN_ID, new HashSet<>());
Assert.assertTrue(pplan.getContainers().isEmpty());
// Fail to schedule due to PackingPlan is empty
Assert.assertFalse(scheduler.onSchedule(pplan));
Set<PackingPlan.ContainerPlan> containers = new HashSet<>();
containers.add(Mockito.mock(PackingPlan.ContainerPlan.class));
PackingPlan validPlan = new PackingPlan(PACKING_PLAN_ID, containers);
// Failed to submit topology due to controller failure
Mockito.doReturn(false).when(controller).submit(Mockito.any(PackingPlan.class));
Assert.assertFalse(scheduler.onSchedule(validPlan));
Mockito.verify(controller).submit(Mockito.any(PackingPlan.class));
// Succeed to submit topology
Mockito.doReturn(true).when(controller).submit(Mockito.any(PackingPlan.class));
Assert.assertTrue(scheduler.onSchedule(validPlan));
Mockito.verify(controller, Mockito.times(2)).submit(Mockito.any(PackingPlan.class));
}
use of org.apache.heron.spi.packing.PackingPlan in project heron by twitter.
the class LocalLauncherTest method testLaunch.
@Test
public void testLaunch() throws Exception {
Config config = createRunnerConfig();
Config runtime = Mockito.mock(Config.class);
URI mockURI = new URI("h:a");
Mockito.doReturn(mockURI).when(runtime).get(Key.TOPOLOGY_PACKAGE_URI);
PackingPlan packingPlan = Mockito.mock(PackingPlan.class);
PowerMockito.spy(LocalContext.class);
PowerMockito.doReturn(WORKING_DIRECTORY).when(LocalContext.class, "workingDirectory", config);
LocalLauncher localLauncher = Mockito.spy(new LocalLauncher());
localLauncher.initialize(config, runtime);
// Failed to setup working directory
Mockito.doReturn(false).when(localLauncher).setupWorkingDirectoryAndExtractPackages();
Assert.assertFalse(localLauncher.launch(packingPlan));
// setup successfully
Mockito.doReturn(true).when(localLauncher).setupWorkingDirectoryAndExtractPackages();
String[] expectedSchedulerCommand = { "expected", "scheduler", "command" };
Mockito.doReturn(expectedSchedulerCommand).when(localLauncher).getSchedulerCommand();
// Failed to start the Scheduler Process
Mockito.doReturn(null).when(localLauncher).startScheduler(Mockito.any(String[].class));
Assert.assertFalse(localLauncher.launch(packingPlan));
Mockito.verify(localLauncher).startScheduler(expectedSchedulerCommand);
// Happy path
Mockito.doReturn(Mockito.mock(Process.class)).when(localLauncher).startScheduler(Mockito.any(String[].class));
Assert.assertTrue(localLauncher.launch(packingPlan));
Mockito.verify(localLauncher, Mockito.times(2)).startScheduler(expectedSchedulerCommand);
localLauncher.close();
}
use of org.apache.heron.spi.packing.PackingPlan in project heron by twitter.
the class MarathonSchedulerTest method testOnSchedule.
@Test
public void testOnSchedule() throws Exception {
MarathonController controller = Mockito.mock(MarathonController.class);
Mockito.doReturn(controller).when(scheduler).getController();
Mockito.doReturn(TOPOLOGY_CONF).when(scheduler).getTopologyConf(Mockito.any(PackingPlan.class));
scheduler.initialize(Mockito.mock(Config.class), Mockito.mock(Config.class));
// Fail to schedule due to null PackingPlan
Assert.assertFalse(scheduler.onSchedule(null));
PackingPlan pplan = new PackingPlan(PACKING_PLAN_ID, new HashSet<PackingPlan.ContainerPlan>());
Assert.assertTrue(pplan.getContainers().isEmpty());
// Fail to schedule due to PackingPlan is empty
Assert.assertFalse(scheduler.onSchedule(pplan));
Set<PackingPlan.ContainerPlan> containers = new HashSet<>();
containers.add(Mockito.mock(PackingPlan.ContainerPlan.class));
PackingPlan validPlan = new PackingPlan(PACKING_PLAN_ID, containers);
// Failed to submit topology due to controller failure
Mockito.doReturn(false).when(controller).submitTopology(Mockito.anyString());
Assert.assertFalse(scheduler.onSchedule(validPlan));
Mockito.verify(controller).submitTopology(Matchers.anyString());
// Succeed to submit topology
Mockito.doReturn(true).when(controller).submitTopology(Mockito.anyString());
Assert.assertTrue(scheduler.onSchedule(validPlan));
Mockito.verify(controller, Mockito.times(2)).submitTopology(Matchers.anyString());
}
Aggregations