CheckRamAndRunAction extends AbstractRunnerAction { @Override public void perform(@NotNull final Runner runner) { this.runner = runner; project = appContext.getCurrentProject(); if (project == null) { return; } AsyncRequestCallback<ResourcesDescriptor> callback = callbackBuilderProvider .get() .unmarshaller(ResourcesDescriptor.class) .success(new SuccessCallback<ResourcesDescriptor>() { @Override public void onSuccess(ResourcesDescriptor resourcesDescriptor) { checkRamAndRunProject(resourcesDescriptor); } }) .failure(new FailureCallback() { @Override public void onFailure(@NotNull Throwable reason) { runnerUtil.showError(runner, constant.getResourcesFailed(), reason); } }) .build(); service.getResources(callback); } @Inject  CheckRamAndRunAction(RunnerServiceClient service,
                                AppContext appContext,
                                @LeftPanel TabContainer tabContainer,
                                RunnerLocalizationConstant locale,
                                DialogFactory dialogFactory,
                                ConsoleContainer consoleContainer,
                                Provider<AsyncCallbackBuilder<ResourcesDescriptor>> callbackBuilderProvider,
                                RunnerLocalizationConstant constant,
                                RunnerUtil runnerUtil,
                                RunnerActionFactory actionFactory,
                                RunnerManagerPresenter managerPresenter); @Override void perform(@NotNull final Runner runner);  }
