Skip to content

Commit e977182

Browse files
authored
Test: Enable strict deprecation on all tests (#36558)
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.
1 parent 21e392e commit e977182

File tree

2 files changed

+12
-24
lines changed

2 files changed

+12
-24
lines changed

modules/transport-netty4/src/test/java/org/elasticsearch/rest/Netty4HeadBodyIsEmptyIT.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,22 +73,20 @@ public void testIndexExists() throws IOException {
7373
headTestCase("/test", singletonMap("pretty", "true"), greaterThan(0));
7474
}
7575

76-
@Override
77-
protected boolean getStrictDeprecationMode() {
78-
// Remove this override when we remove the reference to types below
79-
return false;
80-
}
81-
8276
public void testTypeExists() throws IOException {
8377
createTestDoc();
84-
headTestCase("/test/_mapping/_doc", emptyMap(), greaterThan(0));
85-
headTestCase("/test/_mapping/_doc", singletonMap("pretty", "true"), greaterThan(0));
78+
headTestCase("/test/_mapping/_doc", emptyMap(), OK.getStatus(), greaterThan(0),
79+
"Type exists requests are deprecated, as types have been deprecated.");
80+
headTestCase("/test/_mapping/_doc", singletonMap("pretty", "true"), OK.getStatus(), greaterThan(0),
81+
"Type exists requests are deprecated, as types have been deprecated.");
8682
}
8783

8884
public void testTypeDoesNotExist() throws IOException {
8985
createTestDoc();
90-
headTestCase("/test/_mapping/does-not-exist", emptyMap(), NOT_FOUND.getStatus(), greaterThan(0));
91-
headTestCase("/text/_mapping/_doc,does-not-exist", emptyMap(), NOT_FOUND.getStatus(), greaterThan(0));
86+
headTestCase("/test/_mapping/does-not-exist", emptyMap(), NOT_FOUND.getStatus(), greaterThan(0),
87+
"Type exists requests are deprecated, as types have been deprecated.");
88+
headTestCase("/text/_mapping/test,does-not-exist", emptyMap(), NOT_FOUND.getStatus(), greaterThan(0),
89+
"Type exists requests are deprecated, as types have been deprecated.");
9290
}
9391

9492
public void testAliasExists() throws IOException {
@@ -193,11 +191,13 @@ private void headTestCase(
193191
final String url,
194192
final Map<String, String> params,
195193
final int expectedStatusCode,
196-
final Matcher<Integer> matcher) throws IOException {
194+
final Matcher<Integer> matcher,
195+
final String... expectedWarnings) throws IOException {
197196
Request request = new Request("HEAD", url);
198197
for (Map.Entry<String, String> param : params.entrySet()) {
199198
request.addParameter(param.getKey(), param.getValue());
200199
}
200+
request.setOptions(expectWarnings(expectedWarnings));
201201
Response response = client().performRequest(request);
202202
assertEquals(expectedStatusCode, response.getStatusLine().getStatusCode());
203203
assertThat(Integer.valueOf(response.getHeader("Content-Length")), matcher);

test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -692,22 +692,10 @@ protected String getProtocol() {
692692
protected RestClient buildClient(Settings settings, HttpHost[] hosts) throws IOException {
693693
RestClientBuilder builder = RestClient.builder(hosts);
694694
configureClient(builder, settings);
695-
builder.setStrictDeprecationMode(getStrictDeprecationMode());
695+
builder.setStrictDeprecationMode(true);
696696
return builder.build();
697697
}
698698

699-
/**
700-
* Whether the used REST client should return any response containing at
701-
* least one warning header as a failure.
702-
* @deprecated always run in strict mode and use
703-
* {@link RequestOptions.Builder#setWarningsHandler} to override this
704-
* behavior on individual requests
705-
*/
706-
@Deprecated
707-
protected boolean getStrictDeprecationMode() {
708-
return true;
709-
}
710-
711699
protected static void configureClient(RestClientBuilder builder, Settings settings) throws IOException {
712700
String keystorePath = settings.get(TRUSTSTORE_PATH);
713701
if (keystorePath != null) {

0 commit comments

Comments
 (0)