HADOOP-16925. MetricsConfig incorrectly loads the configuration whose value is String list in the properties file (#1896)
Contributed by Jiayi Liu
This commit is contained in:
parent
28db29d32f
commit
956c097f25
|
@ -37,6 +37,7 @@ import com.google.common.collect.Maps;
|
||||||
import org.apache.commons.configuration2.Configuration;
|
import org.apache.commons.configuration2.Configuration;
|
||||||
import org.apache.commons.configuration2.PropertiesConfiguration;
|
import org.apache.commons.configuration2.PropertiesConfiguration;
|
||||||
import org.apache.commons.configuration2.SubsetConfiguration;
|
import org.apache.commons.configuration2.SubsetConfiguration;
|
||||||
|
import org.apache.commons.configuration2.convert.DefaultListDelimiterHandler;
|
||||||
import org.apache.commons.configuration2.ex.ConfigurationException;
|
import org.apache.commons.configuration2.ex.ConfigurationException;
|
||||||
import org.apache.commons.configuration2.io.FileHandler;
|
import org.apache.commons.configuration2.io.FileHandler;
|
||||||
import org.apache.hadoop.metrics2.MetricsFilter;
|
import org.apache.hadoop.metrics2.MetricsFilter;
|
||||||
|
@ -111,6 +112,7 @@ class MetricsConfig extends SubsetConfiguration {
|
||||||
for (String fname : fileNames) {
|
for (String fname : fileNames) {
|
||||||
try {
|
try {
|
||||||
PropertiesConfiguration pcf = new PropertiesConfiguration();
|
PropertiesConfiguration pcf = new PropertiesConfiguration();
|
||||||
|
pcf.setListDelimiterHandler(new DefaultListDelimiterHandler(','));
|
||||||
FileHandler fh = new FileHandler(pcf);
|
FileHandler fh = new FileHandler(pcf);
|
||||||
fh.setFileName(fname);
|
fh.setFileName(fname);
|
||||||
fh.load();
|
fh.load();
|
||||||
|
|
|
@ -133,6 +133,22 @@ public class TestMetricsConfig {
|
||||||
assertEq(expected, mc2);
|
assertEq(expected, mc2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test the config value separated by delimiter
|
||||||
|
*/
|
||||||
|
@Test public void testDelimiterConf() {
|
||||||
|
String filename = getTestFilename("test-metrics2-delimiter");
|
||||||
|
new ConfigBuilder().add("p1.foo", "p1foo1,p1foo2,p1foo3").save(filename);
|
||||||
|
|
||||||
|
MetricsConfig mc = MetricsConfig.create("p1", filename);
|
||||||
|
Configuration expected = new ConfigBuilder()
|
||||||
|
.add("foo", "p1foo1")
|
||||||
|
.add("foo", "p1foo2")
|
||||||
|
.add("foo", "p1foo3")
|
||||||
|
.config;
|
||||||
|
assertEq(expected, mc);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a test filename in the class path
|
* Return a test filename in the class path
|
||||||
* @param basename
|
* @param basename
|
||||||
|
|
Loading…
Reference in New Issue