Search in sources :

Example 6 with PackingPlan

use of com.twitter.heron.spi.packing.PackingPlan in project heron by twitter.

the class AuroraSchedulerTest method testOnSchedule.

/**
   * Tests that we can schedule
   */
@Test
public void testOnSchedule() throws Exception {
    AuroraController controller = Mockito.mock(AuroraController.class);
    doReturn(controller).when(scheduler).getController();
    SchedulerStateManagerAdaptor stateManager = mock(SchedulerStateManagerAdaptor.class);
    Config runtime = Mockito.mock(Config.class);
    when(runtime.get(Key.SCHEDULER_STATE_MANAGER_ADAPTOR)).thenReturn(stateManager);
    when(runtime.getStringValue(Key.TOPOLOGY_NAME)).thenReturn(TOPOLOGY_NAME);
    Config mConfig = Mockito.mock(Config.class);
    PowerMockito.mockStatic(Config.class);
    when(Config.toClusterMode(mConfig)).thenReturn(mConfig);
    when(mConfig.getStringValue(eq(AuroraContext.JOB_TEMPLATE), anyString())).thenReturn(AURORA_PATH);
    scheduler.initialize(mConfig, runtime);
    // Fail to schedule due to null PackingPlan
    Assert.assertFalse(scheduler.onSchedule(null));
    PackingPlan plan = new PackingPlan(PACKING_PLAN_ID, new HashSet<PackingPlan.ContainerPlan>());
    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(PackingTestUtils.testContainerPlan(CONTAINER_ID));
    PackingPlan validPlan = new PackingPlan(PACKING_PLAN_ID, containers);
    // Failed to create job via controller
    doReturn(false).when(controller).createJob(Matchers.anyMapOf(AuroraField.class, String.class));
    doReturn(true).when(stateManager).updatePackingPlan(any(PackingPlans.PackingPlan.class), eq(TOPOLOGY_NAME));
    Assert.assertFalse(scheduler.onSchedule(validPlan));
    Mockito.verify(controller).createJob(Matchers.anyMapOf(AuroraField.class, String.class));
    Mockito.verify(stateManager).updatePackingPlan(any(PackingPlans.PackingPlan.class), eq(TOPOLOGY_NAME));
    // Happy path
    doReturn(true).when(controller).createJob(Matchers.anyMapOf(AuroraField.class, String.class));
    assertTrue(scheduler.onSchedule(validPlan));
    Mockito.verify(controller, Mockito.times(2)).createJob(Matchers.anyMapOf(AuroraField.class, String.class));
    Mockito.verify(stateManager, Mockito.times(2)).updatePackingPlan(any(PackingPlans.PackingPlan.class), eq(TOPOLOGY_NAME));
}
Also used : Config(com.twitter.heron.spi.common.Config) PackingPlan(com.twitter.heron.spi.packing.PackingPlan) Matchers.anyString(org.mockito.Matchers.anyString) SchedulerStateManagerAdaptor(com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor) HashSet(java.util.HashSet) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 7 with PackingPlan

use of com.twitter.heron.spi.packing.PackingPlan in project heron by twitter.

the class LocalSchedulerTest method testRemoveContainer.

/**
   * Verify containers can be removed by Local Scheduler
   */
@Test
public void testRemoveContainer() throws Exception {
    final int LOCAL_NUM_CONTAINER = 6;
    //verify plan is deployed and containers are created
    Mockito.doNothing().when(scheduler).startExecutorMonitor(Mockito.anyInt(), Mockito.any(Process.class));
    Process[] processes = new Process[LOCAL_NUM_CONTAINER];
    Set<PackingPlan.ContainerPlan> existingContainers = new HashSet<>();
    for (int i = 0; i < LOCAL_NUM_CONTAINER; i++) {
        processes[i] = Mockito.mock(Process.class);
        Mockito.doReturn(processes[i]).when(scheduler).startExecutorProcess(i);
        if (i > 0) {
            // ignore the container for TMaster. existing containers simulate the containers created
            // by packing plan
            existingContainers.add(PackingTestUtils.testContainerPlan(i));
        }
    }
    PackingPlan packingPlan = Mockito.mock(PackingPlan.class);
    Mockito.when(packingPlan.getContainers()).thenReturn(existingContainers);
    Assert.assertTrue(scheduler.onSchedule(packingPlan));
    verifyIdsOfLaunchedContainers(0, 1, 2, 3, 4, 5);
    Mockito.verify(scheduler, Mockito.times(LOCAL_NUM_CONTAINER)).startExecutor(Mockito.anyInt());
    Set<PackingPlan.ContainerPlan> containersToRemove = new HashSet<>();
    PackingPlan.ContainerPlan containerToRemove = PackingTestUtils.testContainerPlan(LOCAL_NUM_CONTAINER - 1);
    containersToRemove.add(containerToRemove);
    scheduler.removeContainers(containersToRemove);
    verifyIdsOfLaunchedContainers(0, 1, 2, 3, 4);
    Mockito.verify(processes[LOCAL_NUM_CONTAINER - 1]).destroy();
    // verify no new process restarts
    Mockito.verify(scheduler, Mockito.times(LOCAL_NUM_CONTAINER)).startExecutor(Mockito.anyInt());
    containersToRemove.clear();
    containersToRemove.add(PackingTestUtils.testContainerPlan(1));
    containersToRemove.add(PackingTestUtils.testContainerPlan(2));
    scheduler.removeContainers(containersToRemove);
    verifyIdsOfLaunchedContainers(0, 3, 4);
    Mockito.verify(processes[1]).destroy();
    Mockito.verify(processes[2]).destroy();
    // verify no new process restarts
    Mockito.verify(scheduler, Mockito.times(LOCAL_NUM_CONTAINER)).startExecutor(Mockito.anyInt());
}
Also used : PackingPlan(com.twitter.heron.spi.packing.PackingPlan) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 8 with PackingPlan

