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));
}
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());
}
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);
}
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());
}
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());
}
Aggregations