Search in sources :

Example 31 with PackingPlan

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));
}
Also used : PackingPlan(org.apache.heron.spi.packing.PackingPlan) Job(com.hashicorp.nomad.apimodel.Job) NomadApiClient(com.hashicorp.nomad.javasdk.NomadApiClient) HashSet(java.util.HashSet) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 32 with PackingPlan

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();
}
Also used : Config(org.apache.heron.spi.common.Config) PackingPlan(org.apache.heron.spi.packing.PackingPlan) LauncherUtils(org.apache.heron.scheduler.utils.LauncherUtils) IScheduler(org.apache.heron.spi.scheduler.IScheduler) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 33 with PackingPlan

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));
}
Also used : PackingPlan(org.apache.heron.spi.packing.PackingPlan) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 34 with PackingPlan

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();
}
Also used : Config(org.apache.heron.spi.common.Config) PackingPlan(org.apache.heron.spi.packing.PackingPlan) URI(java.net.URI) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 35 with PackingPlan

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());
}
Also used : Config(org.apache.heron.spi.common.Config) PackingPlan(org.apache.heron.spi.packing.PackingPlan) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

PackingPlan (org.apache.heron.spi.packing.PackingPlan)83 Test (org.junit.Test)43 HashSet (java.util.HashSet)32 Resource (org.apache.heron.spi.packing.Resource)18 Config (org.apache.heron.spi.common.Config)15 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)14 ByteAmount (org.apache.heron.common.basics.ByteAmount)13 HashMap (java.util.HashMap)10 SchedulerStateManagerAdaptor (org.apache.heron.spi.statemgr.SchedulerStateManagerAdaptor)9 TopologyAPI (org.apache.heron.api.generated.TopologyAPI)8 RoundRobinPacking (org.apache.heron.packing.roundrobin.RoundRobinPacking)7 InstanceId (org.apache.heron.spi.packing.InstanceId)7 Pair (org.apache.heron.common.basics.Pair)6 PackingPlans (org.apache.heron.proto.system.PackingPlans)6 PackingPlanProtoDeserializer (org.apache.heron.spi.packing.PackingPlanProtoDeserializer)6 ContainerPlan (org.apache.heron.spi.packing.PackingPlan.ContainerPlan)5 ArrayList (java.util.ArrayList)4 PackingPlanProtoSerializer (org.apache.heron.spi.packing.PackingPlanProtoSerializer)4 EvaluatorRequest (org.apache.reef.driver.evaluator.EvaluatorRequest)4 Before (org.junit.Before)3