@Test public void shouldNotPerformWhenCurrentProjectIsNull() { reset(runnerUtil, constant, service, runner, runAction); when(appContext.getCurrentProject()).thenReturn(null); checkRamAndRunAction.perform(runner); verify(appContext).getCurrentProject(); verifyNoMoreInteractions(runnerUtil, constant, service, runner, runAction); }
@Test public void shouldFailedPerform() { checkRamAndRunAction.perform(runner); verify(appContext).getCurrentProject(); verify(service).getResources(asyncRequestCallback); verify(callbackBuilderProvider).get(); verify(asyncCallbackBuilder).unmarshaller(ResourcesDescriptor.class); verify(asyncCallbackBuilder).failure(failedCallBackCaptor.capture()); FailureCallback failureCallback = failedCallBackCaptor.getValue(); failureCallback.onFailure(reason); verify(runnerUtil).showError(runner, RESOURCE, reason); }
@Test public void shouldPerformWithDefaultRunnerConfiguration() { String defaultRunnerConfig = "defaultRunnerConfigTesT"; when(project.getProjectDescription()).thenReturn(projectDescriptor); when(projectDescriptor.getRunners()).thenReturn(runners); when(runner.getEnvironmentId()).thenReturn(ID_ENVIRONMENT); when(runners.getConfigs()).thenReturn(hashMap); when(hashMap.get(ID_ENVIRONMENT)).thenReturn(null); when(runners.getDefault()).thenReturn(defaultRunnerConfig); when(hashMap.get(defaultRunnerConfig)).thenReturn(runnerConfiguration); when(resourcesDescriptor.getTotalMemory()).thenReturn("1024"); when(resourcesDescriptor.getUsedMemory()).thenReturn("256"); when(runner.getRAM()).thenReturn(256); when(runnerConfiguration.getRam()).thenReturn(256); checkRamAndRunAction.perform(runner); verify(service).getResources(asyncRequestCallback); verify(callbackBuilderProvider).get(); verify(asyncCallbackBuilder).unmarshaller(ResourcesDescriptor.class); verify(asyncCallbackBuilder).success(successCallBackCaptor.capture()); SuccessCallback<ResourcesDescriptor> successCallback = successCallBackCaptor.getValue(); successCallback.onSuccess(resourcesDescriptor); verify(resourcesDescriptor).getTotalMemory(); verify(resourcesDescriptor).getUsedMemory(); verify(project).getProjectDescription(); verify(runners, times(2)).getConfigs(); verify(hashMap).get(ID_ENVIRONMENT); verify(hashMap).get(defaultRunnerConfig); verify(runners).getDefault(); verify(runner).getRAM(); verify(runnerConfiguration).getRam(); verify(runner).setRAM(256); verify(runAction).perform(runner); }
@Test public void shouldPerformWhenEnoughMemory() { when(project.getProjectDescription()).thenReturn(projectDescriptor); when(projectDescriptor.getRunners()).thenReturn(runners); when(runner.getEnvironmentId()).thenReturn(ID_ENVIRONMENT); when(runners.getConfigs()).thenReturn(hashMap); when(hashMap.get(ID_ENVIRONMENT)).thenReturn(runnerConfiguration); when(resourcesDescriptor.getTotalMemory()).thenReturn("1024"); when(resourcesDescriptor.getUsedMemory()).thenReturn("256"); when(runner.getRAM()).thenReturn(256); when(runnerConfiguration.getRam()).thenReturn(256); checkRamAndRunAction.perform(runner); verify(service).getResources(asyncRequestCallback); verify(callbackBuilderProvider).get(); verify(asyncCallbackBuilder).unmarshaller(ResourcesDescriptor.class); verify(asyncCallbackBuilder).success(successCallBackCaptor.capture()); SuccessCallback<ResourcesDescriptor> successCallback = successCallBackCaptor.getValue(); successCallback.onSuccess(resourcesDescriptor); verify(resourcesDescriptor).getTotalMemory(); verify(resourcesDescriptor).getUsedMemory(); verify(project).getProjectDescription(); verify(runners).getConfigs(); verify(hashMap).get(ID_ENVIRONMENT); verify(runners, never()).getDefault(); verify(runner).getRAM(); verify(runnerConfiguration).getRam(); verify(runner).setRAM(256); verify(runAction).perform(runner); }
@Test public void shouldPerformWhenOverrideMemoryIsZero() { when(project.getProjectDescription()).thenReturn(projectDescriptor); when(projectDescriptor.getRunners()).thenReturn(runners); when(runner.getEnvironmentId()).thenReturn(ID_ENVIRONMENT); when(runners.getConfigs()).thenReturn(hashMap); when(hashMap.get(ID_ENVIRONMENT)).thenReturn(runnerConfiguration); when(resourcesDescriptor.getTotalMemory()).thenReturn("1024"); when(resourcesDescriptor.getUsedMemory()).thenReturn("256"); when(runner.getRAM()).thenReturn(0); when(runnerConfiguration.getRam()).thenReturn(384); checkRamAndRunAction.perform(runner); verify(service).getResources(asyncRequestCallback); verify(asyncCallbackBuilder).success(successCallBackCaptor.capture()); SuccessCallback<ResourcesDescriptor> successCallback = successCallBackCaptor.getValue(); successCallback.onSuccess(resourcesDescriptor); verify(resourcesDescriptor).getTotalMemory(); verify(resourcesDescriptor).getUsedMemory(); verify(project).getProjectDescription(); verify(runners).getConfigs(); verify(hashMap).get(ID_ENVIRONMENT); verify(runners, never()).getDefault(); verify(runner).getRAM(); verify(runnerConfiguration).getRam(); verify(runner).setRAM(384); verify(runAction).perform(runner); }
@Test public void shouldPerformWhenOverrideAndRequiredMemoriesAreZero() { when(project.getProjectDescription()).thenReturn(projectDescriptor); when(projectDescriptor.getRunners()).thenReturn(runners); when(runner.getEnvironmentId()).thenReturn(ID_ENVIRONMENT); when(runners.getConfigs()).thenReturn(hashMap); when(hashMap.get(ID_ENVIRONMENT)).thenReturn(runnerConfiguration); when(resourcesDescriptor.getTotalMemory()).thenReturn("1024"); when(resourcesDescriptor.getUsedMemory()).thenReturn("256"); when(runner.getRAM()).thenReturn(0); when(runnerConfiguration.getRam()).thenReturn(0); checkRamAndRunAction.perform(runner); verify(service).getResources(asyncRequestCallback); verify(asyncCallbackBuilder).success(successCallBackCaptor.capture()); SuccessCallback<ResourcesDescriptor> successCallback = successCallBackCaptor.getValue(); successCallback.onSuccess(resourcesDescriptor); verify(resourcesDescriptor).getTotalMemory(); verify(resourcesDescriptor).getUsedMemory(); verify(project).getProjectDescription(); verify(runners).getConfigs(); verify(hashMap).get(ID_ENVIRONMENT); verify(runners, never()).getDefault(); verify(runner).getRAM(); verify(runnerConfiguration).getRam(); verify(runAction).perform(runner); }
@Test public void shouldShowMessageTotalLessRequiredMemory() { when(project.getProjectDescription()).thenReturn(projectDescriptor); when(projectDescriptor.getRunners()).thenReturn(runners); when(runner.getEnvironmentId()).thenReturn(ID_ENVIRONMENT); when(runners.getConfigs()).thenReturn(hashMap); when(hashMap.get(ID_ENVIRONMENT)).thenReturn(runnerConfiguration); when(constant.messagesAvailableLessOverrideMemoryContent()).thenReturn(MESSAGES_AVAILABLE_LESS_OVERRIDE_MEMORY); when(constant.messagesAvailableLessOverrideMemoryTitle()).thenReturn(SOME_TXT); when(constant.messagesAvailableLessOverrideMemorySettingsLink()).thenReturn(SOME_TXT); when(constant.messagesAvailableLessOverrideMemoryBackToConfig()).thenReturn(SOME_TXT); when(dialogFactory.createChoiceDialog(anyString(), anyString(), anyString(), anyString(), any(ConfirmCallback.class), any(ConfirmCallback.class))) .thenReturn(choiceDialog); when(resourcesDescriptor.getTotalMemory()).thenReturn("512"); when(resourcesDescriptor.getUsedMemory()).thenReturn("256"); when(runner.getRAM()).thenReturn(512); when(runnerConfiguration.getRam()).thenReturn(1024); checkRamAndRunAction.perform(runner); verify(service).getResources(asyncRequestCallback); verify(asyncCallbackBuilder).success(successCallBackCaptor.capture()); SuccessCallback<ResourcesDescriptor> successCallback = successCallBackCaptor.getValue(); successCallback.onSuccess(resourcesDescriptor); verify(resourcesDescriptor).getTotalMemory(); verify(resourcesDescriptor).getUsedMemory(); verify(project).getProjectDescription(); verify(runners).getConfigs(); verify(hashMap).get(ID_ENVIRONMENT); verify(runners, never()).getDefault(); verify(runner).getRAM(); verify(runnerConfiguration).getRam(); verify(constant).messagesAvailableLessOverrideMemoryContent(); verify(choiceDialog).show(); verify(runner).setStatus(Runner.Status.FAILED); verify(managerPresenter).update(runner); }
@Test public void shouldShowMessagesAvailableLessRequiredMemory() { when(project.getProjectDescription()).thenReturn(projectDescriptor); when(projectDescriptor.getRunners()).thenReturn(runners); when(runner.getEnvironmentId()).thenReturn(ID_ENVIRONMENT); when(runners.getConfigs()).thenReturn(hashMap); when(hashMap.get(ID_ENVIRONMENT)).thenReturn(runnerConfiguration); when(constant.messagesAvailableLessOverrideMemoryContent()).thenReturn(MESSAGES_AVAILABLE_LESS_OVERRIDE_MEMORY); when(constant.messagesAvailableLessOverrideMemoryTitle()).thenReturn(SOME_TXT); when(constant.messagesAvailableLessOverrideMemorySettingsLink()).thenReturn(SOME_TXT); when(constant.messagesAvailableLessOverrideMemoryBackToConfig()).thenReturn(SOME_TXT); when(dialogFactory.createChoiceDialog(anyString(), anyString(), anyString(), anyString(), any(ConfirmCallback.class), any(ConfirmCallback.class))) .thenReturn(choiceDialog); when(resourcesDescriptor.getTotalMemory()).thenReturn("512"); when(resourcesDescriptor.getUsedMemory()).thenReturn("256"); when(runner.getRAM()).thenReturn(512); when(runnerConfiguration.getRam()).thenReturn(384); checkRamAndRunAction.perform(runner); verify(service).getResources(asyncRequestCallback); verify(asyncCallbackBuilder).success(successCallBackCaptor.capture()); SuccessCallback<ResourcesDescriptor> successCallback = successCallBackCaptor.getValue(); successCallback.onSuccess(resourcesDescriptor); verify(resourcesDescriptor).getTotalMemory(); verify(resourcesDescriptor).getUsedMemory(); verify(project).getProjectDescription(); verify(runners).getConfigs(); verify(hashMap).get(ID_ENVIRONMENT); verify(runners, never()).getDefault(); verify(runner).getRAM(); verify(runnerConfiguration).getRam(); verify(constant).messagesAvailableLessOverrideMemoryContent(); verify(choiceDialog).show(); verify(runner).setStatus(Runner.Status.FAILED); verify(managerPresenter).update(runner); }
@Test public void shouldShowMessageAvailableMemoryLessOverrideMemory() { when(project.getProjectDescription()).thenReturn(projectDescriptor); when(projectDescriptor.getRunners()).thenReturn(runners); when(runner.getEnvironmentId()).thenReturn(ID_ENVIRONMENT); when(runners.getConfigs()).thenReturn(hashMap); when(hashMap.get(ID_ENVIRONMENT)).thenReturn(runnerConfiguration); when(constant.messagesAvailableLessOverrideMemoryContent()).thenReturn(MESSAGES_AVAILABLE_LESS_OVERRIDE_MEMORY); when(constant.messagesAvailableLessOverrideMemoryTitle()).thenReturn(SOME_TXT); when(constant.messagesAvailableLessOverrideMemorySettingsLink()).thenReturn(SOME_TXT); when(constant.messagesAvailableLessOverrideMemoryBackToConfig()).thenReturn(SOME_TXT); when(dialogFactory.createChoiceDialog(anyString(), anyString(), anyString(), anyString(), any(ConfirmCallback.class), any(ConfirmCallback.class))) .thenReturn(choiceDialog); when(resourcesDescriptor.getTotalMemory()).thenReturn("512"); when(resourcesDescriptor.getUsedMemory()).thenReturn("256"); when(runner.getRAM()).thenReturn(384); when(runnerConfiguration.getRam()).thenReturn(128); checkRamAndRunAction.perform(runner); verify(service).getResources(asyncRequestCallback); verify(asyncCallbackBuilder).success(successCallBackCaptor.capture()); SuccessCallback<ResourcesDescriptor> successCallback = successCallBackCaptor.getValue(); successCallback.onSuccess(resourcesDescriptor); verify(resourcesDescriptor).getTotalMemory(); verify(resourcesDescriptor).getUsedMemory(); verify(project).getProjectDescription(); verify(runners).getConfigs(); verify(hashMap).get(ID_ENVIRONMENT); verify(runners, never()).getDefault(); verify(runner).getRAM(); verify(runnerConfiguration).getRam(); verify(constant).messagesAvailableLessOverrideMemoryContent(); verify(choiceDialog).show(); verify(runner).setStatus(Runner.Status.FAILED); }
@Test public void shouldShowMessageTotalMemoryLessRequiredMemory() { String titleWarning = "some warning"; String messageOverrideMemory = "override memory message"; String messagesOverrideLessRequiredMemory = "some message"; when(project.getProjectDescription()).thenReturn(projectDescriptor); when(projectDescriptor.getRunners()).thenReturn(runners); when(runner.getEnvironmentId()).thenReturn(ID_ENVIRONMENT); when(runners.getConfigs()).thenReturn(hashMap); when(hashMap.get(ID_ENVIRONMENT)).thenReturn(runnerConfiguration); when(constant.titlesWarning()).thenReturn(titleWarning); when(constant.messagesOverrideMemory()).thenReturn(messageOverrideMemory); when(constant.messagesOverrideLessRequiredMemory(128, 384)). thenReturn(messagesOverrideLessRequiredMemory); when(dialogFactory.createConfirmDialog(anyString(), anyString(), any(ConfirmCallback.class), isNull(CancelCallback.class))) .thenReturn(confirmDialog); when(dialogFactory.createMessageDialog(anyString(), anyString(), any(ConfirmCallback.class))).thenReturn(messageDialog); when(resourcesDescriptor.getTotalMemory()).thenReturn("512"); when(resourcesDescriptor.getUsedMemory()).thenReturn("128"); when(runner.getRAM()).thenReturn(128); when(runnerConfiguration.getRam()).thenReturn(384); checkRamAndRunAction.perform(runner); verify(service).getResources(asyncRequestCallback); verify(asyncCallbackBuilder).success(successCallBackCaptor.capture()); SuccessCallback<ResourcesDescriptor> successCallback = successCallBackCaptor.getValue(); successCallback.onSuccess(resourcesDescriptor); verify(resourcesDescriptor).getTotalMemory(); verify(resourcesDescriptor).getUsedMemory(); verify(project).getProjectDescription(); verify(runners).getConfigs(); verify(hashMap).get(ID_ENVIRONMENT); verify(runners, never()).getDefault(); verify(runner).getRAM(); verify(runnerConfiguration).getRam(); verify(dialogFactory).createConfirmDialog(eq(titleWarning), eq(messageOverrideMemory), confirmCallbackArgumentCaptor.capture(), isNull(CancelCallback.class)); ConfirmCallback confirmCallback = confirmCallbackArgumentCaptor.getValue(); confirmCallback.accepted(); verify(constant).messagesOverrideMemory(); verify(runner).setRAM(384); verify(runAction).perform(runner); verify(dialogFactory).createMessageDialog(eq(titleWarning), eq(messagesOverrideLessRequiredMemory), confirmCallbackArgumentCaptor.capture()); ConfirmCallback confirmCallback2 = confirmCallbackArgumentCaptor.getValue(); confirmCallback2.accepted(); verify(constant, times(2)).titlesWarning(); verify(constant).messagesOverrideLessRequiredMemory(128, 384); verify(confirmDialog).show(); verify(messageDialog).show(); }
@Test public void shouldShowMessageTotalMemoryLessRequiredMemoryButRunnerDescriptorIsNull() { String titleWarning = "some warning"; String messageOverrideMemory = "override memory message"; String messagesOverrideLessRequiredMemory = "some message"; when(project.getProjectDescription()).thenReturn(projectDescriptor); when(projectDescriptor.getRunners()).thenReturn(null); when(runner.getEnvironmentId()).thenReturn(ID_ENVIRONMENT); when(runners.getConfigs()).thenReturn(hashMap); when(hashMap.get(ID_ENVIRONMENT)).thenReturn(runnerConfiguration); when(constant.titlesWarning()).thenReturn(titleWarning); when(constant.messagesOverrideMemory()).thenReturn(messageOverrideMemory); when(constant.messagesOverrideLessRequiredMemory(128, 384)).thenReturn(messagesOverrideLessRequiredMemory); when(dialogFactory.createConfirmDialog(anyString(), anyString(), any(ConfirmCallback.class), isNull(CancelCallback.class))) .thenReturn(confirmDialog); when(dialogFactory.createMessageDialog(anyString(), anyString(), any(ConfirmCallback.class))).thenReturn(messageDialog); when(resourcesDescriptor.getTotalMemory()).thenReturn("512"); when(resourcesDescriptor.getUsedMemory()).thenReturn("128"); when(runner.getRAM()).thenReturn(0); checkRamAndRunAction.perform(runner); verify(service).getResources(asyncRequestCallback); verify(asyncCallbackBuilder).success(successCallBackCaptor.capture()); SuccessCallback<ResourcesDescriptor> successCallback = successCallBackCaptor.getValue(); successCallback.onSuccess(resourcesDescriptor); verify(resourcesDescriptor).getTotalMemory(); verify(resourcesDescriptor).getUsedMemory(); verify(project).getProjectDescription(); verify(runners, never()).getDefault(); verify(runner).getRAM(); verify(runAction).perform(runner); }
@Test public void shouldShowMessagesAvailableLessOverrideMemoryButRunnerDescriptorIsNull() { when(project.getProjectDescription()).thenReturn(projectDescriptor); when(projectDescriptor.getRunners()).thenReturn(null); when(runner.getEnvironmentId()).thenReturn(ID_ENVIRONMENT); when(runners.getConfigs()).thenReturn(hashMap); when(hashMap.get(ID_ENVIRONMENT)).thenReturn(runnerConfiguration); when(constant.messagesAvailableLessOverrideMemoryContent()).thenReturn(MESSAGES_AVAILABLE_LESS_OVERRIDE_MEMORY); when(constant.messagesAvailableLessOverrideMemoryTitle()).thenReturn(SOME_TXT); when(constant.messagesAvailableLessOverrideMemorySettingsLink()).thenReturn(SOME_TXT); when(constant.messagesAvailableLessOverrideMemoryBackToConfig()).thenReturn(SOME_TXT); when(dialogFactory.createChoiceDialog(anyString(), anyString(), anyString(), anyString(), any(ConfirmCallback.class), any(ConfirmCallback.class))) .thenReturn(choiceDialog); when(resourcesDescriptor.getTotalMemory()).thenReturn("1024"); when(resourcesDescriptor.getUsedMemory()).thenReturn("756"); when(runner.getRAM()).thenReturn(512); checkRamAndRunAction.perform(runner); verify(service).getResources(asyncRequestCallback); verify(asyncCallbackBuilder).success(successCallBackCaptor.capture()); SuccessCallback<ResourcesDescriptor> successCallback = successCallBackCaptor.getValue(); successCallback.onSuccess(resourcesDescriptor); verify(resourcesDescriptor).getTotalMemory(); verify(resourcesDescriptor).getUsedMemory(); verify(project).getProjectDescription(); verify(runners, never()).getDefault(); verify(runner).getRAM(); verify(constant).messagesAvailableLessOverrideMemoryContent(); verify(choiceDialog).show(); verify(runner).setStatus(Runner.Status.FAILED); }
@Test public void shouldPerformWhenOverrideMemoryCorrectAndEnoughButRunnerDescriptorIsNull() { when(project.getProjectDescription()).thenReturn(projectDescriptor); when(projectDescriptor.getRunners()).thenReturn(null); when(runner.getEnvironmentId()).thenReturn(ID_ENVIRONMENT); when(runners.getConfigs()).thenReturn(hashMap); when(hashMap.get(ID_ENVIRONMENT)).thenReturn(runnerConfiguration); when(resourcesDescriptor.getTotalMemory()).thenReturn("1024"); when(resourcesDescriptor.getUsedMemory()).thenReturn("756"); when(runner.getRAM()).thenReturn(256); checkRamAndRunAction.perform(runner); verify(service).getResources(asyncRequestCallback); verify(asyncCallbackBuilder).success(successCallBackCaptor.capture()); SuccessCallback<ResourcesDescriptor> successCallback = successCallBackCaptor.getValue(); successCallback.onSuccess(resourcesDescriptor); verify(resourcesDescriptor).getTotalMemory(); verify(resourcesDescriptor).getUsedMemory(); verify(project).getProjectDescription(); verify(runners, never()).getDefault(); verify(runner).getRAM(); runner.setRAM(256); verify(runAction).perform(runner); }