hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e..@apache.org
Subject svn commit: r1054904 - in /hadoop/common/branches/branch-0.22: ./ src/contrib/ec2/ src/docs/ src/java/ src/java/org/apache/hadoop/conf/ src/test/core/ src/test/core/org/apache/hadoop/conf/ src/test/core/org/apache/hadoop/io/
Date Tue, 04 Jan 2011 05:30:21 GMT
Author: eli
Date: Tue Jan  4 05:30:20 2011
New Revision: 1054904

URL: http://svn.apache.org/viewvc?rev=1054904&view=rev
Log:
HADOOP-6578. svn merge -c 1054903 from trunk

Modified:
    hadoop/common/branches/branch-0.22/   (props changed)
    hadoop/common/branches/branch-0.22/CHANGES.txt   (contents, props changed)
    hadoop/common/branches/branch-0.22/src/contrib/ec2/   (props changed)
    hadoop/common/branches/branch-0.22/src/docs/   (props changed)
    hadoop/common/branches/branch-0.22/src/java/   (props changed)
    hadoop/common/branches/branch-0.22/src/java/org/apache/hadoop/conf/Configuration.java
    hadoop/common/branches/branch-0.22/src/test/core/   (props changed)
    hadoop/common/branches/branch-0.22/src/test/core/org/apache/hadoop/conf/TestConfiguration.java
    hadoop/common/branches/branch-0.22/src/test/core/org/apache/hadoop/io/TestSequenceFile.java
  (props changed)

Propchange: hadoop/common/branches/branch-0.22/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Jan  4 05:30:20 2011
@@ -1,2 +1,2 @@
-/hadoop/common/trunk:1037901,1039952,1040408,1040849,1044490,1050070,1054848,1054853
+/hadoop/common/trunk:1037901,1039952,1040408,1040849,1044490,1050070,1054848,1054853,1054903
 /hadoop/core/branches/branch-0.19/core:713112

Modified: hadoop/common/branches/branch-0.22/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.22/CHANGES.txt?rev=1054904&r1=1054903&r2=1054904&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.22/CHANGES.txt (original)
+++ hadoop/common/branches/branch-0.22/CHANGES.txt Tue Jan  4 05:30:20 2011
@@ -193,6 +193,9 @@ Release 0.22.0 - Unreleased
 
     HADOOP-6298. Add copyBytes to Text and BytesWritable. (omalley)
 
+    HADOOP-6578. Configuration should trim whitespace around a lot of value
+    types. (Michele Catasta via eli)
+
   OPTIMIZATIONS
 
     HADOOP-6884. Add LOG.isDebugEnabled() guard for each LOG.debug(..).

Propchange: hadoop/common/branches/branch-0.22/CHANGES.txt
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Jan  4 05:30:20 2011
@@ -1,4 +1,4 @@
-/hadoop/common/trunk/CHANGES.txt:1037901,1039952,1040408,1040849,1044490,1050070,1054848,1054853
+/hadoop/common/trunk/CHANGES.txt:1037901,1039952,1040408,1040849,1044490,1050070,1054848,1054853,1054903
 /hadoop/core/branches/branch-0.18/CHANGES.txt:727226
 /hadoop/core/branches/branch-0.19/CHANGES.txt:713112
 /hadoop/core/trunk/CHANGES.txt:776175-785643,785929-786278

Propchange: hadoop/common/branches/branch-0.22/src/contrib/ec2/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Jan  4 05:30:20 2011
@@ -1,3 +1,3 @@
-/hadoop/common/trunk/src/contrib/ec2:1037901,1039952,1040408,1040849,1044490,1050070,1054848,1054853
+/hadoop/common/trunk/src/contrib/ec2:1037901,1039952,1040408,1040849,1044490,1050070,1054848,1054853,1054903
 /hadoop/core/branches/branch-0.19/core/src/contrib/ec2:713112
 /hadoop/core/trunk/src/contrib/ec2:776175-784663

Propchange: hadoop/common/branches/branch-0.22/src/docs/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Jan  4 05:30:20 2011
@@ -1,2 +1,2 @@
-/hadoop/common/trunk/src/docs:1037901,1039952,1040408,1040849,1044490,1050070,1054848,1054853
+/hadoop/common/trunk/src/docs:1037901,1039952,1040408,1040849,1044490,1050070,1054848,1054853,1054903
 /hadoop/core/branches/branch-0.19/src/docs:713112

Propchange: hadoop/common/branches/branch-0.22/src/java/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Jan  4 05:30:20 2011
@@ -1,3 +1,3 @@
-/hadoop/common/trunk/src/java:1037901,1039952,1040408,1040849,1044490,1050070,1054848,1054853
+/hadoop/common/trunk/src/java:1037901,1039952,1040408,1040849,1044490,1050070,1054848,1054853,1054903
 /hadoop/core/branches/branch-0.19/core/src/java:713112
 /hadoop/core/trunk/src/core:776175-785643,785929-786278

