diff --git a/qa/full-cluster-restart/src/test/java/org/elasticsearch/upgrades/FullClusterRestartIT.java b/qa/full-cluster-restart/src/test/java/org/elasticsearch/upgrades/FullClusterRestartIT.java index 73846871b00..634c3367249 100644 --- a/qa/full-cluster-restart/src/test/java/org/elasticsearch/upgrades/FullClusterRestartIT.java +++ b/qa/full-cluster-restart/src/test/java/org/elasticsearch/upgrades/FullClusterRestartIT.java @@ -22,12 +22,10 @@ package org.elasticsearch.upgrades; import org.apache.http.util.EntityUtils; import org.elasticsearch.Version; import org.elasticsearch.client.Request; -import org.elasticsearch.client.RequestOptions; import org.elasticsearch.client.Response; import org.elasticsearch.client.ResponseException; import org.elasticsearch.client.RestClient; import org.elasticsearch.client.WarningFailureException; -import org.elasticsearch.client.WarningsHandler; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.Booleans; import org.elasticsearch.common.CheckedFunction; @@ -135,11 +133,10 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase { mappingsAndSettings.endObject(); } mappingsAndSettings.endObject(); + Request createIndex = new Request("PUT", "/" + index); createIndex.setJsonEntity(Strings.toString(mappingsAndSettings)); - RequestOptions.Builder options = createIndex.getOptions().toBuilder(); - options.setWarningsHandler(WarningsHandler.PERMISSIVE); - createIndex.setOptions(options); + createIndex.setOptions(allowTypesRemovalWarnings()); client().performRequest(createIndex); count = randomIntBetween(2000, 3000); @@ -200,11 +197,10 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase { mappingsAndSettings.endObject(); } mappingsAndSettings.endObject(); + Request createIndex = new Request("PUT", "/" + index); createIndex.setJsonEntity(Strings.toString(mappingsAndSettings)); - RequestOptions.Builder options = createIndex.getOptions().toBuilder(); - options.setWarningsHandler(WarningsHandler.PERMISSIVE); - createIndex.setOptions(options); + createIndex.setOptions(allowTypesRemovalWarnings()); client().performRequest(createIndex); int numDocs = randomIntBetween(2000, 3000); @@ -320,12 +316,10 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase { } } mappingsAndSettings.endObject(); + Request createIndex = new Request("PUT", "/" + index); createIndex.setJsonEntity(Strings.toString(mappingsAndSettings)); - RequestOptions.Builder options = createIndex.getOptions().toBuilder(); - options.setWarningsHandler(WarningsHandler.PERMISSIVE); - expectWarnings(RestIndexAction.TYPES_DEPRECATION_MESSAGE); - createIndex.setOptions(options); + createIndex.setOptions(allowTypesRemovalWarnings()); client().performRequest(createIndex); numDocs = randomIntBetween(512, 1024); @@ -403,11 +397,10 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase { } } mappingsAndSettings.endObject(); + Request createIndex = new Request("PUT", "/" + index); createIndex.setJsonEntity(Strings.toString(mappingsAndSettings)); - RequestOptions.Builder options = createIndex.getOptions().toBuilder(); - options.setWarningsHandler(WarningsHandler.PERMISSIVE); - createIndex.setOptions(options); + createIndex.setOptions(allowTypesRemovalWarnings()); client().performRequest(createIndex); numDocs = randomIntBetween(512, 1024); @@ -491,7 +484,7 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase { if (isRunningAgainstOldCluster()) { Request rolloverRequest = new Request("POST", "/" + index + "_write/_rollover"); - rolloverRequest.setOptions(allowTypeRemovalWarnings()); + rolloverRequest.setOptions(allowTypesRemovalWarnings()); rolloverRequest.setJsonEntity("{" + " \"conditions\": {" + " \"max_docs\": 5" @@ -914,7 +907,7 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase { if (isRunningAgainstOldCluster() == false && getOldClusterVersion().major < 7) { createTemplateRequest.addParameter(INCLUDE_TYPE_NAME_PARAMETER, "true"); } - createTemplateRequest.setOptions(allowTypeRemovalWarnings()); + createTemplateRequest.setOptions(allowTypesRemovalWarnings()); client().performRequest(createTemplateRequest); @@ -1125,7 +1118,7 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase { if (isRunningAgainstAncientCluster() == false) { getTemplateRequest.addParameter(INCLUDE_TYPE_NAME_PARAMETER, "true"); } - getTemplateRequest.setOptions(allowTypeRemovalWarnings()); + getTemplateRequest.setOptions(allowTypesRemovalWarnings()); Map getTemplateResponse = entityAsMap(client().performRequest(getTemplateRequest)); Map expectedTemplate = new HashMap<>(); diff --git a/qa/full-cluster-restart/src/test/java/org/elasticsearch/upgrades/QueryBuilderBWCIT.java b/qa/full-cluster-restart/src/test/java/org/elasticsearch/upgrades/QueryBuilderBWCIT.java index d6cc9f078e0..fb4e33863ca 100644 --- a/qa/full-cluster-restart/src/test/java/org/elasticsearch/upgrades/QueryBuilderBWCIT.java +++ b/qa/full-cluster-restart/src/test/java/org/elasticsearch/upgrades/QueryBuilderBWCIT.java @@ -22,9 +22,7 @@ package org.elasticsearch.upgrades; import org.apache.http.util.EntityUtils; import org.elasticsearch.Version; import org.elasticsearch.client.Request; -import org.elasticsearch.client.RequestOptions; import org.elasticsearch.client.Response; -import org.elasticsearch.client.WarningsHandler; import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.InputStreamStreamInput; import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput; @@ -186,9 +184,7 @@ public class QueryBuilderBWCIT extends AbstractFullClusterRestartTestCase { } mappingsAndSettings.endObject(); Request request = new Request("PUT", "/" + index); - RequestOptions.Builder options = request.getOptions().toBuilder(); - options.setWarningsHandler(WarningsHandler.PERMISSIVE); - request.setOptions(options); + request.setOptions(allowTypesRemovalWarnings()); request.setJsonEntity(Strings.toString(mappingsAndSettings)); Response rsp = client().performRequest(request); assertEquals(200, rsp.getStatusLine().getStatusCode()); 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 177cdaad941..00900271a25 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 @@ -256,13 +256,13 @@ public abstract class ESRestTestCase extends ESTestCase { public static RequestOptions expectWarnings(String... warnings) { return expectVersionSpecificWarnings(consumer -> consumer.current(warnings)); } - + /** - * Creates RequestOptions designed to ignore [types removal] warnings but nothing else + * Creates RequestOptions designed to ignore [types removal] warnings but nothing else * @deprecated this method is only required while we deprecate types and can be removed in 8.0 */ @Deprecated - public static RequestOptions allowTypeRemovalWarnings() { + public static RequestOptions allowTypesRemovalWarnings() { Builder builder = RequestOptions.DEFAULT.toBuilder(); builder.setWarningsHandler(new WarningsHandler() { @Override @@ -277,7 +277,7 @@ public abstract class ESRestTestCase extends ESTestCase { } }); return builder.build(); - } + } /** * Construct an HttpHost from the given host and port 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 863908ab7fa..28d0ccd682f 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 @@ -14,7 +14,6 @@ import org.elasticsearch.client.RestClient; import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.test.rest.ESRestTestCase; import org.elasticsearch.xpack.core.ml.MlMetaIndex; import org.elasticsearch.xpack.core.ml.job.persistence.AnomalyDetectorsIndex; import org.elasticsearch.xpack.core.ml.job.persistence.AnomalyDetectorsIndexFields; @@ -27,6 +26,8 @@ import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicReference; +import static org.elasticsearch.test.rest.ESRestTestCase.allowTypesRemovalWarnings; + public final class XPackRestTestHelper { public static final List ML_PRE_V660_TEMPLATES = Collections.unmodifiableList( @@ -78,7 +79,7 @@ public final class XPackRestTestHelper { Map response; try { final Request getRequest = new Request("GET", "_template/" + template); - getRequest.setOptions(ESRestTestCase.allowTypeRemovalWarnings()); + getRequest.setOptions(allowTypesRemovalWarnings()); String string = EntityUtils.toString(client.performRequest(getRequest).getEntity()); response = XContentHelper.convertToMap(JsonXContent.jsonXContent, string, false); } catch (ResponseException e) { diff --git a/x-pack/qa/full-cluster-restart/src/test/java/org/elasticsearch/xpack/restart/MlMigrationFullClusterRestartIT.java b/x-pack/qa/full-cluster-restart/src/test/java/org/elasticsearch/xpack/restart/MlMigrationFullClusterRestartIT.java index 36673fa4984..e8bce60ae0b 100644 --- a/x-pack/qa/full-cluster-restart/src/test/java/org/elasticsearch/xpack/restart/MlMigrationFullClusterRestartIT.java +++ b/x-pack/qa/full-cluster-restart/src/test/java/org/elasticsearch/xpack/restart/MlMigrationFullClusterRestartIT.java @@ -7,9 +7,7 @@ package org.elasticsearch.xpack.restart; import org.elasticsearch.Version; import org.elasticsearch.client.Request; -import org.elasticsearch.client.RequestOptions; import org.elasticsearch.client.Response; -import org.elasticsearch.client.WarningsHandler; import org.elasticsearch.common.Strings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; @@ -72,9 +70,7 @@ public class MlMigrationFullClusterRestartIT extends AbstractFullClusterRestartT "\"airline\": {\"type\": \"keyword\"}," + "\"responsetime\": {\"type\": \"float\"}" + "}}}}"); - RequestOptions.Builder options = createTestIndex.getOptions().toBuilder(); - options.setWarningsHandler(WarningsHandler.PERMISSIVE); - createTestIndex.setOptions(options); + createTestIndex.setOptions(allowTypesRemovalWarnings()); client().performRequest(createTestIndex); } diff --git a/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/AbstractUpgradeTestCase.java b/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/AbstractUpgradeTestCase.java index d077ecedbeb..0d0f05bcf9c 100644 --- a/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/AbstractUpgradeTestCase.java +++ b/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/AbstractUpgradeTestCase.java @@ -87,7 +87,7 @@ public abstract class AbstractUpgradeTestCase extends ESRestTestCase { for (String template : templatesToWaitFor()) { try { final Request headRequest = new Request("HEAD", "_template/" + template); - headRequest.setOptions(allowTypeRemovalWarnings()); + headRequest.setOptions(allowTypesRemovalWarnings()); final boolean exists = adminClient() .performRequest(headRequest) .getStatusLine().getStatusCode() == 200;