From acdf881491a008872631199e0ebc1f4f7964c441 Mon Sep 17 00:00:00 2001 From: Jacek Date: Wed, 26 Jan 2022 14:11:35 +0100 Subject: [PATCH] SONAR-13997 Allow to override 'sonar.es.bootstrap.checks.disable' - default for jdbc other than H2 to check es bootstrap at startup - default for H2 to not check es bootstrap at startup --- .../application/command/EsJvmOptions.java | 3 +- .../application/command/EsJvmOptionsTest.java | 52 +++++++++++++++++++ .../org/sonar/process/ProcessProperties.java | 1 + 3 files changed, 55 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 5bb7aaafd2e..b9f9e9d18d1 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 @@ -46,7 +46,8 @@ public class EsJvmOptions extends JvmOptions { 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"); } 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 fe9cc2b40ab..8d0abbe22aa 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 @@ -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. */ diff --git a/server/sonar-process/src/main/java/org/sonar/process/ProcessProperties.java b/server/sonar-process/src/main/java/org/sonar/process/ProcessProperties.java index c23d684c859..425b566f45e 100644 --- a/server/sonar-process/src/main/java/org/sonar/process/ProcessProperties.java +++ b/server/sonar-process/src/main/java/org/sonar/process/ProcessProperties.java @@ -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"), -- 2.39.5