use of org.powermock.core.classloader.annotations.PrepareForTest in project heron by twitter.
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);
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));
spyUpdateManager.updateTopology(currentProtoPlan, proposedProtoPlan);
verify(spyUpdateManager).deactivateTopology(eq(mockStateMgr), eq(testTopology));
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 heron by twitter.
the class HeronExecutorTaskTest method setsEnvironmentForExecutor.
/**
* Tests launcher execution by yarn task
*/
@Test
@PrepareForTest({ ShellUtils.class, HeronReefUtils.class, REEFFileNames.class })
public void setsEnvironmentForExecutor() throws Exception {
PowerMockito.spy(HeronReefUtils.class);
PowerMockito.doNothing().when(HeronReefUtils.class, "extractPackageInSandbox", Mockito.anyString(), Mockito.anyString(), Mockito.anyString());
REEFFileNames mockFiles = PowerMockito.mock(REEFFileNames.class);
File global = new File(".");
PowerMockito.when(mockFiles.getGlobalFolder()).thenReturn(global);
HeronExecutorTask spyTask = getSpyOnHeronExecutorTask(mockFiles);
String[] testCmd = { "cmd" };
Mockito.doReturn(testCmd).when(spyTask).getExecutorCommand();
HashMap<String, String> env = spyTask.getEnvironment("testCWD");
Assert.assertEquals(1, env.size());
String pexRoot = env.get("PEX_ROOT");
Assert.assertNotNull(pexRoot);
Assert.assertEquals("testCWD", pexRoot);
Mockito.when(spyTask.getEnvironment(Mockito.anyString())).thenReturn(env);
Process mockProcess = Mockito.mock(Process.class);
Mockito.doReturn(0).when(mockProcess).waitFor();
PowerMockito.spy(ShellUtils.class);
PowerMockito.doReturn(mockProcess).when(ShellUtils.class, "runASyncProcess", Mockito.eq(testCmd), Mockito.any(File.class), Mockito.eq(env), Mockito.any(String.class), Mockito.any(Boolean.class));
spyTask.call(null);
Mockito.verify(mockProcess).waitFor();
}
use of org.powermock.core.classloader.annotations.PrepareForTest in project mobile-center-sdk-android by Microsoft.
the class CrashesTest method minidumpAppLaunchTimestampFromSessionContext.
@Test
@PrepareForTest({ SessionContext.class, DeviceInfoHelper.class })
public void minidumpAppLaunchTimestampFromSessionContext() throws Exception {
long appStartTime = 99L;
long crashTime = 123L;
ManagedErrorLog crashLog = testNativeCrashLog(appStartTime, crashTime, true);
assertEquals(new Date(crashTime), crashLog.getTimestamp());
assertEquals(new Date(appStartTime), crashLog.getAppLaunchTimestamp());
}
use of org.powermock.core.classloader.annotations.PrepareForTest in project mobile-center-sdk-android by Microsoft.
the class CrashesTest method minidumpAppLaunchTimestampFromSessionContextInFuture.
@Test
@PrepareForTest({ SessionContext.class, DeviceInfoHelper.class })
public void minidumpAppLaunchTimestampFromSessionContextInFuture() throws Exception {
long appStartTime = 101L;
long crashTime = 100L;
ManagedErrorLog crashLog = testNativeCrashLog(appStartTime, crashTime, true);
/* Verify we fall back to crash time for app start time. */
assertEquals(new Date(crashTime), crashLog.getTimestamp());
assertEquals(new Date(crashTime), crashLog.getAppLaunchTimestamp());
}
use of org.powermock.core.classloader.annotations.PrepareForTest in project mobile-center-sdk-android by Microsoft.
the class DistributeBeforeDownloadTest method disableBeforeDownload.
@Test
@PrepareForTest(AsyncTaskUtils.class)
public void disableBeforeDownload() throws Exception {
/* Mock we already have redirection parameters. */
when(PreferencesStorage.getString(PREFERENCE_KEY_DISTRIBUTION_GROUP_ID)).thenReturn("some group");
when(PreferencesStorage.getString(PREFERENCE_KEY_UPDATE_TOKEN)).thenReturn("some token");
HttpClientNetworkStateHandler httpClient = mock(HttpClientNetworkStateHandler.class);
whenNew(HttpClientNetworkStateHandler.class).withAnyArguments().thenReturn(httpClient);
when(httpClient.callAsync(anyString(), anyString(), anyMapOf(String.class, String.class), any(HttpClient.CallTemplate.class), any(ServiceCallback.class))).thenAnswer(new Answer<ServiceCall>() {
@Override
public ServiceCall answer(InvocationOnMock invocation) throws Throwable {
((ServiceCallback) invocation.getArguments()[4]).onCallSucceeded("mock");
return mock(ServiceCall.class);
}
});
ReleaseDetails releaseDetails = mock(ReleaseDetails.class);
when(releaseDetails.getId()).thenReturn(4);
when(releaseDetails.getVersion()).thenReturn(7);
when(ReleaseDetails.parse(anyString())).thenReturn(releaseDetails);
mockStatic(AsyncTaskUtils.class);
when(InstallerUtils.isUnknownSourcesEnabled(any(Context.class))).thenReturn(true);
/* Trigger call. */
start();
Distribute.getInstance().onActivityResumed(mock(Activity.class));
/* Verify dialog. */
ArgumentCaptor<DialogInterface.OnClickListener> clickListener = ArgumentCaptor.forClass(DialogInterface.OnClickListener.class);
verify(mDialogBuilder).setPositiveButton(eq(R.string.appcenter_distribute_update_dialog_download), clickListener.capture());
verify(mDialog).show();
/* Disable. */
Distribute.setEnabled(false);
verifyStatic();
PreferencesStorage.remove(PREFERENCE_KEY_DOWNLOAD_STATE);
/* Click on download. */
clickListener.getValue().onClick(mDialog, DialogInterface.BUTTON_POSITIVE);
when(mDialog.isShowing()).thenReturn(false);
/* Since we were disabled, no action but toast to explain what happened. */
verify(mToast).show();
/* Verify no more calls, e.g. happened only once. */
Distribute.getInstance().onActivityPaused(mock(Activity.class));
Distribute.getInstance().onActivityResumed(mock(Activity.class));
verify(mDialog).show();
verify(httpClient).callAsync(anyString(), anyString(), anyMapOf(String.class, String.class), any(HttpClient.CallTemplate.class), any(ServiceCallback.class));
verifyStatic();
PreferencesStorage.remove(PREFERENCE_KEY_DOWNLOAD_STATE);
/* Verify no download scheduled. */
verifyStatic(never());
AsyncTaskUtils.execute(anyString(), any(DownloadTask.class), Mockito.<Void>anyVararg());
}
Aggregations