diff options
author | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2017-10-18 16:21:12 +0200 |
---|---|---|
committer | Grégoire Aubert <gregoire.aubert@sonarsource.com> | 2017-10-23 08:01:13 -0700 |
commit | 9c48d41cee8baa7ae557e77faf22afce0c4a0b85 (patch) | |
tree | 6e2393453ae922503965bfac3e1392b692d737c4 /server | |
parent | b7a7173803bf2329dceba52b11c04bad416def33 (diff) | |
download | sonarqube-9c48d41cee8baa7ae557e77faf22afce0c4a0b85.tar.gz sonarqube-9c48d41cee8baa7ae557e77faf22afce0c4a0b85.zip |
SONAR-10002 AUTOMATIC_IN_PROGRESS at startup resets to NONE
and stores an installation failure into the edition management state
Diffstat (limited to 'server')
2 files changed, 135 insertions, 18 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/edition/CommitPendingEditionOnStartup.java b/server/sonar-server/src/main/java/org/sonar/server/edition/CommitPendingEditionOnStartup.java index 2459645c715..bd518af77e1 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/edition/CommitPendingEditionOnStartup.java +++ b/server/sonar-server/src/main/java/org/sonar/server/edition/CommitPendingEditionOnStartup.java @@ -22,6 +22,7 @@ package org.sonar.server.edition; import javax.annotation.CheckForNull; import javax.annotation.Nullable; import org.sonar.api.Startable; +import org.sonar.api.utils.log.Loggers; import org.sonar.server.license.LicenseCommit; public class CommitPendingEditionOnStartup implements Startable { @@ -53,9 +54,7 @@ public class CommitPendingEditionOnStartup implements Startable { finalizeInstall(status); break; case AUTOMATIC_IN_PROGRESS: - // FIXME temporary hack until download of edition is implemented, should move status to AUTOMATIC_FAILURE - editionManagementState.automaticInstallReady(); - finalizeInstall(status); + editionManagementState.installFailed("SonarQube was restarted before asynchronous installation of edition completed"); break; case UNINSTALL_IN_PROGRESS: failIfLicenseCommitIsPresent(); @@ -75,6 +74,7 @@ public class CommitPendingEditionOnStartup implements Startable { private void finalizeInstall(EditionManagementState.PendingStatus status) { // license manager is not installed, can't finalize if (licenseCommit == null) { + Loggers.get(CommitPendingEditionOnStartup.class).debug("No LicenseCommit instance is not available, can not finalize installation"); return; } diff --git a/server/sonar-server/src/test/java/org/sonar/server/edition/CommitPendingEditionOnStartupTest.java b/server/sonar-server/src/test/java/org/sonar/server/edition/CommitPendingEditionOnStartupTest.java index 24cda0b8fe8..478c9d066e6 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/edition/CommitPendingEditionOnStartupTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/edition/CommitPendingEditionOnStartupTest.java @@ -19,44 +19,161 @@ */ package org.sonar.server.edition; +import java.util.Optional; +import org.apache.commons.lang.RandomStringUtils; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import org.sonar.server.edition.EditionManagementState.PendingStatus; +import org.sonar.api.utils.log.LogTester; +import org.sonar.api.utils.log.LoggerLevel; import org.sonar.server.license.LicenseCommit; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; +import static org.sonar.server.edition.EditionManagementState.PendingStatus.AUTOMATIC_IN_PROGRESS; +import static org.sonar.server.edition.EditionManagementState.PendingStatus.AUTOMATIC_READY; +import static org.sonar.server.edition.EditionManagementState.PendingStatus.MANUAL_IN_PROGRESS; +import static org.sonar.server.edition.EditionManagementState.PendingStatus.NONE; public class CommitPendingEditionOnStartupTest { @Rule - public ExpectedException exception = ExpectedException.none(); + public ExpectedException expectedException = ExpectedException.none(); + @Rule + public LogTester logTester = new LogTester() + .setLevel(LoggerLevel.DEBUG); - private MutableEditionManagementState mutableEditionManagementState = mock(MutableEditionManagementState.class); + private MutableEditionManagementState editionManagementState = mock(MutableEditionManagementState.class); + private LicenseCommit licenseCommit = mock(LicenseCommit.class); + private CommitPendingEditionOnStartup underTest = new CommitPendingEditionOnStartup(editionManagementState); + private CommitPendingEditionOnStartup underTestWithLicenseCommit = new CommitPendingEditionOnStartup(editionManagementState, licenseCommit); @Test - public void should_commit_uninstall() { - CommitPendingEditionOnStartup underTest = new CommitPendingEditionOnStartup(mutableEditionManagementState); - when(mutableEditionManagementState.getPendingInstallationStatus()).thenReturn(PendingStatus.UNINSTALL_IN_PROGRESS); + public void start_has_no_effect_when_status_is_NONE_without_LicenseCommit() { + when(editionManagementState.getPendingInstallationStatus()).thenReturn(NONE); underTest.start(); - verify(mutableEditionManagementState).getPendingInstallationStatus(); - verify(mutableEditionManagementState).finalizeInstallation(); - verifyNoMoreInteractions(mutableEditionManagementState); + verify(editionManagementState).getPendingInstallationStatus(); + verifyNoMoreInteractions(editionManagementState); } @Test - public void should_fail_uninstall_if_license_commit_is_present() { - when(mutableEditionManagementState.getPendingInstallationStatus()).thenReturn(PendingStatus.UNINSTALL_IN_PROGRESS); - CommitPendingEditionOnStartup underTest = new CommitPendingEditionOnStartup(mutableEditionManagementState, - mock(LicenseCommit.class)); + public void start_has_no_effect_when_status_is_NONE_with_LicenseCommit() { + when(editionManagementState.getPendingInstallationStatus()).thenReturn(NONE); + + underTestWithLicenseCommit.start(); + + verify(editionManagementState).getPendingInstallationStatus(); + verifyNoMoreInteractions(editionManagementState); + verifyZeroInteractions(licenseCommit); + } + + @Test + public void starts_has_no_effect_when_status_is_AUTOMATIC_READY_and_no_LicenseCommit_is_available_but_logs_at_debug_level() { + when(editionManagementState.getPendingInstallationStatus()).thenReturn(AUTOMATIC_READY); + + underTest.start(); + + verify(editionManagementState).getPendingInstallationStatus(); + verifyNoMoreInteractions(editionManagementState); + verifyZeroInteractions(licenseCommit); + assertThat(logTester.logs()).hasSize(1); + assertThat(logTester.logs(LoggerLevel.DEBUG)) + .containsOnly("No LicenseCommit instance is not available, can not finalize installation"); + } + + @Test + public void start_commit_license_and_finalizeInstallation_in_editionManagementState_when_status_is_AUTOMATIC_READY_and_LicenseCommit_is_available() { + when(editionManagementState.getPendingInstallationStatus()).thenReturn(AUTOMATIC_READY); + String license = RandomStringUtils.randomAlphanumeric(20); + when(editionManagementState.getPendingLicense()).thenReturn(Optional.of(license)); + + underTestWithLicenseCommit.start(); + + verify(editionManagementState).getPendingInstallationStatus(); + verify(editionManagementState).getPendingLicense(); + verify(editionManagementState).finalizeInstallation(); + verifyNoMoreInteractions(editionManagementState); + verify(licenseCommit).update(license); + verifyNoMoreInteractions(licenseCommit); + } + + @Test + public void starts_has_no_effect_when_status_is_MANUAL_IN_PROGRESS_and_no_LicenseCommit_is_available_but_logs_at_debug_level() { + when(editionManagementState.getPendingInstallationStatus()).thenReturn(MANUAL_IN_PROGRESS); + + underTest.start(); + + verify(editionManagementState).getPendingInstallationStatus(); + verifyNoMoreInteractions(editionManagementState); + verifyZeroInteractions(licenseCommit); + assertThat(logTester.logs()).hasSize(1); + assertThat(logTester.logs(LoggerLevel.DEBUG)) + .containsOnly("No LicenseCommit instance is not available, can not finalize installation"); + } + + @Test + public void start_commit_license_and_finalizeInstallation_in_editionManagementState_when_status_is_MANUAL_IN_PROGRESS_and_LicenseCommit_is_available() { + when(editionManagementState.getPendingInstallationStatus()).thenReturn(MANUAL_IN_PROGRESS); + String license = RandomStringUtils.randomAlphanumeric(20); + when(editionManagementState.getPendingLicense()).thenReturn(Optional.of(license)); + + underTestWithLicenseCommit.start(); + + verify(editionManagementState).getPendingInstallationStatus(); + verify(editionManagementState).getPendingLicense(); + verify(editionManagementState).finalizeInstallation(); + verifyNoMoreInteractions(editionManagementState); + verify(licenseCommit).update(license); + verifyNoMoreInteractions(licenseCommit); + } + + @Test + public void starts_put_editionManagement_set_in_automaticInstallError_when_status_is_AUTOMATIC_PROGRESS_and_no_LicenseCommit_is_available() { + when(editionManagementState.getPendingInstallationStatus()).thenReturn(AUTOMATIC_IN_PROGRESS); + + underTest.start(); + + verify(editionManagementState).getPendingInstallationStatus(); + verify(editionManagementState).installFailed("SonarQube was restarted before asynchronous installation of edition completed"); + verifyNoMoreInteractions(editionManagementState); + verifyZeroInteractions(licenseCommit); + } + + @Test + public void starts_put_editionManagement_set_in_automaticInstallError_when_status_is_AUTOMATIC_PROGRESS_and_LicenseCommit_is_available() { + when(editionManagementState.getPendingInstallationStatus()).thenReturn(AUTOMATIC_IN_PROGRESS); + + underTestWithLicenseCommit.start(); + + verify(editionManagementState).getPendingInstallationStatus(); + verify(editionManagementState).installFailed("SonarQube was restarted before asynchronous installation of edition completed"); + verifyNoMoreInteractions(editionManagementState); + verifyZeroInteractions(licenseCommit); + } + + @Test + public void should_commit_uninstall() { + when(editionManagementState.getPendingInstallationStatus()).thenReturn(EditionManagementState.PendingStatus.UNINSTALL_IN_PROGRESS); - exception.expect(IllegalStateException.class); - exception.expectMessage("License Manager plugin is still present"); underTest.start(); + + verify(editionManagementState).getPendingInstallationStatus(); + verify(editionManagementState).finalizeInstallation(); + verifyNoMoreInteractions(editionManagementState); } + @Test + public void should_fail_uninstall_if_license_commit_is_present() { + when(editionManagementState.getPendingInstallationStatus()).thenReturn(EditionManagementState.PendingStatus.UNINSTALL_IN_PROGRESS); + + expectedException.expect(IllegalStateException.class); + expectedException.expectMessage("License Manager plugin is still present"); + + underTestWithLicenseCommit.start(); + } } |