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
This commit is contained in:
Suresh Srinivas 2009-09-11 00:14:22 +00:00
parent 86724941c5
commit ae6721a85a
3 changed files with 42 additions and 1 deletions

View File

@ -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

View File

@ -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 <code>name</code> in the
* deprecation map. Returns the first of the list of new keys if present

View File

@ -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"));
}
}