1010
1111import org .elasticsearch .client .Request ;
1212import org .elasticsearch .core .PathUtils ;
13- import org .elasticsearch .common .settings .SecureString ;
14- import org .elasticsearch .common .settings .Settings ;
15- import org .elasticsearch .common .util .concurrent .ThreadContext ;
1613import org .elasticsearch .test .rest .ESRestTestCase ;
1714
1815import java .io .BufferedReader ;
3027public class DieWithDignityIT extends ESRestTestCase {
3128
3229 public void testDieWithDignity () throws Exception {
33- expectThrows (
34- IOException .class ,
35- () -> client ().performRequest (new Request ("GET" , "/_die_with_dignity" ))
36- );
30+ // there should be an Elasticsearch process running with the die.with.dignity.test system property
31+ {
32+ final String jpsPath = PathUtils .get (System .getProperty ("runtime.java.home" ), "bin/jps" ).toString ();
33+ final Process process = new ProcessBuilder ().command (jpsPath , "-v" ).start ();
34+
35+ boolean found = false ;
36+ try (InputStream is = process .getInputStream (); BufferedReader in = new BufferedReader (new InputStreamReader (is , "UTF-8" ))) {
37+ String line ;
38+ while ((line = in .readLine ()) != null ) {
39+ if (line .contains ("-Ddie.with.dignity.test=true" )) {
40+ found = true ;
41+ break ;
42+ }
43+ }
44+ }
45+ assertTrue (found );
46+ }
47+
48+ expectThrows (IOException .class , () -> client ().performRequest (new Request ("GET" , "/_die_with_dignity" )));
3749
3850 // the Elasticsearch process should die and disappear from the output of jps
3951 assertBusy (() -> {
4052 final String jpsPath = PathUtils .get (System .getProperty ("runtime.java.home" ), "bin/jps" ).toString ();
4153 final Process process = new ProcessBuilder ().command (jpsPath , "-v" ).start ();
4254
43- try (InputStream is = process .getInputStream ();
44- BufferedReader in = new BufferedReader (new InputStreamReader (is , "UTF-8" ))) {
55+ try (InputStream is = process .getInputStream (); BufferedReader in = new BufferedReader (new InputStreamReader (is , "UTF-8" ))) {
4556 String line ;
4657 while ((line = in .readLine ()) != null ) {
47- assertThat (line , line , not (containsString ("-Ddie.with.dignity.test" )));
58+ assertThat (line , line , not (containsString ("-Ddie.with.dignity.test=true " )));
4859 }
4960 }
5061 });
@@ -61,8 +72,10 @@ public void testDieWithDignity() throws Exception {
6172 final String line = it .next ();
6273 if (line .matches (".*ERROR.*o\\ .e\\ .ExceptionsHelper.*javaRestTest-0.*fatal error.*" )) {
6374 fatalError = true ;
64- } else if (line .matches (".*ERROR.*o\\ .e\\ .b\\ .ElasticsearchUncaughtExceptionHandler.*javaRestTest-0.*"
65- + "fatal error in thread \\ [Thread-\\ d+\\ ], exiting.*" )) {
75+ } else if (line .matches (
76+ ".*ERROR.*o\\ .e\\ .b\\ .ElasticsearchUncaughtExceptionHandler.*javaRestTest-0.*"
77+ + "fatal error in thread \\ [Thread-\\ d+\\ ], exiting.*"
78+ )) {
6679 fatalErrorInThreadExiting = true ;
6780 assertTrue (it .hasNext ());
6881 assertThat (it .next (), containsString ("java.lang.OutOfMemoryError: Requested array size exceeds VM limit" ));
@@ -100,16 +113,4 @@ protected boolean preserveClusterUponCompletion() {
100113 return true ;
101114 }
102115
103- @ Override
104- protected final Settings restClientSettings () {
105- String token = basicAuthHeaderValue ("admin" , new SecureString ("admin-password" .toCharArray ()));
106- return Settings .builder ().put (super .restClientSettings ())
107- .put (ThreadContext .PREFIX + ".Authorization" , token )
108- // increase the timeout here to 90 seconds to handle long waits for a green
109- // cluster health. the waits for green need to be longer than a minute to
110- // account for delayed shards
111- .put (ESRestTestCase .CLIENT_SOCKET_TIMEOUT , "1s" )
112- .build ();
113- }
114-
115116}
0 commit comments