Author: shv
Date: Tue Apr 29 15:43:18 2008
New Revision: 652178

URL: http://svn.apache.org/viewvc?rev=652178&view=rev
Log:
HADOOP-2461. Trim property names in configuration. Contributed by Tsz Wo 
(Nicholas), SZE.

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

Modified: hadoop/core/trunk/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/hadoop/core/trunk/CHANGES.txt?rev=652178&r1=652177&r2=652178&view=diff
==============================================================================
--- hadoop/core/trunk/CHANGES.txt (original)
+++ hadoop/core/trunk/CHANGES.txt Tue Apr 29 15:43:18 2008
@@ -52,6 +52,9 @@
     HADOOP-3308. Improve QuickSort by excluding values eq the pivot from the
     partition. (cdouglas)
 
+    HADOOP-2461. Trim property names in configuration.
+    (Tsz Wo (Nicholas), SZE via shv)
+
   OPTIMIZATIONS
 
     HADOOP-3274. The default constructor of BytesWritable creates empty 

Modified: hadoop/core/trunk/src/java/org/apache/hadoop/conf/Configuration.java
URL: 
http://svn.apache.org/viewvc/hadoop/core/trunk/src/java/org/apache/hadoop/conf/Configuration.java?rev=652178&r1=652177&r2=652178&view=diff
==============================================================================
--- hadoop/core/trunk/src/java/org/apache/hadoop/conf/Configuration.java 
(original)
+++ hadoop/core/trunk/src/java/org/apache/hadoop/conf/Configuration.java Tue 
Apr 29 15:43:18 2008
@@ -892,7 +892,7 @@
             continue;
           Element field = (Element)fieldNode;
           if ("name".equals(field.getTagName()) && field.hasChildNodes())
-            attr = ((Text)field.getFirstChild()).getData();
+            attr = ((Text)field.getFirstChild()).getData().trim();
           if ("value".equals(field.getTagName()) && field.hasChildNodes())
             value = ((Text)field.getFirstChild()).getData();
           if ("final".equals(field.getTagName()) && field.hasChildNodes())

Modified: 
hadoop/core/trunk/src/test/org/apache/hadoop/conf/TestConfiguration.java
URL: 
http://svn.apache.org/viewvc/hadoop/core/trunk/src/test/org/apache/hadoop/conf/TestConfiguration.java?rev=652178&r1=652177&r2=652178&view=diff
==============================================================================
--- hadoop/core/trunk/src/test/org/apache/hadoop/conf/TestConfiguration.java 
(original)
+++ hadoop/core/trunk/src/test/org/apache/hadoop/conf/TestConfiguration.java 
Tue Apr 29 15:43:18 2008
@@ -22,6 +22,7 @@
 import java.io.FileWriter;
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Random;
 
 import junit.framework.TestCase;
 
@@ -33,6 +34,7 @@
   private Configuration conf;
   final static String CONFIG = new File("./test-config.xml").getAbsolutePath();
   final static String CONFIG2 = new 
File("./test-config2.xml").getAbsolutePath();
+  final static Random RAN = new Random();
 
   @Override
   protected void setUp() throws Exception {
@@ -186,6 +188,30 @@
     assertEquals("this  contains a comment", conf.get("my.comment"));
   }
   
+  public void testTrim() throws IOException {
+    out=new BufferedWriter(new FileWriter(CONFIG));
+    startConfig();
+    String[] whitespaces = {"", " ", "\n", "\t"};
+    String[] name = new String[100];
+    for(int i = 0; i < name.length; i++) {
+      name[i] = "foo" + i;
+      StringBuilder prefix = new StringBuilder(); 
+      StringBuilder postfix = new StringBuilder(); 
+      for(int j = 0; j < 3; j++) {
+        prefix.append(whitespaces[RAN.nextInt(whitespaces.length)]);
+        postfix.append(whitespaces[RAN.nextInt(whitespaces.length)]);
+      }
+      
+      appendProperty(prefix + name[i] + postfix, name[i] + ".value");
+    }
+    endConfig();
+
+    conf.addResource(new Path(CONFIG));
+    for(String n : name) {
+      assertEquals(n + ".value", conf.get(n));
+    }
+  }
+
   public void testToString() throws IOException {
     out=new BufferedWriter(new FileWriter(CONFIG));
     startConfig();


Reply via email to