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 committed Sep 3, 2021
1 parent 4039c35 commit ba9bc17
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 38 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,21 +27,35 @@
public class DieWithDignityIT extends ESRestTestCase {

public void testDieWithDignity() throws Exception {
expectThrows(
IOException.class,
() -> client().performRequest(new Request("GET", "/_die_with_dignity"))
);
// 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
assertBusy(() -> {
final String jpsPath = PathUtils.get(System.getProperty("runtime.java.home"), "bin/jps").toString();
final Process process = new ProcessBuilder().command(jpsPath, "-v").start();

try (InputStream is = process.getInputStream();
BufferedReader in = new BufferedReader(new InputStreamReader(is, "UTF-8"))) {
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 All @@ -61,8 +72,10 @@ public void testDieWithDignity() throws Exception {
final String line = it.next();
if (line.matches(".*ERROR.*o\\.e\\.ExceptionsHelper.*javaRestTest-0.*fatal error.*")) {
fatalError = true;
} else if (line.matches(".*ERROR.*o\\.e\\.b\\.ElasticsearchUncaughtExceptionHandler.*javaRestTest-0.*"
+ "fatal error in thread \\[Thread-\\d+\\], exiting.*")) {
} else if (line.matches(
".*ERROR.*o\\.e\\.b\\.ElasticsearchUncaughtExceptionHandler.*javaRestTest-0.*"
+ "fatal error in thread \\[Thread-\\d+\\], exiting.*"
)) {
fatalErrorInThreadExiting = true;
assertTrue(it.hasNext());
assertThat(it.next(), containsString("java.lang.OutOfMemoryError: Requested array size exceeds VM limit"));
Expand Down Expand Up @@ -100,16 +113,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,19 +25,16 @@

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,
final RestController restController,
final ClusterSettings clusterSettings,
final IndexScopedSettings indexScopedSettings,
final SettingsFilter settingsFilter,
final IndexNameExpressionResolver indexNameExpressionResolver,
final Supplier<DiscoveryNodes> nodesInCluster) {
final Settings settings,
final RestController restController,
final ClusterSettings clusterSettings,
final IndexScopedSettings indexScopedSettings,
final SettingsFilter settingsFilter,
final IndexNameExpressionResolver indexNameExpressionResolver,
final Supplier<DiscoveryNodes> nodesInCluster
) {
return Collections.singletonList(new RestDieWithDignityAction());
}

Expand Down

0 comments on commit ba9bc17

Please sign in to comment.