File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed
tools/jvm-options-parser/src
main/java/org/logstash/launchers
test/java/org/logstash/launchers Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -198,7 +198,9 @@ private Set<String> nettyMaxOrderDefaultTo11(Set<String> options) {
198198 if (maxOrderAlreadyContained ) {
199199 return options ;
200200 }
201- final Set <String > acc = new HashSet <>(options );
201+ // Order is important because LS_JAVA_OPTS is added last and must take precedence
202+ // over settings in jvm.options
203+ final Set <String > acc = new LinkedHashSet <>(options );
202204 acc .add ("-Dio.netty.allocator.maxOrder=11" );
203205 return acc ;
204206 }
Original file line number Diff line number Diff line change @@ -151,6 +151,26 @@ public void testNettyMaxOrderRuleDoNotAppliesIfAlreadyDefinedExplicitlyByUser()
151151
152152 }
153153
154+ @ Test
155+ public void testEnvironmentOPTSVariableTakesPrecedenceOverOptionsFile () throws IOException {
156+ String regex = "Xmx[^ ]+" ;
157+ String expected = "Xmx25g" ;
158+ File optionsFile = writeIntoTempOptionsFile (writer -> writer .println ("-Xmx1g" ));
159+
160+ JvmOptionsParser .handleJvmOptions (new String [] {"/path/to/ls_home" , optionsFile .toString ()}, expected );
161+
162+ final String output = outputStreamCaptor .toString ();
163+
164+ java .util .regex .Pattern pattern = java .util .regex .Pattern .compile (regex );
165+ String lastMatch = pattern .matcher (output )
166+ .results ()
167+ .map (java .util .regex .MatchResult ::group )
168+ .reduce ((first , second ) -> second )
169+ .orElse (null );
170+
171+ assertEquals ("LS_JAVA_OPTS env must take precedence over jvm.options file" , expected , lastMatch );
172+ }
173+
154174 private File writeIntoTempOptionsFile (Consumer <PrintWriter > writer ) throws IOException {
155175 File optionsFile = temp .newFile ("jvm.options" );
156176 PrintWriter optionsWriter = new PrintWriter (new FileWriter (optionsFile ));
You can’t perform that action at this time.
0 commit comments