From f5186dabb8288b2aa0b75da1d6694addc3967b9e Mon Sep 17 00:00:00 2001 From: Suresh Srinivas Date: Tue, 3 Jul 2012 18:28:47 +0000 Subject: [PATCH] HADOOP-8434. Add tests for Configuration setter methods. Contributed by Madhukara Phatak. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1356864 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop-common/CHANGES.txt | 3 + .../apache/hadoop/conf/TestConfiguration.java | 78 +++++++++++++++++-- 2 files changed, 73 insertions(+), 8 deletions(-) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index d7cae726e2..ecaaa3b956 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -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. diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java index 4878031262..63a357aab8 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java @@ -577,7 +577,7 @@ public void testGetClasses() throws IOException { assertArrayEquals(expectedNames, extractClassNames(classes2)); } - public void testGetStringCollection() throws IOException { + public void testGetStringCollection() { Configuration c = new Configuration(); c.set("x", " a, b\n,\nc "); Collection strs = c.getTrimmedStringCollection("x"); @@ -594,7 +594,7 @@ public void testGetStringCollection() throws IOException { strs.add("z"); } - public void testGetTrimmedStringCollection() throws IOException { + public void testGetTrimmedStringCollection() { Configuration c = new Configuration(); c.set("x", "a, b, c"); Collection strs = c.getStringCollection("x"); @@ -621,7 +621,7 @@ private static String[] extractClassNames(Class[] classes) { 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 void testEnum() throws IOException { 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 void testPropertySource() throws IOException { 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 void testSocketAddress() throws IOException { } } - 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 void testReload() throws IOException { 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 void testInvalidSubstitutation() { 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