Skip to content

Commit

Permalink
Move yaml rest test case to separate test lib (elastic#84835)
Browse files Browse the repository at this point in the history
The ESClientYamlSuiteTestCase is used to run yaml tests throughout
Elasticsearch. It utilizes the low level rest client in sniffing for
nodes, but the sniffer is not needed anywhere else in the test
framework.

This commit creates a new project, `:test:rest-runner` which is meant to
house the rest test running infrastructure. This has two purposes. First
is to remove the sniffer from the test framework dependencies, because
it transitively depends on Jackson. Second is to setup the runner for
future refactorings where it could be made to not depend on the entire
test framework, though how that could work is left for the future.
  • Loading branch information
rjernst authored Mar 11, 2022
1 parent 5c857d1 commit 0ec2290
Show file tree
Hide file tree
Showing 120 changed files with 95 additions and 147 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ abstract class AbstractRestResourcesFuncTest extends AbstractGradleFuncTest {

def setup() {
addSubProject(":test:framework") << "apply plugin: 'elasticsearch.java'"
addSubProject(":test:yaml-rest-runner") << "apply plugin: 'elasticsearch.java'"

addSubProject(":rest-api-spec") << """
configurations { restSpecs\nrestTests }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import java.util.Arrays;
import java.util.Map;

import static org.elasticsearch.gradle.internal.test.rest.RestTestUtil.setupTestDependenciesDefaults;
import static org.elasticsearch.gradle.internal.test.rest.RestTestUtil.setupYamlRestTestDependenciesDefaults;

/**
* Apply this plugin to run the YAML based REST tests from a prior major version against this version's cluster.
Expand Down Expand Up @@ -215,7 +215,7 @@ public void apply(Project project) {
testTask.onlyIf(t -> isEnabled(project));
});

setupTestDependenciesDefaults(project, yamlCompatTestSourceSet);
setupYamlRestTestDependenciesDefaults(project, yamlCompatTestSourceSet);

// setup IDE
GradleUtils.setupIdeForTestSourceSet(project, yamlCompatTestSourceSet);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void apply(final Project project) {

// create a compileOnly configuration as others might expect it
project.getConfigurations().create("compileOnly");
RestTestUtil.setupTestDependenciesDefaults(project, testSourceSet);
RestTestUtil.setupJavaRestTestDependenciesDefaults(project, testSourceSet);

EclipseModel eclipse = project.getExtensions().getByType(EclipseModel.class);
eclipse.getClasspath().setSourceSets(Arrays.asList(testSourceSet));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import org.gradle.api.tasks.SourceSetContainer;

import static org.elasticsearch.gradle.internal.test.rest.RestTestUtil.registerTestTask;
import static org.elasticsearch.gradle.internal.test.rest.RestTestUtil.setupTestDependenciesDefaults;
import static org.elasticsearch.gradle.internal.test.rest.RestTestUtil.setupJavaRestTestDependenciesDefaults;

/**
* Apply this plugin to run the Java based REST tests.
Expand All @@ -37,7 +37,7 @@ public void apply(Project project) {
registerTestTask(project, javaTestSourceSet);

// setup dependencies
setupTestDependenciesDefaults(project, javaTestSourceSet);
setupJavaRestTestDependenciesDefaults(project, javaTestSourceSet);

// setup IDE
GradleUtils.setupIdeForTestSourceSet(project, javaTestSourceSet);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import org.gradle.api.tasks.SourceSetContainer;

import static org.elasticsearch.gradle.internal.test.rest.RestTestUtil.registerTestTask;
import static org.elasticsearch.gradle.internal.test.rest.RestTestUtil.setupTestDependenciesDefaults;
import static org.elasticsearch.gradle.internal.test.rest.RestTestUtil.setupYamlRestTestDependenciesDefaults;

/**
* Apply this plugin to run the YAML based REST tests.
Expand All @@ -37,7 +37,7 @@ public void apply(Project project) {
registerTestTask(project, yamlTestSourceSet);

// setup the dependencies
setupTestDependenciesDefaults(project, yamlTestSourceSet);
setupYamlRestTestDependenciesDefaults(project, yamlTestSourceSet);

// setup the copy for the rest resources
project.getTasks().withType(CopyRestApiTask.class).configureEach(copyRestApiTask -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,17 @@ public static Provider<RestIntegTestTask> registerTestTask(Project project, Sour
}

/**
* Setup the dependencies needed for the REST tests.
* Setup the dependencies needed for the YAML REST tests.
*/
public static void setupTestDependenciesDefaults(Project project, SourceSet sourceSet) {
project.getDependencies().add(sourceSet.getImplementationConfigurationName(), project.project(":test:framework"));
public static void setupYamlRestTestDependenciesDefaults(Project project, SourceSet sourceSet) {
project.getDependencies().add(sourceSet.getImplementationConfigurationName(), project.project(":test:yaml-rest-runner"));
}

/**
* Setup the dependencies needed for the Java REST tests.
*/
public static void setupJavaRestTestDependenciesDefaults(Project project, SourceSet sourceSet) {
// TODO: this should just be test framework, but some cleanup is needed in places incorrectly specifying java vs yaml
project.getDependencies().add(sourceSet.getImplementationConfigurationName(), project.project(":test:yaml-rest-runner"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ restTestSpecs
/--- org.elasticsearch:rest-api-spec:${VersionProperties.elasticsearch} FAILED""")
output.contains(normalized("""
yamlRestTestImplementation - Implementation only dependencies for source set 'yaml rest test'. (n)
/--- org.elasticsearch.test:framework:${VersionProperties.elasticsearch} (n)"""))
/--- org.elasticsearch.test:yaml-rest-runner:${VersionProperties.elasticsearch} (n)"""))
}

def "yamlRestTest does nothing when there are no tests"() {
Expand All @@ -40,11 +40,11 @@ yamlRestTestImplementation - Implementation only dependencies for source set 'ya
plugins {
id 'elasticsearch.yaml-rest-test'
}
repositories {
mavenCentral()
}
dependencies {
yamlRestTestImplementation "org.elasticsearch.test:framework:7.14.0"
restTestSpecs "org.elasticsearch:rest-api-spec:7.14.0"
Expand All @@ -59,4 +59,4 @@ yamlRestTestImplementation - Implementation only dependencies for source set 'ya
result.task(':yamlRestTest').outcome == TaskOutcome.NO_SOURCE
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private static void setupDefaultDependencies(
) {
String elasticsearchVersion = VersionProperties.getElasticsearch();
yamlRestTestImplementation.defaultDependencies(
deps -> deps.add(dependencyHandler.create("org.elasticsearch.test:framework:" + elasticsearchVersion))
deps -> deps.add(dependencyHandler.create("org.elasticsearch.test:yaml-rest-runner:" + elasticsearchVersion))
);

restTestSpecs.defaultDependencies(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.elasticsearch.common.time.DateFormatter;
import org.elasticsearch.common.time.FormatNames;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.test.rest.yaml.ObjectPath;
import org.elasticsearch.test.rest.ObjectPath;

import java.io.IOException;
import java.time.Instant;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.http.HttpTransportSettings;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.test.rest.yaml.ObjectPath;
import org.elasticsearch.test.rest.ObjectPath;

import java.io.IOException;
import java.nio.charset.Charset;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.test.hamcrest.ElasticsearchAssertions;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.test.rest.yaml.ObjectPath;
import org.elasticsearch.test.rest.ObjectPath;
import org.elasticsearch.xcontent.DeprecationHandler;
import org.elasticsearch.xcontent.NamedXContentRegistry;
import org.elasticsearch.xcontent.XContentParser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import org.elasticsearch.test.NotEqualMessageBuilder;
import org.elasticsearch.test.XContentTestUtils;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.test.rest.yaml.ObjectPath;
import org.elasticsearch.test.rest.ObjectPath;
import org.elasticsearch.transport.Compression;
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.XContentParser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.elasticsearch.index.seqno.SeqNoStats;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.test.rest.yaml.ObjectPath;
import org.elasticsearch.test.rest.ObjectPath;
import org.elasticsearch.xcontent.MediaType;
import org.elasticsearch.xcontent.XContentType;
import org.elasticsearch.xcontent.json.JsonXContent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.elasticsearch.core.CheckedRunnable;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.test.rest.yaml.ObjectPath;
import org.elasticsearch.test.rest.ObjectPath;
import org.junit.Before;

import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.elasticsearch.common.xcontent.support.XContentMapValues;
import org.elasticsearch.core.Booleans;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.test.rest.yaml.ObjectPath;
import org.elasticsearch.test.rest.ObjectPath;
import org.hamcrest.Matchers;

import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.test.rest.yaml.ObjectPath;
import org.elasticsearch.test.rest.ObjectPath;

import java.io.IOException;
import java.text.ParseException;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@

package org.elasticsearch.index.query;

import com.fasterxml.jackson.core.io.JsonStringEncoder;

import org.elasticsearch.test.AbstractQueryTestCase;
import org.elasticsearch.xcontent.json.JsonStringEncoder;

import java.util.HashMap;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@

package org.elasticsearch.index.query;

import com.fasterxml.jackson.core.io.JsonStringEncoder;

import org.apache.lucene.index.Term;
import org.apache.lucene.queries.spans.SpanTermQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermQuery;
import org.elasticsearch.common.ParsingException;
import org.elasticsearch.common.lucene.BytesRefs;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.xcontent.json.JsonStringEncoder;

import java.io.IOException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

package org.elasticsearch.index.query;

import com.fasterxml.jackson.core.io.JsonStringEncoder;

import org.apache.lucene.index.Term;
import org.apache.lucene.search.AutomatonQuery;
import org.apache.lucene.search.MatchNoDocsQuery;
Expand All @@ -19,6 +17,7 @@
import org.elasticsearch.common.ParsingException;
import org.elasticsearch.index.mapper.FieldTypeTestCase;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.xcontent.json.JsonStringEncoder;

import java.io.IOException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import org.elasticsearch.script.ScriptType;
import org.elasticsearch.test.AbstractQueryTestCase;
import org.elasticsearch.test.TestGeoShapeFieldMapperPlugin;
import org.elasticsearch.test.rest.yaml.ObjectPath;
import org.elasticsearch.test.rest.ObjectPath;

import java.io.IOException;
import java.io.UncheckedIOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

package org.elasticsearch.rest.action;

import com.fasterxml.jackson.core.io.JsonEOFException;

import org.elasticsearch.action.ShardOperationFailedException;
import org.elasticsearch.action.search.ShardSearchFailure;
import org.elasticsearch.cluster.metadata.IndexMetadata;
Expand All @@ -26,6 +24,7 @@
import org.elasticsearch.xcontent.NamedXContentRegistry;
import org.elasticsearch.xcontent.ToXContent;
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.XContentEOFException;
import org.elasticsearch.xcontent.XContentParser;
import org.elasticsearch.xcontent.json.JsonXContent;
import org.junit.AfterClass;
Expand Down Expand Up @@ -83,7 +82,7 @@ public void testParseTopLevelBuilderIncompleteJson() throws IOException {
try (XContentParser parser = createParser(JsonXContent.jsonXContent, requestBody)) {
ParsingException exception = expectThrows(ParsingException.class, () -> RestActions.getQueryContent(parser));
assertEquals("Failed to parse", exception.getMessage());
assertEquals(JsonEOFException.class, exception.getRootCause().getClass());
assertEquals(XContentEOFException.class, exception.getCause().getClass());
}
}
}
Expand Down
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ List projects = [
'test:fixtures:url-fixture',
'test:fixtures:nginx-fixture',
'test:logger-usage',
'test:yaml-rest-runner',
'test:x-content'
]

Expand Down
1 change: 0 additions & 1 deletion test/framework/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ apply plugin: 'elasticsearch.publish'

dependencies {
api project(":client:rest")
api project(":client:sniffer")
api project(':modules:transport-netty4')
api project(':libs:elasticsearch-ssl-config')
api project(":server")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import org.elasticsearch.xcontent.XContentType;
import org.elasticsearch.xcontent.json.JsonStringEncoder;
import org.elasticsearch.xcontent.json.JsonXContent;
import org.elasticsearch.xcontent.spi.XContentProvider;

import java.io.IOException;
import java.time.Instant;
Expand Down Expand Up @@ -646,7 +645,7 @@ protected static Object getRandomValueForFieldName(String fieldName) {
case TEXT_ALIAS_FIELD_NAME:
if (rarely()) {
// unicode in 10% cases
JsonStringEncoder encoder = XContentProvider.provider().getJsonStringEncoder();
JsonStringEncoder encoder = JsonStringEncoder.getInstance();
value = new String(encoder.quoteAsString(randomUnicodeOfLength(10)));
} else {
value = randomAlphaOfLengthBetween(1, 10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.test.rest.yaml.ObjectPath;
import org.elasticsearch.test.rest.ObjectPath;
import org.elasticsearch.xcontent.DeprecationHandler;
import org.elasticsearch.xcontent.NamedXContentRegistry;
import org.elasticsearch.xcontent.ToXContent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.snapshots.SnapshotState;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.rest.yaml.ObjectPath;
import org.elasticsearch.xcontent.DeprecationHandler;
import org.elasticsearch.xcontent.NamedXContentRegistry;
import org.elasticsearch.xcontent.XContentBuilder;
Expand Down
Loading

0 comments on commit 0ec2290

Please sign in to comment.