use of com.twitter.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
doNothing().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));
runtimeManagerMain.manageTopology();
}
use of com.twitter.heron.scheduler.client.ISchedulerClient in project heron by twitter.
the class RuntimeManagerMainTest method testManageTopologyOk.
@PrepareForTest(ReflectionUtils.class)
@Test
public void testManageTopologyOk() 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
doNothing().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));
// Happy path
doNothing().when(runtimeManagerMain).callRuntimeManagerRunner(any(Config.class), eq(client));
runtimeManagerMain.manageTopology();
}
use of com.twitter.heron.scheduler.client.ISchedulerClient 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.NEW_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()));
doNothing().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);
RoundRobinPacking packing = new RoundRobinPacking();
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);
}
}
use of com.twitter.heron.scheduler.client.ISchedulerClient in project heron by twitter.
the class RuntimeManagerRunnerTest method doUpdateTopologyHandlerTest.
private void doUpdateTopologyHandlerTest(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.updateTopologyHandler(TOPOLOGY_NAME, newParallelism);
} finally {
int expectedClientUpdateCalls = expectedResult ? 1 : 0;
verify(client, times(expectedClientUpdateCalls)).updateTopology(updateTopologyRequest);
}
}
use of com.twitter.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);
}
}
Aggregations