Skip to content

Commit

Permalink
Remove tests and branches that will never execute (#38772)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
alpar-t authored Feb 18, 2019
1 parent e2c329f commit 6891475
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 706 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.elasticsearch.client.Response;
import org.elasticsearch.client.ResponseException;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.WarningFailureException;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.Booleans;
import org.elasticsearch.common.CheckedFunction;
Expand Down Expand Up @@ -62,7 +61,6 @@
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.startsWith;

/**
* Tests to run before and after a full cluster restart. This is run twice,
Expand Down Expand Up @@ -273,6 +271,7 @@ public void testShrink() throws IOException {
mappingsAndSettings.endObject();
}
mappingsAndSettings.endObject();

mappingsAndSettings.startObject("settings");
{
mappingsAndSettings.field("index.number_of_shards", 5);
Expand Down Expand Up @@ -428,7 +427,9 @@ public void testRollover() throws IOException {
bulk.append("{\"index\":{}}\n");
bulk.append("{\"test\":\"test\"}\n");
}

Request bulkRequest = new Request("POST", "/" + index + "_write/_bulk");

bulkRequest.setJsonEntity(bulk.toString());
bulkRequest.addParameter("refresh", "");
assertThat(EntityUtils.toString(client().performRequest(bulkRequest).getEntity()), containsString("\"errors\":false"));
Expand Down Expand Up @@ -563,8 +564,7 @@ void assertRealtimeGetWorks() throws IOException {
client().performRequest(updateRequest);

Request getRequest = new Request("GET", "/" + index + "/_doc/" + docId);
if (getOldClusterVersion().before(Version.V_6_7_0)) {
}

Map<String, Object> getRsp = entityAsMap(client().performRequest(getRequest));
Map<?, ?> source = (Map<?, ?>) getRsp.get("_source");
assertTrue("doc does not contain 'foo' key: " + source, source.containsKey("foo"));
Expand Down Expand Up @@ -960,26 +960,10 @@ private void checkSnapshot(final String snapshotName, final int count, final Ver
assertEquals(singletonList(tookOnVersion.toString()), XContentMapValues.extractValue("snapshots.version", listSnapshotResponse));

// Remove the routing setting and template so we can test restoring them.
try {
Request clearRoutingFromSettings = new Request("PUT", "/_cluster/settings");
clearRoutingFromSettings.setJsonEntity("{\"persistent\":{\"cluster.routing.allocation.exclude.test_attr\": null}}");
client().performRequest(clearRoutingFromSettings);
} catch (WarningFailureException e) {
/*
* If this test is executed on the upgraded mode before testRemoteClusterSettingsUpgraded,
* we will hit a warning exception because we put some deprecated settings in that test.
*/
if (isRunningAgainstOldCluster() == false) {
for (String warning : e.getResponse().getWarnings()) {
assertThat(warning, containsString(
"setting was deprecated in Elasticsearch and will be removed in a future release! "
+ "See the breaking changes documentation for the next major version."));
assertThat(warning, startsWith("[search.remote."));
}
} else {
throw e;
}
}
Request clearRoutingFromSettings = new Request("PUT", "/_cluster/settings");
clearRoutingFromSettings.setJsonEntity("{\"persistent\":{\"cluster.routing.allocation.exclude.test_attr\": null}}");
client().performRequest(clearRoutingFromSettings);

client().performRequest(new Request("DELETE", "/_template/test_template"));

// Restore
Expand Down Expand Up @@ -1007,7 +991,9 @@ private void checkSnapshot(final String snapshotName, final int count, final Ver
bulk.append("{\"index\":{\"_id\":\"").append(count + i).append("\"}}\n");
bulk.append("{\"test\":\"test\"}\n");
}

Request writeToRestoredRequest = new Request("POST", "/restored_" + index + "/_bulk");

