Search in sources :

Example 11 with ISchedulerClient

use of org.apache.heron.scheduler.client.ISchedulerClient in project heron by twitter.

the class RuntimeManagerRunnerTest method testKillTopologyHandlerFailCleanState.

@Test(expected = TopologyRuntimeManagementException.class)
public void testKillTopologyHandlerFailCleanState() {
    Scheduler.KillTopologyRequest killTopologyRequest = Scheduler.KillTopologyRequest.newBuilder().setTopologyName(TOPOLOGY_NAME).build();
    ISchedulerClient client = mock(ISchedulerClient.class);
    RuntimeManagerRunner runner = newRuntimeManagerRunner(Command.KILL, client);
    // Failed to invoke client's killTopology
    when(client.killTopology(killTopologyRequest)).thenReturn(true);
    doThrow(new TopologyRuntimeManagementException("")).when(runner).cleanState(eq(TOPOLOGY_NAME), any(SchedulerStateManagerAdaptor.class));
    try {
        runner.killTopologyHandler(TOPOLOGY_NAME);
    } finally {
        verify(client).killTopology(killTopologyRequest);
    }
}
Also used : Scheduler(org.apache.heron.proto.scheduler.Scheduler) 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)

Example 12 with ISchedulerClient

use of org.apache.heron.scheduler.client.ISchedulerClient in project heron by twitter.

the class RuntimeManagerRunnerTest method testKillTopologyHandlerOk.

@Test
public void testKillTopologyHandlerOk() {
    Scheduler.KillTopologyRequest killTopologyRequest = Scheduler.KillTopologyRequest.newBuilder().setTopologyName(TOPOLOGY_NAME).build();
    ISchedulerClient client = mock(ISchedulerClient.class);
    RuntimeManagerRunner runner = newRuntimeManagerRunner(Command.KILL, client);
    when(client.killTopology(killTopologyRequest)).thenReturn(true);
    // Success case
    doNothing().when(runner).cleanState(eq(TOPOLOGY_NAME), any(SchedulerStateManagerAdaptor.class));
    runner.killTopologyHandler(TOPOLOGY_NAME);
    verify(client).killTopology(killTopologyRequest);
}
Also used : Scheduler(org.apache.heron.proto.scheduler.Scheduler) 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)

Example 13 with ISchedulerClient

use of org.apache.heron.scheduler.client.ISchedulerClient in project heron by twitter.

the class RuntimeManagerRunnerTest method testKillTopologyHandlerClientCantKill.

@Test(expected = TopologyRuntimeManagementException.class)
public void testKillTopologyHandlerClientCantKill() {
    Scheduler.KillTopologyRequest killTopologyRequest = Scheduler.KillTopologyRequest.newBuilder().setTopologyName(TOPOLOGY_NAME).build();
    ISchedulerClient client = mock(ISchedulerClient.class);
    RuntimeManagerRunner runner = newRuntimeManagerRunner(Command.KILL, client);
    // Failed to invoke client's killTopology
    when(client.killTopology(killTopologyRequest)).thenReturn(false);
    try {
        runner.killTopologyHandler(TOPOLOGY_NAME);
    } finally {
        verify(client).killTopology(killTopologyRequest);
    }
}
Also used : Scheduler(org.apache.heron.proto.scheduler.Scheduler) ISchedulerClient(org.apache.heron.scheduler.client.ISchedulerClient) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 14 with ISchedulerClient

use of org.apache.heron.scheduler.client.ISchedulerClient in project heron by twitter.

the class RuntimeManagerMainTest method testManageTopologyFailCall.

@PrepareForTest(ReflectionUtils.class)
@Test(expected = TopologyRuntimeManagementException.class)
public void testManageTopologyFailCall() throws Exception {
    config = mock(Config.class);
    when(config.getStringValue(Key.TOPOLOGY_NAME)).thenReturn(TOPOLOGY_NAME);
    RuntimeManagerMain runtimeManagerMain = spy(new RuntimeManagerMain(config, MOCK_COMMAND));
    // Valid state manager class
    Mockito.when(config.getStringValue(Key.STATE_MANAGER_CLASS)).thenReturn(IStateManager.class.getName());
    PowerMockito.mockStatic(ReflectionUtils.class);
    PowerMockito.doReturn(Mockito.mock(IStateManager.class)).when(ReflectionUtils.class, "newInstance", Mockito.eq(IStateManager.class.getName()));
    // Legal request
    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));
    // Failed to callRuntimeManagerRunner
    doThrow(new TopologyRuntimeManagementException("")).when(runtimeManagerMain).callRuntimeManagerRunner(any(Config.class), eq(client), eq(false));
    runtimeManagerMain.manageTopology();
}
Also used : IStateManager(org.apache.heron.spi.statemgr.IStateManager) 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)

Aggregations

ISchedulerClient (org.apache.heron.scheduler.client.ISchedulerClient)14 SchedulerStateManagerAdaptor (org.apache.heron.spi.statemgr.SchedulerStateManagerAdaptor)12 Test (org.junit.Test)11 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)10 Scheduler (org.apache.heron.proto.scheduler.Scheduler)7 Config (org.apache.heron.spi.common.Config)5 IStateManager (org.apache.heron.spi.statemgr.IStateManager)4 TopologyAPI (org.apache.heron.api.generated.TopologyAPI)2 PackingPlans (org.apache.heron.proto.system.PackingPlans)2 PackingPlan (org.apache.heron.spi.packing.PackingPlan)2 Action (com.microsoft.dhalion.core.Action)1 Diagnosis (com.microsoft.dhalion.core.Diagnosis)1 Measurement (com.microsoft.dhalion.core.Measurement)1 ExecutionContext (com.microsoft.dhalion.policy.PoliciesExecutor.ExecutionContext)1 HttpURLConnection (java.net.HttpURLConnection)1 URL (java.net.URL)1 Instant (java.time.Instant)1 HashMap (java.util.HashMap)1 PackingPlanProvider (org.apache.heron.healthmgr.common.PackingPlanProvider)1 ResourceCompliantRRPacking (org.apache.heron.packing.roundrobin.ResourceCompliantRRPacking)1