From 12529a2491051c4213fc1e355674b5c82c03c2dc Mon Sep 17 00:00:00 2001 From: Till Rohrmann Date: Mon, 7 Aug 2017 14:37:04 +0200 Subject: [PATCH] [FLINK-7383] Remove ConfigurationUtil --- .../apache/flink/util/ConfigurationUtil.java | 101 --------------- .../flink/util/ConfigurationUtilTest.java | 115 ------------------ 2 files changed, 216 deletions(-) delete mode 100644 flink-core/src/main/java/org/apache/flink/util/ConfigurationUtil.java delete mode 100644 flink-core/src/test/java/org/apache/flink/util/ConfigurationUtilTest.java diff --git a/flink-core/src/main/java/org/apache/flink/util/ConfigurationUtil.java b/flink-core/src/main/java/org/apache/flink/util/ConfigurationUtil.java deleted file mode 100644 index 44f098b772733..0000000000000 --- a/flink-core/src/main/java/org/apache/flink/util/ConfigurationUtil.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.flink.util; - -import org.apache.flink.annotation.Internal; -import org.apache.flink.configuration.Configuration; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Utility for accessing deprecated {@link Configuration} values. - */ -@Internal -public class ConfigurationUtil { - - private static final Logger LOG = LoggerFactory.getLogger(ConfigurationUtil.class); - - /** - * Returns the value associated with the given key as an Integer in the - * given Configuration. - * - *

The regular key has precedence over any deprecated keys. The - * precedence of deprecated keys depends on the argument order, first - * deprecated keys have higher precedence than later ones. - * - * @param config Configuration to access - * @param key Configuration key (highest precedence) - * @param defaultValue Default value (if no key is set) - * @param deprecatedKeys Optional deprecated keys in precedence order - * @return Integer value associated with first found key or the default value - */ - public static int getIntegerWithDeprecatedKeys( - Configuration config, - String key, - int defaultValue, - String... deprecatedKeys) { - - if (config.containsKey(key)) { - return config.getInteger(key, defaultValue); - } else { - // Check deprecated keys - for (String deprecatedKey : deprecatedKeys) { - if (config.containsKey(deprecatedKey)) { - LOG.warn("Configuration key '{}' has been deprecated. Please use '{}' instead.", deprecatedKey, key); - return config.getInteger(deprecatedKey, defaultValue); - } - } - return defaultValue; - } - } - - /** - * Returns the value associated with the given key as a String in the - * given Configuration. - * - *

The regular key has precedence over any deprecated keys. The - * precedence of deprecated keys depends on the argument order, first - * deprecated keys have higher precedence than later ones. - * - * @param config Configuration to access - * @param key Configuration key (highest precedence) - * @param defaultValue Default value (if no key is set) - * @param deprecatedKeys Optional deprecated keys in precedence order - * @return String associated with first found key or the default value - */ - public static String getStringWithDeprecatedKeys( - Configuration config, - String key, - String defaultValue, - String... deprecatedKeys) { - - if (config.containsKey(key)) { - return config.getString(key, defaultValue); - } else { - // Check deprecated keys - for (String deprecatedKey : deprecatedKeys) { - if (config.containsKey(deprecatedKey)) { - LOG.warn("Configuration key {} has been deprecated. Please use {} instead.", deprecatedKey, key); - return config.getString(deprecatedKey, defaultValue); - } - } - return defaultValue; - } - } -} diff --git a/flink-core/src/test/java/org/apache/flink/util/ConfigurationUtilTest.java b/flink-core/src/test/java/org/apache/flink/util/ConfigurationUtilTest.java deleted file mode 100644 index 7ecbd3fa03133..0000000000000 --- a/flink-core/src/test/java/org/apache/flink/util/ConfigurationUtilTest.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.flink.util; - -import org.apache.flink.configuration.Configuration; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -public class ConfigurationUtilTest { - - /** - * Tests getInteger without any deprecated keys. - */ - @Test - public void testGetIntegerNoDeprecatedKeys() throws Exception { - Configuration config = new Configuration(); - String key = "asdasd"; - int value = 1223239; - int defaultValue = 272770; - - assertEquals(defaultValue, ConfigurationUtil.getIntegerWithDeprecatedKeys(config, key, defaultValue)); - - config.setInteger(key, value); - assertEquals(value, ConfigurationUtil.getIntegerWithDeprecatedKeys(config, key, defaultValue)); - } - - /** - * Tests getInteger with deprecated keys and checks precedence. - */ - @Test - public void testGetIntegerWithDeprecatedKeys() throws Exception { - Configuration config = new Configuration(); - String key = "asdasd"; - int value = 1223239; - int defaultValue = 272770; - - String[] deprecatedKey = new String[] { "deprecated-0", "deprecated-1" }; - int[] deprecatedValue = new int[] { 99192, 7727 }; - - assertEquals(defaultValue, ConfigurationUtil.getIntegerWithDeprecatedKeys(config, key, defaultValue)); - - // Set 2nd deprecated key - config.setInteger(deprecatedKey[1], deprecatedValue[1]); - assertEquals(deprecatedValue[1], ConfigurationUtil.getIntegerWithDeprecatedKeys(config, key, defaultValue, deprecatedKey[1])); - - // Set 1st deprecated key (precedence) - config.setInteger(deprecatedKey[0], deprecatedValue[0]); - assertEquals(deprecatedValue[0], ConfigurationUtil.getIntegerWithDeprecatedKeys(config, key, defaultValue, deprecatedKey[0])); - - // Set current key - config.setInteger(key, value); - assertEquals(value, ConfigurationUtil.getIntegerWithDeprecatedKeys(config, key, defaultValue)); - } - - /** - * Tests getString without any deprecated keys. - */ - @Test - public void testGetStringNoDeprecatedKeys() throws Exception { - Configuration config = new Configuration(); - String key = "asdasd"; - String value = "1223239"; - String defaultValue = "272770"; - - assertEquals(defaultValue, ConfigurationUtil.getStringWithDeprecatedKeys(config, key, defaultValue)); - - config.setString(key, value); - assertEquals(value, ConfigurationUtil.getStringWithDeprecatedKeys(config, key, defaultValue)); - } - - /** - * Tests getString with deprecated keys and checks precedence. - */ - @Test - public void testGetStringWithDeprecatedKeys() throws Exception { - Configuration config = new Configuration(); - String key = "asdasd"; - String value = "1223239"; - String defaultValue = "272770"; - - String[] deprecatedKey = new String[] { "deprecated-0", "deprecated-1" }; - String[] deprecatedValue = new String[] { "99192", "7727" }; - - assertEquals(defaultValue, ConfigurationUtil.getStringWithDeprecatedKeys(config, key, defaultValue)); - - // Set 2nd deprecated key - config.setString(deprecatedKey[1], deprecatedValue[1]); - assertEquals(deprecatedValue[1], ConfigurationUtil.getStringWithDeprecatedKeys(config, key, defaultValue, deprecatedKey[1])); - - // Set 1st deprecated key (precedence) - config.setString(deprecatedKey[0], deprecatedValue[0]); - assertEquals(deprecatedValue[0], ConfigurationUtil.getStringWithDeprecatedKeys(config, key, defaultValue, deprecatedKey[0])); - - // Set current key - config.setString(key, value); - assertEquals(value, ConfigurationUtil.getStringWithDeprecatedKeys(config, key, defaultValue)); - } -}