]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-13997 Allow to override 'sonar.es.bootstrap.checks.disable'
authorJacek <jacek.poreda@sonarsource.com>
Wed, 26 Jan 2022 13:11:35 +0000 (14:11 +0100)
committersonartech <sonartech@sonarsource.com>
Thu, 27 Jan 2022 20:03:05 +0000 (20:03 +0000)
- default for jdbc other than H2 to check es bootstrap at startup
- default for H2 to not check es bootstrap at startup

server/sonar-main/src/main/java/org/sonar/application/command/EsJvmOptions.java
server/sonar-main/src/test/java/org/sonar/application/command/EsJvmOptionsTest.java
server/sonar-process/src/main/java/org/sonar/process/ProcessProperties.java

index 5bb7aaafd2e458e4ca019dbdd5beb5b6d47af901..b9f9e9d18d1ce916a3e4da8b6d7d5350957438f4 100644 (file)
@@ -46,7 +46,8 @@ public class EsJvmOptions extends JvmOptions<EsJvmOptions> {
     fromJvmDotOptionsFile(tmpDir, res);
     fromSystemJvmOptionsClass(tmpDir, res);
 
-    if (!props.value("sonar.jdbc.url", "").contains("jdbc:h2") && !props.valueAsBoolean("sonar.es.bootstrap.checks.disable")) {
+    boolean defaultDisableBootstrapChecks = props.value("sonar.jdbc.url", "").contains("jdbc:h2");
+    if (!props.valueAsBoolean("sonar.es.bootstrap.checks.disable", defaultDisableBootstrapChecks)) {
       res.put("-Des.enforce.bootstrap.checks=", "true");
     }
 
index fe9cc2b40ab4978dcfd736f37ad8881bee4ab837..8d0abbe22aaf7ec753d204a5b4cac80e566a2c42 100644 (file)
@@ -112,6 +112,58 @@ public class EsJvmOptionsTest {
       .doesNotContain("-Des.enforce.bootstrap.checks=true");
   }
 
+  @Test
+  public void boostrap_checks_can_be_set_true_if_h2() throws IOException {
+    properties.put("sonar.jdbc.url", "jdbc:h2:tcp://ffoo:bar/sonar");
+    properties.put("sonar.es.bootstrap.checks.disable", "true");
+
+    File tmpDir = temporaryFolder.newFolder();
+    EsJvmOptions underTest = new EsJvmOptions(new Props(properties), tmpDir);
+
+    assertThat(underTest.getAll())
+        .isNotEmpty()
+        .doesNotContain("-Des.enforce.bootstrap.checks=true");
+  }
+
+  @Test
+  public void boostrap_checks_can_be_set_false_if_h2() throws IOException {
+    properties.put("sonar.jdbc.url", "jdbc:h2:tcp://ffoo:bar/sonar");
+    properties.put("sonar.es.bootstrap.checks.disable", "false");
+
+    File tmpDir = temporaryFolder.newFolder();
+    EsJvmOptions underTest = new EsJvmOptions(new Props(properties), tmpDir);
+
+    assertThat(underTest.getAll())
+        .isNotEmpty()
+        .contains("-Des.enforce.bootstrap.checks=true");
+  }
+
+  @Test
+  public void boostrap_checks_can_be_set_true_if_jdbc_other_than_h2() throws IOException {
+    properties.put("sonar.jdbc.url", randomAlphanumeric(53));
+    properties.put("sonar.es.bootstrap.checks.disable", "true");
+
+    File tmpDir = temporaryFolder.newFolder();
+    EsJvmOptions underTest = new EsJvmOptions(new Props(properties), tmpDir);
+
+    assertThat(underTest.getAll())
+        .isNotEmpty()
+        .doesNotContain("-Des.enforce.bootstrap.checks=true");
+  }
+
+  @Test
+  public void boostrap_checks_can_be_set_false_if_jdbc_other_than_h2() throws IOException {
+    properties.put("sonar.jdbc.url", randomAlphanumeric(53));
+    properties.put("sonar.es.bootstrap.checks.disable", "false");
+
+    File tmpDir = temporaryFolder.newFolder();
+    EsJvmOptions underTest = new EsJvmOptions(new Props(properties), tmpDir);
+
+    assertThat(underTest.getAll())
+        .isNotEmpty()
+        .contains("-Des.enforce.bootstrap.checks=true");
+  }
+
   /**
    * This test may fail if SQ's test are not executed with target Java version 8.
    */
index c23d684c859616b711c56465f673096cfc3ddf0d..425b566f45e460501f3b0fa690968de91d01f2ff 100644 (file)
@@ -85,6 +85,7 @@ public class ProcessProperties {
     SEARCH_JAVA_ADDITIONAL_OPTS("sonar.search.javaAdditionalOpts", ""),
     SEARCH_REPLICAS("sonar.search.replicas"),
     SEARCH_INITIAL_STATE_TIMEOUT("sonar.search.initialStateTimeout"),
+    SONAR_ES_BOOTSTRAP_CHECKS_DISABLE("sonar.es.bootstrap.checks.disable"),
 
     WEB_HOST("sonar.web.host"),
     WEB_JAVA_OPTS("sonar.web.javaOpts", "-Xmx512m -Xms128m -XX:+HeapDumpOnOutOfMemoryError"),