From 3ba477c1925deb0fe2a3097877d4560b5db591c0 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Sat, 20 Oct 2018 20:02:29 -0400 Subject: [PATCH] Refactor --- .../elasticsearch/xpack/ccr/CcrRestIT.java | 4 +- .../xpack/test/rest/XPackRestTestHelper.java | 53 ------------------- .../ml/integration/DatafeedJobsRestIT.java | 5 +- .../xpack/ml/integration/MlJobIT.java | 3 +- .../xpack/test/rest/XPackRestIT.java | 3 +- 5 files changed, 7 insertions(+), 61 deletions(-) diff --git a/x-pack/plugin/ccr/qa/rest/src/test/java/org/elasticsearch/xpack/ccr/CcrRestIT.java b/x-pack/plugin/ccr/qa/rest/src/test/java/org/elasticsearch/xpack/ccr/CcrRestIT.java index b0225fc5bf97e..106bb116af7c9 100644 --- a/x-pack/plugin/ccr/qa/rest/src/test/java/org/elasticsearch/xpack/ccr/CcrRestIT.java +++ b/x-pack/plugin/ccr/qa/rest/src/test/java/org/elasticsearch/xpack/ccr/CcrRestIT.java @@ -10,10 +10,10 @@ 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 org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; import org.elasticsearch.xpack.ccr.action.ShardChangesAction; -import org.elasticsearch.xpack.test.rest.XPackRestTestHelper; import org.junit.After; import static org.elasticsearch.xpack.core.security.authc.support.UsernamePasswordToken.basicAuthHeaderValue; @@ -37,7 +37,7 @@ protected Settings restClientSettings() { @After public void cleanup() throws Exception { - XPackRestTestHelper.waitForPendingTasks(adminClient(), taskName -> taskName.startsWith(ShardChangesAction.NAME)); + ESRestTestCase.waitForPendingTasks(adminClient(), taskName -> taskName.startsWith(ShardChangesAction.NAME)); } } diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/test/rest/XPackRestTestHelper.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/test/rest/XPackRestTestHelper.java index da2002fd4b564..f6e2d16952d6c 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/test/rest/XPackRestTestHelper.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/test/rest/XPackRestTestHelper.java @@ -86,57 +86,4 @@ public static void waitForMlTemplates(RestClient client) throws InterruptedExcep } } - /** - * Wait for outstanding tasks to complete. The specified admin client is used to check the outstanding tasks and this is done using - * {@link ESTestCase#assertBusy(CheckedRunnable)} to give a chance to any outstanding tasks to complete. - * - * @param adminClient the admin client - * @throws Exception if an exception is thrown while checking the outstanding tasks - */ - public static void waitForPendingTasks(final RestClient adminClient) throws Exception { - waitForPendingTasks(adminClient, taskName -> false); - } - - /** - * Wait for outstanding tasks to complete. The specified admin client is used to check the outstanding tasks and this is done using - * {@link ESTestCase#assertBusy(CheckedRunnable)} to give a chance to any outstanding tasks to complete. The specified filter is used - * to filter out outstanding tasks that are expected to be there. - * - * @param adminClient the admin client - * @param taskFilter predicate used to filter tasks that are expected to be there - * @throws Exception if an exception is thrown while checking the outstanding tasks - */ - public static void waitForPendingTasks(final RestClient adminClient, final Predicate taskFilter) throws Exception { - assertBusy(() -> { - try { - final Request request = new Request("GET", "/_cat/tasks"); - request.addParameter("detailed", "true"); - final Response response = adminClient.performRequest(request); - /* - * Check to see if there are outstanding tasks; we exclude the list task itself, and any expected outstanding tasks using - * the specified task filter. - */ - if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { - try (BufferedReader responseReader = new BufferedReader( - new InputStreamReader(response.getEntity().getContent(), StandardCharsets.UTF_8))) { - int activeTasks = 0; - String line; - final StringBuilder tasksListString = new StringBuilder(); - while ((line = responseReader.readLine()) != null) { - final String taskName = line.split("\\s+")[0]; - if (taskName.startsWith(ListTasksAction.NAME) || taskFilter.test(taskName)) { - continue; - } - activeTasks++; - tasksListString.append(line); - tasksListString.append('\n'); - } - assertEquals(activeTasks + " active tasks found:\n" + tasksListString, 0, activeTasks); - } - } - } catch (final IOException e) { - throw new AssertionError("Error getting active tasks list", e); - } - }); - } } diff --git a/x-pack/plugin/ml/qa/native-multi-node-tests/src/test/java/org/elasticsearch/xpack/ml/integration/DatafeedJobsRestIT.java b/x-pack/plugin/ml/qa/native-multi-node-tests/src/test/java/org/elasticsearch/xpack/ml/integration/DatafeedJobsRestIT.java index 7a93ecdd9e1cd..5772d0be42853 100644 --- a/x-pack/plugin/ml/qa/native-multi-node-tests/src/test/java/org/elasticsearch/xpack/ml/integration/DatafeedJobsRestIT.java +++ b/x-pack/plugin/ml/qa/native-multi-node-tests/src/test/java/org/elasticsearch/xpack/ml/integration/DatafeedJobsRestIT.java @@ -16,9 +16,8 @@ import org.elasticsearch.test.SecuritySettingsSourceField; import org.elasticsearch.test.rest.ESRestTestCase; import org.elasticsearch.xpack.core.ml.integration.MlRestTestStateCleaner; -import org.elasticsearch.xpack.ml.MachineLearning; import org.elasticsearch.xpack.core.ml.notifications.AuditorField; -import org.elasticsearch.xpack.test.rest.XPackRestTestHelper; +import org.elasticsearch.xpack.ml.MachineLearning; import org.junit.After; import org.junit.Before; @@ -883,7 +882,7 @@ public static void openJob(RestClient client, String jobId) throws IOException { @After public void clearMlState() throws Exception { new MlRestTestStateCleaner(logger, adminClient()).clearMlMetadata(); - XPackRestTestHelper.waitForPendingTasks(adminClient()); + ESRestTestCase.waitForPendingTasks(adminClient()); } private static class DatafeedBuilder { diff --git a/x-pack/plugin/ml/qa/native-multi-node-tests/src/test/java/org/elasticsearch/xpack/ml/integration/MlJobIT.java b/x-pack/plugin/ml/qa/native-multi-node-tests/src/test/java/org/elasticsearch/xpack/ml/integration/MlJobIT.java index e9f9166a2a3ba..633653714fc31 100644 --- a/x-pack/plugin/ml/qa/native-multi-node-tests/src/test/java/org/elasticsearch/xpack/ml/integration/MlJobIT.java +++ b/x-pack/plugin/ml/qa/native-multi-node-tests/src/test/java/org/elasticsearch/xpack/ml/integration/MlJobIT.java @@ -19,7 +19,6 @@ import org.elasticsearch.xpack.core.ml.job.persistence.AnomalyDetectorsIndex; import org.elasticsearch.xpack.core.ml.job.persistence.AnomalyDetectorsIndexFields; import org.elasticsearch.xpack.ml.MachineLearning; -import org.elasticsearch.xpack.test.rest.XPackRestTestHelper; import org.junit.After; import java.io.IOException; @@ -680,6 +679,6 @@ private String getAliases() throws IOException { @After public void clearMlState() throws Exception { new MlRestTestStateCleaner(logger, adminClient()).clearMlMetadata(); - XPackRestTestHelper.waitForPendingTasks(adminClient()); + ESRestTestCase.waitForPendingTasks(adminClient()); } } diff --git a/x-pack/plugin/src/test/java/org/elasticsearch/xpack/test/rest/XPackRestIT.java b/x-pack/plugin/src/test/java/org/elasticsearch/xpack/test/rest/XPackRestIT.java index 5baacf69c8da3..a8d97f44b8d7d 100644 --- a/x-pack/plugin/src/test/java/org/elasticsearch/xpack/test/rest/XPackRestIT.java +++ b/x-pack/plugin/src/test/java/org/elasticsearch/xpack/test/rest/XPackRestIT.java @@ -16,6 +16,7 @@ import org.elasticsearch.common.xcontent.support.XContentMapValues; import org.elasticsearch.plugins.MetaDataUpgrader; import org.elasticsearch.test.SecuritySettingsSourceField; +import org.elasticsearch.test.rest.ESRestTestCase; import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; import org.elasticsearch.test.rest.yaml.ClientYamlTestResponse; import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; @@ -246,7 +247,7 @@ public void cleanup() throws Exception { if (isWaitForPendingTasks()) { // This waits for pending tasks to complete, so must go last (otherwise // it could be waiting for pending tasks while monitoring is still running). - XPackRestTestHelper.waitForPendingTasks(adminClient(), task -> { + ESRestTestCase.waitForPendingTasks(adminClient(), task -> { // Don't check rollup jobs because we clear them in the superclass. return task.contains(RollupJob.NAME); });