|
@@ -34,6 +34,7 @@ import java.util.Map;
|
|
|
import java.util.Random;
|
|
|
|
|
|
import junit.framework.TestCase;
|
|
|
+import static org.junit.Assert.assertArrayEquals;
|
|
|
|
|
|
import org.apache.hadoop.fs.Path;
|
|
|
import org.apache.hadoop.io.IOUtils;
|
|
@@ -385,6 +386,7 @@ public class TestConfiguration extends TestCase {
|
|
|
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);
|
|
@@ -394,8 +396,80 @@ public class TestConfiguration extends TestCase {
|
|
|
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 {
|