Skip to content

Commit d5ad3de

Browse files
lipsillnik9000
authored andcommitted
[test] Introduce strict deprecation mode for REST tests (#34338)
#33708 introduced a strict deprecation mode that makes a REST request fail if there is a warning header in the response returned by Elasticsearch (usually a deprecation message signaling that a feature or a field has been deprecated). This change adds the strict deprecation mode into the REST integration tests, and makes the tests fail if a deprecated feature is used. Also any test using a deprecated feature has been modified to pass the build. The YAML integration tests already analyzed HTTP warnings so they do not use this mode, keeping their "expected vs actual" behavior.
1 parent 76240e6 commit d5ad3de

File tree

9 files changed

+147
-9
lines changed

9 files changed

+147
-9
lines changed

qa/full-cluster-restart/src/test/java/org/elasticsearch/upgrades/FullClusterRestartIT.java

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
import static org.hamcrest.Matchers.equalTo;
6161
import static org.hamcrest.Matchers.greaterThan;
6262
import static org.hamcrest.Matchers.notNullValue;
63+
import static org.hamcrest.Matchers.startsWith;
6364

6465
/**
6566
* Tests to run before and after a full cluster restart. This is run twice,
@@ -75,7 +76,7 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase {
7576
private String index;
7677

7778
@Before
78-
public void setIndex() {
79+
public void setIndex() throws IOException {
7980
index = getTestName().toLowerCase(Locale.ROOT);
8081
}
8182

@@ -283,7 +284,8 @@ public void testClusterState() throws Exception {
283284
if (isRunningAgainstOldCluster()) {
284285
XContentBuilder mappingsAndSettings = jsonBuilder();
285286
mappingsAndSettings.startObject();
286-
mappingsAndSettings.field("template", index);
287+
mappingsAndSettings.field("index_patterns", index);
288+
mappingsAndSettings.field("order", "1000");
287289
{
288290
mappingsAndSettings.startObject("settings");
289291
mappingsAndSettings.field("number_of_shards", 1);
@@ -361,6 +363,7 @@ public void testShrink() throws IOException {
361363
client().performRequest(updateSettingsRequest);
362364

363365
Request shrinkIndexRequest = new Request("PUT", "/" + index + "/_shrink/" + shrunkenIndex);
366+
shrinkIndexRequest.addParameter("copy_settings", "true");
364367
shrinkIndexRequest.setJsonEntity("{\"settings\": {\"index.number_of_shards\": 1}}");
365368
client().performRequest(shrinkIndexRequest);
366369

@@ -844,7 +847,7 @@ public void testSnapshotRestore() throws IOException {
844847

845848
// Stick a template into the cluster so we can see it after the restore
846849
XContentBuilder templateBuilder = JsonXContent.contentBuilder().startObject();
847-
templateBuilder.field("template", "evil_*"); // Don't confuse other tests by applying the template
850+
templateBuilder.field("index_patterns", "evil_*"); // Don't confuse other tests by applying the template
848851
templateBuilder.startObject("settings"); {
849852
templateBuilder.field("number_of_shards", 1);
850853
}
@@ -949,9 +952,23 @@ private void checkSnapshot(String snapshotName, int count, Version tookOnVersion
949952
assertEquals(singletonList(tookOnVersion.toString()), XContentMapValues.extractValue("snapshots.version", listSnapshotResponse));
950953

951954
// Remove the routing setting and template so we can test restoring them.
952-
Request clearRoutingFromSettings = new Request("PUT", "/_cluster/settings");
953-
clearRoutingFromSettings.setJsonEntity("{\"persistent\":{\"cluster.routing.allocation.exclude.test_attr\": null}}");
954-
client().performRequest(clearRoutingFromSettings);
955+
try {
956+
Request clearRoutingFromSettings = new Request("PUT", "/_cluster/settings");
957+
clearRoutingFromSettings.setJsonEntity("{\"persistent\":{\"cluster.routing.allocation.exclude.test_attr\": null}}");
958+
client().performRequest(clearRoutingFromSettings);
959+
} catch (ResponseException e) {
960+
if (e.getResponse().hasWarnings()
961+
&& (isRunningAgainstOldCluster() == false || getOldClusterVersion().onOrAfter(Version.V_6_5_0))) {
962+
e.getResponse().getWarnings().stream().forEach(warning -> {
963+
assertThat(warning, containsString(
964+
"setting was deprecated in Elasticsearch and will be removed in a future release! "
965+
+ "See the breaking changes documentation for the next major version."));
966+
assertThat(warning, startsWith("[search.remote."));
967+
});
968+
} else {
969+
throw e;
970+
}
971+
}
955972
client().performRequest(new Request("DELETE", "/_template/test_template"));
956973

957974
// Restore

qa/full-cluster-restart/src/test/java/org/elasticsearch/upgrades/QueryBuilderBWCIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ public void testQueryBuilderBWC() throws Exception {
196196
QueryBuilder expectedQueryBuilder = (QueryBuilder) CANDIDATES.get(i)[1];
197197
Request request = new Request("GET", "/" + index + "/_search");
198198
request.setJsonEntity("{\"query\": {\"ids\": {\"values\": [\"" + Integer.toString(i) + "\"]}}, " +
199-
"\"docvalue_fields\" : [\"query.query_builder_field\"]}");
199+
"\"docvalue_fields\": [{\"field\":\"query.query_builder_field\", \"format\":\"use_field_mapping\"}]}");
200200
Response rsp = client().performRequest(request);
201201
assertEquals(200, rsp.getStatusLine().getStatusCode());
202202
Map<?, ?> hitRsp = (Map<?, ?>) ((List<?>) ((Map<?, ?>)toMap(rsp).get("hits")).get("hits")).get(0);

qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/IndexingIT.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,18 @@
2020

2121
import org.apache.http.util.EntityUtils;
2222
import org.elasticsearch.common.Booleans;
23+
import org.elasticsearch.common.Strings;
24+
import org.elasticsearch.common.xcontent.XContentBuilder;
25+
import org.elasticsearch.Version;
2326
import org.elasticsearch.client.Request;
2427
import org.elasticsearch.client.Response;
2528

2629
import java.io.IOException;
2730
import java.nio.charset.StandardCharsets;
2831

32+
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
33+
import static org.hamcrest.Matchers.equalTo;
34+
2935
/**
3036
* Basic test that indexed documents survive the rolling restart. See
3137
* {@link RecoveryIT} for much more in depth testing of the mechanism
@@ -60,6 +66,26 @@ public void testIndexing() throws IOException {
6066
}
6167

6268
if (CLUSTER_TYPE == ClusterType.OLD) {
69+
{
70+
Version minimumIndexCompatibilityVersion = Version.CURRENT.minimumIndexCompatibilityVersion();
71+
assertThat("this branch is not needed if we aren't compatible with 6.0",
72+
minimumIndexCompatibilityVersion.onOrBefore(Version.V_6_0_0), equalTo(true));
73+
if (minimumIndexCompatibilityVersion.before(Version.V_7_0_0_alpha1)) {
74+
XContentBuilder template = jsonBuilder();
75+
template.startObject();
76+
{
77+
template.field("index_patterns", "*");
78+
template.startObject("settings");
79+
template.field("number_of_shards", 5);
80+
template.endObject();
81+
}
82+
template.endObject();
83+
Request createTemplate = new Request("PUT", "/_template/template");
84+
createTemplate.setJsonEntity(Strings.toString(template));
85+
client().performRequest(createTemplate);
86+
}
87+
}
88+
6389
Request createTestIndex = new Request("PUT", "/test_index");
6490
createTestIndex.setJsonEntity("{\"settings\": {\"index.number_of_replicas\": 0}}");
6591
client().performRequest(createTestIndex);

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,9 +577,18 @@ protected String getProtocol() {
577577
protected RestClient buildClient(Settings settings, HttpHost[] hosts) throws IOException {
578578
RestClientBuilder builder = RestClient.builder(hosts);
579579
configureClient(builder, settings);
580+
builder.setStrictDeprecationMode(getStrictDeprecationMode());
580581
return builder.build();
581582
}
582583

584+
/**
585+
* Whether the used REST client should return any response containing at
586+
* least one warning header as a failure.
587+
*/
588+
protected boolean getStrictDeprecationMode() {
589+
return true;
590+
}
591+
583592
protected static void configureClient(RestClientBuilder builder, Settings settings) throws IOException {
584593
String keystorePath = settings.get(TRUSTSTORE_PATH);
585594
if (keystorePath != null) {

test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ESClientYamlSuiteTestCase.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,4 +408,9 @@ protected final RestClientBuilder getClientBuilderWithSniffedHosts() throws IOEx
408408
configureClient(builder, restClientSettings());
409409
return builder;
410410
}
411+
412+
@Override
413+
protected boolean getStrictDeprecationMode() {
414+
return false;
415+
}
411416
}

test/framework/src/main/java/org/elasticsearch/upgrades/AbstractFullClusterRestartTestCase.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,43 @@
2020
package org.elasticsearch.upgrades;
2121

2222
import org.elasticsearch.Version;
23+
import org.elasticsearch.client.Request;
2324
import org.elasticsearch.common.Booleans;
25+
import org.elasticsearch.common.Strings;
26+
import org.elasticsearch.common.xcontent.XContentBuilder;
2427
import org.elasticsearch.test.rest.ESRestTestCase;
28+
import org.junit.Before;
29+
30+
import java.io.IOException;
31+
32+
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
33+
import static org.hamcrest.Matchers.equalTo;
2534

2635
public abstract class AbstractFullClusterRestartTestCase extends ESRestTestCase {
2736

2837
private final boolean runningAgainstOldCluster = Booleans.parseBoolean(System.getProperty("tests.is_old_cluster"));
2938

39+
@Before
40+
public void init() throws IOException {
41+
assertThat("we don't need this branch if we aren't compatible with 6.0",
42+
Version.CURRENT.minimumIndexCompatibilityVersion().onOrBefore(Version.V_6_0_0), equalTo(true));
43+
if (isRunningAgainstOldCluster() && getOldClusterVersion().before(Version.V_7_0_0_alpha1)) {
44+
XContentBuilder template = jsonBuilder();
45+
template.startObject();
46+
{
47+
template.field("index_patterns", "*");
48+
template.field("order", "0");
49+
template.startObject("settings");
50+
template.field("number_of_shards", 5);
51+
template.endObject();
52+
}
53+
template.endObject();
54+
Request createTemplate = new Request("PUT", "/_template/template");
55+
createTemplate.setJsonEntity(Strings.toString(template));
56+
client().performRequest(createTemplate);
57+
}
58+
}
59+
3060
public final boolean isRunningAgainstOldCluster() {
3161
return runningAgainstOldCluster;
3262
}

x-pack/plugin/ml/qa/single-node-tests/src/test/java/org/elasticsearch/xpack/ml/transforms/PainlessDomainSplitIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public void testIsolated() throws Exception {
195195
String mapAsJson = Strings.toString(jsonBuilder().map(params));
196196
logger.info("params={}", mapAsJson);
197197

198-
Request searchRequest = new Request("GET", "/painless/test/_search");
198+
Request searchRequest = new Request("GET", "/painless/_search");
199199
searchRequest.setJsonEntity(
200200
"{\n" +
201201
" \"query\" : {\n" +
@@ -205,7 +205,7 @@ public void testIsolated() throws Exception {
205205
" \"domain_split\" : {\n" +
206206
" \"script\" : {\n" +
207207
" \"lang\": \"painless\",\n" +
208-
" \"inline\": \"" +
208+
" \"source\": \"" +
209209
" return domainSplit(params['host']); \",\n" +
210210
" \"params\": " + mapAsJson + "\n" +
211211
" }\n" +

x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/IndexingIT.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,18 @@
77

88
import org.apache.http.util.EntityUtils;
99
import org.elasticsearch.common.Booleans;
10+
import org.elasticsearch.common.Strings;
11+
import org.elasticsearch.common.xcontent.XContentBuilder;
12+
import org.elasticsearch.Version;
1013
import org.elasticsearch.client.Request;
1114
import org.elasticsearch.client.Response;
1215

1316
import java.io.IOException;
1417
import java.nio.charset.StandardCharsets;
1518

19+
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
20+
import static org.hamcrest.Matchers.equalTo;
21+
1622
/**
1723
* Basic test that indexed documents survive the rolling restart.
1824
* <p>
@@ -45,6 +51,26 @@ public void testIndexing() throws IOException {
4551
}
4652

4753
if (CLUSTER_TYPE == ClusterType.OLD) {
54+
{
55+
Version minimumIndexCompatibilityVersion = Version.CURRENT.minimumIndexCompatibilityVersion();
56+
assertThat("this branch is not needed if we aren't compatible with 6.0",
57+
minimumIndexCompatibilityVersion.onOrBefore(Version.V_6_0_0), equalTo(true));
58+
if (minimumIndexCompatibilityVersion.before(Version.V_7_0_0_alpha1)) {
59+
XContentBuilder template = jsonBuilder();
60+
template.startObject();
61+
{
62+
template.field("index_patterns", "*");
63+
template.startObject("settings");
64+
template.field("number_of_shards", 5);
65+
template.endObject();
66+
}
67+
template.endObject();
68+
Request createTemplate = new Request("PUT", "/_template/template");
69+
createTemplate.setJsonEntity(Strings.toString(template));
70+
client().performRequest(createTemplate);
71+
}
72+
}
73+
4874
Request createTestIndex = new Request("PUT", "/test_index");
4975
createTestIndex.setJsonEntity("{\"settings\": {\"index.number_of_replicas\": 0}}");
5076
client().performRequest(createTestIndex);

x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/TokenBackwardsCompatibilityIT.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,42 @@
1313
import org.elasticsearch.client.Response;
1414
import org.elasticsearch.client.ResponseException;
1515
import org.elasticsearch.client.RestClient;
16+
import org.elasticsearch.common.Strings;
17+
import org.elasticsearch.common.xcontent.XContentBuilder;
1618
import org.elasticsearch.test.rest.yaml.ObjectPath;
1719

1820
import java.io.IOException;
1921
import java.util.ArrayList;
2022
import java.util.List;
2123
import java.util.Map;
2224

25+
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
26+
import static org.hamcrest.Matchers.equalTo;
27+
2328
public class TokenBackwardsCompatibilityIT extends AbstractUpgradeTestCase {
2429

2530
public void testGeneratingTokenInOldCluster() throws Exception {
2631
assumeTrue("this test should only run against the old cluster", CLUSTER_TYPE == ClusterType.OLD);
32+
{
33+
Version minimumIndexCompatibilityVersion = Version.CURRENT.minimumIndexCompatibilityVersion();
34+
assertThat("this branch is not needed if we aren't compatible with 6.0",
35+
minimumIndexCompatibilityVersion.onOrBefore(Version.V_6_0_0), equalTo(true));
36+
if (minimumIndexCompatibilityVersion.before(Version.V_7_0_0_alpha1)) {
37+
XContentBuilder template = jsonBuilder();
38+
template.startObject();
39+
{
40+
template.field("index_patterns", "*");
41+
template.startObject("settings");
42+
template.field("number_of_shards", 5);
43+
template.endObject();
44+
}
45+
template.endObject();
46+
Request createTemplate = new Request("PUT", "/_template/template");
47+
createTemplate.setJsonEntity(Strings.toString(template));
48+
client().performRequest(createTemplate);
49+
}
50+
}
51+
2752
Request createTokenRequest = new Request("POST", "_xpack/security/oauth2/token");
2853
createTokenRequest.setJsonEntity(
2954
"{\n" +

0 commit comments

Comments
 (0)