private void mockSdkStatusChange(SdkStatus fromStatus, SdkStatus toStatus) { when(mockSdkService.getStatus()).thenReturn(fromStatus); when(mockSdkService.isInstallSupported()).thenReturn(true); // the only way to enable READY status before blocking on the same thread test thread starts. doAnswer( invocation -> { ((SdkStatusUpdateListener) invocation.getArgument(0)) .onSdkStatusChange(mockSdkService, toStatus); when(mockSdkService.getStatus()).thenReturn(toStatus); return null; }) .when(mockSdkService) .addStatusUpdateListener(any()); } }
@Test public void checkConfiguration_when_sdkSupportsInstallation_doesNotThrowException() { setUpValidFlexConfiguration(); when(mockSdkService.getStatus()).thenReturn(SdkStatus.NOT_AVAILABLE); when(mockSdkService.isInstallSupported()).thenReturn(true); when(mockSdkValidator.validateCloudSdk()).thenReturn(ImmutableSet.of(CLOUD_SDK_NOT_FOUND)); try { configuration.checkConfiguration(mockRemoteServer, mockAppEngineDeployable, project); } catch (RuntimeConfigurationException e) { throw new AssertionError("installable SDK should not be validated", e); } }
private void checkCommonConfig(AppEngineDeployable deployable) throws RuntimeConfigurationError { // do not check SDK if it supports dynamic install - the deployment runner will block itself // until installation is done. CloudSdkService cloudSdkService = CloudSdkService.getInstance(); SdkStatus sdkStatus = cloudSdkService.getStatus(); if (sdkStatus != SdkStatus.READY && !cloudSdkService.isInstallSupported()) { Set<CloudSdkValidationResult> sdkValidationResult = CloudSdkValidator.getInstance().validateCloudSdk(); if (!sdkValidationResult.isEmpty()) { CloudSdkValidationResult result = Iterables.getFirst(sdkValidationResult, null); throw new RuntimeConfigurationError( AppEngineMessageBundle.message( "appengine.flex.config.server.error", result.getMessage())); } } check( deployable instanceof UserSpecifiedPathDeploymentSource || deployable.isValid(), "appengine.config.deployment.source.error"); check( StringUtils.isNotBlank(cloudProjectName), "appengine.flex.config.project.missing.message"); }
@Test public void waitFor_when_sdkInstallNotSupported_showsFatalErrorNotification() throws InterruptedException { mockSdkStatusChange(SdkStatus.NOT_AVAILABLE, SdkStatus.NOT_AVAILABLE); when(mockSdkService.isInstallSupported()).thenReturn(false); cloudSdkServiceManager.blockUntilSdkReady(mockProject, "", mockStatusHandler); ApplicationManager.getApplication() .invokeAndWait( () -> verify(cloudSdkServiceManager) .showCloudSdkNotification( CloudSdkMessageBundle.message("managedsdk.not.available"), NotificationType.ERROR)); }
if (cloudSdkService.isInstallSupported()) { cloudSdkService.install();
/** Checks the current SDK status after waiting for readiness, notifies and logs about errors. */ private void handleErrors(CloudSdkStatusHandler sdkLogging) { // check the status of SDK after install. SdkStatus postInstallSdkStatus = CloudSdkService.getInstance().getStatus(); switch (postInstallSdkStatus) { case READY: // can continue without logging anything. break; case INSTALLING: // still installing, do nothing, up to caller to decide which message to show. break; case NOT_AVAILABLE: case INVALID: String message; NotificationType notificationType; boolean fatalSdkError = !CloudSdkService.getInstance().isInstallSupported(); if (fatalSdkError) { message = CloudSdkMessageBundle.message("managedsdk.not.available"); notificationType = NotificationType.ERROR; } else { message = sdkLogging.getErrorMessage(postInstallSdkStatus); notificationType = NotificationType.WARNING; } sdkLogging.onError(message); showCloudSdkNotification(message, notificationType); break; default: // do nothing, no error, not ready. } }
@Override public void checkConfiguration() throws RuntimeConfigurationException { if (artifactPointer == null || artifactPointer.getArtifact() == null) { throw new RuntimeConfigurationError( AppEngineMessageBundle.message("appengine.run.server.artifact.missing")); } // do not check SDK if it supports dynamic install - the deployment runner will block itself // until installation is done. CloudSdkService cloudSdkService = CloudSdkService.getInstance(); SdkStatus sdkStatus = cloudSdkService.getStatus(); if (sdkStatus != SdkStatus.READY && !cloudSdkService.isInstallSupported()) { if (!CloudSdkValidator.getInstance().isValidCloudSdk()) { throw new RuntimeConfigurationError( AppEngineMessageBundle.message("appengine.run.server.sdk.misconfigured.panel.message")); } } if (ProjectRootManager.getInstance(commonModel.getProject()).getProjectSdk() == null) { throw new RuntimeConfigurationError( AppEngineMessageBundle.getString("appengine.run.server.nojdk")); } }