Skip to content

Commit

Permalink
Move die with dignity to be a test module (#77136)
Browse files Browse the repository at this point in the history
This commit moves the die with dignity tests to be a test module. The
purpose of this is so the _die_with_dignity endpoint is available in
snapshot builds, for the purpose of enabling testing orchestration logic
that manages what happens to a node after it dies with an
OutOfMemoryError.
  • Loading branch information
jasontedor authored Sep 3, 2021
1 parent 26dfe02 commit c7130eb
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@ tasks.named("javaRestTest").configure {
}

testClusters.matching { it.name == "javaRestTest" }.configureEach {
systemProperty "die.with.dignity.test", "whatever"
setting 'xpack.security.enabled', 'true'
user username: 'admin', password: 'admin-password', role: 'superuser'
systemProperty "die.with.dignity.test", "true"
}

tasks.named("test").configure {
enabled = false
}

tasks.named("yamlRestTest").configure {
enabled = false
}

tasks.named('splitPackagesAudit').configure {
// these should be moved to an actual package, not the root package
ignoreClasses 'org.elasticsearch.DieWithDignityPlugin',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@

import org.elasticsearch.client.Request;
import org.elasticsearch.core.PathUtils;
import org.elasticsearch.common.settings.SecureString;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.test.rest.ESRestTestCase;

import java.io.BufferedReader;
Expand All @@ -30,6 +27,24 @@
public class DieWithDignityIT extends ESRestTestCase {

public void testDieWithDignity() throws Exception {
// there should be an Elasticsearch process running with the die.with.dignity.test system property
{
final String jpsPath = PathUtils.get(System.getProperty("runtime.java.home"), "bin/jps").toString();
final Process process = new ProcessBuilder().command(jpsPath, "-v").start();

boolean found = false;
try (InputStream is = process.getInputStream(); BufferedReader in = new BufferedReader(new InputStreamReader(is, "UTF-8"))) {
String line;
while ((line = in.readLine()) != null) {
if (line.contains("-Ddie.with.dignity.test=true")) {
found = true;
break;
}
}
}
assertTrue(found);
}

expectThrows(IOException.class, () -> client().performRequest(new Request("GET", "/_die_with_dignity")));

// the Elasticsearch process should die and disappear from the output of jps
Expand All @@ -40,7 +55,7 @@ public void testDieWithDignity() throws Exception {
try (InputStream is = process.getInputStream(); BufferedReader in = new BufferedReader(new InputStreamReader(is, "UTF-8"))) {
String line;
while ((line = in.readLine()) != null) {
assertThat(line, line, not(containsString("-Ddie.with.dignity.test")));
assertThat(line, line, not(containsString("-Ddie.with.dignity.test=true")));
}
}
});
Expand Down Expand Up @@ -99,16 +114,4 @@ protected boolean preserveClusterUponCompletion() {
return true;
}

@Override
protected final Settings restClientSettings() {
String token = basicAuthHeaderValue("admin", new SecureString("admin-password".toCharArray()));
return Settings.builder()
.put(super.restClientSettings())
.put(ThreadContext.PREFIX + ".Authorization", token)
// increase the timeout here to 90 seconds to handle long waits for a green
// cluster health. the waits for green need to be longer than a minute to
// account for delayed shards
.put(ESRestTestCase.CLIENT_SOCKET_TIMEOUT, "1s")
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@

public class DieWithDignityPlugin extends Plugin implements ActionPlugin {

public DieWithDignityPlugin() {
assert System.getProperty("die.with.dignity.test") != null : "test should pass the `die.with.dignity.test` property";
}

@Override
public List<RestHandler> getRestHandlers(
final Settings settings,
Expand Down

0 comments on commit c7130eb

Please sign in to comment.