Return-Path: X-Original-To: apmail-hadoop-common-commits-archive@www.apache.org Delivered-To: apmail-hadoop-common-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 088BB10C3E for ; Mon, 16 Feb 2015 18:31:16 +0000 (UTC) Received: (qmail 7018 invoked by uid 500); 16 Feb 2015 18:31:09 -0000 Delivered-To: apmail-hadoop-common-commits-archive@hadoop.apache.org Received: (qmail 6343 invoked by uid 500); 16 Feb 2015 18:31:09 -0000 Mailing-List: contact common-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: common-dev@hadoop.apache.org Delivered-To: mailing list common-commits@hadoop.apache.org Received: (qmail 5489 invoked by uid 99); 16 Feb 2015 18:31:08 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 16 Feb 2015 18:31:08 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 8A76AE0663; Mon, 16 Feb 2015 18:31:08 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: zhz@apache.org To: common-commits@hadoop.apache.org Date: Mon, 16 Feb 2015 18:31:14 -0000 Message-Id: <6f8b0d56746f474fa4432465d0763a10@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [07/50] [abbrv] hadoop git commit: HADOOP-9869. Configuration.getSocketAddr()/getEnum() should use getTrimmed(). Contributed by Tsuyoshi Ozawa. HADOOP-9869. Configuration.getSocketAddr()/getEnum() should use getTrimmed(). Contributed by Tsuyoshi Ozawa. Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/b12bedef Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/b12bedef Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/b12bedef Branch: refs/heads/HDFS-7285 Commit: b12bedef6ed6b00ffd48efbba69b58c1db73d127 Parents: 90741b1 Author: Akira Ajisaka Authored: Thu Feb 12 15:50:48 2015 -0800 Committer: Zhe Zhang Committed: Mon Feb 16 10:29:47 2015 -0800 ---------------------------------------------------------------------- hadoop-common-project/hadoop-common/CHANGES.txt | 3 ++ .../org/apache/hadoop/conf/Configuration.java | 6 ++-- .../apache/hadoop/conf/TestConfiguration.java | 29 +++++++++++++++++++- 3 files changed, 35 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/b12bedef/hadoop-common-project/hadoop-common/CHANGES.txt ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index 7078d42..c11e340 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -597,6 +597,9 @@ Release 2.7.0 - UNRELEASED HADOOP-11586. Update use of Iterator to Iterable in AbstractMetricsContext.java. (Ray Chiang via aajisaka) + HADOOP-9869. Configuration.getSocketAddr()/getEnum() should use + getTrimmed(). (Tsuyoshi Ozawa via aajisaka) + OPTIMIZATIONS HADOOP-11323. WritableComparator#compare keeps reference to byte array. http://git-wip-us.apache.org/repos/asf/hadoop/blob/b12bedef/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 ea0d3a6..02654b7 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 @@ -1491,13 +1491,14 @@ public class Configuration implements Iterable>, /** * Return value matching this enumerated type. + * Note that the returned value is trimmed by this method. * @param name Property name * @param defaultValue Value returned if no mapping exists * @throws IllegalArgumentException If mapping is illegal for the type * provided */ public > T getEnum(String name, T defaultValue) { - final String val = get(name); + final String val = getTrimmed(name); return null == val ? defaultValue : Enum.valueOf(defaultValue.getDeclaringClass(), val); @@ -1594,6 +1595,7 @@ public class Configuration implements Iterable>, * Get the value of the name property as a Pattern. * If no such property is specified, or if the specified value is not a valid * Pattern, then DefaultValue is returned. + * Note that the returned value is NOT trimmed by this method. * * @param name property name * @param defaultValue default value @@ -2044,7 +2046,7 @@ public class Configuration implements Iterable>, */ public InetSocketAddress getSocketAddr( String name, String defaultAddress, int defaultPort) { - final String address = get(name, defaultAddress); + final String address = getTrimmed(name, defaultAddress); return NetUtils.createSocketAddr(address, defaultPort, name); } http://git-wip-us.apache.org/repos/asf/hadoop/blob/b12bedef/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 b84045d..a367553 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 @@ -56,6 +56,7 @@ public class TestConfiguration extends TestCase { private Configuration conf; final static String CONFIG = new File("./test-config-TestConfiguration.xml").getAbsolutePath(); final static String CONFIG2 = new File("./test-config2-TestConfiguration.xml").getAbsolutePath(); + final static String CONFIG_FOR_ENUM = new File("./test-config-enum-TestConfiguration.xml").getAbsolutePath(); private static final String CONFIG_MULTI_BYTE = new File( "./test-config-multi-byte-TestConfiguration.xml").getAbsolutePath(); private static final String CONFIG_MULTI_BYTE_SAVED = new File( @@ -76,6 +77,7 @@ public class TestConfiguration extends TestCase { super.tearDown(); new File(CONFIG).delete(); new File(CONFIG2).delete(); + new File(CONFIG_FOR_ENUM).delete(); new File(CONFIG_MULTI_BYTE).delete(); new File(CONFIG_MULTI_BYTE_SAVED).delete(); } @@ -792,6 +794,7 @@ public class TestConfiguration extends TestCase { conf.setEnum("test.enum", Dingo.FOO); assertSame(Dingo.FOO, conf.getEnum("test.enum", Dingo.BAR)); assertSame(Yak.FOO, conf.getEnum("test.enum", Yak.RAB)); + conf.setEnum("test.enum", Dingo.FOO); boolean fail = false; try { conf.setEnum("test.enum", Dingo.BAR); @@ -802,6 +805,26 @@ public class TestConfiguration extends TestCase { assertTrue(fail); } + public void testEnumFromXml() throws IOException { + out=new BufferedWriter(new FileWriter(CONFIG_FOR_ENUM)); + startConfig(); + appendProperty("test.enum"," \t \n FOO \t \n"); + appendProperty("test.enum2"," \t \n Yak.FOO \t \n"); + endConfig(); + + Configuration conf = new Configuration(); + Path fileResource = new Path(CONFIG_FOR_ENUM); + conf.addResource(fileResource); + assertSame(Yak.FOO, conf.getEnum("test.enum", Yak.FOO)); + boolean fail = false; + try { + conf.getEnum("test.enum2", Yak.FOO); + } catch (IllegalArgumentException e) { + fail = true; + } + assertTrue(fail); + } + public void testTimeDuration() { Configuration conf = new Configuration(false); conf.setTimeDuration("test.time.a", 7L, SECONDS); @@ -918,7 +941,11 @@ public class TestConfiguration extends TestCase { conf.set("myAddress", "host2:3"); addr = conf.getSocketAddr("myAddress", defaultAddr, defaultPort); assertEquals("host2:3", NetUtils.getHostPortString(addr)); - + + conf.set("myAddress", " \n \t host4:5 \t \n "); + addr = conf.getSocketAddr("myAddress", defaultAddr, defaultPort); + assertEquals("host4:5", NetUtils.getHostPortString(addr)); + boolean threwException = false; conf.set("myAddress", "bad:-port"); try {