private void executeWithSdkWriteLock(ThrowableRunnable<Exception> runWithLock) throws Exception { try { // if write lock is not available, show a progress to a user that all SDK processes must be // finished in order to update SDK. if (!CloudSdkServiceManager.getInstance().getSdkWriteLock().tryLock()) { ProgressListener waitForSdkProcessesProgress = ManagedCloudSdkServiceUiPresenter.getInstance().createProgressListener(this); waitForSdkProcessesProgress.start( CloudSdkMessageBundle.message("managedsdk.progress.wait.for.processes"), ProgressListener.UNKNOWN); try { CloudSdkServiceManager.getInstance().getSdkWriteLock().lockInterruptibly(); } finally { // make sure the indicator goes away in case of this job error/cancel waitForSdkProcessesProgress.done(); } } runWithLock.run(); } finally { CloudSdkServiceManager.getInstance().getSdkWriteLock().unlock(); } }
@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); } }
@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(); }
progressListener.done();