Skip to content

Commit

Permalink
[FLINK-13965] Keep hasDeprecatedKeys and deprecatedKeys methods in Co…
Browse files Browse the repository at this point in the history
…nfigOption and mark it with @deprecated annotation

This closes apache#9691.
  • Loading branch information
yanghua authored and tillrohrmann committed Sep 18, 2019
1 parent cc3a27b commit 64b656b
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

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;
Expand Down Expand Up @@ -195,6 +196,31 @@ public T defaultValue() {
return defaultValue;
}

/**
* 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@

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;
Expand Down Expand Up @@ -86,4 +91,30 @@ public void testDeprecationFlagForMixedAlternativeKeys() {
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());
}

}

0 comments on commit 64b656b

Please sign in to comment.