Skip to content

Commit

Permalink
Removing code that rarely adds a legacy global template to yaml rest …
Browse files Browse the repository at this point in the history
…tests
  • Loading branch information
masseyke committed Oct 28, 2024
1 parent 232622a commit 8d25734
Showing 1 changed file with 4 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,10 @@
import org.apache.lucene.tests.util.TimeUnits;
import org.elasticsearch.client.Node;
import org.elasticsearch.client.Request;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.Response;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.WarningsHandler;
import org.elasticsearch.client.sniff.ElasticsearchNodesSniffer;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.support.XContentMapValues;
Expand All @@ -41,11 +38,8 @@
import org.elasticsearch.test.rest.yaml.section.ExecutableSection;
import org.elasticsearch.xcontent.NamedXContentRegistry;
import org.elasticsearch.xcontent.ParseField;
import org.elasticsearch.xcontent.ToXContent;
import org.elasticsearch.xcontent.XContentBuilder;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;

import java.io.IOException;
import java.nio.file.Files;
Expand All @@ -67,8 +61,6 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.elasticsearch.xcontent.XContentFactory.jsonBuilder;

/**
* Runs a suite of yaml tests shared with all the official Elasticsearch
* clients against an elasticsearch cluster.
Expand Down Expand Up @@ -125,15 +117,6 @@ protected ESClientYamlSuiteTestCase(ClientYamlTestCandidate testCandidate) {
this.testCandidate = testCandidate;
}

private static Settings globalTemplateIndexSettings;

@BeforeClass
public static void initializeGlobalTemplateIndexSettings() {
globalTemplateIndexSettings = usually()
? Settings.EMPTY
: Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 2).build();
}

@Before
public void initAndResetContext() throws Exception {
if (restTestExecutionContext == null) {
Expand Down Expand Up @@ -511,34 +494,6 @@ public void test() throws IOException {
inFipsJvm() && testCandidate.getTestSection().getPrerequisiteSection().hasYamlRunnerFeature("fips_140")
);

final Settings globalTemplateSettings = getGlobalTemplateSettings(
testCandidate.getTestSection().getPrerequisiteSection().hasYamlRunnerFeature("default_shards")
);
if (globalTemplateSettings.isEmpty() == false && ESRestTestCase.has(ProductFeature.LEGACY_TEMPLATES)) {

final XContentBuilder template = jsonBuilder();
template.startObject();
{
template.array("index_patterns", "*");
template.startObject("settings");
globalTemplateSettings.toXContent(template, ToXContent.EMPTY_PARAMS);
template.endObject();
}
template.endObject();

final Request request = new Request("PUT", "/_template/global");
request.setJsonEntity(Strings.toString(template));
// Because not all case have transitioned to a composable template, it's possible that
// this can overlap an installed composable template since this is a global (*)
// template. In order to avoid this failing the test, we override the warnings handler
// to be permissive in this case. This can be removed once all tests use composable
// templates instead of legacy templates
RequestOptions.Builder builder = RequestOptions.DEFAULT.toBuilder();
builder.setWarningsHandler(WarningsHandler.PERMISSIVE);
request.setOptions(builder.build());
adminClient().performRequest(request);
}

if (skipSetupSections() == false && testCandidate.getSetupSection().isEmpty() == false) {
logger.debug("start setup test [{}]", testCandidate.getTestPath());
for (ExecutableSection executableSection : testCandidate.getSetupSection().getExecutableSections()) {
Expand All @@ -564,19 +519,13 @@ public void test() throws IOException {

@Deprecated
protected Settings getGlobalTemplateSettings(List<String> features) {
if (features.contains("default_shards")) {
return Settings.EMPTY;
} else {
return globalTemplateIndexSettings;
}
// This method will be deleted once its uses in serverless are deleted
return Settings.EMPTY;
}

protected Settings getGlobalTemplateSettings(boolean defaultShardsFeature) {
if (defaultShardsFeature) {
return Settings.EMPTY;
} else {
return globalTemplateIndexSettings;
}
// This method will be deleted once its uses in serverless are deleted
return Settings.EMPTY;
}

protected boolean skipSetupSections() {
Expand Down

0 comments on commit 8d25734

Please sign in to comment.