From a22748242b5b290b9ee978b451736512a89db761 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Fri, 9 Dec 2016 12:41:42 +0100 Subject: [PATCH] Use local SonarQube ZIP in performance and upgrade tests --- tests/perf/pom.xml | 1 + tests/pom.xml | 46 +++++++++- tests/upgrade/pom.xml | 4 + .../sonarqube/upgrade/UpgradeTest.java | 83 ++++++++++--------- 4 files changed, 94 insertions(+), 40 deletions(-) diff --git a/tests/perf/pom.xml b/tests/perf/pom.xml index 3a60a286011..f2a5c637294 100644 --- a/tests/perf/pom.xml +++ b/tests/perf/pom.xml @@ -14,6 +14,7 @@ * + ../../sonar-application/target diff --git a/tests/pom.xml b/tests/pom.xml index d5ab2ef9248..6a220d580d0 100644 --- a/tests/pom.xml +++ b/tests/pom.xml @@ -1,5 +1,6 @@ - 4.0.0 @@ -17,6 +18,7 @@ true true true + ../sonar-application/target @@ -24,4 +26,46 @@ upgrade + + + qa + + + env.SONARSOURCE_QA + true + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + copy-sonarqube-zip + generate-test-resources + + copy + + + + + ${project.groupId} + sonar-application + ${project.version} + zip + true + + + ${sqZipDir} + true + true + + + + + + + + diff --git a/tests/upgrade/pom.xml b/tests/upgrade/pom.xml index d17d17f10c2..6af57d8e5a0 100644 --- a/tests/upgrade/pom.xml +++ b/tests/upgrade/pom.xml @@ -12,6 +12,10 @@ upgrade SonarQube :: Upgrade Tests + + ../../sonar-application/target + + org.codehaus.sonar diff --git a/tests/upgrade/src/test/java/org/sonarsource/sonarqube/upgrade/UpgradeTest.java b/tests/upgrade/src/test/java/org/sonarsource/sonarqube/upgrade/UpgradeTest.java index fb6e1b42436..399db797d5a 100644 --- a/tests/upgrade/src/test/java/org/sonarsource/sonarqube/upgrade/UpgradeTest.java +++ b/tests/upgrade/src/test/java/org/sonarsource/sonarqube/upgrade/UpgradeTest.java @@ -22,7 +22,6 @@ package org.sonarsource.sonarqube.upgrade; import com.sonar.orchestrator.Orchestrator; import com.sonar.orchestrator.OrchestratorBuilder; import com.sonar.orchestrator.build.MavenBuild; -import com.sonar.orchestrator.config.Configuration; import com.sonar.orchestrator.container.Server; import com.sonar.orchestrator.locator.FileLocation; import com.sonar.orchestrator.version.Version; @@ -31,7 +30,6 @@ import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; import java.util.Arrays; -import java.util.stream.Stream; import org.apache.commons.io.IOUtils; import org.junit.After; import org.junit.Test; @@ -47,7 +45,6 @@ import static org.assertj.core.api.Assertions.assertThat; public class UpgradeTest { private static final String PROJECT_KEY = "org.apache.struts:struts-parent"; - private static final String SQ_VERSION_DEV = "DEV"; private static final String LATEST_JAVA_RELEASE = "LATEST_RELEASE"; private Orchestrator orchestrator; @@ -62,36 +59,52 @@ public class UpgradeTest { @Test public void test_upgrade_from_5_6_1() { - testDatabaseUpgrade("3.14", Version.create("5.6.1")); + testDatabaseUpgrade(Version.create("5.6.1")); } @Test public void test_upgrade_from_5_2_via_5_6() { - testDatabaseUpgrade("3.14", Version.create("5.2"), Version.create("5.6")); + testDatabaseUpgrade(Version.create("5.2"), Version.create("5.6")); } - private void testDatabaseUpgrade(String javaVersion, Version fromVersion, Version... intermediaryVersions) { - startOldServer(fromVersion, javaVersion); + @Test + public void test_upgrade_from_6_0() { + testDatabaseUpgrade(Version.create("6.0")); + } + + @Test + public void test_upgrade_from_6_1() { + testDatabaseUpgrade(Version.create("6.1")); + } + + private void testDatabaseUpgrade(Version fromVersion, Version... intermediaryVersions) { + startOldVersionServer(fromVersion, false); scanProject(); int files = countFiles(PROJECT_KEY); assertThat(files).isGreaterThan(0); stopServer(); - Stream.concat(Arrays.stream(intermediaryVersions).map(Version::toString), Stream.of(SQ_VERSION_DEV)) - .forEach((sqVersion) -> { - upgradeTo(sqVersion, javaVersion); + Arrays.stream(intermediaryVersions).forEach((sqVersion) -> { + startOldVersionServer(sqVersion, true); + upgrade(); + verifyAnalysis(files); + stopServer(); + }); - assertThat(countFiles(PROJECT_KEY)).isEqualTo(files); - scanProject(); - assertThat(countFiles(PROJECT_KEY)).isEqualTo(files); - browseWebapp(); + startDevServer(); + upgrade(); + verifyAnalysis(files); + stopServer(); + } - stopServer(); - }); + private void verifyAnalysis(int expectedNumberOfFiles) { + assertThat(countFiles(PROJECT_KEY)).isEqualTo(expectedNumberOfFiles); + scanProject(); + assertThat(countFiles(PROJECT_KEY)).isEqualTo(expectedNumberOfFiles); + browseWebapp(); } - private void upgradeTo(String sqVersion, String javaVersion) { - startNewServer(sqVersion, SQ_VERSION_DEV.equals(sqVersion) ? LATEST_JAVA_RELEASE : javaVersion); + private void upgrade() { checkSystemStatus(ServerStatusResponse.Status.DB_MIGRATION_NEEDED); checkUrlsBeforeUpgrade(); @@ -152,31 +165,24 @@ public class UpgradeTest { testUrl("/profiles"); } - private void upgrade() { - ServerMigrationResponse serverMigrationResponse = new ServerMigrationCall(orchestrator).callAndWait(); - - assertThat(serverMigrationResponse.getStatus()).isEqualTo(ServerMigrationResponse.Status.MIGRATION_SUCCEEDED); - } - - private void startOldServer(Version sqVersion, String javaVersion) { - String jdbcUrl = MssqlConfig.fixUrl(Configuration.createEnv(), sqVersion); - orchestrator = Orchestrator.builderEnv() - .setOrchestratorProperty("sonar.jdbc.url", jdbcUrl) + private void startOldVersionServer(Version sqVersion, boolean keepDatabase) { + OrchestratorBuilder builder = Orchestrator.builderEnv() .setSonarVersion(sqVersion.toString()) - .setOrchestratorProperty("orchestrator.keepDatabase", "false") - .restoreProfileAtStartup(FileLocation.ofClasspath("/sonar-way-5.1.xml")) - .setOrchestratorProperty("javaVersion", javaVersion) - .addPlugin("java").build(); + .setOrchestratorProperty("orchestrator.keepDatabase", String.valueOf(keepDatabase)) + .setOrchestratorProperty("javaVersion", "3.14") + .addPlugin("java") + .setStartupLogWatcher(log -> log.contains("Process[web] is up")); + orchestrator = builder.build(); orchestrator.start(); } - private void startNewServer(String sqVersion, String javaVersion) { + private void startDevServer() { OrchestratorBuilder builder = Orchestrator.builderEnv() - .setSonarVersion(sqVersion) + .setZipFile(FileLocation.byWildcardMavenFilename(new File("../../sonar-application/target"), "sonar*.zip").getFile()) .setOrchestratorProperty("orchestrator.keepDatabase", "true") - .setOrchestratorProperty("javaVersion", javaVersion) - .setStartupLogWatcher(log -> log.contains("Process[web] is up")) - .addPlugin("java"); + .setOrchestratorProperty("javaVersion", LATEST_JAVA_RELEASE) + .addPlugin("java") + .setStartupLogWatcher(log -> log.contains("Process[web] is up")); orchestrator = builder.build(); orchestrator.start(); } @@ -192,8 +198,7 @@ public class UpgradeTest { .setCleanSonarGoals() .setProperty("sonar.dynamicAnalysis", "false") .setProperty("sonar.scm.disabled", "true") - .setProperty("sonar.cpd.cross_project", "true") - .setProperty("sonar.profile", "sonar-way-5.1"); + .setProperty("sonar.cpd.cross_project", "true"); orchestrator.executeBuild(build); } -- 2.39.5