From eca11d092ce9d6682e9f7cb266507d4eca7a9a95 Mon Sep 17 00:00:00 2001 From: Armin Braun Date: Mon, 14 Jan 2019 14:23:57 +0100 Subject: [PATCH] Cleanup Deadcode in Rest Tests * Either dead code outright or redundant overrides removed --- .../test/rest/ESRestTestCase.java | 6 ++-- .../test/rest/FakeRestChannel.java | 35 ------------------- .../rest/yaml/ESClientYamlSuiteTestCase.java | 20 ----------- .../test/rest/yaml/Features.java | 25 ++++++------- 4 files changed, 13 insertions(+), 73 deletions(-) diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java index 02918ea78714e..c711019bf753c 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java @@ -112,7 +112,7 @@ public static Map entityAsMap(Response response) throws IOExcept /** * Does any node in the cluster being tested have x-pack installed? */ - public static boolean hasXPack() throws IOException { + public static boolean hasXPack() { if (hasXPack == null) { throw new IllegalStateException("must be called inside of a rest test case test"); } @@ -554,7 +554,7 @@ private void wipeClusterSettings() throws IOException { } } - private void wipeRollupJobs() throws IOException, InterruptedException { + private void wipeRollupJobs() throws IOException { Response response = adminClient().performRequest(new Request("GET", "/_rollup/job/_all")); Map jobs = entityAsMap(response); @SuppressWarnings("unchecked") @@ -617,7 +617,7 @@ private static void deleteAllPolicies() throws IOException { * Logs a message if there are still running tasks. The reasoning is that any tasks still running are state the is trying to bleed into * other tests. */ - private void logIfThereAreRunningTasks() throws InterruptedException, IOException { + private void logIfThereAreRunningTasks() throws IOException { Set runningTasks = runningTasks(adminClient().performRequest(new Request("GET", "/_tasks"))); // Ignore the task list API - it doesn't count against us runningTasks.remove(ListTasksAction.NAME); diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/FakeRestChannel.java b/test/framework/src/main/java/org/elasticsearch/test/rest/FakeRestChannel.java index 2dcadce2ed17b..ff6b99bdc4a51 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/FakeRestChannel.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/FakeRestChannel.java @@ -18,18 +18,12 @@ */ package org.elasticsearch.test.rest; -import org.elasticsearch.common.Nullable; -import org.elasticsearch.common.io.stream.BytesStreamOutput; -import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.rest.AbstractRestChannel; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; -import java.io.IOException; import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; public final class FakeRestChannel extends AbstractRestChannel { @@ -43,31 +37,6 @@ public FakeRestChannel(RestRequest request, boolean detailedErrorsEnabled, int r this.latch = new CountDownLatch(responseCount); } - @Override - public XContentBuilder newBuilder() throws IOException { - return super.newBuilder(); - } - - @Override - public XContentBuilder newErrorBuilder() throws IOException { - return super.newErrorBuilder(); - } - - @Override - public XContentBuilder newBuilder(@Nullable XContentType requestContentType, boolean useFiltering) throws IOException { - return super.newBuilder(requestContentType, useFiltering); - } - - @Override - protected BytesStreamOutput newBytesOutput() { - return super.newBytesOutput(); - } - - @Override - public RestRequest request() { - return super.request(); - } - @Override public void sendResponse(RestResponse response) { this.capturedRestResponse = response; @@ -83,10 +52,6 @@ public RestResponse capturedResponse() { return capturedRestResponse; } - public boolean await() throws InterruptedException { - return latch.await(10, TimeUnit.SECONDS); - } - public AtomicInteger responses() { return responses; } diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ESClientYamlSuiteTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ESClientYamlSuiteTestCase.java index f04bead4fbfa1..ab155889ac687 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ESClientYamlSuiteTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ESClientYamlSuiteTestCase.java @@ -319,26 +319,6 @@ private static Tuple readVersionsFromCatNodes(RestClient restC return new Tuple<>(version, masterVersion); } - private static Version readVersionsFromInfo(RestClient restClient, int numHosts) throws IOException { - Version version = null; - for (int i = 0; i < numHosts; i++) { - //we don't really use the urls here, we rely on the client doing round-robin to touch all the nodes in the cluster - Response response = restClient.performRequest(new Request("GET", "/")); - ClientYamlTestResponse restTestResponse = new ClientYamlTestResponse(response); - Object latestVersion = restTestResponse.evaluate("version.number"); - if (latestVersion == null) { - throw new RuntimeException("elasticsearch version not found in the response"); - } - final Version currentVersion = Version.fromString(latestVersion.toString()); - if (version == null) { - version = currentVersion; - } else if (version.onOrAfter(currentVersion)) { - version = currentVersion; - } - } - return version; - } - public void test() throws IOException { //skip test if it matches one of the blacklist globs for (BlacklistedPathPatternMatcher blacklistedPathMatcher : blacklistPathMatchers) { diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/Features.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/Features.java index d3fb500ac051a..bb5354e4fedd3 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/Features.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/Features.java @@ -19,7 +19,6 @@ package org.elasticsearch.test.rest.yaml; -import java.io.IOException; import java.util.Arrays; import java.util.List; @@ -58,23 +57,19 @@ private Features() { * Tells whether all the features provided as argument are supported */ public static boolean areAllSupported(List features) { - try { - for (String feature : features) { - if (feature.equals("xpack")) { - if (false == ESRestTestCase.hasXPack()) { - return false; - } - } else if (feature.equals("no_xpack")) { - if (ESRestTestCase.hasXPack()) { - return false; - } - } else if (false == SUPPORTED.contains(feature)) { + for (String feature : features) { + if (feature.equals("xpack")) { + if (false == ESRestTestCase.hasXPack()) { return false; } + } else if (feature.equals("no_xpack")) { + if (ESRestTestCase.hasXPack()) { + return false; + } + } else if (false == SUPPORTED.contains(feature)) { + return false; } - return true; - } catch (IOException e) { - throw new RuntimeException("error checking if xpack is available", e); } + return true; } }