use of org.powermock.core.classloader.annotations.PrepareForTest in project incubator-heron by apache.
the class SchedulerClientFactoryTest method testGetLibrarySchedulerClientNotExist.
@Test(expected = SchedulerException.class)
@PrepareForTest(ReflectionUtils.class)
public void testGetLibrarySchedulerClientNotExist() throws Exception {
// Instantiate mock objects
Config config = Mockito.mock(Config.class);
Config runtime = Mockito.mock(Config.class);
// Return a MockScheduler
Mockito.when(config.getStringValue(Key.SCHEDULER_CLASS)).thenReturn(IScheduler.class.getName());
PowerMockito.mockStatic(ReflectionUtils.class);
PowerMockito.doReturn(Mockito.mock(IScheduler.class)).when(ReflectionUtils.class, "newInstance", Mockito.eq(IScheduler.class.getName()));
// Return some scheduler class not exist
final String SCHEDULER_CLASS_NOT_EXIST = "class_not_exist";
Mockito.when(config.getStringValue(Key.SCHEDULER_CLASS)).thenReturn(SCHEDULER_CLASS_NOT_EXIST);
PowerMockito.doThrow(new ClassNotFoundException()).when(ReflectionUtils.class, "newInstance", Mockito.eq(SCHEDULER_CLASS_NOT_EXIST));
Assert.assertNull(new SchedulerClientFactory(config, runtime).getSchedulerClient());
}
use of org.powermock.core.classloader.annotations.PrepareForTest in project incubator-heron by apache.
the class UpdateTopologyManagerTest method requestsToAddAndRemoveContainers.
/**
* Test scalable scheduler invocation
*/
@Test
@PrepareForTest(TMasterUtils.class)
public void requestsToAddAndRemoveContainers() throws Exception {
Lock lock = mockLock(true);
SchedulerStateManagerAdaptor mockStateMgr = mockStateManager(testTopology, this.currentProtoPlan, lock);
IScalable mockScheduler = mock(IScalable.class);
HashSet<PackingPlan.ContainerPlan> mockRetrunSet = new HashSet<>();
mockRetrunSet.add(new PackingPlan.ContainerPlan(0, new HashSet<>(), new Resource(5, ByteAmount.ZERO, ByteAmount.ZERO)));
mockRetrunSet.add(new PackingPlan.ContainerPlan(1, new HashSet<>(), new Resource(6, ByteAmount.ZERO, ByteAmount.ZERO)));
when(mockScheduler.addContainers(any())).thenReturn(mockRetrunSet);
UpdateTopologyManager spyUpdateManager = spyUpdateManager(mockStateMgr, mockScheduler, testTopology);
PowerMockito.spy(TMasterUtils.class);
PowerMockito.doNothing().when(TMasterUtils.class, "sendToTMaster", any(String.class), eq(TOPOLOGY_NAME), eq(mockStateMgr), any(NetworkUtils.TunnelConfig.class));
// reactivation won't happen since topology state is still running due to mock state manager
PowerMockito.doNothing().when(TMasterUtils.class, "transitionTopologyState", eq(TOPOLOGY_NAME), eq(TMasterUtils.TMasterCommand.ACTIVATE), eq(mockStateMgr), eq(TopologyAPI.TopologyState.PAUSED), eq(TopologyAPI.TopologyState.RUNNING), any(NetworkUtils.TunnelConfig.class));
spyUpdateManager.updateTopology(currentProtoPlan, proposedProtoPlan);
verify(spyUpdateManager).deactivateTopology(eq(mockStateMgr), eq(testTopology), eq(proposedPacking));
verify(spyUpdateManager).reactivateTopology(eq(mockStateMgr), eq(testTopology), eq(2));
verify(mockScheduler).addContainers(expectedContainersToAdd);
verify(mockScheduler).removeContainers(expectedContainersToRemove);
verify(lock).tryLock(any(Long.class), any(TimeUnit.class));
verify(lock).unlock();
PowerMockito.verifyStatic(times(1));
TMasterUtils.transitionTopologyState(eq(TOPOLOGY_NAME), eq(TMasterUtils.TMasterCommand.DEACTIVATE), eq(mockStateMgr), eq(TopologyAPI.TopologyState.RUNNING), eq(TopologyAPI.TopologyState.PAUSED), any(NetworkUtils.TunnelConfig.class));
PowerMockito.verifyStatic(times(1));
TMasterUtils.transitionTopologyState(eq(TOPOLOGY_NAME), eq(TMasterUtils.TMasterCommand.ACTIVATE), eq(mockStateMgr), eq(TopologyAPI.TopologyState.PAUSED), eq(TopologyAPI.TopologyState.RUNNING), any(NetworkUtils.TunnelConfig.class));
}
use of org.powermock.core.classloader.annotations.PrepareForTest in project incubator-heron by apache.
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();
}
use of org.powermock.core.classloader.annotations.PrepareForTest in project incubator-heron by apache.
the class HeronSubmitterTest method testValidTopologySubmission.
@Test
@PrepareForTest(HeronSubmitter.class)
public void testValidTopologySubmission() throws AlreadyAliveException, InvalidTopologyException {
TopologyBuilder builder = createTopologyBuilderWithMinimumSetup();
Config conf = new Config();
Map<String, String> map = new HashMap();
map.put("cmdline.topologydefn.tmpdirectory", folder.getRoot().getPath());
PowerMockito.spy(HeronSubmitter.class);
Mockito.when(HeronSubmitter.getHeronCmdOptions()).thenReturn(map);
HeronSubmitter.submitTopology("test", conf, builder.createTopology());
}
use of org.powermock.core.classloader.annotations.PrepareForTest in project incubator-heron by apache.
the class HeronSubmitterTest method testTopologySubmissionWhenTmpDirectoryIsSetAsInvalidPath.
@Test(expected = TopologySubmissionException.class)
@PrepareForTest(HeronSubmitter.class)
public void testTopologySubmissionWhenTmpDirectoryIsSetAsInvalidPath() throws AlreadyAliveException, InvalidTopologyException {
TopologyBuilder builder = createTopologyBuilderWithMinimumSetup();
Config conf = new Config();
Map<String, String> map = new HashMap();
map.put("cmdline.topologydefn.tmpdirectory", "invalid_path");
PowerMockito.spy(HeronSubmitter.class);
Mockito.when(HeronSubmitter.getHeronCmdOptions()).thenReturn(map);
HeronSubmitter.submitTopology("test", conf, builder.createTopology());
}
Aggregations