Search in sources :

Example 81 with PackingPlan

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

Example 82 with PackingPlan

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());
    }
}
Also used : PackingPlan(com.twitter.heron.spi.packing.PackingPlan) EvaluatorRequest(org.apache.reef.driver.evaluator.EvaluatorRequest) HashSet(java.util.HashSet) AllocatedEvaluator(org.apache.reef.driver.evaluator.AllocatedEvaluator) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 83 with PackingPlan

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));
}
Also used : RoundRobinPacking(com.twitter.heron.packing.roundrobin.RoundRobinPacking) PackingPlan(com.twitter.heron.spi.packing.PackingPlan) EvaluatorRequest(org.apache.reef.driver.evaluator.EvaluatorRequest) HashSet(java.util.HashSet) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 84 with PackingPlan

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);
}
Also used : RoundRobinPacking(com.twitter.heron.packing.roundrobin.RoundRobinPacking) PackingPlan(com.twitter.heron.spi.packing.PackingPlan) EvaluatorRequest(org.apache.reef.driver.evaluator.EvaluatorRequest) HashSet(java.util.HashSet) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 85 with PackingPlan

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

Aggregations

PackingPlan (com.twitter.heron.spi.packing.PackingPlan)87 Test (org.junit.Test)63 TopologyAPI (com.twitter.heron.api.generated.TopologyAPI)34 ByteAmount (com.twitter.heron.common.basics.ByteAmount)27 HashSet (java.util.HashSet)22 HashMap (java.util.HashMap)20 Config (com.twitter.heron.spi.common.Config)18 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)13 Resource (com.twitter.heron.spi.packing.Resource)10 InstanceId (com.twitter.heron.spi.packing.InstanceId)7 SchedulerStateManagerAdaptor (com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor)7 Pair (com.twitter.heron.common.basics.Pair)6 RoundRobinPacking (com.twitter.heron.packing.roundrobin.RoundRobinPacking)5 PackingPlanProtoDeserializer (com.twitter.heron.spi.packing.PackingPlanProtoDeserializer)4 EvaluatorRequest (org.apache.reef.driver.evaluator.EvaluatorRequest)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 PackingPlans (com.twitter.heron.proto.system.PackingPlans)3 LauncherUtils (com.twitter.heron.scheduler.utils.LauncherUtils)3 ContainerPlan (com.twitter.heron.spi.packing.PackingPlan.ContainerPlan)3 PackingPlanProtoSerializer (com.twitter.heron.spi.packing.PackingPlanProtoSerializer)3