@Test public void constructor_sets_mandatory_JVM_options() { EsJvmOptions underTest = new EsJvmOptions(); assertThat(underTest.getAll()).containsExactly( "-XX:+UseConcMarkSweepGC", "-XX:CMSInitiatingOccupancyFraction=75", "-XX:+UseCMSInitiatingOccupancyOnly", "-XX:+AlwaysPreTouch", "-server", "-Xss1m", "-Djava.awt.headless=true", "-Dfile.encoding=UTF-8", "-Djna.nosys=true", "-Djdk.io.permissionsUseCanonicalPath=true", "-Dio.netty.noUnsafe=true", "-Dio.netty.noKeySetOptimization=true", "-Dio.netty.recycler.maxCapacityPerThread=0", "-Dlog4j.shutdownHookEnabled=false", "-Dlog4j2.disable.jmx=true", "-Dlog4j.skipJansi=true"); }
private EsInstallation createEsInstallation() { EsInstallation esInstallation = new EsInstallation(props); if (!esInstallation.getExecutable().exists()) { throw new IllegalStateException("Cannot find elasticsearch binary"); } Map<String, String> settingsMap = new EsSettings(props, esInstallation, System2.INSTANCE).build(); esInstallation .setLog4j2Properties(new EsLogging().createProperties(props, esInstallation.getLogDirectory())) .setEsJvmOptions(new EsJvmOptions() .addFromMandatoryProperty(props, SEARCH_JAVA_OPTS.getKey()) .addFromMandatoryProperty(props, SEARCH_JAVA_ADDITIONAL_OPTS.getKey())) .setEsYmlSettings(new EsYmlSettings(settingsMap)) .setClusterName(settingsMap.get("cluster.name")) .setHost(settingsMap.get("network.host")) .setPort(Integer.valueOf(settingsMap.get("transport.tcp.port"))); return esInstallation; }
private EsInstallation createEsInstallation() throws IOException { 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())) .setClusterName("cluster") .setPort(9001) .setHost("localhost") .setEsYmlSettings(new EsYmlSettings(new HashMap<>())) .setEsJvmOptions(new EsJvmOptions()) .setLog4j2Properties(new Properties()); }
private JavaCommand createEsCommandForWindows() { EsInstallation esInstallation = createEsInstallation(); return new JavaCommand<EsJvmOptions>(ProcessId.ELASTICSEARCH, esInstallation.getHomeDirectory()) .setEsInstallation(esInstallation) .setReadsArgumentsFromFile(false) .setArgument("path.conf", esInstallation.getConfDirectory().getAbsolutePath()) .setJvmOptions(new EsJvmOptions() .addFromMandatoryProperty(props, SEARCH_JAVA_OPTS.getKey()) .addFromMandatoryProperty(props, SEARCH_JAVA_ADDITIONAL_OPTS.getKey()) .add("-Delasticsearch") .add("-Des.path.home=" + esInstallation.getHomeDirectory())) .setEnvVariable("ES_JVM_OPTIONS", esInstallation.getJvmOptions().getAbsolutePath()) .setEnvVariable("JAVA_HOME", System.getProperties().getProperty("java.home")) .setClassName("org.elasticsearch.bootstrap.Elasticsearch") .addClasspath("lib/*") .suppressEnvVariable(ENV_VAR_JAVA_TOOL_OPTIONS) .suppressEnvVariable(ENV_VAR_ES_JAVA_OPTS); }
@Test public void writeToJvmOptionFile_writes_all_JVM_options_to_file_with_warning_header() throws IOException { File file = temporaryFolder.newFile(); EsJvmOptions underTest = new EsJvmOptions() .add("-foo") .add("-bar");
@Test public void writeToJvmOptionFile_throws_ISE_in_case_of_IOException() throws IOException { File notAFile = temporaryFolder.newFolder(); EsJvmOptions underTest = new EsJvmOptions(); expectedException.expect(IllegalStateException.class); expectedException.expectMessage("Cannot write Elasticsearch jvm options file"); expectedException.expectCause(ExceptionCauseMatcher.hasType(IOException.class)); underTest.writeToJvmOptionFile(notAFile); } }
private EsInstallation createEsInstallation() { EsInstallation esInstallation = new EsInstallation(props); if (!esInstallation.getExecutable().exists()) { throw new IllegalStateException("Cannot find elasticsearch binary"); } Map<String, String> settingsMap = new EsSettings(props, esInstallation, System2.INSTANCE).build(); esInstallation .setLog4j2Properties(new EsLogging().createProperties(props, esInstallation.getLogDirectory())) .setEsJvmOptions(new EsJvmOptions() .addFromMandatoryProperty(props, ProcessProperties.SEARCH_JAVA_OPTS) .addFromMandatoryProperty(props, ProcessProperties.SEARCH_JAVA_ADDITIONAL_OPTS)) .setEsYmlSettings(new EsYmlSettings(settingsMap)) .setClusterName(settingsMap.get("cluster.name")) .setHost(settingsMap.get("network.host")) .setPort(Integer.valueOf(settingsMap.get("transport.tcp.port"))); return esInstallation; }
private JavaCommand createEsCommandForWindows() { EsInstallation esInstallation = createEsInstallation(); return new JavaCommand<EsJvmOptions>(ProcessId.ELASTICSEARCH, esInstallation.getHomeDirectory()) .setEsInstallation(esInstallation) .setReadsArgumentsFromFile(false) .setArgument("path.conf", esInstallation.getConfDirectory().getAbsolutePath()) .setJvmOptions(new EsJvmOptions() .addFromMandatoryProperty(props, ProcessProperties.SEARCH_JAVA_OPTS) .addFromMandatoryProperty(props, ProcessProperties.SEARCH_JAVA_ADDITIONAL_OPTS) .add("-Delasticsearch") .add("-Des.path.home=" + esInstallation.getHomeDirectory()) ) .setEnvVariable("ES_JVM_OPTIONS", esInstallation.getJvmOptions().getAbsolutePath()) .setEnvVariable("JAVA_HOME", System.getProperties().getProperty("java.home")) .setClassName("org.elasticsearch.bootstrap.Elasticsearch") .addClasspath("lib/*") .suppressEnvVariable(ENV_VAR_JAVA_TOOL_OPTIONS); }