forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose historical feature metadata to rest tests (elastic#102110)
This introduces a new getHistoricalFeatures() method on ESRestTestCase which returns a map of historical feature version mappings loaded from FeatureSpecification implementations from any plugins/modules in use by the current test suite. The mappings are generated by a new Gradle task at build time, and then injected into the test runtime as a System property.
- Loading branch information
1 parent
f12afe4
commit 5d37962
Showing
13 changed files
with
402 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...rc/main/java/org/elasticsearch/gradle/internal/test/HistoricalFeaturesMetadataPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.gradle.internal.test; | ||
|
||
import org.elasticsearch.gradle.dependencies.CompileOnlyResolvePlugin; | ||
import org.gradle.api.Plugin; | ||
import org.gradle.api.Project; | ||
import org.gradle.api.artifacts.Configuration; | ||
import org.gradle.api.artifacts.type.ArtifactTypeDefinition; | ||
import org.gradle.api.tasks.SourceSet; | ||
import org.gradle.api.tasks.SourceSetContainer; | ||
import org.gradle.api.tasks.TaskProvider; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* Extracts historical feature metadata into a machine-readable format for use in backward compatibility testing. | ||
*/ | ||
public class HistoricalFeaturesMetadataPlugin implements Plugin<Project> { | ||
public static final String HISTORICAL_FEATURES_JSON = "historical-features.json"; | ||
public static final String FEATURES_METADATA_TYPE = "features-metadata-json"; | ||
public static final String FEATURES_METADATA_CONFIGURATION = "featuresMetadata"; | ||
|
||
@Override | ||
public void apply(Project project) { | ||
Configuration featureMetadataExtractorConfig = project.getConfigurations().create("featuresMetadataExtractor", c -> { | ||
// Don't bother adding this dependency if the project doesn't exist which simplifies testing | ||
if (project.findProject(":test:metadata-extractor") != null) { | ||
c.defaultDependencies(d -> d.add(project.getDependencies().project(Map.of("path", ":test:metadata-extractor")))); | ||
} | ||
}); | ||
|
||
SourceSetContainer sourceSets = project.getExtensions().getByType(SourceSetContainer.class); | ||
SourceSet mainSourceSet = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME); | ||
|
||
TaskProvider<HistoricalFeaturesMetadataTask> generateTask = project.getTasks() | ||
.register("generateHistoricalFeaturesMetadata", HistoricalFeaturesMetadataTask.class, task -> { | ||
task.setClasspath( | ||
featureMetadataExtractorConfig.plus(mainSourceSet.getRuntimeClasspath()) | ||
.plus(project.getConfigurations().getByName(CompileOnlyResolvePlugin.RESOLVEABLE_COMPILE_ONLY_CONFIGURATION_NAME)) | ||
); | ||
task.getOutputFile().convention(project.getLayout().getBuildDirectory().file(HISTORICAL_FEATURES_JSON)); | ||
}); | ||
|
||
Configuration featuresMetadataArtifactConfig = project.getConfigurations().create(FEATURES_METADATA_CONFIGURATION, c -> { | ||
c.setCanBeResolved(false); | ||
c.setCanBeConsumed(true); | ||
c.attributes(a -> { a.attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, FEATURES_METADATA_TYPE); }); | ||
}); | ||
|
||
project.getArtifacts().add(featuresMetadataArtifactConfig.getName(), generateTask); | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
.../src/main/java/org/elasticsearch/gradle/internal/test/HistoricalFeaturesMetadataTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.gradle.internal.test; | ||
|
||
import org.elasticsearch.gradle.LoggedExec; | ||
import org.gradle.api.DefaultTask; | ||
import org.gradle.api.file.ConfigurableFileCollection; | ||
import org.gradle.api.file.FileCollection; | ||
import org.gradle.api.file.RegularFileProperty; | ||
import org.gradle.api.tasks.CacheableTask; | ||
import org.gradle.api.tasks.Classpath; | ||
import org.gradle.api.tasks.OutputFile; | ||
import org.gradle.api.tasks.TaskAction; | ||
import org.gradle.process.ExecOperations; | ||
import org.gradle.workers.WorkAction; | ||
import org.gradle.workers.WorkParameters; | ||
import org.gradle.workers.WorkerExecutor; | ||
|
||
import javax.inject.Inject; | ||
|
||
@CacheableTask | ||
public abstract class HistoricalFeaturesMetadataTask extends DefaultTask { | ||
private FileCollection classpath; | ||
|
||
@OutputFile | ||
public abstract RegularFileProperty getOutputFile(); | ||
|
||
@Classpath | ||
public FileCollection getClasspath() { | ||
return classpath; | ||
} | ||
|
||
public void setClasspath(FileCollection classpath) { | ||
this.classpath = classpath; | ||
} | ||
|
||
@Inject | ||
public abstract WorkerExecutor getWorkerExecutor(); | ||
|
||
@TaskAction | ||
public void execute() { | ||
getWorkerExecutor().noIsolation().submit(HistoricalFeaturesMetadataWorkAction.class, params -> { | ||
params.getClasspath().setFrom(getClasspath()); | ||
params.getOutputFile().set(getOutputFile()); | ||
}); | ||
} | ||
|
||
public interface HistoricalFeaturesWorkParameters extends WorkParameters { | ||
ConfigurableFileCollection getClasspath(); | ||
|
||
RegularFileProperty getOutputFile(); | ||
} | ||
|
||
public abstract static class HistoricalFeaturesMetadataWorkAction implements WorkAction<HistoricalFeaturesWorkParameters> { | ||
private final ExecOperations execOperations; | ||
|
||
@Inject | ||
public HistoricalFeaturesMetadataWorkAction(ExecOperations execOperations) { | ||
this.execOperations = execOperations; | ||
} | ||
|
||
@Override | ||
public void execute() { | ||
LoggedExec.javaexec(execOperations, spec -> { | ||
spec.getMainClass().set("org.elasticsearch.extractor.features.HistoricalFeaturesMetadataExtractor"); | ||
spec.classpath(getParameters().getClasspath()); | ||
spec.args(getParameters().getOutputFile().get().getAsFile().getAbsolutePath()); | ||
}); | ||
} | ||
} | ||
} |
Oops, something went wrong.