Search in sources :

Example 6 with SchedulerStateManagerAdaptor

use of org.apache.heron.spi.statemgr.SchedulerStateManagerAdaptor in project heron by twitter.

the class RuntimeManagerMainTest method testValidateRuntimeManageWrongStateForKillCommand.

@Test(expected = TopologyRuntimeManagementException.class)
public void testValidateRuntimeManageWrongStateForKillCommand() {
    SchedulerStateManagerAdaptor adaptor = mock(SchedulerStateManagerAdaptor.class);
    RuntimeManagerMain runtimeManagerMain = new RuntimeManagerMain(config, Command.KILL);
    when(adaptor.isTopologyRunning(eq(TOPOLOGY_NAME))).thenReturn(true);
    // Topology is running
    ExecutionEnvironment.ExecutionState.Builder stateBuilder = ExecutionEnvironment.ExecutionState.newBuilder().setTopologyName(TOPOLOGY_NAME).setTopologyId(TOPOLOGY_ID).setCluster(CLUSTER).setEnviron(ENVIRON);
    final String WRONG_ROLE = "wrong";
    ExecutionEnvironment.ExecutionState wrongState = stateBuilder.setRole(WRONG_ROLE).build();
    // cluster/role/environ not matched
    when(adaptor.getExecutionState(eq(TOPOLOGY_NAME))).thenReturn(wrongState);
    runtimeManagerMain.validateRuntimeManage(adaptor, TOPOLOGY_NAME);
}
Also used : ExecutionEnvironment(org.apache.heron.proto.system.ExecutionEnvironment) SchedulerStateManagerAdaptor(org.apache.heron.spi.statemgr.SchedulerStateManagerAdaptor) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 7 with SchedulerStateManagerAdaptor

use of org.apache.heron.spi.statemgr.SchedulerStateManagerAdaptor in project heron by twitter.

the class RuntimeManagerMainTest method testValidateRuntimeManageWrongState.

@Test(expected = TopologyRuntimeManagementException.class)
public void testValidateRuntimeManageWrongState() {
    SchedulerStateManagerAdaptor adaptor = mock(SchedulerStateManagerAdaptor.class);
    RuntimeManagerMain runtimeManagerMain = new RuntimeManagerMain(config, MOCK_COMMAND);
    when(adaptor.isTopologyRunning(eq(TOPOLOGY_NAME))).thenReturn(true);
    // Topology is running
    ExecutionEnvironment.ExecutionState.Builder stateBuilder = ExecutionEnvironment.ExecutionState.newBuilder().setTopologyName(TOPOLOGY_NAME).setTopologyId(TOPOLOGY_ID).setCluster(CLUSTER).setEnviron(ENVIRON);
    final String WRONG_ROLE = "wrong";
    ExecutionEnvironment.ExecutionState wrongState = stateBuilder.setRole(WRONG_ROLE).build();
    // cluster/role/environ not matched
    when(adaptor.getExecutionState(eq(TOPOLOGY_NAME))).thenReturn(wrongState);
    runtimeManagerMain.validateRuntimeManage(adaptor, TOPOLOGY_NAME);
}
Also used : ExecutionEnvironment(org.apache.heron.proto.system.ExecutionEnvironment) SchedulerStateManagerAdaptor(org.apache.heron.spi.statemgr.SchedulerStateManagerAdaptor) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 8 with SchedulerStateManagerAdaptor

use of org.apache.heron.spi.statemgr.SchedulerStateManagerAdaptor in project heron by twitter.

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

Example 9 with SchedulerStateManagerAdaptor

use of org.apache.heron.spi.statemgr.SchedulerStateManagerAdaptor in project heron by twitter.

the class RuntimeManagerMainTest method testManageTopologyDryRun.

