import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
+import java.nio.file.Paths;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.stream.Collectors;
// with some changes to fit running bundled in SQ
private static Map<String, String> mandatoryOptions(File tmpDir, Props props) {
Map<String, String> res = new LinkedHashMap<>(30);
- fromJvmDotOptionsFile(tmpDir, res);
+ fromJvmDotOptionsFile(tmpDir, res, props);
fromSystemJvmOptionsClass(tmpDir, res);
boolean defaultDisableBootstrapChecks = props.value("sonar.jdbc.url", "").contains("jdbc:h2");
return res;
}
- private static void fromJvmDotOptionsFile(File tmpDir, Map<String, String> res) {
+ private static void fromJvmDotOptionsFile(File tmpDir, Map<String, String> res, Props props) {
// GC configuration
res.put("-XX:+UseG1GC", "");
// has sufficient space
// res.put("-XX:HeapDumpPath", "data");
// specify an alternative path for JVM fatal error logs (ES 6.6.1 default is "logs/hs_err_pid%p.log")
- res.put("-XX:ErrorFile=", "../logs/es_hs_err_pid%p.log");
+ var path = Paths.get(props.value("sonar.path.logs", "logs"), "es_hs_err_pid%p.log");
+ res.put("-XX:ErrorFile=", path.toAbsolutePath().toString());
}
import com.tngtech.java.junit.dataprovider.DataProviderRunner;
import java.io.File;
import java.io.IOException;
+import java.nio.file.Paths;
import java.util.Properties;
+import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
@RunWith(DataProviderRunner.class)
public class EsJvmOptionsTest {
@Rule
- public TemporaryFolder temporaryFolder = new TemporaryFolder();
+ public final TemporaryFolder temporaryFolder = new TemporaryFolder();
- private Properties properties = new Properties();
+ private final Properties properties = new Properties();
+
+ @Before
+ public void before() {
+ properties.put("sonar.path.logs", "path_to_logs");
+ }
@Test
public void constructor_sets_mandatory_JVM_options() throws IOException {
.containsExactlyInAnyOrder(
"-XX:+UseG1GC",
"-Djava.io.tmpdir=" + tmpDir.getAbsolutePath(),
- "-XX:ErrorFile=../logs/es_hs_err_pid%p.log",
+ "-XX:ErrorFile=" + Paths.get("path_to_logs/es_hs_err_pid%p.log").toAbsolutePath(),
"-Des.networkaddress.cache.ttl=60",
"-Des.networkaddress.cache.negative.ttl=10",
"-XX:+AlwaysPreTouch",
EsJvmOptions underTest = new EsJvmOptions(new Props(properties), tmpDir);
assertThat(underTest.getAll())
- .isNotEmpty()
- .doesNotContain("-Des.enforce.bootstrap.checks=true");
+ .isNotEmpty()
+ .doesNotContain("-Des.enforce.bootstrap.checks=true");
}
@Test
EsJvmOptions underTest = new EsJvmOptions(new Props(properties), tmpDir);
assertThat(underTest.getAll())
- .isNotEmpty()
- .contains("-Des.enforce.bootstrap.checks=true");
+ .isNotEmpty()
+ .contains("-Des.enforce.bootstrap.checks=true");
}
@Test
EsJvmOptions underTest = new EsJvmOptions(new Props(properties), tmpDir);
assertThat(underTest.getAll())
- .isNotEmpty()
- .doesNotContain("-Des.enforce.bootstrap.checks=true");
+ .isNotEmpty()
+ .doesNotContain("-Des.enforce.bootstrap.checks=true");
}
@Test
EsJvmOptions underTest = new EsJvmOptions(new Props(properties), tmpDir);
assertThat(underTest.getAll())
- .isNotEmpty()
- .contains("-Des.enforce.bootstrap.checks=true");
+ .isNotEmpty()
+ .contains("-Des.enforce.bootstrap.checks=true");
}
/**
"\n" +
"-XX:+UseG1GC\n" +
"-Djava.io.tmpdir=" + tmpDir.getAbsolutePath() + "\n" +
- "-XX:ErrorFile=../logs/es_hs_err_pid%p.log\n" +
+ "-XX:ErrorFile=" + Paths.get("path_to_logs/es_hs_err_pid%p.log").toAbsolutePath() + "\n" +
"-Des.networkaddress.cache.ttl=60\n" +
"-Des.networkaddress.cache.negative.ttl=10\n" +
"-XX:+AlwaysPreTouch\n" +