From ae6721a85a233e10af18d8d87983afb0f518277a Mon Sep 17 00:00:00 2001 From: Suresh Srinivas Date: Fri, 11 Sep 2009 00:14:22 +0000 Subject: [PATCH] HADOOP-6252. Provide a method to determine if a deprecated key is set in config file. Contributed by Jakob Homan. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@813639 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 3 +++ .../org/apache/hadoop/conf/Configuration.java | 15 ++++++++++- .../conf/TestConfigurationDeprecation.java | 25 +++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/CHANGES.txt b/CHANGES.txt index ad726d1b37..8eabd3e1b0 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -547,6 +547,9 @@ Trunk (unreleased changes) alleviate a performance regression introduced in a compatibility layer. (Todd Lipcon via cdouglas) + HADOOP-6252. Provide a method to determine if a deprecated key is set in + config file. (Jakob Homan via suresh) + OPTIMIZATIONS HADOOP-5595. NameNode does not need to run a replicator to choose a diff --git a/src/java/org/apache/hadoop/conf/Configuration.java b/src/java/org/apache/hadoop/conf/Configuration.java index d257259584..c0bac19cb6 100644 --- a/src/java/org/apache/hadoop/conf/Configuration.java +++ b/src/java/org/apache/hadoop/conf/Configuration.java @@ -44,7 +44,6 @@ import java.util.Set; import java.util.StringTokenizer; import java.util.WeakHashMap; -import java.util.concurrent.atomic.AtomicBoolean; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -297,6 +296,20 @@ private static boolean isDeprecated(String key) { return deprecatedKeyMap.containsKey(key); } + /** + * Check whether or not the deprecated key has been specified in the + * configuration file rather than the new key + * + * Returns false if the specified key is not included in the deprecated + * key mapping. + * + * @param oldKey Old configuration key + * @return If the old configuration key was specified rather than the new one + */ + public boolean deprecatedKeyWasSet(String oldKey) { + return isDeprecated(oldKey) && deprecatedKeyMap.get(oldKey).accessed; + } + /** * Checks for the presence of the property name in the * deprecation map. Returns the first of the list of new keys if present diff --git a/src/test/core/org/apache/hadoop/conf/TestConfigurationDeprecation.java b/src/test/core/org/apache/hadoop/conf/TestConfigurationDeprecation.java index a5cb59de7f..33ec317c6a 100644 --- a/src/test/core/org/apache/hadoop/conf/TestConfigurationDeprecation.java +++ b/src/test/core/org/apache/hadoop/conf/TestConfigurationDeprecation.java @@ -19,6 +19,8 @@ package org.apache.hadoop.conf; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import java.io.BufferedWriter; import java.io.File; @@ -304,5 +306,28 @@ public void testDeprecation() throws IOException { assertEquals("valueG", conf.get("H")); assertEquals("valueG", conf.get("I")); } + + // Ensure that wasDeprecatedKeySet returns the correct result under + // the three code paths possible + @Test + public void testWasDeprecatedKeySet() { + Configuration.addDeprecation("oldKeyA", new String [] { "newKeyA"}); + Configuration.addDeprecation("oldKeyB", new String [] { "newKeyB"}); + + // Used the deprecated key rather than the new, therefore should trigger + conf.set("oldKeyA", "AAA"); + assertEquals("AAA", conf.get("newKeyA")); + assertTrue(conf.deprecatedKeyWasSet("oldKeyA")); + + // There is a deprecated key, but it wasn't specified. Therefore, don't trigger + conf.set("newKeyB", "AndrewBird"); + assertEquals("AndrewBird", conf.get("newKeyB")); + assertFalse(conf.deprecatedKeyWasSet("oldKeyB")); + + // Not a deprecated key, therefore shouldn't trigger deprecatedKeyWasSet + conf.set("BrandNewKey", "BrandNewValue"); + assertEquals("BrandNewValue", conf.get("BrandNewKey")); + assertFalse(conf.deprecatedKeyWasSet("BrandNewKey")); + } }