Myasuka commented on a change in pull request #10748: [FLINK-15458][conf][docs]
Add support for whitelisting ambiguous options
URL: https://github.com/apache/flink/pull/10748#discussion_r363283498
##########
File path:
flink-docs/src/test/java/org/apache/flink/docs/configuration/ConfigOptionsDocsCompletenessITCase.java
##########
@@ -61,50 +64,103 @@
private static final Formatter htmlFormatter = new HtmlFormatter();
+ // options for which we allow distinct definitions
+ // this allows reporters to define their own options that are
technically only key suffixes
+ private static final Set<String> WELL_DEFINED_WHITELIST = new
HashSet<>(Arrays.asList(
+ ));
+
@Test
public void testCommonSectionCompleteness() throws IOException,
ClassNotFoundException {
- Map<String, DocumentedOption> documentedOptions =
parseDocumentedCommonOptions();
- Map<String, ExistingOption> existingOptions =
findExistingOptions(
+ Map<String, List<DocumentedOption>> documentedOptions =
parseDocumentedCommonOptions();
+ Map<String, List<ExistingOption>> existingOptions =
findExistingOptions(
optionWithMetaInfo ->
optionWithMetaInfo.field.getAnnotation(Documentation.CommonOption.class) !=
null);
+ assertDocumentedOptionsAreWellDefined(documentedOptions);
+ assertExistingOptionsAreWellDefined(existingOptions);
+
compareDocumentedAndExistingOptions(documentedOptions,
existingOptions);
}
@Test
public void testFullReferenceCompleteness() throws IOException,
ClassNotFoundException {
- Map<String, DocumentedOption> documentedOptions =
parseDocumentedOptions();
- Map<String, ExistingOption> existingOptions =
findExistingOptions(ignored -> true);
+ Map<String, List<DocumentedOption>> documentedOptions =
parseDocumentedOptions();
+ Map<String, List<ExistingOption>> existingOptions =
findExistingOptions(ignored -> true);
+
+ assertDocumentedOptionsAreWellDefined(documentedOptions);
+ assertExistingOptionsAreWellDefined(existingOptions);
compareDocumentedAndExistingOptions(documentedOptions,
existingOptions);
}
- private static void compareDocumentedAndExistingOptions(Map<String,
DocumentedOption> documentedOptions, Map<String, ExistingOption>
existingOptions) {
+ private static void assertDocumentedOptionsAreWellDefined(Map<String,
List<DocumentedOption>> documentedOptions) {
+ assertOptionsAreWellDefined(documentedOptions, (option1,
option2) -> {
+ // found a ConfigOption pair with the same key
that aren't equal
+ // we fail here outright as this is not a
documentation-completeness problem
+ if
(!option1.defaultValue.equals(option2.defaultValue)) {
+ throw new AssertionError("Documentation
contains distinct defaults for " +
+ option1.key + " in " +
option1.containingFile + " and " + option2.containingFile + '.');
+ } else {
+ throw new AssertionError("Documentation
contains distinct descriptions for " +
+ option1.key + " in " +
option1.containingFile + " and " + option2.containingFile + '.');
+ }
+ });
+ }
+
+ private static void assertExistingOptionsAreWellDefined(Map<String,
List<ExistingOption>> existingOptions) {
+ assertOptionsAreWellDefined(existingOptions, (option1, option2)
-> {
+ // found a ConfigOption pair with the same key
that aren't equal
+ // we fail here outright as this is not a
documentation-completeness problem
+ if
(!option1.defaultValue.equals(option2.defaultValue)) {
+ throw new AssertionError("Ambiguous
option " + option1.key + " due to distinct default values (" +
option1.defaultValue + " vs " + option2.defaultValue + ").");
+ } else {
+ throw new AssertionError("Ambiguous
option " + option1.key + " due to distinct descriptions.");
+ }
+ });
+ }
+
+ private static <O> void assertOptionsAreWellDefined(Map<String,
List<O>> allOptions, BiFunction<O, O, AssertionError> duplicateHandler) {
+ allOptions.entrySet().stream()
+ .filter(entry ->
!WELL_DEFINED_WHITELIST.contains(entry.getKey()))
+ .map(Map.Entry::getValue)
+ .forEach(options -> options.stream().reduce((option1,
option2) -> {
+ if (option1.equals(option2)) {
Review comment:
Thanks for your interpretation, I still reserve my judgment on this problem
and I agree this should be out of scope of this PR since this problem has been
existed for a while.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services