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
This commit is contained in:
Suresh Srinivas 2012-07-03 18:28:47 +00:00
parent 4b2e0e15fd
commit f5186dabb8
2 changed files with 73 additions and 8 deletions

View File

@ -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.

View File

@ -577,7 +577,7 @@ public class TestConfiguration extends TestCase {
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 TestCase {
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 TestCase {
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 TestCase {
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 TestCase {
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 TestCase {
}
}
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 TestCase {
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 TestCase {
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[]{