hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sur...@apache.org
Subject svn commit: r1356864 - in /hadoop/common/trunk/hadoop-common-project/hadoop-common: CHANGES.txt src/test/java/org/apache/hadoop/conf/TestConfiguration.java
Date Tue, 03 Jul 2012 18:28:48 GMT
Author: suresh
Date: Tue Jul  3 18:28:47 2012
New Revision: 1356864

URL: http://svn.apache.org/viewvc?rev=1356864&view=rev
Log:
HADOOP-8434. Add tests for Configuration setter methods. Contributed by Madhukara Phatak.


Modified:
    hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt
    hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java

Modified: hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt?rev=1356864&r1=1356863&r2=1356864&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt (original)
+++ hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt Tue Jul  3 18:28:47
2012
@@ -82,6 +82,9 @@ Trunk (unreleased changes)
     HADOOP-8059. Add javadoc to InterfaceAudience and InterfaceStability.
     (Brandon Li via suresh)
 
+    HADOOP-8434. Add tests for Configuration setter methods.
+    (Madhukara Phatak via suresh)
+
   BUG FIXES
 
     HADOOP-8177. MBeans shouldn't try to register when it fails to create MBeanName.

Modified: hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java?rev=1356864&r1=1356863&r2=1356864&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java
(original)
+++ hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java
Tue Jul  3 18:28:47 2012
@@ -577,7 +577,7 @@ public class TestConfiguration extends T
     assertArrayEquals(expectedNames, extractClassNames(classes2));
   }
   
-  public void testGetStringCollection() throws IOException {
+  public void testGetStringCollection() {
     Configuration c = new Configuration();
     c.set("x", " a, b\n,\nc ");
     Collection<String> strs = c.getTrimmedStringCollection("x");
@@ -594,7 +594,7 @@ public class TestConfiguration extends T
     strs.add("z");
   }
 
-  public void testGetTrimmedStringCollection() throws IOException {
+  public void testGetTrimmedStringCollection() {
     Configuration c = new Configuration();
     c.set("x", "a, b, c");
     Collection<String> strs = c.getStringCollection("x");
@@ -621,7 +621,7 @@ public class TestConfiguration extends T
   
   enum Dingo { FOO, BAR };
   enum Yak { RAB, FOO };
-  public void testEnum() throws IOException {
+  public void testEnum() {
     Configuration conf = new Configuration();
     conf.setEnum("test.enum", Dingo.FOO);
     assertSame(Dingo.FOO, conf.getEnum("test.enum", Dingo.BAR));
@@ -629,7 +629,7 @@ public class TestConfiguration extends T
     boolean fail = false;
     try {
       conf.setEnum("test.enum", Dingo.BAR);
-      Yak y = conf.getEnum("test.enum", Yak.FOO);
+      conf.getEnum("test.enum", Yak.FOO);
     } catch (IllegalArgumentException e) {
       fail = true;
     }
@@ -683,7 +683,7 @@ public class TestConfiguration extends T
         null, conf.getPropertySource("fs.defaultFoo"));
   }
 
-  public void testSocketAddress() throws IOException {
+  public void testSocketAddress() {
     Configuration conf = new Configuration();
     final String defaultAddr = "host:1";
     final int defaultPort = 2;
@@ -715,7 +715,7 @@ public class TestConfiguration extends T
     }
   }
 
-  public void testSetSocketAddress() throws IOException {
+  public void testSetSocketAddress() {
     Configuration conf = new Configuration();
     NetUtils.addStaticResolution("host", "127.0.0.1");
     final String defaultAddr = "host:1";
@@ -777,14 +777,14 @@ public class TestConfiguration extends T
     assertEquals("value5", conf.get("test.key4"));
   }
 
-  public void testSize() throws IOException {
+  public void testSize() {
     Configuration conf = new Configuration(false);
     conf.set("a", "A");
     conf.set("b", "B");
     assertEquals(2, conf.size());
   }
 
-  public void testClear() throws IOException {
+  public void testClear() {
     Configuration conf = new Configuration(false);
     conf.set("a", "A");
     conf.set("b", "B");
@@ -1028,6 +1028,68 @@ public class TestConfiguration extends T
     String value = configuration.get(key);
     assertTrue("Unexpected value " + value, value.equals(keyExpression));
   }
+
+  public void testBoolean() {
+    boolean value = true;
+    Configuration configuration = new Configuration();
+    configuration.setBoolean("value", value);
+    assertEquals(value, configuration.getBoolean("value", false));
+  }
+
+  public void testBooleanIfUnset() {
+    boolean value = true;
+    Configuration configuration = new Configuration();
+    configuration.setBooleanIfUnset("value", value);
+    assertEquals(value, configuration.getBoolean("value", false));
+    configuration.setBooleanIfUnset("value", false);
+    assertEquals(value, configuration.getBoolean("value", false));
+  }
+
+  public void testFloat() {
+    float value = 1.0F;
+    Configuration configuration = new Configuration();
+    configuration.setFloat("value", value);
+    assertEquals(value, configuration.getFloat("value", 0.0F));
+  }
+  
+  public void testDouble() {
+    double value = 1.0D;
+    Configuration configuration = new Configuration();
+    configuration.setDouble("value", value);
+    assertEquals(value, configuration.getDouble("value", 0.0D));
+  }
+
+  public void testInt() {
+    int value = 1;
+    Configuration configuration = new Configuration();
+    configuration.setInt("value", value);
+    assertEquals(value, configuration.getInt("value", 0));
+  }
+
+  public void testLong() {
+    long value = 1L;
+    Configuration configuration = new Configuration();
+    configuration.setLong("value", value);
+    assertEquals(value, configuration.getLong("value", 0L));
+  }
+
+  public void testStrings() {
+    String [] strings = {"FOO","BAR"};
+    Configuration configuration = new Configuration();
+    configuration.setStrings("strings", strings);
+    String [] returnStrings = configuration.getStrings("strings");
+    for(int i=0;i<returnStrings.length;i++) {
+       assertEquals(strings[i], returnStrings[i]);
+    }
+  }
+  
+  public void testSetPattern() {
+    Pattern testPattern = Pattern.compile("a+b");
+    Configuration configuration = new Configuration();
+    configuration.setPattern("testPattern", testPattern);
+    assertEquals(testPattern.pattern(),
+        configuration.getPattern("testPattern", Pattern.compile("")).pattern());
+  }
   
   public static void main(String[] argv) throws Exception {
     junit.textui.TestRunner.main(new String[]{



Mime
View raw message