use of com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor in project incubator-heron by apache.
the class RuntimeManagerMainTest method testValidateRuntimeManageOk.
@Test
public void testValidateRuntimeManageOk() throws TopologyRuntimeManagementException {
SchedulerStateManagerAdaptor adaptor = mock(SchedulerStateManagerAdaptor.class);
RuntimeManagerMain runtimeManagerMain = new RuntimeManagerMain(config, MOCK_COMMAND);
when(adaptor.isTopologyRunning(eq(TOPOLOGY_NAME))).thenReturn(true);
ExecutionEnvironment.ExecutionState.Builder stateBuilder = ExecutionEnvironment.ExecutionState.newBuilder().setTopologyName(TOPOLOGY_NAME).setTopologyId(TOPOLOGY_ID).setCluster(CLUSTER).setEnviron(ENVIRON);
// Matched
ExecutionEnvironment.ExecutionState correctState = stateBuilder.setRole(ROLE).build();
when(adaptor.getExecutionState(eq(TOPOLOGY_NAME))).thenReturn(correctState);
runtimeManagerMain.validateRuntimeManage(adaptor, TOPOLOGY_NAME);
}
use of com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor in project incubator-heron by apache.
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.statemgr.SchedulerStateManagerAdaptor in project incubator-heron by apache.
the class PackingPlanProviderTest method providesBoltInstanceNames.
@Test
public void providesBoltInstanceNames() {
PackingPlans.PackingPlan proto = PackingTestUtils.testProtoPackingPlan(topologyName, new RoundRobinPacking());
SchedulerStateManagerAdaptor adaptor = mock(SchedulerStateManagerAdaptor.class);
when(adaptor.getPackingPlan(topologyName)).thenReturn(proto);
PackingPlanProvider packing = new PackingPlanProvider(adaptor, eventManager, topologyName);
String[] boltNames = packing.getBoltInstanceNames("testBolt");
assertEquals(3, boltNames.length);
HashSet<String> expectedBoltNames = new HashSet<>();
expectedBoltNames.add("container_1_testBolt_3");
expectedBoltNames.add("container_1_testBolt_4");
expectedBoltNames.add("container_1_testBolt_5");
for (String name : boltNames) {
expectedBoltNames.remove(name);
}
assertEquals(0, expectedBoltNames.size());
}
use of com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor in project incubator-heron by apache.
the class PackingPlanProviderTest method refreshesPackingPlanOnUpdate.
@Test
public void refreshesPackingPlanOnUpdate() {
PackingPlans.PackingPlan proto = PackingTestUtils.testProtoPackingPlan(topologyName, new RoundRobinPacking());
SchedulerStateManagerAdaptor adaptor = mock(SchedulerStateManagerAdaptor.class);
when(adaptor.getPackingPlan(topologyName)).thenReturn(proto);
PackingPlanProvider provider = new PackingPlanProvider(adaptor, eventManager, topologyName);
PackingPlan packing = provider.get();
Assert.assertEquals(1, packing.getContainers().size());
provider.onEvent(new TopologyUpdate());
provider.get();
verify(adaptor, times(2)).getPackingPlan(topologyName);
}
use of com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor in project incubator-heron by apache.
the class TopologyProviderTest method providesBoltNames.
@Test
public void providesBoltNames() {
SchedulerStateManagerAdaptor adaptor = getMockSchedulerStateManagerAdaptor();
TopologyProvider topologyProvider = new TopologyProvider(adaptor, eventManager, topology);
Map<String, Integer> bolts = getBolts();
assertEquals(2, bolts.size());
String[] boltNames = topologyProvider.getBoltNames();
assertEquals(bolts.size(), boltNames.length);
for (String boltName : boltNames) {
bolts.remove(boltName);
}
assertEquals(0, bolts.size());
}
Aggregations