From bcd1bf53c45459ec754270a0c6408e3d68144442 Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20Lesaint?= Date: Thu, 23 May 2019 13:50:32 +0200 Subject: [PATCH] SONAR-11264 don't enforce ES bootstrap checks when connecting to H2 --- .../application/command/EsJvmOptions.java | 2 +- .../application/command/EsJvmOptionsTest.java | 33 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/server/sonar-main/src/main/java/org/sonar/application/command/EsJvmOptions.java b/server/sonar-main/src/main/java/org/sonar/application/command/EsJvmOptions.java index 75dc84ef5b3..92272e5bd6c 100644 --- a/server/sonar-main/src/main/java/org/sonar/application/command/EsJvmOptions.java +++ b/server/sonar-main/src/main/java/org/sonar/application/command/EsJvmOptions.java @@ -126,7 +126,7 @@ public class EsJvmOptions extends JvmOptions { 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"); } diff --git a/server/sonar-main/src/test/java/org/sonar/application/command/EsJvmOptionsTest.java b/server/sonar-main/src/test/java/org/sonar/application/command/EsJvmOptionsTest.java index 5c0d30e2987..f1a9b08552f 100644 --- a/server/sonar-main/src/test/java/org/sonar/application/command/EsJvmOptionsTest.java +++ b/server/sonar-main/src/test/java/org/sonar/application/command/EsJvmOptionsTest.java @@ -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); -- 2.39.5