[02/44] hadoop git commit: HADOOP-15357. Configuration.getPropsWithPrefix no longer does variable substitution. Contributed by Jim Brennan
HADOOP-15357. Configuration.getPropsWithPrefix no longer does variable substitution. Contributed by Jim Brennan Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/e8139754 Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/e8139754 Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/e8139754 Branch: refs/heads/HDFS-7240 Commit: e81397545a273cf9a090010eb644b836e0ef8c7b Parents: d553799 Author: Jason LoweAuthored: Tue Apr 10 16:44:03 2018 -0500 Committer: Jason Lowe Committed: Tue Apr 10 16:44:55 2018 -0500 -- .../org/apache/hadoop/conf/Configuration.java | 11 +++-- .../apache/hadoop/conf/TestConfiguration.java | 26 +++- 2 files changed, 24 insertions(+), 13 deletions(-) -- http://git-wip-us.apache.org/repos/asf/hadoop/blob/e8139754/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java -- diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java index 78a2e9f..f1e2a9d 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java @@ -2869,15 +2869,12 @@ public class Configuration implements Iterable >, */ public Map getPropsWithPrefix(String confPrefix) { Properties props = getProps(); -Enumeration e = props.propertyNames(); Map configMap = new HashMap<>(); -String name = null; -while (e.hasMoreElements()) { - name = (String) e.nextElement(); +for (String name : props.stringPropertyNames()) { if (name.startsWith(confPrefix)) { -String value = props.getProperty(name); -name = name.substring(confPrefix.length()); -configMap.put(name, value); +String value = get(name); +String keyName = name.substring(confPrefix.length()); +configMap.put(keyName, value); } } return configMap; http://git-wip-us.apache.org/repos/asf/hadoop/blob/e8139754/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java -- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java index b0bb0d7..33a9880 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java @@ -2320,19 +2320,33 @@ public class TestConfiguration { FileUtil.fullyDelete(tmpDir); } + @Test public void testGettingPropertiesWithPrefix() throws Exception { Configuration conf = new Configuration(); 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"); -Map props = conf.getPropsWithPrefix("prefix"); -assertEquals(props.size(), 10); +Map prefixedProps = conf.getPropsWithPrefix("prefix."); +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 -props = conf.getPropsWithPrefix("none"); -assertNotNull(props.isEmpty()); -assertTrue(props.isEmpty()); +prefixedProps = conf.getPropsWithPrefix("none"); +assertNotNull(prefixedProps.isEmpty()); +assertTrue(prefixedProps.isEmpty()); } public static void main(String[] argv) throws Exception { - To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-commits-h...@hadoop.apache.org
hadoop git commit: HADOOP-15357. Configuration.getPropsWithPrefix no longer does variable substitution. Contributed by Jim Brennan
Repository: hadoop Updated Branches: refs/heads/branch-2.9 33cf224dc -> 87485d40c HADOOP-15357. Configuration.getPropsWithPrefix no longer does variable substitution. Contributed by Jim Brennan (cherry picked from commit 0fb1457d862660e14c3f5cf42d2cc5a2475ee097) Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/87485d40 Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/87485d40 Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/87485d40 Branch: refs/heads/branch-2.9 Commit: 87485d40cdade8349e088a5bcbe603fd585390af Parents: 33cf224 Author: Jason LoweAuthored: Tue Apr 10 16:44:03 2018 -0500 Committer: Jason Lowe Committed: Tue Apr 10 17:00:50 2018 -0500 -- .../org/apache/hadoop/conf/Configuration.java | 11 - .../apache/hadoop/conf/TestConfiguration.java | 25 +++- 2 files changed, 23 insertions(+), 13 deletions(-) -- http://git-wip-us.apache.org/repos/asf/hadoop/blob/87485d40/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java -- diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java index bfb1a67..802242f 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java @@ -2669,15 +2669,12 @@ public class Configuration implements Iterable >, */ public Map getPropsWithPrefix(String confPrefix) { Properties props = getProps(); -Enumeration e = props.propertyNames(); Map configMap = new HashMap<>(); -String name = null; -while (e.hasMoreElements()) { - name = (String) e.nextElement(); +for (String name : props.stringPropertyNames()) { if (name.startsWith(confPrefix)) { -String value = props.getProperty(name); -name = name.substring(confPrefix.length()); -configMap.put(name, value); +String value = get(name); +String keyName = name.substring(confPrefix.length()); +configMap.put(keyName, value); } } return configMap; http://git-wip-us.apache.org/repos/asf/hadoop/blob/87485d40/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java -- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java index bceae3c..214be63 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java @@ -1966,16 +1966,29 @@ public class TestConfiguration extends TestCase { public void testGettingPropertiesWithPrefix() throws Exception { Configuration conf = new Configuration(); 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"); -Map props = conf.getPropsWithPrefix("prefix"); -assertEquals(props.size(), 10); +Map prefixedProps = conf.getPropsWithPrefix("prefix."); +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 -props = conf.getPropsWithPrefix("none"); -assertNotNull(props.isEmpty()); -assertTrue(props.isEmpty()); +prefixedProps = conf.getPropsWithPrefix("none"); +assertNotNull(prefixedProps.isEmpty()); +assertTrue(prefixedProps.isEmpty()); } public static void main(String[] argv) throws Exception { - To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org For additional commands, e-mail:
hadoop git commit: HADOOP-15357. Configuration.getPropsWithPrefix no longer does variable substitution. Contributed by Jim Brennan
Repository: hadoop Updated Branches: refs/heads/branch-2 ea51ef44f -> 0fb1457d8 HADOOP-15357. Configuration.getPropsWithPrefix no longer does variable substitution. Contributed by Jim Brennan Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/0fb1457d Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/0fb1457d Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/0fb1457d Branch: refs/heads/branch-2 Commit: 0fb1457d862660e14c3f5cf42d2cc5a2475ee097 Parents: ea51ef4 Author: Jason LoweAuthored: Tue Apr 10 16:44:03 2018 -0500 Committer: Jason Lowe Committed: Tue Apr 10 16:59:31 2018 -0500 -- .../org/apache/hadoop/conf/Configuration.java | 11 - .../apache/hadoop/conf/TestConfiguration.java | 25 +++- 2 files changed, 23 insertions(+), 13 deletions(-) -- http://git-wip-us.apache.org/repos/asf/hadoop/blob/0fb1457d/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java -- diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java index bfb1a67..802242f 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java @@ -2669,15 +2669,12 @@ public class Configuration implements Iterable >, */ public Map getPropsWithPrefix(String confPrefix) { Properties props = getProps(); -Enumeration e = props.propertyNames(); Map configMap = new HashMap<>(); -String name = null; -while (e.hasMoreElements()) { - name = (String) e.nextElement(); +for (String name : props.stringPropertyNames()) { if (name.startsWith(confPrefix)) { -String value = props.getProperty(name); -name = name.substring(confPrefix.length()); -configMap.put(name, value); +String value = get(name); +String keyName = name.substring(confPrefix.length()); +configMap.put(keyName, value); } } return configMap; http://git-wip-us.apache.org/repos/asf/hadoop/blob/0fb1457d/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java -- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java index bceae3c..214be63 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java @@ -1966,16 +1966,29 @@ public class TestConfiguration extends TestCase { public void testGettingPropertiesWithPrefix() throws Exception { Configuration conf = new Configuration(); 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"); -Map props = conf.getPropsWithPrefix("prefix"); -assertEquals(props.size(), 10); +Map prefixedProps = conf.getPropsWithPrefix("prefix."); +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 -props = conf.getPropsWithPrefix("none"); -assertNotNull(props.isEmpty()); -assertTrue(props.isEmpty()); +prefixedProps = conf.getPropsWithPrefix("none"); +assertNotNull(prefixedProps.isEmpty()); +assertTrue(prefixedProps.isEmpty()); } public static void main(String[] argv) throws Exception { - To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-commits-h...@hadoop.apache.org
hadoop git commit: HADOOP-15357. Configuration.getPropsWithPrefix no longer does variable substitution. Contributed by Jim Brennan
Repository: hadoop Updated Branches: refs/heads/branch-3.0 afbdd8fdc -> eef5d1947 HADOOP-15357. Configuration.getPropsWithPrefix no longer does variable substitution. Contributed by Jim Brennan (cherry picked from commit e81397545a273cf9a090010eb644b836e0ef8c7b) Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/eef5d194 Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/eef5d194 Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/eef5d194 Branch: refs/heads/branch-3.0 Commit: eef5d1947e22fec89c77f47a6f462c9ce71a13f6 Parents: afbdd8f Author: Jason LoweAuthored: Tue Apr 10 16:44:03 2018 -0500 Committer: Jason Lowe Committed: Tue Apr 10 16:54:17 2018 -0500 -- .../org/apache/hadoop/conf/Configuration.java | 11 +++-- .../apache/hadoop/conf/TestConfiguration.java | 26 +++- 2 files changed, 24 insertions(+), 13 deletions(-) -- http://git-wip-us.apache.org/repos/asf/hadoop/blob/eef5d194/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java -- diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java index 7eaf00e..0d4c30a 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java @@ -2833,15 +2833,12 @@ public class Configuration implements Iterable >, */ public Map getPropsWithPrefix(String confPrefix) { Properties props = getProps(); -Enumeration e = props.propertyNames(); Map configMap = new HashMap<>(); -String name = null; -while (e.hasMoreElements()) { - name = (String) e.nextElement(); +for (String name : props.stringPropertyNames()) { if (name.startsWith(confPrefix)) { -String value = props.getProperty(name); -name = name.substring(confPrefix.length()); -configMap.put(name, value); +String value = get(name); +String keyName = name.substring(confPrefix.length()); +configMap.put(keyName, value); } } return configMap; http://git-wip-us.apache.org/repos/asf/hadoop/blob/eef5d194/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java -- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java index 1ebfa35..b11349e 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java @@ -2285,19 +2285,33 @@ public class TestConfiguration { FileUtil.fullyDelete(tmpDir); } + @Test public void testGettingPropertiesWithPrefix() throws Exception { Configuration conf = new Configuration(); 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"); -Map props = conf.getPropsWithPrefix("prefix"); -assertEquals(props.size(), 10); +Map prefixedProps = conf.getPropsWithPrefix("prefix."); +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 -props = conf.getPropsWithPrefix("none"); -assertNotNull(props.isEmpty()); -assertTrue(props.isEmpty()); +prefixedProps = conf.getPropsWithPrefix("none"); +assertNotNull(prefixedProps.isEmpty()); +assertTrue(prefixedProps.isEmpty()); } public static void main(String[] argv) throws Exception { - To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org For additional commands,
hadoop git commit: HADOOP-15357. Configuration.getPropsWithPrefix no longer does variable substitution. Contributed by Jim Brennan
Repository: hadoop Updated Branches: refs/heads/branch-3.1 3414bf6db -> ffceb907f HADOOP-15357. Configuration.getPropsWithPrefix no longer does variable substitution. Contributed by Jim Brennan (cherry picked from commit e81397545a273cf9a090010eb644b836e0ef8c7b) Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/ffceb907 Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/ffceb907 Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/ffceb907 Branch: refs/heads/branch-3.1 Commit: ffceb907fe6290ae462cadaf3942c0db3b4c9525 Parents: 3414bf6 Author: Jason LoweAuthored: Tue Apr 10 16:44:03 2018 -0500 Committer: Jason Lowe Committed: Tue Apr 10 16:49:27 2018 -0500 -- .../org/apache/hadoop/conf/Configuration.java | 11 +++-- .../apache/hadoop/conf/TestConfiguration.java | 26 +++- 2 files changed, 24 insertions(+), 13 deletions(-) -- http://git-wip-us.apache.org/repos/asf/hadoop/blob/ffceb907/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java -- diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java index 6557356..0b2196b 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java @@ -2866,15 +2866,12 @@ public class Configuration implements Iterable >, */ public Map getPropsWithPrefix(String confPrefix) { Properties props = getProps(); -Enumeration e = props.propertyNames(); Map configMap = new HashMap<>(); -String name = null; -while (e.hasMoreElements()) { - name = (String) e.nextElement(); +for (String name : props.stringPropertyNames()) { if (name.startsWith(confPrefix)) { -String value = props.getProperty(name); -name = name.substring(confPrefix.length()); -configMap.put(name, value); +String value = get(name); +String keyName = name.substring(confPrefix.length()); +configMap.put(keyName, value); } } return configMap; http://git-wip-us.apache.org/repos/asf/hadoop/blob/ffceb907/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java -- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java index f1d68cd..265e007 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java @@ -2320,19 +2320,33 @@ public class TestConfiguration { FileUtil.fullyDelete(tmpDir); } + @Test public void testGettingPropertiesWithPrefix() throws Exception { Configuration conf = new Configuration(); 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"); -Map props = conf.getPropsWithPrefix("prefix"); -assertEquals(props.size(), 10); +Map prefixedProps = conf.getPropsWithPrefix("prefix."); +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 -props = conf.getPropsWithPrefix("none"); -assertNotNull(props.isEmpty()); -assertTrue(props.isEmpty()); +prefixedProps = conf.getPropsWithPrefix("none"); +assertNotNull(prefixedProps.isEmpty()); +assertTrue(prefixedProps.isEmpty()); } public static void main(String[] argv) throws Exception { - To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org For additional commands,
hadoop git commit: HADOOP-15357. Configuration.getPropsWithPrefix no longer does variable substitution. Contributed by Jim Brennan
Repository: hadoop Updated Branches: refs/heads/trunk d55379903 -> e81397545 HADOOP-15357. Configuration.getPropsWithPrefix no longer does variable substitution. Contributed by Jim Brennan Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/e8139754 Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/e8139754 Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/e8139754 Branch: refs/heads/trunk Commit: e81397545a273cf9a090010eb644b836e0ef8c7b Parents: d553799 Author: Jason LoweAuthored: Tue Apr 10 16:44:03 2018 -0500 Committer: Jason Lowe Committed: Tue Apr 10 16:44:55 2018 -0500 -- .../org/apache/hadoop/conf/Configuration.java | 11 +++-- .../apache/hadoop/conf/TestConfiguration.java | 26 +++- 2 files changed, 24 insertions(+), 13 deletions(-) -- http://git-wip-us.apache.org/repos/asf/hadoop/blob/e8139754/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java -- diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java index 78a2e9f..f1e2a9d 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java @@ -2869,15 +2869,12 @@ public class Configuration implements Iterable >, */ public Map getPropsWithPrefix(String confPrefix) { Properties props = getProps(); -Enumeration e = props.propertyNames(); Map configMap = new HashMap<>(); -String name = null; -while (e.hasMoreElements()) { - name = (String) e.nextElement(); +for (String name : props.stringPropertyNames()) { if (name.startsWith(confPrefix)) { -String value = props.getProperty(name); -name = name.substring(confPrefix.length()); -configMap.put(name, value); +String value = get(name); +String keyName = name.substring(confPrefix.length()); +configMap.put(keyName, value); } } return configMap; http://git-wip-us.apache.org/repos/asf/hadoop/blob/e8139754/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java -- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java index b0bb0d7..33a9880 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java @@ -2320,19 +2320,33 @@ public class TestConfiguration { FileUtil.fullyDelete(tmpDir); } + @Test public void testGettingPropertiesWithPrefix() throws Exception { Configuration conf = new Configuration(); 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"); -Map props = conf.getPropsWithPrefix("prefix"); -assertEquals(props.size(), 10); +Map prefixedProps = conf.getPropsWithPrefix("prefix."); +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 -props = conf.getPropsWithPrefix("none"); -assertNotNull(props.isEmpty()); -assertTrue(props.isEmpty()); +prefixedProps = conf.getPropsWithPrefix("none"); +assertNotNull(prefixedProps.isEmpty()); +assertTrue(prefixedProps.isEmpty()); } public static void main(String[] argv) throws Exception { - To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-commits-h...@hadoop.apache.org