]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7908 add integration test on ES + web nodes in cluster
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Wed, 3 Aug 2016 13:47:18 +0000 (15:47 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Wed, 3 Aug 2016 15:59:19 +0000 (17:59 +0200)
it/it-tests/src/test/java/it/serverSystem/ClusterTest.java
pom.xml
tests/upgrade/src/test/java/org/sonarsource/sonarqube/upgrade/UpgradeTest.java

index c0a9a887104a345a7973fc747c62115e2281bb8d..4655f9d72e0ea458b04f1accc3601b967d0e5f1f 100644 (file)
@@ -22,6 +22,7 @@ package it.serverSystem;
 import com.google.common.base.Joiner;
 import com.google.common.collect.ImmutableMap;
 import com.sonar.orchestrator.Orchestrator;
+import com.sonar.orchestrator.server.StartupLogWatcher;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
@@ -30,10 +31,13 @@ import java.nio.file.Files;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 import org.apache.commons.io.FileUtils;
 import org.junit.Test;
+import org.sonarqube.ws.Issues;
 import org.sonarqube.ws.client.rule.SearchWsRequest;
 import util.ItUtils;
 
@@ -74,6 +78,63 @@ public class ClusterTest {
     orchestrator.stop();
   }
 
+  @Test
+  public void start_cluster_of_elasticsearch_and_web_nodes() {
+    Orchestrator elasticsearch = null;
+    Orchestrator web = null;
+
+    try {
+      ElasticsearchStartupWatcher esWatcher = new ElasticsearchStartupWatcher();
+      elasticsearch = Orchestrator.builderEnv()
+        .setServerProperty("sonar.cluster.enabled", "true")
+        .setServerProperty("sonar.cluster.web.disabled", "true")
+        .setServerProperty("sonar.cluster.ce.disabled", "true")
+        .setStartupLogWatcher(esWatcher)
+        .build();
+      elasticsearch.start();
+      assertThat(esWatcher.port).isGreaterThan(0);
+
+      web = Orchestrator.builderEnv()
+        .setServerProperty("sonar.cluster.enabled", "true")
+        .setServerProperty("sonar.cluster.startupLeader", "true")
+        .setServerProperty("sonar.cluster.search.disabled", "true")
+        .setServerProperty("sonar.cluster.search.hosts", "localhost:" + esWatcher.port)
+        // no need for compute engine in this test. Disable it for faster test.
+        .setServerProperty("sonar.cluster.ce.disabled", "true")
+        // override the default watcher provided by Orchestrator
+        // which waits for Compute Engine to be up
+        .setStartupLogWatcher(log -> log.contains("Process[web] is up"))
+        .build();
+      web.start();
+
+      // call a web service that requires Elasticsearch
+      Issues.SearchWsResponse wsResponse = ItUtils.newWsClient(web).issues().search(new org.sonarqube.ws.client.issue.SearchWsRequest());
+      assertThat(wsResponse.getIssuesCount()).isEqualTo(0);
+
+    } finally {
+      if (web != null) {
+        web.stop();
+      }
+      if (elasticsearch != null) {
+        elasticsearch.stop();
+      }
+    }
+  }
+
+  private static class ElasticsearchStartupWatcher implements StartupLogWatcher {
+    private final Pattern pattern = Pattern.compile("Elasticsearch listening on .*:(\\d+)");
+    private int port = -1;
+
+    @Override
+    public boolean isStarted(String log) {
+      Matcher matcher = pattern.matcher(log);
+      if (matcher.find()) {
+        port = Integer.parseInt(matcher.group(1));
+      }
+      return log.contains("Process[es] is up");
+    }
+  }
+
   private static void expectLog(Orchestrator orchestrator, String expectedLog) throws IOException {
     File logFile = orchestrator.getServer().getLogs();
     try (Stream<String> lines = Files.lines(logFile.toPath())) {
diff --git a/pom.xml b/pom.xml
index 3f33c0e947f8ff0e190fce61fe8870ee44a5a654..645ef1c7b6b83b7c771c4d750b665ded2503eaca 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -66,7 +66,7 @@
     <slf4j.version>1.7.12</slf4j.version>
     <tomcat.version>8.0.32</tomcat.version>
     <elasticsearch.version>2.3.3</elasticsearch.version>
-    <orchestrator.version>3.11</orchestrator.version>
+    <orchestrator.version>3.13-build640</orchestrator.version>
     <okhttp.version>3.3.1</okhttp.version>
     <jackson.version>2.6.6</jackson.version>
 
index dd9a803c7b1015cd55799a6fcba9c9cf87ec8d7e..bcc3d539ecc4cd759971cff0d24e6d5dda1f383c 100644 (file)
@@ -19,8 +19,6 @@
  */
 package org.sonarsource.sonarqube.upgrade;
 
-import static org.assertj.core.api.Assertions.assertThat;
-
 import com.sonar.orchestrator.Orchestrator;
 import com.sonar.orchestrator.OrchestratorBuilder;
 import com.sonar.orchestrator.build.MavenBuild;
@@ -42,6 +40,8 @@ import org.sonarqube.ws.client.WsClient;
 import org.sonarqube.ws.client.WsClientFactories;
 import org.sonarqube.ws.client.WsResponse;
 
+import static org.assertj.core.api.Assertions.assertThat;
+
 public class UpgradeTest {
 
   public static final String PROJECT_KEY = "org.apache.struts:struts-parent";
@@ -57,8 +57,8 @@ public class UpgradeTest {
   }
 
   @Test
-  public void test_upgrade_from_4_5_lts() {
-    testDatabaseUpgrade(Version.create("4.5.7"), "3.14");
+  public void test_upgrade_from_5_6() {
+    testDatabaseUpgrade(Version.create("5.6.1"), "3.14");
   }
 
   @Test
@@ -67,18 +67,17 @@ public class UpgradeTest {
   }
 
   private void testDatabaseUpgrade(Version fromVersion, String javaVersion) {
-    startServer(fromVersion, javaVersion, false);
+    startOldServer(fromVersion, javaVersion);
     scanProject();
     int files = countFiles(PROJECT_KEY);
     assertThat(files).isGreaterThan(0);
-
     stopServer();
-    // latest version
-    startServer(Version.create(Orchestrator.builderEnv().getSonarVersion()), "LATEST_RELEASE", true);
+
+    startNewServer();
     checkSystemStatus(ServerStatusResponse.Status.DB_MIGRATION_NEEDED);
     checkUrlsBeforeUpgrade();
 
-    upgradeDatabase();
+    upgrade();
     checkSystemStatus(ServerStatusResponse.Status.UP);
     checkUrlsAfterUpgrade();
 
@@ -139,22 +138,31 @@ public class UpgradeTest {
     testUrl("/profiles");
   }
 
-  private void upgradeDatabase() {
+  private void upgrade() {
     ServerMigrationResponse serverMigrationResponse = new ServerMigrationCall(orchestrator).callAndWait();
 
     assertThat(serverMigrationResponse.getStatus()).isEqualTo(ServerMigrationResponse.Status.MIGRATION_SUCCEEDED);
   }
 
-  private void startServer(Version sqVersion, String javaVersion, boolean keepDatabase) {
+  private void startOldServer(Version sqVersion, String javaVersion) {
     String jdbcUrl = MssqlConfig.fixUrl(Configuration.createEnv(), sqVersion);
-    OrchestratorBuilder builder = Orchestrator.builderEnv()
+    orchestrator = Orchestrator.builderEnv()
       .setOrchestratorProperty("sonar.jdbc.url", jdbcUrl)
-      .setSonarVersion(sqVersion.toString());
-    builder.setOrchestratorProperty("orchestrator.keepDatabase", String.valueOf(keepDatabase));
-    if (!keepDatabase) {
-      builder.restoreProfileAtStartup(FileLocation.ofClasspath("/sonar-way-5.1.xml"));
-    }
-    builder.setOrchestratorProperty("javaVersion", javaVersion).addPlugin("java");
+      .setSonarVersion(sqVersion.toString())
+      .setOrchestratorProperty("orchestrator.keepDatabase", "false")
+      .restoreProfileAtStartup(FileLocation.ofClasspath("/sonar-way-5.1.xml"))
+      .setOrchestratorProperty("javaVersion", javaVersion)
+      .addPlugin("java").build();
+    orchestrator.start();
+  }
+
+  private void startNewServer() {
+    OrchestratorBuilder builder = Orchestrator.builderEnv()
+      .setSonarVersion("DEV")
+      .setOrchestratorProperty("orchestrator.keepDatabase", "true")
+      .setOrchestratorProperty("javaVersion", "LATEST_RELEASE")
+      .setStartupLogWatcher(log -> log.contains("Process[web] is up"))
+      .addPlugin("java");
     orchestrator = builder.build();
     orchestrator.start();
   }