mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 22:57:16 -04:00
Co-authored-by: Andrea Selva <selva.andre@gmail.com>
(cherry picked from commit 43614ede50
)
Co-authored-by: João Duarte <jsvd@users.noreply.github.com>
This commit is contained in:
parent
17784fd09b
commit
e5b988fed2
2 changed files with 23 additions and 1 deletions
|
@ -198,7 +198,9 @@ public class JvmOptionsParser {
|
||||||
if (maxOrderAlreadyContained) {
|
if (maxOrderAlreadyContained) {
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
final Set<String> acc = new HashSet<>(options);
|
// Order is important because LS_JAVA_OPTS is added last and must take precedence
|
||||||
|
// over settings in jvm.options
|
||||||
|
final Set<String> acc = new LinkedHashSet<>(options);
|
||||||
acc.add("-Dio.netty.allocator.maxOrder=11");
|
acc.add("-Dio.netty.allocator.maxOrder=11");
|
||||||
return acc;
|
return acc;
|
||||||
}
|
}
|
||||||
|
|
|
@ -151,6 +151,26 @@ public class JvmOptionsParserTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEnvironmentOPTSVariableTakesPrecedenceOverOptionsFile() throws IOException {
|
||||||
|
String regex = "Xmx[^ ]+";
|
||||||
|
String expected = "Xmx25g";
|
||||||
|
File optionsFile = writeIntoTempOptionsFile(writer -> writer.println("-Xmx1g"));
|
||||||
|
|
||||||
|
JvmOptionsParser.handleJvmOptions(new String[] {"/path/to/ls_home", optionsFile.toString()}, expected);
|
||||||
|
|
||||||
|
final String output = outputStreamCaptor.toString();
|
||||||
|
|
||||||
|
java.util.regex.Pattern pattern = java.util.regex.Pattern.compile(regex);
|
||||||
|
String lastMatch = pattern.matcher(output)
|
||||||
|
.results()
|
||||||
|
.map(java.util.regex.MatchResult::group)
|
||||||
|
.reduce((first, second) -> second)
|
||||||
|
.orElse(null);
|
||||||
|
|
||||||
|
assertEquals("LS_JAVA_OPTS env must take precedence over jvm.options file", expected, lastMatch);
|
||||||
|
}
|
||||||
|
|
||||||
private File writeIntoTempOptionsFile(Consumer<PrintWriter> writer) throws IOException {
|
private File writeIntoTempOptionsFile(Consumer<PrintWriter> writer) throws IOException {
|
||||||
File optionsFile = temp.newFile("jvm.options");
|
File optionsFile = temp.newFile("jvm.options");
|
||||||
PrintWriter optionsWriter = new PrintWriter(new FileWriter(optionsFile));
|
PrintWriter optionsWriter = new PrintWriter(new FileWriter(optionsFile));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue