use of java.io.FileWriter in project hadoop by apache.
the class TestConfiguration method testPattern.
public void testPattern() throws IOException {
out = new BufferedWriter(new FileWriter(CONFIG));
startConfig();
appendProperty("test.pattern1", "");
appendProperty("test.pattern2", "(");
appendProperty("test.pattern3", "a+b");
endConfig();
Path fileResource = new Path(CONFIG);
conf.addResource(fileResource);
Pattern defaultPattern = Pattern.compile("x+");
// Return default if missing
assertEquals(defaultPattern.pattern(), conf.getPattern("xxxxx", defaultPattern).pattern());
// Return null if empty and default is null
assertNull(conf.getPattern("test.pattern1", null));
// Return default for empty
assertEquals(defaultPattern.pattern(), conf.getPattern("test.pattern1", defaultPattern).pattern());
// Return default for malformed
assertEquals(defaultPattern.pattern(), conf.getPattern("test.pattern2", defaultPattern).pattern());
// Works for correct patterns
assertEquals("a+b", conf.getPattern("test.pattern3", defaultPattern).pattern());
}
use of java.io.FileWriter in project hadoop by apache.
the class TestConfiguration method testDoubleValues.
public void testDoubleValues() throws IOException {
out = new BufferedWriter(new FileWriter(CONFIG));
startConfig();
appendProperty("test.double1", "3.1415");
appendProperty("test.double2", "003.1415");
appendProperty("test.double3", "-3.1415");
appendProperty("test.double4", " -3.1415 ");
appendProperty("test.double5", "xyz-3.1415xyz");
endConfig();
Path fileResource = new Path(CONFIG);
conf.addResource(fileResource);
assertEquals(3.1415, conf.getDouble("test.double1", 0.0));
assertEquals(3.1415, conf.getDouble("test.double2", 0.0));
assertEquals(-3.1415, conf.getDouble("test.double3", 0.0));
assertEquals(-3.1415, conf.getDouble("test.double4", 0.0));
try {
conf.getDouble("test.double5", 0.0);
fail("Property had invalid double value, but was read successfully.");
} catch (NumberFormatException e) {
// pass
}
}
use of java.io.FileWriter in project hadoop by apache.
the class TestConfiguration method testPropertySource.
public void testPropertySource() throws IOException {
out = new BufferedWriter(new FileWriter(CONFIG));
startConfig();
appendProperty("test.foo", "bar");
endConfig();
Path fileResource = new Path(CONFIG);
conf.addResource(fileResource);
conf.set("fs.defaultFS", "value");
String[] sources = conf.getPropertySources("test.foo");
assertEquals(1, sources.length);
assertEquals("Resource string returned for a file-loaded property" + " must be a proper absolute path", fileResource, new Path(sources[0]));
assertArrayEquals("Resource string returned for a set() property must be " + "\"programmatically\"", new String[] { "programmatically" }, conf.getPropertySources("fs.defaultFS"));
assertEquals("Resource string returned for an unset property must be null", null, conf.getPropertySources("fs.defaultFoo"));
}
use of java.io.FileWriter in project hadoop by apache.
the class TestConfiguration method testEscapedCharactersInValue.
public void testEscapedCharactersInValue() throws IOException {
out = new BufferedWriter(new FileWriter(CONFIG));
startConfig();
appendProperty("my.comment", ESCAPED);
endConfig();
Path fileResource = new Path(CONFIG);
conf.addResource(fileResource);
//two spaces one after "this", one before "contains"
assertEquals("''''", conf.get("my.comment"));
}
use of java.io.FileWriter in project hadoop by apache.
the class TestConfiguration method testMultiplePropertySource.
public void testMultiplePropertySource() throws IOException {
out = new BufferedWriter(new FileWriter(CONFIG));
startConfig();
appendProperty("test.foo", "bar", false, "a", "b", "c");
endConfig();
Path fileResource = new Path(CONFIG);
conf.addResource(fileResource);
String[] sources = conf.getPropertySources("test.foo");
assertEquals(4, sources.length);
assertEquals("a", sources[0]);
assertEquals("b", sources[1]);
assertEquals("c", sources[2]);
assertEquals("Resource string returned for a file-loaded property" + " must be a proper absolute path", fileResource, new Path(sources[3]));
}
Aggregations