Skip to content

Commit ba9bc17

Browse files
committed
Move die with dignity to be a test module (#77136)
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.
1 parent 4039c35 commit ba9bc17

File tree

4 files changed

+38
-38
lines changed

4 files changed

+38
-38
lines changed

qa/die-with-dignity/build.gradle renamed to test/external-modules/die-with-dignity/build.gradle

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,17 @@ tasks.named("javaRestTest").configure {
2020
}
2121

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

2826
tasks.named("test").configure {
2927
enabled = false
3028
}
3129

30+
tasks.named("yamlRestTest").configure {
31+
enabled = false
32+
}
33+
3234
tasks.named('splitPackagesAudit').configure {
3335
// these should be moved to an actual package, not the root package
3436
ignoreClasses 'org.elasticsearch.DieWithDignityPlugin',

qa/die-with-dignity/src/javaRestTest/java/org/elasticsearch/qa/die_with_dignity/DieWithDignityIT.java renamed to test/external-modules/die-with-dignity/src/javaRestTest/java/org/elasticsearch/qa/die_with_dignity/DieWithDignityIT.java

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010

1111
import org.elasticsearch.client.Request;
1212
import 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;
1613
import org.elasticsearch.test.rest.ESRestTestCase;
1714

1815
import java.io.BufferedReader;
@@ -30,21 +27,35 @@
3027
public 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
}

qa/die-with-dignity/src/main/java/org/elasticsearch/DieWithDignityPlugin.java renamed to test/external-modules/die-with-dignity/src/main/java/org/elasticsearch/DieWithDignityPlugin.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,16 @@
2525

2626
public class DieWithDignityPlugin extends Plugin implements ActionPlugin {
2727

28-
public DieWithDignityPlugin() {
29-
assert System.getProperty("die.with.dignity.test") != null : "test should pass the `die.with.dignity.test` property";
30-
}
31-
3228
@Override
3329
public List<RestHandler> getRestHandlers(
34-
final Settings settings,
35-
final RestController restController,
36-
final ClusterSettings clusterSettings,
37-
final IndexScopedSettings indexScopedSettings,
38-
final SettingsFilter settingsFilter,
39-
final IndexNameExpressionResolver indexNameExpressionResolver,
40-
final Supplier<DiscoveryNodes> nodesInCluster) {
30+
final Settings settings,
31+
final RestController restController,
32+
final ClusterSettings clusterSettings,
33+
final IndexScopedSettings indexScopedSettings,
34+
final SettingsFilter settingsFilter,
35+
final IndexNameExpressionResolver indexNameExpressionResolver,
36+
final Supplier<DiscoveryNodes> nodesInCluster
37+
) {
4138
return Collections.singletonList(new RestDieWithDignityAction());
4239
}
4340

0 commit comments

Comments
 (0)