Search in sources :

Example 16 with SchedulerStateManagerAdaptor

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;
}
Also used : ContainerPlan(org.apache.heron.spi.packing.PackingPlan.ContainerPlan) IPacking(org.apache.heron.spi.packing.IPacking) ILauncher(org.apache.heron.spi.scheduler.ILauncher) Config(org.apache.heron.spi.common.Config) PackingPlan(org.apache.heron.spi.packing.PackingPlan) LauncherUtils(org.apache.heron.scheduler.utils.LauncherUtils) SchedulerStateManagerAdaptor(org.apache.heron.spi.statemgr.SchedulerStateManagerAdaptor) TopologyAPI(org.apache.heron.api.generated.TopologyAPI) HashSet(java.util.HashSet)

Example 17 with SchedulerStateManagerAdaptor

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);
    }
}
Also used : ISchedulerClient(org.apache.heron.scheduler.client.ISchedulerClient) Scheduler(org.apache.heron.proto.scheduler.Scheduler) SchedulerStateManagerAdaptor(org.apache.heron.spi.statemgr.SchedulerStateManagerAdaptor) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 18 with SchedulerStateManagerAdaptor

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);
}
Also used : TopologyManager(org.apache.heron.proto.tmanager.TopologyManager) HttpURLConnection(java.net.HttpURLConnection) ISchedulerClient(org.apache.heron.scheduler.client.ISchedulerClient) URL(java.net.URL) SchedulerStateManagerAdaptor(org.apache.heron.spi.statemgr.SchedulerStateManagerAdaptor) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 19 with SchedulerStateManagerAdaptor

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);
}
Also used : SchedulerStateManagerAdaptor(org.apache.heron.spi.statemgr.SchedulerStateManagerAdaptor) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 20 with SchedulerStateManagerAdaptor

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;
}
Also used : SchedulerStateManagerAdaptor(org.apache.heron.spi.statemgr.SchedulerStateManagerAdaptor)

Aggregations

SchedulerStateManagerAdaptor (org.apache.heron.spi.statemgr.SchedulerStateManagerAdaptor)46 Test (org.junit.Test)28 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)24 PackingPlan (org.apache.heron.spi.packing.PackingPlan)15 Config (org.apache.heron.spi.common.Config)14 PackingPlans (org.apache.heron.proto.system.PackingPlans)10 ISchedulerClient (org.apache.heron.scheduler.client.ISchedulerClient)8 Scheduler (org.apache.heron.proto.scheduler.Scheduler)7 ILauncher (org.apache.heron.spi.scheduler.ILauncher)6 HashSet (java.util.HashSet)5 TopologyAPI (org.apache.heron.api.generated.TopologyAPI)5 ExecutionEnvironment (org.apache.heron.proto.system.ExecutionEnvironment)5 IStateManager (org.apache.heron.spi.statemgr.IStateManager)5 VisibleForTesting (com.google.common.annotations.VisibleForTesting)4 HeronTopology (org.apache.heron.api.HeronTopology)4 RoundRobinPacking (org.apache.heron.packing.roundrobin.RoundRobinPacking)4 IScheduler (org.apache.heron.spi.scheduler.IScheduler)3 HashMap (java.util.HashMap)2 LauncherUtils (org.apache.heron.scheduler.utils.LauncherUtils)2 PackingException (org.apache.heron.spi.packing.PackingException)2