This is an automated email from the ASF dual-hosted git repository. trohrmann pushed a commit to branch release-1.8 in repository https://gitbox.apache.org/repos/asf/flink.git
The following commit(s) were added to refs/heads/release-1.8 by this push: new 517bd29 [FLINK-13965] Keep hasDeprecatedKeys and deprecatedKeys methods in ConfigOption and mark it with @Deprecated annotation 517bd29 is described below commit 517bd293600d787b47175ce4e46be8746f15af97 Author: yanghua <yanghua1...@gmail.com> AuthorDate: Mon Sep 16 20:06:55 2019 +0800 [FLINK-13965] Keep hasDeprecatedKeys and deprecatedKeys methods in ConfigOption and mark it with @Deprecated annotation This closes #9691. --- .../apache/flink/configuration/ConfigOption.java | 26 ++++++++++++++++++ .../flink/configuration/ConfigOptionTest.java | 31 ++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/flink-core/src/main/java/org/apache/flink/configuration/ConfigOption.java b/flink-core/src/main/java/org/apache/flink/configuration/ConfigOption.java index 1168255..9ad49c0 100644 --- a/flink-core/src/main/java/org/apache/flink/configuration/ConfigOption.java +++ b/flink-core/src/main/java/org/apache/flink/configuration/ConfigOption.java @@ -23,6 +23,7 @@ import org.apache.flink.configuration.description.Description; import java.util.Arrays; import java.util.Collections; +import java.util.stream.Collectors; import java.util.stream.Stream; import static org.apache.flink.util.Preconditions.checkNotNull; @@ -196,6 +197,31 @@ public class ConfigOption<T> { } /** + * Checks whether this option has deprecated keys. + * @return True if the option has deprecated keys, false if not. + * @deprecated Replaced by {@link #hasFallbackKeys()} + */ + @Deprecated + public boolean hasDeprecatedKeys() { + return fallbackKeys == EMPTY ? false : + Arrays.stream(fallbackKeys).anyMatch(FallbackKey::isDeprecated); + } + + /** + * Gets the deprecated keys, in the order to be checked. + * @return The option's deprecated keys. + * @deprecated Replaced by {@link #fallbackKeys()} + */ + @Deprecated + public Iterable<String> deprecatedKeys() { + return fallbackKeys == EMPTY ? Collections.<String>emptyList() : + Arrays.stream(fallbackKeys) + .filter(FallbackKey::isDeprecated) + .map(FallbackKey::getKey) + .collect(Collectors.toList()); + } + + /** * Checks whether this option has fallback keys. * @return True if the option has fallback keys, false if not. */ diff --git a/flink-core/src/test/java/org/apache/flink/configuration/ConfigOptionTest.java b/flink-core/src/test/java/org/apache/flink/configuration/ConfigOptionTest.java index 26c94e1..4515d1d 100644 --- a/flink-core/src/test/java/org/apache/flink/configuration/ConfigOptionTest.java +++ b/flink-core/src/test/java/org/apache/flink/configuration/ConfigOptionTest.java @@ -20,10 +20,15 @@ package org.apache.flink.configuration; import org.apache.flink.util.TestLogger; +import org.apache.flink.shaded.guava18.com.google.common.collect.Sets; + import org.junit.Test; import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; import java.util.List; +import java.util.Set; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.junit.Assert.assertEquals; @@ -86,4 +91,30 @@ public class ConfigOptionTest extends TestLogger { assertThat(fallbackKeys, containsInAnyOrder("fallback1", "fallback2")); assertThat(deprecatedKeys, containsInAnyOrder("deprecated1", "deprecated2")); } + + @Test + public void testDeprecationForDeprecatedKeys() { + String[] deprecatedKeys = new String[] { "deprecated1", "deprecated2" }; + final Set<String> expectedDeprecatedKeys = new HashSet<>(Arrays.asList(deprecatedKeys)); + + final ConfigOption<Integer> optionWithDeprecatedKeys = ConfigOptions + .key("key") + .defaultValue(0) + .withDeprecatedKeys(deprecatedKeys) + .withFallbackKeys("fallback1"); + + assertTrue(optionWithDeprecatedKeys.hasDeprecatedKeys()); + assertEquals(expectedDeprecatedKeys, Sets.newHashSet(optionWithDeprecatedKeys.deprecatedKeys())); + } + + @Test + public void testNoDeprecationForFallbackKeysWithoutDeprecated() { + final ConfigOption<Integer> optionWithFallbackKeys = ConfigOptions + .key("key") + .defaultValue(0) + .withFallbackKeys("fallback1"); + + assertFalse(optionWithFallbackKeys.hasDeprecatedKeys()); + } + }