return new JavaCommand<EsJvmOptions>(ProcessId.ELASTICSEARCH, esInstallation.getHomeDirectory())
.setEsInstallation(esInstallation)
.setReadsArgumentsFromFile(false)
- .setJvmOptions(new EsJvmOptions()
+ .setJvmOptions(new EsJvmOptions(tempDir)
.addFromMandatoryProperty(props, SEARCH_JAVA_OPTS.getKey())
.addFromMandatoryProperty(props, SEARCH_JAVA_ADDITIONAL_OPTS.getKey())
.add("-Delasticsearch")
esInstallation
.setLog4j2Properties(new EsLogging().createProperties(props, esInstallation.getLogDirectory()))
- .setEsJvmOptions(new EsJvmOptions()
+ .setEsJvmOptions(new EsJvmOptions(tempDir)
.addFromMandatoryProperty(props, SEARCH_JAVA_OPTS.getKey())
.addFromMandatoryProperty(props, SEARCH_JAVA_ADDITIONAL_OPTS.getKey()))
.setEsYmlSettings(new EsYmlSettings(settingsMap))
"# DO NOT EDIT THIS FILE\n" +
"\n";
- public EsJvmOptions() {
- super(mandatoryOptions());
+ public EsJvmOptions(File tmpDir) {
+ super(mandatoryOptions(tmpDir));
}
- private static Map<String, String> mandatoryOptions() {
+ private static Map<String, String> mandatoryOptions(File tmpDir) {
Map<String, String> res = new LinkedHashMap<>(16);
res.put("-XX:+UseConcMarkSweepGC", "");
res.put("-XX:CMSInitiatingOccupancyFraction=", "75");
res.put("-XX:+AlwaysPreTouch", "");
res.put("-Xss", "1m");
res.put("-Djava.awt.headless=", "true");
+ res.put("-Djava.io.tmpdir=", tmpDir.getAbsolutePath());
res.put("-Dfile.encoding=", "UTF-8");
res.put("-Djna.nosys=", "true");
res.put("-Djdk.io.permissionsUseCanonicalPath=", "true");
if (command instanceof EsScriptCommand) {
process = launchExternal((EsScriptCommand) command);
} else if (command instanceof JavaCommand) {
- process = launchJava((JavaCommand) command);
+ process = launchJava((JavaCommand<?>) command);
} else {
throw new IllegalStateException("Unexpected type of command: " + command.getClass());
}
.contains(entry("ES_JVM_OPTIONS", new File(esConfDir, "jvm.options").getAbsolutePath()))
.containsKey("JAVA_HOME");
assertThat(esCommand.getSuppressedEnvVariables()).containsOnly("JAVA_TOOL_OPTIONS", "ES_JAVA_OPTS");
+
+ assertThat(esConfig.getEsJvmOptions().getAll())
+ .contains("-Djava.io.tmpdir=" + tempDir.getAbsolutePath());
}
@Test
.containsKey("JAVA_HOME");
assertThat(esCommand.getSuppressedEnvVariables()).containsOnly("JAVA_TOOL_OPTIONS", "ES_JAVA_OPTS");
+ assertThat(esConfig.getEsJvmOptions().getAll())
+ .contains("-Djava.io.tmpdir=" + tempDir.getAbsolutePath());
assertThat(esCommand.getJvmOptions().getAll())
.containsAll(esConfig.getEsJvmOptions().getAll())
.contains("-Delasticsearch")
assertThat(esConfig.getPort()).isEqualTo(1234);
assertThat(esConfig.getEsJvmOptions().getAll())
// enforced values
- .contains("-XX:+UseConcMarkSweepGC", "-Dfile.encoding=UTF-8")
+ .contains("-XX:+UseConcMarkSweepGC", "-server", "-Dfile.encoding=UTF-8")
+ .contains("-Djava.io.tmpdir=" + tempDir.getAbsolutePath())
// user settings
.contains("-Xms10G", "-Xmx10G")
// default values disabled
public ExpectedException expectedException = ExpectedException.none();
@Test
- public void constructor_sets_mandatory_JVM_options() {
- EsJvmOptions underTest = new EsJvmOptions();
+ public void constructor_sets_mandatory_JVM_options() throws IOException {
+ File tmpDir = temporaryFolder.newFolder();
+ EsJvmOptions underTest = new EsJvmOptions(tmpDir);
assertThat(underTest.getAll()).containsExactly(
"-XX:+UseConcMarkSweepGC",
"-XX:+AlwaysPreTouch",
"-Xss1m",
"-Djava.awt.headless=true",
+ "-Djava.io.tmpdir="+ tmpDir.getAbsolutePath(),
"-Dfile.encoding=UTF-8",
"-Djna.nosys=true",
"-Djdk.io.permissionsUseCanonicalPath=true",
@Test
public void writeToJvmOptionFile_writes_all_JVM_options_to_file_with_warning_header() throws IOException {
+ File tmpDir = temporaryFolder.newFolder("with space");
File file = temporaryFolder.newFile();
- EsJvmOptions underTest = new EsJvmOptions()
+ EsJvmOptions underTest = new EsJvmOptions(tmpDir)
.add("-foo")
.add("-bar");
"-XX:+AlwaysPreTouch\n" +
"-Xss1m\n" +
"-Djava.awt.headless=true\n" +
+ "-Djava.io.tmpdir=" + tmpDir.getAbsolutePath() + "\n" +
"-Dfile.encoding=UTF-8\n" +
"-Djna.nosys=true\n" +
"-Djdk.io.permissionsUseCanonicalPath=true\n" +
@Test
public void writeToJvmOptionFile_throws_ISE_in_case_of_IOException() throws IOException {
File notAFile = temporaryFolder.newFolder();
- EsJvmOptions underTest = new EsJvmOptions();
+ EsJvmOptions underTest = new EsJvmOptions(temporaryFolder.newFolder());
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("Cannot write Elasticsearch jvm options file");
}
private EsInstallation createEsInstallation() throws IOException {
+ File tempFolder = this.temp.newFolder("temp");
return new EsInstallation(new Props(new Properties())
- .set("sonar.path.home", temp.newFolder("home").getAbsolutePath())
- .set("sonar.path.data", temp.newFolder("data").getAbsolutePath())
- .set("sonar.path.temp", temp.newFolder("temp").getAbsolutePath())
- .set("sonar.path.logs", temp.newFolder("logs").getAbsolutePath()))
+ .set("sonar.path.home", this.temp.newFolder("home").getAbsolutePath())
+ .set("sonar.path.data", this.temp.newFolder("data").getAbsolutePath())
+ .set("sonar.path.temp", tempFolder.getAbsolutePath())
+ .set("sonar.path.logs", this.temp.newFolder("logs").getAbsolutePath()))
.setClusterName("cluster")
.setPort(9001)
.setHost("localhost")
.setEsYmlSettings(new EsYmlSettings(new HashMap<>()))
- .setEsJvmOptions(new EsJvmOptions())
+ .setEsJvmOptions(new EsJvmOptions(tempFolder))
.setLog4j2Properties(new Properties());
}