From 6c65e31c63e7a452ad29a87551357b0fd8e539c4 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Wed, 12 Dec 2018 11:12:24 -0500 Subject: [PATCH 1/3] Test: Enable strict deprecation on all tests This drops the option for tests to disable strict deprecation mode in the low level rest client in favor of configuring expected warnings on any calls that should expect warnings. This behavior is paranoid-by-default which is generally the right way to handle deprecations and tests in general. --- .../rest/Netty4HeadBodyIsEmptyIT.java | 33 +++++++++++-------- .../test/rest/ESRestTestCase.java | 14 +------- 2 files changed, 20 insertions(+), 27 deletions(-) diff --git a/modules/transport-netty4/src/test/java/org/elasticsearch/rest/Netty4HeadBodyIsEmptyIT.java b/modules/transport-netty4/src/test/java/org/elasticsearch/rest/Netty4HeadBodyIsEmptyIT.java index 3a9315015c06d..22055f33e78e1 100644 --- a/modules/transport-netty4/src/test/java/org/elasticsearch/rest/Netty4HeadBodyIsEmptyIT.java +++ b/modules/transport-netty4/src/test/java/org/elasticsearch/rest/Netty4HeadBodyIsEmptyIT.java @@ -62,9 +62,12 @@ private void createTestDoc(final String indexName, final String typeName) throws public void testDocumentExists() throws IOException { createTestDoc(); - headTestCase("/test/test/1", emptyMap(), greaterThan(0)); - headTestCase("/test/test/1", singletonMap("pretty", "true"), greaterThan(0)); - headTestCase("/test/test/2", emptyMap(), NOT_FOUND.getStatus(), greaterThan(0)); + headTestCase("/test/test/1", emptyMap(), OK.getStatus(), greaterThan(0), + "[types removal] Specifying types in document get requests is deprecated, use the /{index}/_doc/{id} endpoint instead."); + headTestCase("/test/test/1", singletonMap("pretty", "true"), OK.getStatus(), greaterThan(0), + "[types removal] Specifying types in document get requests is deprecated, use the /{index}/_doc/{id} endpoint instead."); + headTestCase("/test/test/2", emptyMap(), NOT_FOUND.getStatus(), greaterThan(0), + "[types removal] Specifying types in document get requests is deprecated, use the /{index}/_doc/{id} endpoint instead."); } public void testIndexExists() throws IOException { @@ -73,22 +76,20 @@ public void testIndexExists() throws IOException { headTestCase("/test", singletonMap("pretty", "true"), greaterThan(0)); } - @Override - protected boolean getStrictDeprecationMode() { - // Remove this override when we remove the reference to types below - return false; - } - public void testTypeExists() throws IOException { createTestDoc(); - headTestCase("/test/_mapping/test", emptyMap(), greaterThan(0)); - headTestCase("/test/_mapping/test", singletonMap("pretty", "true"), greaterThan(0)); + headTestCase("/test/_mapping/test", emptyMap(), OK.getStatus(), greaterThan(0), + "Type exists requests are deprecated, as types have been deprecated."); + headTestCase("/test/_mapping/test", singletonMap("pretty", "true"), OK.getStatus(), greaterThan(0), + "Type exists requests are deprecated, as types have been deprecated."); } public void testTypeDoesNotExist() throws IOException { createTestDoc(); - headTestCase("/test/_mapping/does-not-exist", emptyMap(), NOT_FOUND.getStatus(), greaterThan(0)); - headTestCase("/text/_mapping/test,does-not-exist", emptyMap(), NOT_FOUND.getStatus(), greaterThan(0)); + headTestCase("/test/_mapping/does-not-exist", emptyMap(), NOT_FOUND.getStatus(), greaterThan(0), + "Type exists requests are deprecated, as types have been deprecated."); + headTestCase("/text/_mapping/test,does-not-exist", emptyMap(), NOT_FOUND.getStatus(), greaterThan(0), + "Type exists requests are deprecated, as types have been deprecated."); } public void testAliasExists() throws IOException { @@ -197,11 +198,15 @@ private void headTestCase( final String url, final Map params, final int expectedStatusCode, - final Matcher matcher) throws IOException { + final Matcher matcher, + final String... expectedWarnings) throws IOException { Request request = new Request("HEAD", url); for (Map.Entry param : params.entrySet()) { request.addParameter(param.getKey(), param.getValue()); } + request.setOptions(expectVersionSpecificWarnings(w -> { + w.current(expectedWarnings); + })); Response response = client().performRequest(request); assertEquals(expectedStatusCode, response.getStatusLine().getStatusCode()); assertThat(Integer.valueOf(response.getHeader("Content-Length")), matcher); 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 94f5091fee4ed..43f3e091ed555 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 @@ -681,22 +681,10 @@ protected String getProtocol() { protected RestClient buildClient(Settings settings, HttpHost[] hosts) throws IOException { RestClientBuilder builder = RestClient.builder(hosts); configureClient(builder, settings); - builder.setStrictDeprecationMode(getStrictDeprecationMode()); + builder.setStrictDeprecationMode(true); return builder.build(); } - /** - * Whether the used REST client should return any response containing at - * least one warning header as a failure. - * @deprecated always run in strict mode and use - * {@link RequestOptions.Builder#setWarningsHandler} to override this - * behavior on individual requests - */ - @Deprecated - protected boolean getStrictDeprecationMode() { - return true; - } - protected static void configureClient(RestClientBuilder builder, Settings settings) throws IOException { String keystorePath = settings.get(TRUSTSTORE_PATH); if (keystorePath != null) { From b23861f69dc5cd8ee18c43b39b6fa0abe098ce09 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Wed, 30 Jan 2019 08:30:52 -0500 Subject: [PATCH 2/3] expectwarnings --- .../java/org/elasticsearch/rest/Netty4HeadBodyIsEmptyIT.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/modules/transport-netty4/src/test/java/org/elasticsearch/rest/Netty4HeadBodyIsEmptyIT.java b/modules/transport-netty4/src/test/java/org/elasticsearch/rest/Netty4HeadBodyIsEmptyIT.java index 8c5de1f4ec346..23bbcd6bd4cc1 100644 --- a/modules/transport-netty4/src/test/java/org/elasticsearch/rest/Netty4HeadBodyIsEmptyIT.java +++ b/modules/transport-netty4/src/test/java/org/elasticsearch/rest/Netty4HeadBodyIsEmptyIT.java @@ -195,9 +195,7 @@ private void headTestCase( for (Map.Entry param : params.entrySet()) { request.addParameter(param.getKey(), param.getValue()); } - request.setOptions(expectVersionSpecificWarnings(w -> { - w.current(expectedWarnings); - })); + request.setOptions(expectWarnings(expectedWarnings)); Response response = client().performRequest(request); assertEquals(expectedStatusCode, response.getStatusLine().getStatusCode()); assertThat(Integer.valueOf(response.getHeader("Content-Length")), matcher); From 9bef4e891239caa3b67f5f33069aba3c78e628f3 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Wed, 30 Jan 2019 08:59:42 -0500 Subject: [PATCH 3/3] Cleanup --- .../org/elasticsearch/rest/Netty4HeadBodyIsEmptyIT.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/transport-netty4/src/test/java/org/elasticsearch/rest/Netty4HeadBodyIsEmptyIT.java b/modules/transport-netty4/src/test/java/org/elasticsearch/rest/Netty4HeadBodyIsEmptyIT.java index 23bbcd6bd4cc1..3f7f8d7739dee 100644 --- a/modules/transport-netty4/src/test/java/org/elasticsearch/rest/Netty4HeadBodyIsEmptyIT.java +++ b/modules/transport-netty4/src/test/java/org/elasticsearch/rest/Netty4HeadBodyIsEmptyIT.java @@ -75,8 +75,10 @@ public void testIndexExists() throws IOException { public void testTypeExists() throws IOException { createTestDoc(); - headTestCase("/test/_mapping/_doc", emptyMap(), greaterThan(0)); - headTestCase("/test/_mapping/_doc", singletonMap("pretty", "true"), greaterThan(0)); + headTestCase("/test/_mapping/_doc", emptyMap(), OK.getStatus(), greaterThan(0), + "Type exists requests are deprecated, as types have been deprecated."); + headTestCase("/test/_mapping/_doc", singletonMap("pretty", "true"), OK.getStatus(), greaterThan(0), + "Type exists requests are deprecated, as types have been deprecated."); } public void testTypeDoesNotExist() throws IOException {