HADOOP-15357. Configuration.getPropsWithPrefix no longer does variable substitution. Contributed by Jim Brennan
This commit is contained in:
parent
ea51ef44fc
commit
0fb1457d86
@ -2669,15 +2669,12 @@ public Iterator<Map.Entry<String, String>> iterator() {
|
|||||||
*/
|
*/
|
||||||
public Map<String, String> getPropsWithPrefix(String confPrefix) {
|
public Map<String, String> getPropsWithPrefix(String confPrefix) {
|
||||||
Properties props = getProps();
|
Properties props = getProps();
|
||||||
Enumeration e = props.propertyNames();
|
|
||||||
Map<String, String> configMap = new HashMap<>();
|
Map<String, String> configMap = new HashMap<>();
|
||||||
String name = null;
|
for (String name : props.stringPropertyNames()) {
|
||||||
while (e.hasMoreElements()) {
|
|
||||||
name = (String) e.nextElement();
|
|
||||||
if (name.startsWith(confPrefix)) {
|
if (name.startsWith(confPrefix)) {
|
||||||
String value = props.getProperty(name);
|
String value = get(name);
|
||||||
name = name.substring(confPrefix.length());
|
String keyName = name.substring(confPrefix.length());
|
||||||
configMap.put(name, value);
|
configMap.put(keyName, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return configMap;
|
return configMap;
|
||||||
|
@ -1966,16 +1966,29 @@ public void testGetPasswordByDeprecatedKey() throws Exception {
|
|||||||
public void testGettingPropertiesWithPrefix() throws Exception {
|
public void testGettingPropertiesWithPrefix() throws Exception {
|
||||||
Configuration conf = new Configuration();
|
Configuration conf = new Configuration();
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
conf.set("prefix" + ".name" + i, "value");
|
conf.set("prefix." + "name" + i, "value" + i);
|
||||||
}
|
}
|
||||||
conf.set("different.prefix" + ".name", "value");
|
conf.set("different.prefix" + ".name", "value");
|
||||||
Map<String, String> props = conf.getPropsWithPrefix("prefix");
|
Map<String, String> prefixedProps = conf.getPropsWithPrefix("prefix.");
|
||||||
assertEquals(props.size(), 10);
|
assertEquals(prefixedProps.size(), 10);
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
assertEquals("value" + i, prefixedProps.get("name" + i));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Repeat test with variable substitution
|
||||||
|
conf.set("foo", "bar");
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
conf.set("subprefix." + "subname" + i, "value_${foo}" + i);
|
||||||
|
}
|
||||||
|
prefixedProps = conf.getPropsWithPrefix("subprefix.");
|
||||||
|
assertEquals(prefixedProps.size(), 10);
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
assertEquals("value_bar" + i, prefixedProps.get("subname" + i));
|
||||||
|
}
|
||||||
// test call with no properties for a given prefix
|
// test call with no properties for a given prefix
|
||||||
props = conf.getPropsWithPrefix("none");
|
prefixedProps = conf.getPropsWithPrefix("none");
|
||||||
assertNotNull(props.isEmpty());
|
assertNotNull(prefixedProps.isEmpty());
|
||||||
assertTrue(props.isEmpty());
|
assertTrue(prefixedProps.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] argv) throws Exception {
|
public static void main(String[] argv) throws Exception {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user