Modified: hadoop/common/branches/branch-0.22/src/java/org/apache/hadoop/conf/Configuration.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.22/src/java/org/apache/hadoop/conf/Configuration.java?rev=1054904&r1=1054903&r2=1054904&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.22/src/java/org/apache/hadoop/conf/Configuration.java
(original)
+++ hadoop/common/branches/branch-0.22/src/java/org/apache/hadoop/conf/Configuration.java
Tue Jan  4 05:30:20 2011
@@ -544,6 +544,29 @@ public class Configuration implements It
     name = handleDeprecation(name);
     return substituteVars(getProps().getProperty(name));
   }
+  
+  /**
+   * Get the value of the <code>name</code> property as a trimmed <code>String</code>,

+   * <code>null</code> if no such property exists. 
+   * If the key is deprecated, it returns the value of
+   * the first key which replaces the deprecated key and is not null
+   * 
+   * Values are processed for <a href="#VariableExpansion">variable expansion</a>

+   * before being returned. 
+   * 
+   * @param name the property name.
+   * @return the value of the <code>name</code> or its replacing property, 
+   *         or null if no such property exists.
+   */
+  public String getTrimmed(String name) {
+    String value = get(name);
+    
+    if (null == value) {
+      return null;
+    } else {
+      return value.trim();
+    }
+  }
 
   /**
    * Get the value of the <code>name</code> property, without doing
@@ -634,7 +657,7 @@ public class Configuration implements It
    *         or <code>defaultValue</code>. 
    */
   public int getInt(String name, int defaultValue) {
-    String valueString = get(name);
+    String valueString = getTrimmed(name);
     if (valueString == null)
       return defaultValue;
     try {
@@ -670,7 +693,7 @@ public class Configuration implements It
    *         or <code>defaultValue</code>. 
    */
   public long getLong(String name, long defaultValue) {
-    String valueString = get(name);
+    String valueString = getTrimmed(name);
     if (valueString == null)
       return defaultValue;
     try {
@@ -723,7 +746,7 @@ public class Configuration implements It
    *         or <code>defaultValue</code>. 
    */
   public float getFloat(String name, float defaultValue) {
-    String valueString = get(name);
+    String valueString = getTrimmed(name);
     if (valueString == null)
       return defaultValue;
     try {
@@ -753,7 +776,7 @@ public class Configuration implements It
    *         or <code>defaultValue</code>. 
    */
   public boolean getBoolean(String name, boolean defaultValue) {
-    String valueString = get(name);
+    String valueString = getTrimmed(name);
     if ("true".equals(valueString))
       return true;
     else if ("false".equals(valueString))
@@ -1069,7 +1092,7 @@ public class Configuration implements It
       }
     }
 
-    Class clazz = map.get(name);
+    Class<?> clazz = map.get(name);
     if (clazz == null) {
       clazz = Class.forName(name, true, classLoader);
       if (clazz != null) {
@@ -1094,7 +1117,7 @@ public class Configuration implements It
    *         or <code>defaultValue</code>. 
    */
   public Class<?>[] getClasses(String name, Class<?> ... defaultValue) {
-    String[] classnames = getStrings(name);
+    String[] classnames = getTrimmedStrings(name);
     if (classnames == null)
       return defaultValue;
     try {
@@ -1119,7 +1142,7 @@ public class Configuration implements It
    *         or <code>defaultValue</code>. 
    */
   public Class<?> getClass(String name, Class<?> defaultValue) {
-    String valueString = get(name);
+    String valueString = getTrimmed(name);
     if (valueString == null)
       return defaultValue;
     try {

Propchange: hadoop/common/branches/branch-0.22/src/test/core/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Jan  4 05:30:20 2011
@@ -1,3 +1,3 @@
-/hadoop/common/trunk/src/test/core:1037901,1039952,1040408,1040849,1044490,1050070,1054848,1054853
+/hadoop/common/trunk/src/test/core:1037901,1039952,1040408,1040849,1044490,1050070,1054848,1054853,1054903
 /hadoop/core/branches/branch-0.19/core/src/test/core:713112
 /hadoop/core/trunk/src/test/core:776175-785643,785929-786278

Modified: hadoop/common/branches/branch-0.22/src/test/core/org/apache/hadoop/conf/TestConfiguration.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.22/src/test/core/org/apache/hadoop/conf/TestConfiguration.java?rev=1054904&r1=1054903&r2=1054904&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.22/src/test/core/org/apache/hadoop/conf/TestConfiguration.java
(original)
+++ hadoop/common/branches/branch-0.22/src/test/core/org/apache/hadoop/conf/TestConfiguration.java
Tue Jan  4 05:30:20 2011
@@ -29,6 +29,7 @@ import java.util.Random;
 import java.util.regex.Pattern;
 
 import junit.framework.TestCase;
+import static org.junit.Assert.assertArrayEquals;
 
 import org.apache.hadoop.fs.Path;
 import org.codehaus.jackson.map.ObjectMapper; 
@@ -337,6 +338,7 @@ public class TestConfiguration extends T
     appendProperty("test.int1", "20");
     appendProperty("test.int2", "020");
     appendProperty("test.int3", "-20");
+    appendProperty("test.int4", " -20 ");
     endConfig();
     Path fileResource = new Path(CONFIG);
     conf.addResource(fileResource);
@@ -346,8 +348,80 @@ public class TestConfiguration extends T
     assertEquals(20, conf.getLong("test.int2", 0));
     assertEquals(-20, conf.getInt("test.int3", 0));
     assertEquals(-20, conf.getLong("test.int3", 0));
+    assertEquals(-20, conf.getInt("test.int4", 0));
+    assertEquals(-20, conf.getLong("test.int4", 0));
   }
-	
+  
+  public void testBooleanValues() throws IOException {
+    out=new BufferedWriter(new FileWriter(CONFIG));
+    startConfig();
+    appendProperty("test.bool1", "true");
+    appendProperty("test.bool2", "false");
+    appendProperty("test.bool3", "  true ");
+    appendProperty("test.bool4", " false ");
+    appendProperty("test.bool5", "foo");
+    endConfig();
+    Path fileResource = new Path(CONFIG);
+    conf.addResource(fileResource);
+    assertEquals(true, conf.getBoolean("test.bool1", false));
+    assertEquals(false, conf.getBoolean("test.bool2", true));
+    assertEquals(true, conf.getBoolean("test.bool3", false));
+    assertEquals(false, conf.getBoolean("test.bool4", true));
+    assertEquals(true, conf.getBoolean("test.bool5", true));
+  }
+  
+  public void testFloatValues() throws IOException {
+    out=new BufferedWriter(new FileWriter(CONFIG));
+    startConfig();
+    appendProperty("test.float1", "3.1415");
+    appendProperty("test.float2", "003.1415");
+    appendProperty("test.float3", "-3.1415");
+    appendProperty("test.float4", " -3.1415 ");
+    endConfig();
+    Path fileResource = new Path(CONFIG);
+    conf.addResource(fileResource);
+    assertEquals(3.1415f, conf.getFloat("test.float1", 0.0f));
+    assertEquals(3.1415f, conf.getFloat("test.float2", 0.0f));
+    assertEquals(-3.1415f, conf.getFloat("test.float3", 0.0f));
+    assertEquals(-3.1415f, conf.getFloat("test.float4", 0.0f));
+  }
+  
+  public void testGetClass() throws IOException {
+    out=new BufferedWriter(new FileWriter(CONFIG));
+    startConfig();
+    appendProperty("test.class1", "java.lang.Integer");
+    appendProperty("test.class2", " java.lang.Integer ");
+    endConfig();
+    Path fileResource = new Path(CONFIG);
+    conf.addResource(fileResource);
+    assertEquals("java.lang.Integer", conf.getClass("test.class1", null).getCanonicalName());
+    assertEquals("java.lang.Integer", conf.getClass("test.class2", null).getCanonicalName());
+  }
+  
+  public void testGetClasses() throws IOException {
+    out=new BufferedWriter(new FileWriter(CONFIG));
+    startConfig();
+    appendProperty("test.classes1", "java.lang.Integer,java.lang.String");
+    appendProperty("test.classes2", " java.lang.Integer , java.lang.String ");
+    endConfig();
+    Path fileResource = new Path(CONFIG);
+    conf.addResource(fileResource);
+    String[] expectedNames = {"java.lang.Integer", "java.lang.String"};
+    Class<?>[] defaultClasses = {};
+    Class<?>[] classes1 = conf.getClasses("test.classes1", defaultClasses);
+    Class<?>[] classes2 = conf.getClasses("test.classes2", defaultClasses);
+    assertArrayEquals(expectedNames, extractClassNames(classes1));
+    assertArrayEquals(expectedNames, extractClassNames(classes2));
+  }
+
+  private static String[] extractClassNames(Class<?>[] classes) {
+    String[] classNames = new String[classes.length];
+    for (int i = 0; i < classNames.length; i++) {
+      classNames[i] = classes[i].getCanonicalName();
+    }
+    return classNames;
+  }
+  
   enum Dingo { FOO, BAR };
   enum Yak { RAB, FOO };
   public void testEnum() throws IOException {

Propchange: hadoop/common/branches/branch-0.22/src/test/core/org/apache/hadoop/io/TestSequenceFile.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Jan  4 05:30:20 2011
@@ -1,3 +1,3 @@
-/hadoop/common/trunk/src/test/core/org/apache/hadoop/io/TestSequenceFile.java:1037901,1039952,1040408,1040849,1044490,1050070,1054848,1054853
+/hadoop/common/trunk/src/test/core/org/apache/hadoop/io/TestSequenceFile.java:1037901,1039952,1040408,1040849,1044490,1050070,1054848,1054853,1054903
 /hadoop/core/branches/branch-0.19/mapred/src/test/mapred/org/apache/hadoop/io/TestSequenceFile.java:713112
 /hadoop/core/trunk/src/test/mapred/org/apache/hadoop/io/TestSequenceFile.java:776175-785643



Mime
View raw message