use of org.apache.heron.spi.statemgr.SchedulerStateManagerAdaptor in project heron by twitter.
the class LaunchRunnerTest method createRunnerRuntime.
private static Config createRunnerRuntime(org.apache.heron.api.Config topologyConfig) throws Exception {
Config runtime = spy(Config.newBuilder().build());
ILauncher launcher = mock(ILauncher.class);
IPacking packing = mock(IPacking.class);
SchedulerStateManagerAdaptor adaptor = mock(SchedulerStateManagerAdaptor.class);
TopologyAPI.Topology topology = createTopology(topologyConfig);
doReturn(launcher).when(runtime).get(Key.LAUNCHER_CLASS_INSTANCE);
doReturn(adaptor).when(runtime).get(Key.SCHEDULER_STATE_MANAGER_ADAPTOR);
doReturn(topology).when(runtime).get(Key.TOPOLOGY_DEFINITION);
PackingPlan packingPlan = mock(PackingPlan.class);
when(packingPlan.getContainers()).thenReturn(new HashSet<ContainerPlan>());
when(packingPlan.getComponentRamDistribution()).thenReturn("ramdist");
when(packingPlan.getId()).thenReturn("packing_plan_id");
Set<ContainerPlan> containerPlans = new HashSet<>();
// just need it to be of size 1
containerPlans.add(PackingTestUtils.testContainerPlan(1));
when(packingPlan.getContainers()).thenReturn(containerPlans);
when(packing.pack()).thenReturn(packingPlan);
LauncherUtils mockLauncherUtils = mock(LauncherUtils.class);
when(mockLauncherUtils.createPackingPlan(any(Config.class), any(Config.class))).thenReturn(packingPlan);
PowerMockito.spy(LauncherUtils.class);
PowerMockito.doReturn(mockLauncherUtils).when(LauncherUtils.class, "getInstance");
return runtime;
}
use of org.apache.heron.spi.statemgr.SchedulerStateManagerAdaptor in project heron by twitter.
the class RuntimeManagerRunnerTest method testRestartTopologyHandlerFailRestartTopology.
@Test(expected = TopologyRuntimeManagementException.class)
public void testRestartTopologyHandlerFailRestartTopology() {
ISchedulerClient client = mock(ISchedulerClient.class);
SchedulerStateManagerAdaptor adaptor = mock(SchedulerStateManagerAdaptor.class);
RuntimeManagerRunner runner = newRuntimeManagerRunner(Command.RESTART, client);
// Restart container 1, not containing TManager
Scheduler.RestartTopologyRequest restartTopologyRequest = Scheduler.RestartTopologyRequest.newBuilder().setTopologyName(TOPOLOGY_NAME).setContainerIndex(1).build();
when(config.getIntegerValue(Key.TOPOLOGY_CONTAINER_ID)).thenReturn(1);
when(client.restartTopology(restartTopologyRequest)).thenReturn(false);
try {
runner.restartTopologyHandler(TOPOLOGY_NAME);
} finally {
verify(adaptor, never()).deleteTManagerLocation(TOPOLOGY_NAME);
}
}
use of org.apache.heron.spi.statemgr.SchedulerStateManagerAdaptor in project heron by twitter.
the class RuntimeManagerRunnerTest method testUpdateTopologyUserRuntimeConfig.
@PrepareForTest({ NetworkUtils.class, Runtime.class })
@Test
public void testUpdateTopologyUserRuntimeConfig() throws Exception {
String testConfig = "topology.user:test,testSpout:topology.user:1,testBolt:topology.user:4";
URL expectedURL = new URL("http://host:1/runtime_config/update?topologyid=topology-id&" + "runtime-config=topology.user:test&runtime-config=testSpout:topology.user:1&" + "runtime-config=testBolt:topology.user:4");
// Success case
ISchedulerClient client = mock(ISchedulerClient.class);
SchedulerStateManagerAdaptor manager = mock(SchedulerStateManagerAdaptor.class);
HttpURLConnection connection = mock(HttpURLConnection.class);
RuntimeManagerRunner runner = newRuntimeManagerRunner(Command.UPDATE, client);
TopologyManager.TManagerLocation location = TopologyManager.TManagerLocation.newBuilder().setTopologyName("topology-name").setTopologyId("topology-id").setHost("host").setControllerPort(1).setServerPort(2).build();
when(manager.getTManagerLocation(TOPOLOGY_NAME)).thenReturn(location);
when(connection.getResponseCode()).thenReturn(HttpURLConnection.HTTP_OK);
PowerMockito.mockStatic(Runtime.class);
PowerMockito.when(Runtime.schedulerStateManagerAdaptor(runtime)).thenReturn(manager);
PowerMockito.mockStatic(NetworkUtils.class);
PowerMockito.when(NetworkUtils.getProxiedHttpConnectionIfNeeded(eq(expectedURL), any(NetworkUtils.TunnelConfig.class))).thenReturn(connection);
runner.updateTopologyUserRuntimeConfig(TOPOLOGY_NAME, testConfig);
}
use of org.apache.heron.spi.statemgr.SchedulerStateManagerAdaptor in project heron by twitter.
the class SubmitterMainTest method testValidateSubmit.
@Test
public void testValidateSubmit() throws Exception {
SubmitterMain submitterMain = new SubmitterMain(config, topology);
SchedulerStateManagerAdaptor adaptor = mock(SchedulerStateManagerAdaptor.class);
// Topology is not running
when(adaptor.isTopologyRunning(eq(TOPOLOGY_NAME))).thenReturn(null);
submitterMain.validateSubmit(adaptor, TOPOLOGY_NAME);
when(adaptor.isTopologyRunning(eq(TOPOLOGY_NAME))).thenReturn(false);
submitterMain.validateSubmit(adaptor, TOPOLOGY_NAME);
}
use of org.apache.heron.spi.statemgr.SchedulerStateManagerAdaptor in project heron by twitter.
the class UpdateTopologyManagerTest method mockStateManager.
private static SchedulerStateManagerAdaptor mockStateManager(TopologyAPI.Topology topology, PackingPlans.PackingPlan packingPlan, Lock lock) {
SchedulerStateManagerAdaptor stateManager = mock(SchedulerStateManagerAdaptor.class);
when(stateManager.getPhysicalPlan(TOPOLOGY_NAME)).thenReturn(PhysicalPlans.PhysicalPlan.getDefaultInstance());
when(stateManager.getTopology(TOPOLOGY_NAME)).thenReturn(topology);
when(stateManager.getPackingPlan(eq(TOPOLOGY_NAME))).thenReturn(packingPlan);
when(stateManager.getLock(eq(TOPOLOGY_NAME), eq(IStateManager.LockName.UPDATE_TOPOLOGY))).thenReturn(lock);
return stateManager;
}
Aggregations