writeToRestoredRequest.addParameter("refresh", "true");
writeToRestoredRequest.setJsonEntity(bulk.toString());
assertThat(EntityUtils.toString(client().performRequest(writeToRestoredRequest).getEntity()), containsString("\"errors\":false"));
Expand Down Expand Up @@ -1035,14 +1021,12 @@ private void checkSnapshot(final String snapshotName, final int count, final Ver

Map<String, Object> getTemplateResponse = entityAsMap(client().performRequest(getTemplateRequest));
Map<String, Object> expectedTemplate = new HashMap<>();
if (isRunningAgainstOldCluster() && getOldClusterVersion().before(Version.V_6_0_0_beta1)) {
expectedTemplate.put("template", "evil_*");
} else {
expectedTemplate.put("index_patterns", singletonList("evil_*"));
}
expectedTemplate.put("index_patterns", singletonList("evil_*"));

expectedTemplate.put("settings", singletonMap("index", singletonMap("number_of_shards", "1")));
expectedTemplate.put("mappings", singletonMap("_source", singletonMap("enabled", true)));


expectedTemplate.put("order", 0);
Map<String, Object> aliases = new HashMap<>();
aliases.put("alias1", emptyMap());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,84 +19,6 @@

package org.elasticsearch.upgrades;

import org.elasticsearch.Version;
import org.elasticsearch.action.admin.cluster.settings.ClusterGetSettingsResponse;
import org.elasticsearch.client.Request;
import org.elasticsearch.client.Response;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.transport.RemoteClusterService;

import java.io.IOException;
import java.util.Collections;

import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.transport.RemoteClusterAware.SEARCH_REMOTE_CLUSTERS_SEEDS;
import static org.elasticsearch.transport.RemoteClusterService.SEARCH_REMOTE_CLUSTER_SKIP_UNAVAILABLE;
import static org.hamcrest.Matchers.equalTo;

public class FullClusterRestartSettingsUpgradeIT extends AbstractFullClusterRestartTestCase {

public void testRemoteClusterSettingsUpgraded() throws IOException {
assumeTrue("skip_unavailable did not exist until 6.1.0", getOldClusterVersion().onOrAfter(Version.V_6_1_0));
assumeTrue("settings automatically upgraded since 6.5.0", getOldClusterVersion().before(Version.V_6_5_0));
if (isRunningAgainstOldCluster()) {
final Request putSettingsRequest = new Request("PUT", "/_cluster/settings");
try (XContentBuilder builder = jsonBuilder()) {
builder.startObject();
{
builder.startObject("persistent");
{
builder.field("search.remote.foo.skip_unavailable", true);
builder.field("search.remote.foo.seeds", Collections.singletonList("localhost:9200"));
}
builder.endObject();
}
builder.endObject();
putSettingsRequest.setJsonEntity(Strings.toString(builder));
}
client().performRequest(putSettingsRequest);

final Request getSettingsRequest = new Request("GET", "/_cluster/settings");
final Response response = client().performRequest(getSettingsRequest);
try (XContentParser parser = createParser(JsonXContent.jsonXContent, response.getEntity().getContent())) {
final ClusterGetSettingsResponse clusterGetSettingsResponse = ClusterGetSettingsResponse.fromXContent(parser);
final Settings settings = clusterGetSettingsResponse.getPersistentSettings();

assertTrue(SEARCH_REMOTE_CLUSTER_SKIP_UNAVAILABLE.getConcreteSettingForNamespace("foo").exists(settings));
assertTrue(SEARCH_REMOTE_CLUSTER_SKIP_UNAVAILABLE.getConcreteSettingForNamespace("foo").get(settings));
assertTrue(SEARCH_REMOTE_CLUSTERS_SEEDS.getConcreteSettingForNamespace("foo").exists(settings));
assertThat(
SEARCH_REMOTE_CLUSTERS_SEEDS.getConcreteSettingForNamespace("foo").get(settings),
equalTo(Collections.singletonList("localhost:9200")));
}

assertSettingDeprecationsAndWarnings(new Setting<?>[]{
SEARCH_REMOTE_CLUSTER_SKIP_UNAVAILABLE.getConcreteSettingForNamespace("foo"),
SEARCH_REMOTE_CLUSTERS_SEEDS.getConcreteSettingForNamespace("foo")});
} else {
final Request getSettingsRequest = new Request("GET", "/_cluster/settings");
final Response getSettingsResponse = client().performRequest(getSettingsRequest);
try (XContentParser parser = createParser(JsonXContent.jsonXContent, getSettingsResponse.getEntity().getContent())) {
final ClusterGetSettingsResponse clusterGetSettingsResponse = ClusterGetSettingsResponse.fromXContent(parser);
final Settings settings = clusterGetSettingsResponse.getPersistentSettings();

assertFalse(SEARCH_REMOTE_CLUSTER_SKIP_UNAVAILABLE.getConcreteSettingForNamespace("foo").exists(settings));
assertTrue(
settings.toString(),
RemoteClusterService.REMOTE_CLUSTER_SKIP_UNAVAILABLE.getConcreteSettingForNamespace("foo").exists(settings));
assertTrue(RemoteClusterService.REMOTE_CLUSTER_SKIP_UNAVAILABLE.getConcreteSettingForNamespace("foo").get(settings));
assertFalse(SEARCH_REMOTE_CLUSTERS_SEEDS.getConcreteSettingForNamespace("foo").exists(settings));
assertTrue(RemoteClusterService.REMOTE_CLUSTERS_SEEDS.getConcreteSettingForNamespace("foo").exists(settings));
assertThat(
RemoteClusterService.REMOTE_CLUSTERS_SEEDS.getConcreteSettingForNamespace("foo").get(settings),
equalTo(Collections.singletonList("localhost:9200")));
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package org.elasticsearch.upgrades;

import org.apache.http.util.EntityUtils;
import org.elasticsearch.Version;
import org.elasticsearch.client.Request;
import org.elasticsearch.client.Response;
import org.elasticsearch.common.Strings;
Expand Down Expand Up @@ -144,7 +143,6 @@ private static void addCandidate(String querySource, QueryBuilder expectedQb) {
}

public void testQueryBuilderBWC() throws Exception {
final String type = getOldClusterVersion().before(Version.V_7_0_0) ? "doc" : "_doc";
String index = "queries";
if (isRunningAgainstOldCluster()) {
XContentBuilder mappingsAndSettings = jsonBuilder();
Expand All @@ -157,9 +155,6 @@ public void testQueryBuilderBWC() throws Exception {
}
{
mappingsAndSettings.startObject("mappings");
if (isRunningAgainstAncientCluster()) {
mappingsAndSettings.startObject(type);
}
mappingsAndSettings.startObject("properties");
{
mappingsAndSettings.startObject("query");
Expand All @@ -178,9 +173,6 @@ public void testQueryBuilderBWC() throws Exception {
}
mappingsAndSettings.endObject();
mappingsAndSettings.endObject();
if (isRunningAgainstAncientCluster()) {
mappingsAndSettings.endObject();
}
}
mappingsAndSettings.endObject();
Request request = new Request("PUT", "/" + index);
Expand All @@ -190,7 +182,7 @@ public void testQueryBuilderBWC() throws Exception {
assertEquals(200, rsp.getStatusLine().getStatusCode());

for (int i = 0; i < CANDIDATES.size(); i++) {
request = new Request("PUT", "/" + index + "/" + type + "/" + Integer.toString(i));
request = new Request("PUT", "/" + index + "/_doc/" + Integer.toString(i));
request.setJsonEntity((String) CANDIDATES.get(i)[0]);
rsp = client().performRequest(request);
assertEquals(201, rsp.getStatusLine().getStatusCode());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.apache.lucene.search.DocValuesFieldExistsQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermQuery;
import org.elasticsearch.Version;
import org.elasticsearch.common.geo.builders.PointBuilder;
import org.elasticsearch.common.collect.Iterators;
import org.elasticsearch.common.geo.GeoPoint;
Expand Down Expand Up @@ -63,7 +62,6 @@ public static class Builder extends FieldMapper.Builder<Builder, ExternalMapper>
private BooleanFieldMapper.Builder boolBuilder = new BooleanFieldMapper.Builder(Names.FIELD_BOOL);
private GeoPointFieldMapper.Builder latLonPointBuilder = new GeoPointFieldMapper.Builder(Names.FIELD_POINT);
private GeoShapeFieldMapper.Builder shapeBuilder = new GeoShapeFieldMapper.Builder(Names.FIELD_SHAPE);
private LegacyGeoShapeFieldMapper.Builder legacyShapeBuilder = new LegacyGeoShapeFieldMapper.Builder(Names.FIELD_SHAPE);
private Mapper.Builder stringBuilder;
private String generatedValue;
private String mapperName;
Expand All @@ -87,9 +85,7 @@ public ExternalMapper build(BuilderContext context) {
BinaryFieldMapper binMapper = binBuilder.build(context);
BooleanFieldMapper boolMapper = boolBuilder.build(context);
GeoPointFieldMapper pointMapper = latLonPointBuilder.build(context);
BaseGeoShapeFieldMapper shapeMapper = (context.indexCreatedVersion().before(Version.V_6_6_0))
? legacyShapeBuilder.build(context)
: shapeBuilder.build(context);
BaseGeoShapeFieldMapper shapeMapper = shapeBuilder.build(context);
FieldMapper stringMapper = (FieldMapper)stringBuilder.build(context);
context.path().remove();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@
import java.util.List;
import java.util.Map;

import static org.elasticsearch.rest.BaseRestHandler.INCLUDE_TYPE_NAME_PARAMETER;

/**
* Execution context passed across the REST tests.
* Holds the REST client used to communicate with elasticsearch.
Expand Down Expand Up @@ -98,10 +96,6 @@ public ClientYamlTestResponse callApi(String apiName, Map<String, String> params
}
}

if (esVersion().before(Version.V_7_0_0)) {
adaptRequestForOlderVersion(apiName, bodies, requestParams);
}

HttpEntity entity = createEntity(bodies, requestHeaders);
try {
response = callApiInternal(apiName, requestParams, entity, requestHeaders, nodeSelector);
Expand All @@ -117,64 +111,6 @@ public ClientYamlTestResponse callApi(String apiName, Map<String, String> params
}
}

/**
* To allow tests to run against a mixed 7.x/6.x cluster, we make certain modifications to the
* request related to types.
*
* Specifically, we generally use typeless index creation and document writes in test set-up code.
* This functionality is supported in 7.x, but is not supported in 6.x (or is not the default
* behavior). Here we modify the request so that it will work against a 6.x node.
*/
private void adaptRequestForOlderVersion(String apiName,
List<Map<String, Object>> bodies,
Map<String, String> requestParams) {
// For index creations, we specify 'include_type_name=false' if it is not explicitly set. This
// allows us to omit the parameter in the test description, while still being able to communicate
// with 6.x nodes where include_type_name defaults to 'true'.
if (apiName.equals("indices.create") && requestParams.containsKey(INCLUDE_TYPE_NAME_PARAMETER) == false) {
requestParams.put(INCLUDE_TYPE_NAME_PARAMETER, "false");
}

// We add the type to the document API requests if it's not already included.
if ((apiName.equals("index") || apiName.equals("update") || apiName.equals("delete") || apiName.equals("get"))
&& requestParams.containsKey("type") == false) {
requestParams.put("type", "_doc");
}

// We also add the type to the bulk API requests if it's not already included. The type can either
// be on the request parameters or in the action metadata in the body of the request so we need to
// be sensitive to both scenarios.
if (apiName.equals("bulk") && requestParams.containsKey("type") == false) {
if (requestParams.containsKey("index")) {
requestParams.put("type", "_doc");
} else {
for (int i = 0; i < bodies.size(); i++) {
Map<String, Object> body = bodies.get(i);
Map<String, Object> actionMetadata;
if (body.containsKey("index")) {
actionMetadata = (Map<String, Object>) body.get("index");
i++;
} else if (body.containsKey("create")) {
actionMetadata = (Map<String, Object>) body.get("create");
i++;
} else if (body.containsKey("update")) {
actionMetadata = (Map<String, Object>) body.get("update");
i++;
} else if (body.containsKey("delete")) {
actionMetadata = (Map<String, Object>) body.get("delete");
} else {
// action metadata is malformed so leave it malformed since
// the test is probably testing for malformed action metadata
continue;
}
if (actionMetadata.containsKey("_type") == false) {
actionMetadata.put("_type", "_doc");
}
}
}
}
}

private HttpEntity createEntity(List<Map<String, Object>> bodies, Map<String, String> headers) throws IOException {
if (bodies.isEmpty()) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,17 +292,7 @@ void checkWarningHeaders(final List<String> warningHeaders, final Version master
final boolean matches = matcher.matches();
if (matches) {
final String message = matcher.group(1);
// noinspection StatementWithEmptyBody
if (masterVersion.before(Version.V_7_0_0)
&& message.equals("the default number of shards will change from [5] to [1] in 7.0.0; "
+ "if you wish to continue using the default of [5] shards, "
+ "you must manage this on the create index request or with an index template")) {
/*
* This warning header will come back in the vast majority of our tests that create an index when running against an
* older master. Rather than rewrite our tests to assert this warning header, we assume that it is expected.
*/
} else // noinspection StatementWithEmptyBody
if (message.startsWith("[types removal]")) {
if (message.startsWith("[types removal]")) {
/*
* We skip warnings related to types deprecation so that we can continue to run the many
* mixed-version tests that used typed APIs.
Expand Down
Loading

0 comments on commit 6891475

Please sign in to comment.