]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-11264 don't enforce ES bootstrap checks when connecting to H2
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Thu, 23 May 2019 11:50:32 +0000 (13:50 +0200)
committerSonarTech <sonartech@sonarsource.com>
Fri, 24 May 2019 18:21:09 +0000 (20:21 +0200)
server/sonar-main/src/main/java/org/sonar/application/command/EsJvmOptions.java
server/sonar-main/src/test/java/org/sonar/application/command/EsJvmOptionsTest.java

index 75dc84ef5b3f7e460f5babe776d88fb4cd13bcfa..92272e5bd6ceee79c6412b01eebb0370dd359517 100644 (file)
@@ -126,7 +126,7 @@ public class EsJvmOptions extends JvmOptions<EsJvmOptions> {
       res.put("-XX:UseAVX=", "2");
     }
 
-    if (!props.valueAsBoolean("sonar.es.bootstrap.checks.disable")) {
+    if (!props.value("sonar.jdbc.url", "").contains("jdbc:h2") && !props.valueAsBoolean("sonar.es.bootstrap.checks.disable")) {
       res.put("-Des.enforce.bootstrap.checks=", "true");
     }
 
index 5c0d30e29876df1b7b6b7380924740f910f64e77..f1a9b08552f60d5b39ae05de9c7bfc384469457b 100644 (file)
@@ -34,6 +34,7 @@ import org.sonar.process.Props;
 import org.sonar.process.System2;
 import org.sonar.test.ExceptionCauseMatcher;
 
+import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
@@ -87,6 +88,38 @@ public class EsJvmOptionsTest {
       .doesNotContain("-Des.enforce.bootstrap.checks=true");
   }
 
+  @Test
+  @UseDataProvider("java8or11")
+  public void constructor_forces_boostrap_checks_if_jdbc_url_property_does_not_exist(System2 system2) throws IOException {
+    File tmpDir = temporaryFolder.newFolder();
+    EsJvmOptions underTest = new EsJvmOptions(system2, new Props(properties), tmpDir);
+
+    assertThat(underTest.getAll())
+      .contains("-Des.enforce.bootstrap.checks=true");
+  }
+
+  @Test
+  @UseDataProvider("java8or11")
+  public void constructor_forces_boostrap_checks_if_jdbc_url_property_is_not_h2(System2 system2) throws IOException {
+    properties.put("sonar.jdbc.url", randomAlphanumeric(53));
+    File tmpDir = temporaryFolder.newFolder();
+    EsJvmOptions underTest = new EsJvmOptions(system2, new Props(properties), tmpDir);
+
+    assertThat(underTest.getAll())
+      .contains("-Des.enforce.bootstrap.checks=true");
+  }
+
+  @Test
+  @UseDataProvider("java8or11")
+  public void constructor_does_not_force_boostrap_checks_if_jdbc_url_property_contains_h2(System2 system2) throws IOException {
+    properties.put("sonar.jdbc.url", "jdbc:h2:tcp://ffoo:bar/sonar");
+    File tmpDir = temporaryFolder.newFolder();
+    EsJvmOptions underTest = new EsJvmOptions(system2, new Props(properties), tmpDir);
+
+    assertThat(underTest.getAll())
+      .doesNotContain("-Des.enforce.bootstrap.checks=true");
+  }
+
   @DataProvider
   public static Object[][] java8or11() {
     System2 java8 = mock(System2.class);