hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sur...@apache.org
Subject svn commit: r813639 - in /hadoop/common/trunk: CHANGES.txt src/java/org/apache/hadoop/conf/Configuration.java src/test/core/org/apache/hadoop/conf/TestConfigurationDeprecation.java
Date Fri, 11 Sep 2009 00:14:22 GMT
Author: suresh
Date: Fri Sep 11 00:14:22 2009
New Revision: 813639

URL: http://svn.apache.org/viewvc?rev=813639&view=rev
Log:
HADOOP-6252. Provide a method to determine if a deprecated key is set in config file. Contributed
by Jakob Homan.

Modified:
    hadoop/common/trunk/CHANGES.txt
    hadoop/common/trunk/src/java/org/apache/hadoop/conf/Configuration.java
    hadoop/common/trunk/src/test/core/org/apache/hadoop/conf/TestConfigurationDeprecation.java

Modified: hadoop/common/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/CHANGES.txt?rev=813639&r1=813638&r2=813639&view=diff
==============================================================================
--- hadoop/common/trunk/CHANGES.txt (original)
+++ hadoop/common/trunk/CHANGES.txt Fri Sep 11 00:14:22 2009
@@ -547,6 +547,9 @@
     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

Modified: hadoop/common/trunk/src/java/org/apache/hadoop/conf/Configuration.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/conf/Configuration.java?rev=813639&r1=813638&r2=813639&view=diff
==============================================================================
--- hadoop/common/trunk/src/java/org/apache/hadoop/conf/Configuration.java (original)
+++ hadoop/common/trunk/src/java/org/apache/hadoop/conf/Configuration.java Fri Sep 11 00:14:22
2009
@@ -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;
 
@@ -298,6 +297,20 @@
   }
  
   /**
+   * 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
    * in the deprecation map or the <code>name</code> itself.

Modified: hadoop/common/trunk/src/test/core/org/apache/hadoop/conf/TestConfigurationDeprecation.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/test/core/org/apache/hadoop/conf/TestConfigurationDeprecation.java?rev=813639&r1=813638&r2=813639&view=diff
==============================================================================
--- hadoop/common/trunk/src/test/core/org/apache/hadoop/conf/TestConfigurationDeprecation.java
(original)
+++ hadoop/common/trunk/src/test/core/org/apache/hadoop/conf/TestConfigurationDeprecation.java
Fri Sep 11 00:14:22 2009
@@ -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 @@
     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"));
+  }
 
 }



Mime
View raw message