public boolean isUpToDate() { try { return managedCloudSdk.isUpToDate(); } catch (Exception e) { // we ignore the exception and just assume SDK is either not up-to-date or in invalid state. return false; } }
@Override public ProgressListener newChild(long allocation) { return new ChildProgressListener(this, allocation); }
/** Build a new ManagedCloudSdk from a given version. */ public ManagedCloudSdk newManagedSdk() throws UnsupportedOsException, BadCloudSdkVersionException { if (Strings.isNullOrEmpty(version)) { return ManagedCloudSdk.newManagedSdk(); } else { return ManagedCloudSdk.newManagedSdk(new Version(version)); } } }
@Test public void testDownloadCloudSdkAction_update() throws ManagedSdkVerificationException, ManagedSdkVersionMismatchException, InterruptedException, CommandExecutionException, SdkInstallerException, IOException, CommandExitException { downloadCloudSdkTask.setManagedCloudSdk(managedCloudSdk); when(managedCloudSdk.isInstalled()).thenReturn(true); when(managedCloudSdk.isUpToDate()).thenReturn(false); downloadCloudSdkTask.downloadCloudSdkAction(); verify(managedCloudSdk, never()).newInstaller(); verify(managedCloudSdk, never()).newComponentInstaller(); verify(managedCloudSdk).newUpdater(); } }
@Test public void testDownloadCloudSdkAction_installComponent() throws ManagedSdkVerificationException, ManagedSdkVersionMismatchException, InterruptedException, CommandExecutionException, SdkInstallerException, IOException, CommandExitException { downloadCloudSdkTask.setManagedCloudSdk(managedCloudSdk); downloadCloudSdkTask.requiresAppEngineJava(true); when(managedCloudSdk.isInstalled()).thenReturn(true); when(managedCloudSdk.hasComponent(SdkComponent.APP_ENGINE_JAVA)).thenReturn(false); downloadCloudSdkTask.downloadCloudSdkAction(); verify(managedCloudSdk, never()).newInstaller(); verify(managedCloudSdk).newComponentInstaller(); }
private ManagedSdkJobResult updateManagedSdk() throws Exception { if (safeCheckSdkStatus(() -> managedCloudSdk.isInstalled()) && !safeCheckSdkStatus(() -> managedCloudSdk.isUpToDate())) { ConsoleListener sdkUpdateListener = logger::debug; progressListener = ManagedCloudSdkServiceUiPresenter.getInstance().createProgressListener(this); notifySdkProcessingStarted(); executeWithSdkWriteLock( () -> managedCloudSdk.newUpdater().update(progressListener, sdkUpdateListener)); return ManagedSdkJobResult.PROCESSED; } else { return ManagedSdkJobResult.UP_TO_DATE; } }
/** Mocks managed SDK as if installed and having App Engine Component. */ private void makeMockSdkInstalled(Path mockSdkPath) { try { when(mockManagedCloudSdk.isInstalled()).thenReturn(true); when(mockManagedCloudSdk.hasComponent(SdkComponent.APP_ENGINE_JAVA)).thenReturn(true); when(mockManagedCloudSdk.getSdkHome()).thenReturn(mockSdkPath); } catch (Exception ex) { // shouldn't happen in the tests. throw new AssertionError(ex); } }
@Test public void testDownloadCloudSdkAction_skipInstallComponent() throws ManagedSdkVerificationException, ManagedSdkVersionMismatchException, InterruptedException, CommandExecutionException, SdkInstallerException, IOException, CommandExitException { downloadCloudSdkTask.setManagedCloudSdk(managedCloudSdk); downloadCloudSdkTask.requiresAppEngineJava(false); when(managedCloudSdk.isInstalled()).thenReturn(true); downloadCloudSdkTask.downloadCloudSdkAction(); verify(managedCloudSdk, never()).newInstaller(); verify(managedCloudSdk, never()).newComponentInstaller(); }
/** Installs core managed SDK if needed and returns its path if successful. */ private ManagedSdkJobResult installSdk() throws Exception { if (!safeCheckSdkStatus(() -> managedCloudSdk.isInstalled())) { ConsoleListener sdkConsoleListener = logger::debug; progressListener = ManagedCloudSdkServiceUiPresenter.getInstance().createProgressListener(this); notifySdkProcessingStarted(); executeWithSdkWriteLock( () -> managedCloudSdk.newInstaller().install(progressListener, sdkConsoleListener)); return ManagedSdkJobResult.PROCESSED; } return ManagedSdkJobResult.UP_TO_DATE; }
private ManagedSdkJobResult installAppEngineJavaComponent() throws Exception { if (!safeCheckSdkStatus(() -> managedCloudSdk.hasComponent(SdkComponent.APP_ENGINE_JAVA))) { ConsoleListener appEngineConsoleListener = logger::debug; progressListener = ManagedCloudSdkServiceUiPresenter.getInstance().createProgressListener(this); notifySdkProcessingStarted(); executeWithSdkWriteLock( () -> managedCloudSdk .newComponentInstaller() .installComponent( SdkComponent.APP_ENGINE_JAVA, progressListener, appEngineConsoleListener)); return ManagedSdkJobResult.PROCESSED; } else { return ManagedSdkJobResult.UP_TO_DATE; } }
@Test public void testNewManagedSdk_specific() throws UnsupportedOsException, BadCloudSdkVersionException { ManagedCloudSdk sdk = new ManagedCloudSdkFactory("191.0.0").newManagedSdk(); Assert.assertEquals( ManagedCloudSdk.newManagedSdk(new Version("191.0.0")).getSdkHome(), sdk.getSdkHome()); } }
@Test public void failed_install_removesProgressIndicator() throws Exception { emulateMockSdkInstallationProcess(MOCK_SDK_PATH); SdkInstaller mockInstaller = mockManagedCloudSdk.newInstaller(); IOException ioException = new IOException("IO Error"); when(mockInstaller.install(any(), any())).thenThrow(ioException); sdkService.install(); verify(mockProgressListener, atLeastOnce()).done(); }
/** Mocks out-of-date SDK and update process. */ private void emulateMockSdkUpdateProcess() { try { when(mockManagedCloudSdk.isUpToDate()).thenReturn(false); SdkUpdater mockUpdater = mock(SdkUpdater.class); when(mockManagedCloudSdk.newUpdater()).thenReturn(mockUpdater); } catch (Exception ex) { // shouldn't happen in the tests. throw new AssertionError(ex); } } }
@Test public void testDownloadCloudSdkAction_install() throws ManagedSdkVerificationException, ManagedSdkVersionMismatchException, InterruptedException, CommandExecutionException, SdkInstallerException, IOException, CommandExitException { downloadCloudSdkTask.setManagedCloudSdk(managedCloudSdk); when(managedCloudSdk.isInstalled()).thenReturn(false); downloadCloudSdkTask.downloadCloudSdkAction(); verify(managedCloudSdk).newInstaller(); }
@Test public void testNewManagedSdk_null() throws UnsupportedOsException, BadCloudSdkVersionException { // There's no way of testing for direct ManagedCloudSdk equality, so compare home paths ManagedCloudSdk sdk = new ManagedCloudSdkFactory(null).newManagedSdk(); Assert.assertEquals(ManagedCloudSdk.newManagedSdk().getSdkHome(), sdk.getSdkHome()); }
@Nullable @Override public Path getSdkHomePath() { switch (sdkStatus) { case READY: return managedCloudSdk.getSdkHome(); default: return null; } }
private void checkSdkStatusAfterFailedUpdate() { try { if (managedCloudSdk.isInstalled()) { updateStatus(SdkStatus.READY); } else { updateStatus(SdkStatus.NOT_AVAILABLE); } } catch (Exception ex) { updateStatus(SdkStatus.NOT_AVAILABLE); } }
@VisibleForTesting ManagedCloudSdk createManagedSdk() throws UnsupportedOsException { return ManagedCloudSdk.newManagedSdk(); }
@Test public void child_update_setsProportionedFractions() { progressListener.start("main", 100); ProgressListener childListener = progressListener.newChild(20); childListener.start("child", 10); childListener.update(5); verify(mockProgressIndicator) .setText(CloudSdkMessageBundle.message("managedsdk.progress.message", "child")); verify(mockProgressIndicator).setFraction(5d / 10d * 20d / 100d); } }
static Function<String, ManagedCloudSdk> newManagedSdkFactory() { return (version) -> { try { if (Strings.isNullOrEmpty(version)) { return ManagedCloudSdk.newManagedSdk(); } else { return ManagedCloudSdk.newManagedSdk(new Version(version)); } } catch (UnsupportedOsException | BadCloudSdkVersionException ex) { throw new RuntimeException(ex); } }; } }