@PrepareForTest({ ReflectionUtils.class, Runtime.class })
@Test(expected = UpdateDryRunResponse.class)
public void testManageTopologyDryRun() throws Exception {
    config = mock(Config.class);
    // prepare packing class
    ResourceCompliantRRPacking repacking = new ResourceCompliantRRPacking();
    when(config.getStringValue(Key.REPACKING_CLASS)).thenReturn(IRepacking.class.getName());
    when(config.getStringValue(Key.STATE_MANAGER_CLASS)).thenReturn(IStateManager.class.getName());
    when(config.getStringValue(Key.TOPOLOGY_NAME)).thenReturn(TOPOLOGY_NAME);
    when(config.getStringValue(RuntimeManagerRunner.RUNTIME_MANAGER_COMPONENT_PARALLELISM_KEY)).thenReturn("testSpout:4,testBolt:5");
    // mock dry-run mode
    when(config.getBooleanValue(Key.DRY_RUN)).thenReturn(true);
    when(config.getDoubleValue(Key.INSTANCE_CPU)).thenReturn(1.0);
    when(config.getByteAmountValue(Key.INSTANCE_RAM)).thenReturn(ByteAmount.fromGigabytes(1));
    when(config.getByteAmountValue(Key.INSTANCE_DISK)).thenReturn(ByteAmount.fromGigabytes(1));
    RuntimeManagerMain runtimeManagerMain = spy(new RuntimeManagerMain(config, Command.UPDATE));
    // Mock validate runtime
    PowerMockito.mockStatic(ReflectionUtils.class);
    PowerMockito.doReturn(mock(IStateManager.class)).when(ReflectionUtils.class, "newInstance", eq(IStateManager.class.getName()));
    PowerMockito.doReturn(repacking).when(ReflectionUtils.class, "newInstance", eq(IRepacking.class.getName()));
    doReturn(true).when(runtimeManagerMain).validateRuntimeManage(any(SchedulerStateManagerAdaptor.class), eq(TOPOLOGY_NAME));
    // Successfully get ISchedulerClient
    ISchedulerClient client = mock(ISchedulerClient.class);
    doReturn(client).when(runtimeManagerMain).getSchedulerClient(any(Config.class));
    // Mock updateTopologyHandler of runner
    PowerMockito.mockStatic(Runtime.class);
    SchedulerStateManagerAdaptor manager = mock(SchedulerStateManagerAdaptor.class);
    PowerMockito.when(Runtime.schedulerStateManagerAdaptor(any(Config.class))).thenReturn(manager);
    ResourceCompliantRRPacking packing = new ResourceCompliantRRPacking();
    PackingPlans.PackingPlan currentPlan = PackingTestUtils.testProtoPackingPlan(TOPOLOGY_NAME, packing);
    // the actual topology does not matter
    doReturn(TopologyAPI.Topology.getDefaultInstance()).when(manager).getTopology(eq(TOPOLOGY_NAME));
    doReturn(currentPlan).when(manager).getPackingPlan(eq(TOPOLOGY_NAME));
    try {
        runtimeManagerMain.manageTopology();
    } finally {
        // verify scheduler client is never used
        verifyZeroInteractions(client);
    }
}
Also used : ResourceCompliantRRPacking(org.apache.heron.packing.roundrobin.ResourceCompliantRRPacking) IStateManager(org.apache.heron.spi.statemgr.IStateManager) PackingPlans(org.apache.heron.proto.system.PackingPlans) IRepacking(org.apache.heron.spi.packing.IRepacking) Config(org.apache.heron.spi.common.Config) ISchedulerClient(org.apache.heron.scheduler.client.ISchedulerClient) 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 10 with SchedulerStateManagerAdaptor

use of org.apache.heron.spi.statemgr.SchedulerStateManagerAdaptor in project heron by twitter.

the class RuntimeManagerMainTest method testValidateRuntimeManageExecStateNotRequiredForKillCommand.

@Test
public void testValidateRuntimeManageExecStateNotRequiredForKillCommand() {
    SchedulerStateManagerAdaptor adaptor = mock(SchedulerStateManagerAdaptor.class);
    RuntimeManagerMain runtimeManagerMain = new RuntimeManagerMain(config, Command.KILL);
    when(adaptor.isTopologyRunning(eq(TOPOLOGY_NAME))).thenReturn(true);
    when(adaptor.getExecutionState(eq(TOPOLOGY_NAME))).thenReturn(null);
    runtimeManagerMain.validateRuntimeManage(adaptor, TOPOLOGY_NAME);
}
Also used : SchedulerStateManagerAdaptor(org.apache.heron.spi.statemgr.SchedulerStateManagerAdaptor) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

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