-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Add more transport version files validation #132373
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
rjernst
merged 16 commits into
elastic:main
from
rjernst:transport/validation-and-tests
Aug 12, 2025
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
e60b391
Add more transport version files validation
rjernst c0bbefe
[CI] Auto commit changes from spotless
23b27d4
sort definition loading
rjernst cf6fcc8
strip existing read of whitespace
rjernst 32503fa
better validation before migrating
rjernst a13711c
[CI] Auto commit changes from spotless
779eebd
Merge branch 'main' into transport/validation-and-tests
rjernst 6b271ee
make validation pass for server
rjernst 31c1c7f
fix oops
rjernst d2327a8
address feedback
rjernst 42a37b7
feedback
rjernst 02ebfaa
remove project ref
rjernst 1dc253e
[CI] Auto commit changes from spotless
3336d27
cleanup
rjernst 88d2a6b
ignore initial for now
rjernst 29c29a6
Merge branch 'main' into transport/validation-and-tests
rjernst File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
301 changes: 301 additions & 0 deletions
301
...g/elasticsearch/gradle/internal/transport/TransportVersionManagementPluginFuncTest.groovy
This file contains hidden or 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,301 @@ | ||
| /* | ||
| * 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| package org.elasticsearch.gradle.internal.transport | ||
|
|
||
|
|
||
| import org.elasticsearch.gradle.fixtures.AbstractGradleFuncTest | ||
| import org.gradle.testkit.runner.BuildResult | ||
| import org.gradle.testkit.runner.TaskOutcome | ||
|
|
||
| class TransportVersionManagementPluginFuncTest extends AbstractGradleFuncTest { | ||
|
|
||
| /** | ||
| * | ||
| * @param project | ||
| * @param path | ||
| * @param content | ||
| * @return | ||
| */ | ||
| def javaResource(String project, String path, String content) { | ||
| file("${project}/src/main/resources/${path}").withWriter { writer -> | ||
| writer << content | ||
| } | ||
| } | ||
|
|
||
| def javaSource(String project, String packageName, String className, String imports, String content) { | ||
| String packageSlashes = packageName.replace('.', '/') | ||
| file("${project}/src/main/java/${packageSlashes}/${className}.java").withWriter { writer -> | ||
| writer << """ | ||
| package ${packageName}; | ||
| ${imports} | ||
| public class ${className} { | ||
| ${content} | ||
| } | ||
| """ | ||
| } | ||
| } | ||
|
|
||
| def definedTransportVersion(String name, String ids) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: addDefinedTransportVersion or defineTransportVersion. A "defined" TV is the result. |
||
| javaResource("myserver", "transport/defined/" + name + ".csv", ids) | ||
| } | ||
|
|
||
| def definedAndUsedTransportVersion(String name, String ids) { | ||
| return definedAndUsedTransportVersion(name, ids, "Test${name.capitalize()}") | ||
| } | ||
|
|
||
| def definedAndUsedTransportVersion(String name, String ids, String classname) { | ||
| javaSource("myserver", "org.elasticsearch", classname, "", """ | ||
| static final TransportVersion usage = TransportVersion.fromName("${name}"); | ||
| """) | ||
| definedTransportVersion(name, ids) | ||
| } | ||
|
|
||
| def latestTransportVersion(String branch, String name, String id) { | ||
| javaResource("myserver", "transport/latest/" + branch + ".csv","${name},${id}") | ||
| } | ||
|
|
||
| def validateReferencesFails(String project) { | ||
| return gradleRunner(":${project}:validateTransportVersionReferences").buildAndFail() | ||
| } | ||
|
|
||
| def validateDefinitionsFails() { | ||
| return gradleRunner(":myserver:validateTransportVersionDefinitions").buildAndFail() | ||
| } | ||
|
|
||
| def assertReferencesFailure(BuildResult result, String project, String expectedOutput) { | ||
| result.task(":${project}:validateTransportVersionReferences").outcome == TaskOutcome.FAILED | ||
| assertOutputContains(result.output, expectedOutput) | ||
| } | ||
|
|
||
| def assertDefinitionsFailure(BuildResult result, String expectedOutput) { | ||
| result.task(":myserver:validateTransportVersionDefinitions").outcome == TaskOutcome.FAILED | ||
| assertOutputContains(result.output, expectedOutput) | ||
| } | ||
|
|
||
| def setup() { | ||
| configurationCacheCompatible = false | ||
| internalBuild() | ||
| settingsFile << """ | ||
| include ':myserver' | ||
| include ':myplugin' | ||
| """ | ||
| file("gradle.properties") << """ | ||
| org.elasticsearch.transport.definitionsProject=:myserver | ||
| """ | ||
|
|
||
| file("myserver/build.gradle") << """ | ||
| apply plugin: 'java-library' | ||
| apply plugin: 'elasticsearch.transport-version-management' | ||
| apply plugin: 'elasticsearch.global-transport-version-management' | ||
| """ | ||
| definedTransportVersion("existing_91", "8012000") | ||
| definedTransportVersion("existing_92", "8123000,8012001") | ||
| latestTransportVersion("9.2", "existing_92", "8123000") | ||
| latestTransportVersion("9.1", "existing_92", "8012001") | ||
| // a mock version of TransportVersion, just here so we can compile Dummy.java et al | ||
| javaSource("myserver", "org.elasticsearch", "TransportVersion", "", """ | ||
| public static TransportVersion fromName(String name) { | ||
| return null; | ||
| } | ||
| """) | ||
| javaSource("myserver", "org.elasticsearch", "Dummy", "", """ | ||
| static final TransportVersion existing91 = TransportVersion.fromName("existing_91"); | ||
| static final TransportVersion existing92 = TransportVersion.fromName("existing_92"); | ||
| """) | ||
|
|
||
| file("myplugin/build.gradle") << """ | ||
| apply plugin: 'java-library' | ||
| apply plugin: 'elasticsearch.transport-version-management' | ||
|
|
||
| dependencies { | ||
| implementation project(":myserver") | ||
| } | ||
| """ | ||
|
|
||
| setupLocalGitRepo() | ||
| execute("git checkout -b main") | ||
| execute("git checkout -b test") | ||
| } | ||
|
|
||
| def "test setup works"() { | ||
| when: | ||
| def result = gradleRunner("validateTransportVersionDefinitions", "validateTransportVersionReferences").build() | ||
| then: | ||
| result.task(":myserver:validateTransportVersionDefinitions").outcome == TaskOutcome.SUCCESS | ||
| result.task(":myserver:validateTransportVersionReferences").outcome == TaskOutcome.SUCCESS | ||
| result.task(":myplugin:validateTransportVersionReferences").outcome == TaskOutcome.SUCCESS | ||
| } | ||
|
|
||
| def "definitions must be referenced"() { | ||
| given: | ||
| javaSource("myplugin", "org.elasticsearch.plugin", "MyPlugin", | ||
| "import org.elasticsearch.TransportVersion;", """ | ||
| static final TransportVersion dne = TransportVersion.fromName("dne"); | ||
| """) | ||
| when: | ||
| def result = validateReferencesFails("myplugin") | ||
| then: | ||
| assertReferencesFailure(result, "myplugin", "TransportVersion.fromName(\"dne\") was used at " + | ||
| "org.elasticsearch.plugin.MyPlugin line 6, but lacks a transport version definition.") | ||
| } | ||
|
|
||
| def "references must be defined"() { | ||
| given: | ||
| definedTransportVersion("not_used", "1000000") | ||
| when: | ||
| def result = validateDefinitionsFails() | ||
| then: | ||
| assertDefinitionsFailure(result, "Transport version definition file " + | ||
| "[myserver/src/main/resources/transport/defined/not_used.csv] is not referenced") | ||
| } | ||
|
|
||
| def "names must be lowercase alphanum or underscore"() { | ||
| given: | ||
| definedAndUsedTransportVersion("${name}", "8100000", "TestNames") | ||
| when: | ||
| def result = validateDefinitionsFails() | ||
| then: | ||
| assertDefinitionsFailure(result, "Transport version definition file " + | ||
| "[myserver/src/main/resources/transport/defined/${name}.csv] does not have a valid name, " + | ||
| "must be lowercase alphanumeric and underscore") | ||
|
|
||
| where: | ||
| name << ["CapitalTV", "spaces tv", "trailing_spaces_tv ", "hyphen-tv", "period.tv"] | ||
| } | ||
|
|
||
| def "definitions contain at least one id"() { | ||
| given: | ||
| definedAndUsedTransportVersion("empty", "") | ||
| when: | ||
| def result = validateDefinitionsFails() | ||
| then: | ||
| assertDefinitionsFailure(result, "Transport version definition file " + | ||
| "[myserver/src/main/resources/transport/defined/empty.csv] does not contain any ids") | ||
| } | ||
|
|
||
| def "definitions have ids in descending order"() { | ||
| given: | ||
| definedAndUsedTransportVersion("out_of_order", "8100000,8200000") | ||
| when: | ||
| def result = validateDefinitionsFails() | ||
| then: | ||
| assertDefinitionsFailure(result, "Transport version definition file " + | ||
| "[myserver/src/main/resources/transport/defined/out_of_order.csv] does not have ordered ids") | ||
| } | ||
|
|
||
| def "definition ids are unique"() { | ||
| given: | ||
| definedAndUsedTransportVersion("duplicate", "8123000") | ||
| when: | ||
| def result = validateDefinitionsFails() | ||
| then: | ||
| assertDefinitionsFailure(result, "Transport version definition file " + | ||
| "[myserver/src/main/resources/transport/defined/existing_92.csv] contains id 8123000 already defined in " + | ||
| "[myserver/src/main/resources/transport/defined/duplicate.csv]") | ||
| } | ||
|
|
||
| def "definitions have bwc ids with non-zero patch part"() { | ||
| given: | ||
| definedAndUsedTransportVersion("patched", "8200000,8100000") | ||
| when: | ||
| def result = validateDefinitionsFails() | ||
| then: | ||
| assertDefinitionsFailure(result, "Transport version definition file " + | ||
| "[myserver/src/main/resources/transport/defined/patched.csv] contains bwc id [8100000] with a patch part of 0") | ||
| } | ||
|
|
||
| def "definitions have primary ids which cannot change"() { | ||
| given: | ||
| definedTransportVersion("existing_92", "8500000") | ||
| when: | ||
| def result = validateDefinitionsFails() | ||
| then: | ||
| assertDefinitionsFailure(result, "Transport version definition file " + | ||
| "[myserver/src/main/resources/transport/defined/existing_92.csv] has modified primary id from 8123000 to 8500000") | ||
| } | ||
|
|
||
| def "cannot change committed ids to a branch"() { | ||
| given: | ||
| definedTransportVersion("existing_92", "8123000,8012002") | ||
| when: | ||
| def result = validateDefinitionsFails() | ||
| then: | ||
| assertDefinitionsFailure(result, "Transport version definition file " + | ||
| "[myserver/src/main/resources/transport/defined/existing_92.csv] modifies existing patch id from 8012001 to 8012002") | ||
| } | ||
|
|
||
| def "latest files must reference defined name"() { | ||
| given: | ||
| latestTransportVersion("9.2", "dne", "8123000") | ||
| when: | ||
| def result = validateDefinitionsFails() | ||
| then: | ||
| assertDefinitionsFailure(result, "Latest transport version file " + | ||
| "[myserver/src/main/resources/transport/latest/9.2.csv] contains transport version name [dne] which is not defined") | ||
| } | ||
|
|
||
| def "latest files id must exist in definition"() { | ||
| given: | ||
| latestTransportVersion("9.2", "existing_92", "8124000") | ||
| when: | ||
| def result = validateDefinitionsFails() | ||
| then: | ||
| assertDefinitionsFailure(result, "Latest transport version file " + | ||
| "[myserver/src/main/resources/transport/latest/9.2.csv] has id 8124000 which is not in definition " + | ||
| "[myserver/src/main/resources/transport/defined/existing_92.csv]") | ||
| } | ||
|
|
||
| def "latest files have latest id within base"() { | ||
| given: | ||
| latestTransportVersion("9.0", "seemingly_latest", "8110001") | ||
| definedAndUsedTransportVersion("original", "8110000") | ||
| definedAndUsedTransportVersion("seemingly_latest", "8111000,8110001") | ||
| definedAndUsedTransportVersion("actual_latest", "8112000,8110002") | ||
| when: | ||
| def result = validateDefinitionsFails() | ||
| then: | ||
| assertDefinitionsFailure(result, "Latest transport version file " + | ||
| "[myserver/src/main/resources/transport/latest/9.0.csv] has id 8110001 from [seemingly_latest] with base 8110000 " + | ||
| "but another id 8110002 from [actual_latest] is later for that base") | ||
| } | ||
|
|
||
| def "latest files cannot change base id"() { | ||
| given: | ||
| definedAndUsedTransportVersion("original", "8013000") | ||
| definedAndUsedTransportVersion("patch", "8015000,8013001") | ||
| latestTransportVersion("9.1", "patch", "8013001") | ||
| when: | ||
| def result = validateDefinitionsFails() | ||
| then: | ||
| assertDefinitionsFailure(result, "Latest transport version file " + | ||
| "[myserver/src/main/resources/transport/latest/9.1.csv] modifies base id from 8012000 to 8013000") | ||
| } | ||
|
|
||
| def "ids must be dense"() { | ||
| given: | ||
| definedAndUsedTransportVersion("original", "8013000") | ||
| definedAndUsedTransportVersion("patch1", "8015000,8013002") | ||
| latestTransportVersion("9.0", "patch1", "8013002") | ||
| when: | ||
| def result = validateDefinitionsFails() | ||
| then: | ||
| assertDefinitionsFailure(result, "Transport version base id 8013000 is missing patch ids between 8013000 and 8013002") | ||
| } | ||
|
|
||
| def "primary id must not be patch version"() { | ||
| given: | ||
| definedAndUsedTransportVersion("patch", "8015001") | ||
| when: | ||
| def result = validateDefinitionsFails() | ||
| then: | ||
| assertDefinitionsFailure(result, "Transport version definition file " + | ||
| "[myserver/src/main/resources/transport/defined/patch.csv] has patch version 8015001 as primary id") | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: The purpose of this function is unobvious from the name. Some light javadoc or clearer name would help.