Skip to content

Commit 6891475

Browse files
authored
Remove tests and branches that will never execute (#38772)
* Remove tests that will never execute and dead branches These tests have an version conditioned `assumeTrue` that only makes them run on versions prior to `v7.0.0`, but for current master at `v8.0.0` this will never happen.
1 parent e2c329f commit 6891475

File tree

11 files changed

+29
-706
lines changed

11 files changed

+29
-706
lines changed

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

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import org.elasticsearch.client.Response;
2626
import org.elasticsearch.client.ResponseException;
2727
import org.elasticsearch.client.RestClient;
28-
import org.elasticsearch.client.WarningFailureException;
2928
import org.elasticsearch.cluster.metadata.IndexMetaData;
3029
import org.elasticsearch.common.Booleans;
3130
import org.elasticsearch.common.CheckedFunction;
@@ -62,7 +61,6 @@
6261
import static org.hamcrest.Matchers.greaterThan;
6362
import static org.hamcrest.Matchers.hasSize;
6463
import static org.hamcrest.Matchers.notNullValue;
65-
import static org.hamcrest.Matchers.startsWith;
6664

6765
/**
6866
* Tests to run before and after a full cluster restart. This is run twice,
@@ -273,6 +271,7 @@ public void testShrink() throws IOException {
273271
mappingsAndSettings.endObject();
274272
}
275273
mappingsAndSettings.endObject();
274+
276275
mappingsAndSettings.startObject("settings");
277276
{
278277
mappingsAndSettings.field("index.number_of_shards", 5);
@@ -428,7 +427,9 @@ public void testRollover() throws IOException {
428427
bulk.append("{\"index\":{}}\n");
429428
bulk.append("{\"test\":\"test\"}\n");
430429
}
430+
431431
Request bulkRequest = new Request("POST", "/" + index + "_write/_bulk");
432+
432433
bulkRequest.setJsonEntity(bulk.toString());
433434
bulkRequest.addParameter("refresh", "");
434435
assertThat(EntityUtils.toString(client().performRequest(bulkRequest).getEntity()), containsString("\"errors\":false"));
@@ -563,8 +564,7 @@ void assertRealtimeGetWorks() throws IOException {
563564
client().performRequest(updateRequest);
564565

565566
Request getRequest = new Request("GET", "/" + index + "/_doc/" + docId);
566-
if (getOldClusterVersion().before(Version.V_6_7_0)) {
567-
}
567+
568568
Map<String, Object> getRsp = entityAsMap(client().performRequest(getRequest));
569569
Map<?, ?> source = (Map<?, ?>) getRsp.get("_source");
570570
assertTrue("doc does not contain 'foo' key: " + source, source.containsKey("foo"));
@@ -960,26 +960,10 @@ private void checkSnapshot(final String snapshotName, final int count, final Ver
960960
assertEquals(singletonList(tookOnVersion.toString()), XContentMapValues.extractValue("snapshots.version", listSnapshotResponse));
961961

962962
// Remove the routing setting and template so we can test restoring them.
963-
try {
964-
Request clearRoutingFromSettings = new Request("PUT", "/_cluster/settings");
965-
clearRoutingFromSettings.setJsonEntity("{\"persistent\":{\"cluster.routing.allocation.exclude.test_attr\": null}}");
966-
client().performRequest(clearRoutingFromSettings);
967-
} catch (WarningFailureException e) {
968-
/*
969-
* If this test is executed on the upgraded mode before testRemoteClusterSettingsUpgraded,
970-
* we will hit a warning exception because we put some deprecated settings in that test.
971-
*/
972-
if (isRunningAgainstOldCluster() == false) {
973-
for (String warning : e.getResponse().getWarnings()) {
974-
assertThat(warning, containsString(
975-
"setting was deprecated in Elasticsearch and will be removed in a future release! "
976-
+ "See the breaking changes documentation for the next major version."));
977-
assertThat(warning, startsWith("[search.remote."));
978-
}
979-
} else {
980-
throw e;
981-
}
982-
}
963+
Request clearRoutingFromSettings = new Request("PUT", "/_cluster/settings");
964+
clearRoutingFromSettings.setJsonEntity("{\"persistent\":{\"cluster.routing.allocation.exclude.test_attr\": null}}");
965+
client().performRequest(clearRoutingFromSettings);
966+
983967
client().performRequest(new Request("DELETE", "/_template/test_template"));
984968

