Search in sources :

Example 76 with SchedulerStateManagerAdaptor

use of com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor in project incubator-heron by apache.

the class LauncherUtilsTest method constructsConfigWithTopologyInfo.

@Test
public void constructsConfigWithTopologyInfo() throws Exception {
    TopologyAPI.Topology mockTopology = PowerMockito.mock(TopologyAPI.Topology.class);
    PowerMockito.when(mockTopology.getId()).thenReturn("testTopologyId");
    PowerMockito.when(mockTopology.getName()).thenReturn("testTopologyName");
    SchedulerStateManagerAdaptor mockStMgr = Mockito.mock(SchedulerStateManagerAdaptor.class);
    PowerMockito.spy(TopologyUtils.class);
    PowerMockito.doReturn(456).when(TopologyUtils.class, "getNumContainers", mockTopology);
    Config runtime = Config.newBuilder().putAll(LauncherUtils.getInstance().createPrimaryRuntime(mockTopology)).putAll(LauncherUtils.getInstance().createAdaptorRuntime(mockStMgr)).build();
    Assert.assertEquals("testTopologyId", Runtime.topologyId(runtime));
    Assert.assertEquals("testTopologyName", Runtime.topologyName(runtime));
    Assert.assertEquals(mockTopology, Runtime.topology(runtime));
    Assert.assertEquals(mockStMgr, Runtime.schedulerStateManagerAdaptor(runtime));
    Assert.assertEquals(456 + 1, Runtime.numContainers(runtime).longValue());
}
Also used : Config(com.twitter.heron.spi.common.Config) TopologyAPI(com.twitter.heron.api.generated.TopologyAPI) SchedulerStateManagerAdaptor(com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 77 with SchedulerStateManagerAdaptor

use of com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor in project incubator-heron by apache.

the class LaunchRunnerTest method createTestSchedulerStateManager.

private static SchedulerStateManagerAdaptor createTestSchedulerStateManager(Config runtime) {
    SchedulerStateManagerAdaptor statemgr = Runtime.schedulerStateManagerAdaptor(runtime);
    when(statemgr.setTopology(any(TopologyAPI.Topology.class), eq(TOPOLOGY_NAME))).thenReturn(true);
    when(statemgr.setPackingPlan(any(PackingPlans.PackingPlan.class), eq(TOPOLOGY_NAME))).thenReturn(true);
    when(statemgr.setExecutionState(any(ExecutionEnvironment.ExecutionState.class), eq(TOPOLOGY_NAME))).thenReturn(true);
    return statemgr;
}
Also used : PackingPlan(com.twitter.heron.spi.packing.PackingPlan) HeronTopology(com.twitter.heron.api.HeronTopology) SchedulerStateManagerAdaptor(com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor)

Example 78 with SchedulerStateManagerAdaptor

use of com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor in project incubator-heron by apache.

the class LaunchRunnerTest method testSetExecutionStateFail.

@Test(expected = LauncherException.class)
public void testSetExecutionStateFail() throws Exception {
    Config runtime = createRunnerRuntime();
    Config config = createRunnerConfig();
    ILauncher launcher = Runtime.launcherClassInstance(runtime);
    LaunchRunner launchRunner = new LaunchRunner(config, runtime);
    SchedulerStateManagerAdaptor statemgr = Runtime.schedulerStateManagerAdaptor(runtime);
    when(statemgr.setExecutionState(any(ExecutionEnvironment.ExecutionState.class), eq(TOPOLOGY_NAME))).thenReturn(false);
    try {
        launchRunner.call();
    } finally {
        verify(launcher, never()).launch(any(PackingPlan.class));
    }
}
Also used : ILauncher(com.twitter.heron.spi.scheduler.ILauncher) Config(com.twitter.heron.spi.common.Config) PackingPlan(com.twitter.heron.spi.packing.PackingPlan) SchedulerStateManagerAdaptor(com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 79 with SchedulerStateManagerAdaptor

use of com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor in project incubator-heron by apache.

the class LaunchRunnerTest method doTestLaunch.

private void doTestLaunch(com.twitter.heron.api.Config topologyConfig) throws Exception {
    Config runtime = createRunnerRuntime(topologyConfig);
    Config config = createRunnerConfig();
    ILauncher launcher = Runtime.launcherClassInstance(runtime);
    SchedulerStateManagerAdaptor statemgr = createTestSchedulerStateManager(runtime);
    LaunchRunner launchRunner = new LaunchRunner(config, runtime);
    when(launcher.launch(any(PackingPlan.class))).thenReturn(true);
    launchRunner.call();
    // Verify set && clean
    verify(statemgr).setTopology(any(TopologyAPI.Topology.class), eq(TOPOLOGY_NAME));
    verify(statemgr).setExecutionState(any(ExecutionEnvironment.ExecutionState.class), eq(TOPOLOGY_NAME));
    verify(statemgr, never()).deleteExecutionState(eq(TOPOLOGY_NAME));
    verify(statemgr, never()).deleteTopology(eq(TOPOLOGY_NAME));
}
Also used : ILauncher(com.twitter.heron.spi.scheduler.ILauncher) Config(com.twitter.heron.spi.common.Config) PackingPlan(com.twitter.heron.spi.packing.PackingPlan) HeronTopology(com.twitter.heron.api.HeronTopology) SchedulerStateManagerAdaptor(com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor)

Example 80 with SchedulerStateManagerAdaptor

use of com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor in project incubator-heron by apache.

the class RuntimeManagerRunnerTest method doupdateTopologyComponentParallelismTest.

private void doupdateTopologyComponentParallelismTest(String newParallelism, boolean expectedResult) {
    ISchedulerClient client = mock(ISchedulerClient.class);
    SchedulerStateManagerAdaptor manager = mock(SchedulerStateManagerAdaptor.class);
    RuntimeManagerRunner runner = newRuntimeManagerRunner(Command.UPDATE, client);
    PowerMockito.mockStatic(Runtime.class);
    PowerMockito.when(Runtime.schedulerStateManagerAdaptor(runtime)).thenReturn(manager);
    RoundRobinPacking packing = new RoundRobinPacking();
    PackingPlans.PackingPlan currentPlan = PackingTestUtils.testProtoPackingPlan(TOPOLOGY_NAME, packing);
    PackingPlans.PackingPlan proposedPlan = PackingTestUtils.testProtoPackingPlan(TOPOLOGY_NAME, packing);
    Map<String, Integer> changeRequests = runner.parseNewParallelismParam(newParallelism);
    when(manager.getPackingPlan(eq(TOPOLOGY_NAME))).thenReturn(currentPlan);
    doReturn(proposedPlan).when(runner).buildNewPackingPlan(eq(currentPlan), eq(changeRequests), any(TopologyAPI.Topology.class));
    Scheduler.UpdateTopologyRequest updateTopologyRequest = Scheduler.UpdateTopologyRequest.newBuilder().setCurrentPackingPlan(currentPlan).setProposedPackingPlan(proposedPlan).build();
    when(client.updateTopology(updateTopologyRequest)).thenReturn(true);
    try {
        runner.updateTopologyComponentParallelism(TOPOLOGY_NAME, newParallelism);
    } finally {
        int expectedClientUpdateCalls = expectedResult ? 1 : 0;
        verify(client, times(expectedClientUpdateCalls)).updateTopology(updateTopologyRequest);
    }
}
Also used : RoundRobinPacking(com.twitter.heron.packing.roundrobin.RoundRobinPacking) Scheduler(com.twitter.heron.proto.scheduler.Scheduler) SchedulerStateManagerAdaptor(com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor) PackingPlans(com.twitter.heron.proto.system.PackingPlans) ISchedulerClient(com.twitter.heron.scheduler.client.ISchedulerClient)

Aggregations

SchedulerStateManagerAdaptor (com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor)82 Test (org.junit.Test)51 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)44 Config (com.twitter.heron.spi.common.Config)27 PackingPlan (com.twitter.heron.spi.packing.PackingPlan)27 Scheduler (com.twitter.heron.proto.scheduler.Scheduler)16 PackingPlans (com.twitter.heron.proto.system.PackingPlans)13 ISchedulerClient (com.twitter.heron.scheduler.client.ISchedulerClient)13 ILauncher (com.twitter.heron.spi.scheduler.ILauncher)12 IStateManager (com.twitter.heron.spi.statemgr.IStateManager)9 HeronTopology (com.twitter.heron.api.HeronTopology)8 TopologyAPI (com.twitter.heron.api.generated.TopologyAPI)8 ExecutionEnvironment (com.twitter.heron.proto.system.ExecutionEnvironment)8 HashSet (java.util.HashSet)8 RoundRobinPacking (com.twitter.heron.packing.roundrobin.RoundRobinPacking)7 IScheduler (com.twitter.heron.spi.scheduler.IScheduler)6 VisibleForTesting (com.google.common.annotations.VisibleForTesting)5 LauncherUtils (com.twitter.heron.scheduler.utils.LauncherUtils)4 PackingPlanProtoDeserializer (com.twitter.heron.spi.packing.PackingPlanProtoDeserializer)4 IScalable (com.twitter.heron.spi.scheduler.IScalable)4