From ba9bc172d05e7f6f3b7131897a2230c8ecad99cc Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Fri, 3 Sep 2021 12:34:01 -0400 Subject: [PATCH] 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. --- .../die-with-dignity/build.gradle | 8 +-- .../qa/die_with_dignity/DieWithDignityIT.java | 49 ++++++++++--------- .../elasticsearch/DieWithDignityPlugin.java | 19 +++---- .../RestDieWithDignityAction.java | 0 4 files changed, 38 insertions(+), 38 deletions(-) rename {qa => test/external-modules}/die-with-dignity/build.gradle (86%) rename {qa => test/external-modules}/die-with-dignity/src/javaRestTest/java/org/elasticsearch/qa/die_with_dignity/DieWithDignityIT.java (71%) rename {qa => test/external-modules}/die-with-dignity/src/main/java/org/elasticsearch/DieWithDignityPlugin.java (68%) rename {qa => test/external-modules}/die-with-dignity/src/main/java/org/elasticsearch/RestDieWithDignityAction.java (100%) diff --git a/qa/die-with-dignity/build.gradle b/test/external-modules/die-with-dignity/build.gradle similarity index 86% rename from qa/die-with-dignity/build.gradle rename to test/external-modules/die-with-dignity/build.gradle index cd7f2b9f738cc..166a9ca6d138e 100644 --- a/qa/die-with-dignity/build.gradle +++ b/test/external-modules/die-with-dignity/build.gradle @@ -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', diff --git a/qa/die-with-dignity/src/javaRestTest/java/org/elasticsearch/qa/die_with_dignity/DieWithDignityIT.java b/test/external-modules/die-with-dignity/src/javaRestTest/java/org/elasticsearch/qa/die_with_dignity/DieWithDignityIT.java similarity index 71% rename from qa/die-with-dignity/src/javaRestTest/java/org/elasticsearch/qa/die_with_dignity/DieWithDignityIT.java rename to test/external-modules/die-with-dignity/src/javaRestTest/java/org/elasticsearch/qa/die_with_dignity/DieWithDignityIT.java index 55319fa8a6cf2..03a2e274de857 100644 --- a/qa/die-with-dignity/src/javaRestTest/java/org/elasticsearch/qa/die_with_dignity/DieWithDignityIT.java +++ b/test/external-modules/die-with-dignity/src/javaRestTest/java/org/elasticsearch/qa/die_with_dignity/DieWithDignityIT.java @@ -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; @@ -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"))); } } }); @@ -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")); @@ -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(); - } - } diff --git a/qa/die-with-dignity/src/main/java/org/elasticsearch/DieWithDignityPlugin.java b/test/external-modules/die-with-dignity/src/main/java/org/elasticsearch/DieWithDignityPlugin.java similarity index 68% rename from qa/die-with-dignity/src/main/java/org/elasticsearch/DieWithDignityPlugin.java rename to test/external-modules/die-with-dignity/src/main/java/org/elasticsearch/DieWithDignityPlugin.java index 204ac4de849c9..c17369928a4d1 100644 --- a/qa/die-with-dignity/src/main/java/org/elasticsearch/DieWithDignityPlugin.java +++ b/test/external-modules/die-with-dignity/src/main/java/org/elasticsearch/DieWithDignityPlugin.java @@ -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 getRestHandlers( - final Settings settings, - final RestController restController, - final ClusterSettings clusterSettings, - final IndexScopedSettings indexScopedSettings, - final SettingsFilter settingsFilter, - final IndexNameExpressionResolver indexNameExpressionResolver, - final Supplier nodesInCluster) { + final Settings settings, + final RestController restController, + final ClusterSettings clusterSettings, + final IndexScopedSettings indexScopedSettings, + final SettingsFilter settingsFilter, + final IndexNameExpressionResolver indexNameExpressionResolver, + final Supplier nodesInCluster + ) { return Collections.singletonList(new RestDieWithDignityAction()); } diff --git a/qa/die-with-dignity/src/main/java/org/elasticsearch/RestDieWithDignityAction.java b/test/external-modules/die-with-dignity/src/main/java/org/elasticsearch/RestDieWithDignityAction.java similarity index 100% rename from qa/die-with-dignity/src/main/java/org/elasticsearch/RestDieWithDignityAction.java rename to test/external-modules/die-with-dignity/src/main/java/org/elasticsearch/RestDieWithDignityAction.java