985969
// Restore
@@ -1007,7 +991,9 @@ private void checkSnapshot(final String snapshotName, final int count, final Ver
1007991
bulk.append("{\"index\":{\"_id\":\"").append(count + i).append("\"}}\n");
1008992
bulk.append("{\"test\":\"test\"}\n");
1009993
}
994+
1010995
Request writeToRestoredRequest = new Request("POST", "/restored_" + index + "/_bulk");
996+
1011997
writeToRestoredRequest.addParameter("refresh", "true");
1012998
writeToRestoredRequest.setJsonEntity(bulk.toString());
1013999
assertThat(EntityUtils.toString(client().performRequest(writeToRestoredRequest).getEntity()), containsString("\"errors\":false"));
@@ -1035,14 +1021,12 @@ private void checkSnapshot(final String snapshotName, final int count, final Ver
10351021

10361022
Map<String, Object> getTemplateResponse = entityAsMap(client().performRequest(getTemplateRequest));
10371023
Map<String, Object> expectedTemplate = new HashMap<>();
1038-
if (isRunningAgainstOldCluster() && getOldClusterVersion().before(Version.V_6_0_0_beta1)) {
1039-
expectedTemplate.put("template", "evil_*");
1040-
} else {
1041-
expectedTemplate.put("index_patterns", singletonList("evil_*"));
1042-
}
1024+
expectedTemplate.put("index_patterns", singletonList("evil_*"));
1025+
10431026
expectedTemplate.put("settings", singletonMap("index", singletonMap("number_of_shards", "1")));
10441027
expectedTemplate.put("mappings", singletonMap("_source", singletonMap("enabled", true)));
10451028

1029+
10461030
expectedTemplate.put("order", 0);
10471031
Map<String, Object> aliases = new HashMap<>();
10481032
aliases.put("alias1", emptyMap());

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

Lines changed: 0 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -19,84 +19,6 @@
1919

2020
package org.elasticsearch.upgrades;
2121

22-
import org.elasticsearch.Version;
23-
import org.elasticsearch.action.admin.cluster.settings.ClusterGetSettingsResponse;
24-
import org.elasticsearch.client.Request;
25-
import org.elasticsearch.client.Response;
26-
import org.elasticsearch.common.Strings;
27-
import org.elasticsearch.common.settings.Setting;
28-
import org.elasticsearch.common.settings.Settings;
29-
import org.elasticsearch.common.xcontent.XContentBuilder;
30-
import org.elasticsearch.common.xcontent.XContentParser;
31-
import org.elasticsearch.common.xcontent.json.JsonXContent;
32-
import org.elasticsearch.transport.RemoteClusterService;
33-
34-
import java.io.IOException;
35-
import java.util.Collections;
36-
37-
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
38-
import static org.elasticsearch.transport.RemoteClusterAware.SEARCH_REMOTE_CLUSTERS_SEEDS;
39-
import static org.elasticsearch.transport.RemoteClusterService.SEARCH_REMOTE_CLUSTER_SKIP_UNAVAILABLE;
40-
import static org.hamcrest.Matchers.equalTo;
41-
4222
public class FullClusterRestartSettingsUpgradeIT extends AbstractFullClusterRestartTestCase {
4323

44-
public void testRemoteClusterSettingsUpgraded() throws IOException {
45-
assumeTrue("skip_unavailable did not exist until 6.1.0", getOldClusterVersion().onOrAfter(Version.V_6_1_0));
46-
assumeTrue("settings automatically upgraded since 6.5.0", getOldClusterVersion().before(Version.V_6_5_0));
47-
if (isRunningAgainstOldCluster()) {
48-
final Request putSettingsRequest = new Request("PUT", "/_cluster/settings");
49-
try (XContentBuilder builder = jsonBuilder()) {
50-
builder.startObject();
51-
{
52-
builder.startObject("persistent");
53-
{
54-
builder.field("search.remote.foo.skip_unavailable", true);
55-
builder.field("search.remote.foo.seeds", Collections.singletonList("localhost:9200"));
56-
}
57-
builder.endObject();
58-
}
59-
builder.endObject();
60-
putSettingsRequest.setJsonEntity(Strings.toString(builder));
61-
}
62-
client().performRequest(putSettingsRequest);
63-
64-
final Request getSettingsRequest = new Request("GET", "/_cluster/settings");
65-
final Response response = client().performRequest(getSettingsRequest);
66-
try (XContentParser parser = createParser(JsonXContent.jsonXContent, response.getEntity().getContent())) {
67-
final ClusterGetSettingsResponse clusterGetSettingsResponse = ClusterGetSettingsResponse.fromXContent(parser);
68-
final Settings settings = clusterGetSettingsResponse.getPersistentSettings();
69-
70-
assertTrue(SEARCH_REMOTE_CLUSTER_SKIP_UNAVAILABLE.getConcreteSettingForNamespace("foo").exists(settings));
71-
assertTrue(SEARCH_REMOTE_CLUSTER_SKIP_UNAVAILABLE.getConcreteSettingForNamespace("foo").get(settings));
72-
assertTrue(SEARCH_REMOTE_CLUSTERS_SEEDS.getConcreteSettingForNamespace("foo").exists(settings));
73-
assertThat(
74-
SEARCH_REMOTE_CLUSTERS_SEEDS.getConcreteSettingForNamespace("foo").get(settings),
75-
equalTo(Collections.singletonList("localhost:9200")));
76-
}
77-
78-
assertSettingDeprecationsAndWarnings(new Setting<?>[]{
79-
SEARCH_REMOTE_CLUSTER_SKIP_UNAVAILABLE.getConcreteSettingForNamespace("foo"),
80-
SEARCH_REMOTE_CLUSTERS_SEEDS.getConcreteSettingForNamespace("foo")});
81-
} else {
82-
final Request getSettingsRequest = new Request("GET", "/_cluster/settings");
83-
final Response getSettingsResponse = client().performRequest(getSettingsRequest);
84-
try (XContentParser parser = createParser(JsonXContent.jsonXContent, getSettingsResponse.getEntity().getContent())) {
85-
final ClusterGetSettingsResponse clusterGetSettingsResponse = ClusterGetSettingsResponse.fromXContent(parser);
86-
final Settings settings = clusterGetSettingsResponse.getPersistentSettings();
87-
88-
assertFalse(SEARCH_REMOTE_CLUSTER_SKIP_UNAVAILABLE.getConcreteSettingForNamespace("foo").exists(settings));
89-
assertTrue(
90-
settings.toString(),
91-
RemoteClusterService.REMOTE_CLUSTER_SKIP_UNAVAILABLE.getConcreteSettingForNamespace("foo").exists(settings));
92-
assertTrue(RemoteClusterService.REMOTE_CLUSTER_SKIP_UNAVAILABLE.getConcreteSettingForNamespace("foo").get(settings));
93-
assertFalse(SEARCH_REMOTE_CLUSTERS_SEEDS.getConcreteSettingForNamespace("foo").exists(settings));
94-
assertTrue(RemoteClusterService.REMOTE_CLUSTERS_SEEDS.getConcreteSettingForNamespace("foo").exists(settings));
95-
assertThat(
96-
RemoteClusterService.REMOTE_CLUSTERS_SEEDS.getConcreteSettingForNamespace("foo").get(settings),
97-
equalTo(Collections.singletonList("localhost:9200")));
98-
}
99-
}
100-
}
101-
10224
}

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
package org.elasticsearch.upgrades;
2121

2222
import org.apache.http.util.EntityUtils;
23-
import org.elasticsearch.Version;
2423
import org.elasticsearch.client.Request;
2524
import org.elasticsearch.client.Response;
2625
import org.elasticsearch.common.Strings;
@@ -144,7 +143,6 @@ private static void addCandidate(String querySource, QueryBuilder expectedQb) {
144143
}
145144

146145
public void testQueryBuilderBWC() throws Exception {
147-
final String type = getOldClusterVersion().before(Version.V_7_0_0) ? "doc" : "_doc";
148146
String index = "queries";
149147
if (isRunningAgainstOldCluster()) {
150148
XContentBuilder mappingsAndSettings = jsonBuilder();
@@ -157,9 +155,6 @@ public void testQueryBuilderBWC() throws Exception {
157155
}
158156
{
159157
mappingsAndSettings.startObject("mappings");
160-
if (isRunningAgainstAncientCluster()) {
161-
mappingsAndSettings.startObject(type);
162-
}
163158
mappingsAndSettings.startObject("properties");
164159
{
165160
mappingsAndSettings.startObject("query");
@@ -178,9 +173,6 @@ public void testQueryBuilderBWC() throws Exception {
178173
}
179174
mappingsAndSettings.endObject();
180175
mappingsAndSettings.endObject();
181-
if (isRunningAgainstAncientCluster()) {
182-
mappingsAndSettings.endObject();
183-
}
184176
}
185177
mappingsAndSettings.endObject();
186178
Request request = new Request("PUT", "/" + index);
@@ -190,7 +182,7 @@ public void testQueryBuilderBWC() throws Exception {
190182
assertEquals(200, rsp.getStatusLine().getStatusCode());
191183

192184
for (int i = 0; i < CANDIDATES.size(); i++) {
193-
request = new Request("PUT", "/" + index + "/" + type + "/" + Integer.toString(i));
185+
request = new Request("PUT", "/" + index + "/_doc/" + Integer.toString(i));
194186
request.setJsonEntity((String) CANDIDATES.get(i)[0]);
195187
rsp = client().performRequest(request);
196188
assertEquals(201, rsp.getStatusLine().getStatusCode());

server/src/test/java/org/elasticsearch/index/mapper/ExternalMapper.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import org.apache.lucene.search.DocValuesFieldExistsQuery;
2525
import org.apache.lucene.search.Query;
2626
import org.apache.lucene.search.TermQuery;
27-
import org.elasticsearch.Version;
2827
import org.elasticsearch.common.geo.builders.PointBuilder;
2928
import org.elasticsearch.common.collect.Iterators;
3029
import org.elasticsearch.common.geo.GeoPoint;
@@ -63,7 +62,6 @@ public static class Builder extends FieldMapper.Builder<Builder, ExternalMapper>
6362
private BooleanFieldMapper.Builder boolBuilder = new BooleanFieldMapper.Builder(Names.FIELD_BOOL);
6463
private GeoPointFieldMapper.Builder latLonPointBuilder = new GeoPointFieldMapper.Builder(Names.FIELD_POINT);
6564
private GeoShapeFieldMapper.Builder shapeBuilder = new GeoShapeFieldMapper.Builder(Names.FIELD_SHAPE);
66-
private LegacyGeoShapeFieldMapper.Builder legacyShapeBuilder = new LegacyGeoShapeFieldMapper.Builder(Names.FIELD_SHAPE);
6765
private Mapper.Builder stringBuilder;
6866
private String generatedValue;
6967
private String mapperName;
@@ -87,9 +85,7 @@ public ExternalMapper build(BuilderContext context) {
8785
BinaryFieldMapper binMapper = binBuilder.build(context);
8886
BooleanFieldMapper boolMapper = boolBuilder.build(context);
8987
GeoPointFieldMapper pointMapper = latLonPointBuilder.build(context);
90-
BaseGeoShapeFieldMapper shapeMapper = (context.indexCreatedVersion().before(Version.V_6_6_0))
91-
? legacyShapeBuilder.build(context)
92-
: shapeBuilder.build(context);
88+
BaseGeoShapeFieldMapper shapeMapper = shapeBuilder.build(context);
9389
FieldMapper stringMapper = (FieldMapper)stringBuilder.build(context);
9490
context.path().remove();
9591

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

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@
4040
import java.util.List;
4141
import java.util.Map;
4242

43-
import static org.elasticsearch.rest.BaseRestHandler.INCLUDE_TYPE_NAME_PARAMETER;
44-
4543
/**
4644
* Execution context passed across the REST tests.
4745
* Holds the REST client used to communicate with elasticsearch.
@@ -98,10 +96,6 @@ public ClientYamlTestResponse callApi(String apiName, Map<String, String> params
9896
}
9997
}
10098

101-
if (esVersion().before(Version.V_7_0_0)) {
102-
adaptRequestForOlderVersion(apiName, bodies, requestParams);
103-
}
104-
10599
HttpEntity entity = createEntity(bodies, requestHeaders);
106100
try {
107101
response = callApiInternal(apiName, requestParams, entity, requestHeaders, nodeSelector);
@@ -117,64 +111,6 @@ public ClientYamlTestResponse callApi(String apiName, Map<String, String> params
117111
}
118112
}
119113

120-
/**
121-
* To allow tests to run against a mixed 7.x/6.x cluster, we make certain modifications to the
122-
* request related to types.
123-
*
124-
* Specifically, we generally use typeless index creation and document writes in test set-up code.
125-
* This functionality is supported in 7.x, but is not supported in 6.x (or is not the default
126-
* behavior). Here we modify the request so that it will work against a 6.x node.
127-
*/
128-
private void adaptRequestForOlderVersion(String apiName,
129-
List<Map<String, Object>> bodies,
130-
Map<String, String> requestParams) {
131-
// For index creations, we specify 'include_type_name=false' if it is not explicitly set. This
132-
// allows us to omit the parameter in the test description, while still being able to communicate
133-
// with 6.x nodes where include_type_name defaults to 'true'.
134-
if (apiName.equals("indices.create") && requestParams.containsKey(INCLUDE_TYPE_NAME_PARAMETER) == false) {
135-
requestParams.put(INCLUDE_TYPE_NAME_PARAMETER, "false");
136-
}
137-
138-
// We add the type to the document API requests if it's not already included.
139-
if ((apiName.equals("index") || apiName.equals("update") || apiName.equals("delete") || apiName.equals("get"))
140-
&& requestParams.containsKey("type") == false) {
141-
requestParams.put("type", "_doc");
142-
}
143-
144-
// We also add the type to the bulk API requests if it's not already included. The type can either
145-
// be on the request parameters or in the action metadata in the body of the request so we need to
146-
// be sensitive to both scenarios.
147-
if (apiName.equals("bulk") && requestParams.containsKey("type") == false) {
148-
if (requestParams.containsKey("index")) {
149-
requestParams.put("type", "_doc");
150-
} else {
151-
for (int i = 0; i < bodies.size(); i++) {
152-
Map<String, Object> body = bodies.get(i);
153-
Map<String, Object> actionMetadata;
154-
if (body.containsKey("index")) {
155-
actionMetadata = (Map<String, Object>) body.get("index");
156-
i++;
157-
} else if (body.containsKey("create")) {
158-
actionMetadata = (Map<String, Object>) body.get("create");
159-
i++;
160-
} else if (body.containsKey("update")) {
161-
actionMetadata = (Map<String, Object>) body.get("update");
162-
i++;
163-
} else if (body.containsKey("delete")) {
164-
actionMetadata = (Map<String, Object>) body.get("delete");
165-
} else {
166-
// action metadata is malformed so leave it malformed since
167-
// the test is probably testing for malformed action metadata
168-
continue;
169-
}
170-
if (actionMetadata.containsKey("_type") == false) {
171-
actionMetadata.put("_type", "_doc");
172-
}
173-
}
174-
}
175-
}
176-
}
177-
178114
private HttpEntity createEntity(List<Map<String, Object>> bodies, Map<String, String> headers) throws IOException {
179115
if (bodies.isEmpty()) {
180116
return null;

test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/DoSection.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -292,17 +292,7 @@ void checkWarningHeaders(final List<String> warningHeaders, final Version master
292292
final boolean matches = matcher.matches();
293293
if (matches) {
294294
final String message = matcher.group(1);
295-
// noinspection StatementWithEmptyBody
296-
if (masterVersion.before(Version.V_7_0_0)
297-
&& message.equals("the default number of shards will change from [5] to [1] in 7.0.0; "
298-
+ "if you wish to continue using the default of [5] shards, "
299-
+ "you must manage this on the create index request or with an index template")) {
300-
/*
301-
* This warning header will come back in the vast majority of our tests that create an index when running against an
302-
* older master. Rather than rewrite our tests to assert this warning header, we assume that it is expected.
303-
*/
304-
} else // noinspection StatementWithEmptyBody
305-
if (message.startsWith("[types removal]")) {
295+
if (message.startsWith("[types removal]")) {
306296
/*
307297
* We skip warnings related to types deprecation so that we can continue to run the many
308298
* mixed-version tests that used typed APIs.

0 commit comments

Comments
 (0)