use of com.twitter.heron.spi.packing.PackingPlan in project heron by twitter.

the class LocalSchedulerTest method testAddContainer.

@Test
public void testAddContainer() throws Exception {
    Mockito.when(runtime.getLongValue(Key.NUM_CONTAINERS)).thenReturn(2L);
    scheduler.initialize(config, runtime);
    //verify plan is deployed and containers are created
    Mockito.doNothing().when(scheduler).startExecutorMonitor(Mockito.anyInt(), Mockito.any(Process.class));
    Process mockProcessTM = Mockito.mock(Process.class);
    Mockito.doReturn(mockProcessTM).when(scheduler).startExecutorProcess(0);
    Process mockProcessWorker1 = Mockito.mock(Process.class);
    Mockito.doReturn(mockProcessWorker1).when(scheduler).startExecutorProcess(1);
    PackingPlan packingPlan = Mockito.mock(PackingPlan.class);
    Set<PackingPlan.ContainerPlan> containers = new HashSet<>();
    containers.add(PackingTestUtils.testContainerPlan(1));
    Mockito.when(packingPlan.getContainers()).thenReturn(containers);
    Assert.assertTrue(scheduler.onSchedule(packingPlan));
    Mockito.verify(scheduler, Mockito.times(2)).startExecutor(Mockito.anyInt());
    //now verify add container adds new container
    Process mockProcessWorker2 = Mockito.mock(Process.class);
    Mockito.doReturn(mockProcessWorker2).when(scheduler).startExecutorProcess(3);
    containers.clear();
    containers.add(PackingTestUtils.testContainerPlan(3));
    scheduler.addContainers(containers);
    Mockito.verify(scheduler).startExecutor(3);
    Process mockProcess = Mockito.mock(Process.class);
    Mockito.doReturn(mockProcess).when(scheduler).startExecutorProcess(Mockito.anyInt());
    containers.clear();
    containers.add(PackingTestUtils.testContainerPlan(4));
    containers.add(PackingTestUtils.testContainerPlan(5));
    scheduler.addContainers(containers);
    Mockito.verify(scheduler).startExecutor(4);
    Mockito.verify(scheduler).startExecutor(5);
}
Also used : PackingPlan(com.twitter.heron.spi.packing.PackingPlan) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 9 with PackingPlan

use of com.twitter.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(com.twitter.heron.spi.common.Config) PackingPlan(com.twitter.heron.spi.packing.PackingPlan) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 10 with PackingPlan

use of com.twitter.heron.spi.packing.PackingPlan in project heron by twitter.

the class UpdateTopologyManagerTest method init.

@Before
public void init() {
    Integer[] instanceIndexA = new Integer[] { 37, 48, 59 };
    Integer[] instanceIndexB = new Integer[] { 17, 22 };
    currentContainerPlan = buildContainerSet(new Integer[] { 1, 2, 3, 4 }, instanceIndexA);
    proposedContainerPlan = buildContainerSet(new Integer[] { 1, 3, 5, 6 }, instanceIndexB);
    expectedContainersToAdd = buildContainerSet(new Integer[] { 5, 6 }, instanceIndexB);
    expectedContainersToRemove = buildContainerSet(new Integer[] { 2, 4 }, instanceIndexA);
    PackingPlanProtoSerializer serializer = new PackingPlanProtoSerializer();
    PackingPlan currentPacking = new PackingPlan("current", currentContainerPlan);
    proposedPacking = new PackingPlan("proposed", proposedContainerPlan);
    currentProtoPlan = serializer.toProto(currentPacking);
    proposedProtoPlan = serializer.toProto(proposedPacking);
    testTopology = TopologyTests.createTopology(TOPOLOGY_NAME, new com.twitter.heron.api.Config(), "spoutname", "boltname", 1, 1);
    assertEquals(TopologyAPI.TopologyState.RUNNING, testTopology.getState());
}
Also used : PackingPlanProtoSerializer(com.twitter.heron.spi.packing.PackingPlanProtoSerializer) Config(com.twitter.heron.spi.common.Config) PackingPlan(com.twitter.heron.spi.packing.PackingPlan) Before(org.junit.Before)

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