23
23
import org .apache .http .client .fluent .Request ;
24
24
import org .elasticsearch .packaging .util .FileUtils ;
25
25
import org .elasticsearch .packaging .util .Shell .Result ;
26
- import org .hamcrest .CoreMatchers ;
27
26
import org .junit .BeforeClass ;
28
27
29
28
import java .nio .charset .StandardCharsets ;
47
46
import static org .elasticsearch .packaging .util .Packages .SYSTEMD_SERVICE ;
48
47
import static org .elasticsearch .packaging .util .Packages .assertInstalled ;
49
48
import static org .elasticsearch .packaging .util .Packages .assertRemoved ;
49
+ import static org .elasticsearch .packaging .util .Packages .clearJournal ;
50
50
import static org .elasticsearch .packaging .util .Packages .installPackage ;
51
51
import static org .elasticsearch .packaging .util .Packages .remove ;
52
52
import static org .elasticsearch .packaging .util .Packages .restartElasticsearch ;
53
53
import static org .elasticsearch .packaging .util .Packages .startElasticsearch ;
54
+ import static org .elasticsearch .packaging .util .Packages .startElasticsearchIgnoringFailure ;
54
55
import static org .elasticsearch .packaging .util .Packages .stopElasticsearch ;
55
56
import static org .elasticsearch .packaging .util .Packages .verifyPackageInstallation ;
56
57
import static org .elasticsearch .packaging .util .Platforms .getOsRelease ;
60
61
import static org .hamcrest .CoreMatchers .equalTo ;
61
62
import static org .hamcrest .CoreMatchers .not ;
62
63
import static org .hamcrest .Matchers .containsString ;
63
- import static org .hamcrest .Matchers .isEmptyString ;
64
+ import static org .hamcrest .Matchers .emptyString ;
64
65
import static org .hamcrest .core .Is .is ;
65
66
import static org .junit .Assume .assumeThat ;
66
67
import static org .junit .Assume .assumeTrue ;
@@ -79,8 +80,8 @@ public void test10InstallPackage() throws Exception {
79
80
verifyPackageInstallation (installation , distribution (), sh );
80
81
}
81
82
82
- public void test20PluginsCommandWhenNoPlugins () throws Exception {
83
- assertThat (sh .run (installation .bin ("elasticsearch-plugin" ) + " list" ).stdout , isEmptyString ( ));
83
+ public void test20PluginsCommandWhenNoPlugins () {
84
+ assertThat (sh .run (installation .bin ("elasticsearch-plugin" ) + " list" ).stdout , is ( emptyString () ));
84
85
}
85
86
86
87
public void test30DaemonIsNotEnabledOnRestart () {
@@ -95,7 +96,7 @@ public void test31InstallDoesNotStartServer() {
95
96
assertThat (sh .run ("ps aux" ).stdout , not (containsString ("org.elasticsearch.bootstrap.Elasticsearch" )));
96
97
}
97
98
98
- public void assertRunsWithJavaHome () throws Exception {
99
+ private void assertRunsWithJavaHome () throws Exception {
99
100
byte [] originalEnvFile = Files .readAllBytes (installation .envFile );
100
101
try {
101
102
Files .write (installation .envFile , ("JAVA_HOME=" + systemJavaHome + "\n " ).getBytes (StandardCharsets .UTF_8 ),
@@ -286,53 +287,17 @@ public void test80DeletePID_DIRandRestart() throws Exception {
286
287
}
287
288
288
289
public void test81CustomPathConfAndJvmOptions () throws Exception {
289
- assumeTrue (isSystemd ());
290
-
291
- assertPathsExist (installation .envFile );
292
-
293
- stopElasticsearch (sh );
294
-
295
- // The custom config directory is not under /tmp or /var/tmp because
296
- // systemd's private temp directory functionally means different
297
- // processes can have different views of what's in these directories
298
- String randomName = RandomStrings .randomAsciiAlphanumOfLength (getRandom (), 10 );
299
- sh .run ("mkdir /etc/" +randomName );
300
- final Path tempConf = Paths .get ("/etc/" +randomName );
301
-
302
- try {
303
- mkdir (tempConf );
304
- cp (installation .config ("elasticsearch.yml" ), tempConf .resolve ("elasticsearch.yml" ));
305
- cp (installation .config ("log4j2.properties" ), tempConf .resolve ("log4j2.properties" ));
306
-
307
- // we have to disable Log4j from using JMX lest it will hit a security
308
- // manager exception before we have configured logging; this will fail
309
- // startup since we detect usages of logging before it is configured
310
- final String jvmOptions =
311
- "-Xms512m\n " +
312
- "-Xmx512m\n " +
313
- "-Dlog4j2.disable.jmx=true\n " ;
314
- append (tempConf .resolve ("jvm.options" ), jvmOptions );
315
-
316
- sh .runIgnoreExitCode ("chown -R elasticsearch:elasticsearch " + tempConf );
317
-
318
- cp (installation .envFile , tempConf .resolve ("elasticsearch.bk" ));//backup
319
- append (installation .envFile , "ES_PATH_CONF=" + tempConf + "\n " );
290
+ withCustomConfig (tempConf -> {
320
291
append (installation .envFile , "ES_JAVA_OPTS=-XX:-UseCompressedOops" );
321
292
322
293
startElasticsearch (sh , installation );
323
294
324
295
final String nodesResponse = makeRequest (Request .Get ("http://localhost:9200/_nodes" ));
325
- assertThat (nodesResponse , CoreMatchers . containsString ("\" heap_init_in_bytes\" :536870912" ));
326
- assertThat (nodesResponse , CoreMatchers . containsString ("\" using_compressed_ordinary_object_pointers\" :\" false\" " ));
296
+ assertThat (nodesResponse , containsString ("\" heap_init_in_bytes\" :536870912" ));
297
+ assertThat (nodesResponse , containsString ("\" using_compressed_ordinary_object_pointers\" :\" false\" " ));
327
298
328
299
stopElasticsearch (sh );
329
-
330
- } finally {
331
- rm (installation .envFile );
332
- cp (tempConf .resolve ("elasticsearch.bk" ), installation .envFile );
333
- rm (tempConf );
334
- cleanup ();
335
- }
300
+ });
336
301
}
337
302
338
303
public void test82SystemdMask () throws Exception {
@@ -374,4 +339,63 @@ public void test83serviceFileSetsLimits() throws Exception {
374
339
375
340
stopElasticsearch (sh );
376
341
}
342
+
343
+ public void test90DoNotCloseStderrWhenQuiet () throws Exception {
344
+ withCustomConfig (tempConf -> {
345
+ // Create a startup problem by adding an invalid YAML line to the config
346
+ append (tempConf .resolve ("elasticsearch.yml" ), "discovery.zen.ping.unicast.hosts:15172.30.5.3416172.30.5.35, 172.30.5.17]\n " );
347
+
348
+ // Make sure we don't pick up the journal entries for previous ES instances.
349
+ clearJournal (sh );
350
+ startElasticsearchIgnoringFailure (sh );
351
+
352
+ final Result logs = sh .run ("journalctl -u elasticsearch.service" );
353
+
354
+ assertThat (logs .stdout , containsString ("Failed to load settings from [elasticsearch.yml]" ));
355
+ });
356
+ }
357
+
358
+ @ FunctionalInterface
359
+ private interface CustomConfigConsumer {
360
+ void accept (Path path ) throws Exception ;
361
+ }
362
+
363
+ private void withCustomConfig (CustomConfigConsumer pathConsumer ) throws Exception {
364
+ assumeTrue (isSystemd ());
365
+
366
+ assertPathsExist (installation .envFile );
367
+
368
+ stopElasticsearch (sh );
369
+
370
+ // The custom config directory is not under /tmp or /var/tmp because
371
+ // systemd's private temp directory functionally means different
372
+ // processes can have different views of what's in these directories
373
+ String randomName = RandomStrings .randomAsciiAlphanumOfLength (getRandom (), 10 );
374
+ sh .run ("mkdir /etc/" + randomName );
375
+ final Path tempConf = Paths .get ("/etc/" + randomName );
376
+
377
+ try {
378
+ mkdir (tempConf );
379
+ cp (installation .config ("elasticsearch.yml" ), tempConf .resolve ("elasticsearch.yml" ));
380
+ cp (installation .config ("log4j2.properties" ), tempConf .resolve ("log4j2.properties" ));
381
+
382
+ // we have to disable Log4j from using JMX lest it will hit a security
383
+ // manager exception before we have configured logging; this will fail
384
+ // startup since we detect usages of logging before it is configured
385
+ final String jvmOptions = "-Xms512m\n -Xmx512m\n -Dlog4j2.disable.jmx=true\n " ;
386
+ append (tempConf .resolve ("jvm.options" ), jvmOptions );
387
+
388
+ sh .runIgnoreExitCode ("chown -R elasticsearch:elasticsearch " + tempConf );
389
+
390
+ cp (installation .envFile , tempConf .resolve ("elasticsearch.bk" ));// backup
391
+ append (installation .envFile , "ES_PATH_CONF=" + tempConf + "\n " );
392
+
393
+ pathConsumer .accept (tempConf );
394
+ } finally {
395
+ rm (installation .envFile );
396
+ cp (tempConf .resolve ("elasticsearch.bk" ), installation .envFile );
397
+ rm (tempConf );
398
+ cleanup ();
399
+ }
400
+ }
377
401
}
0 commit comments