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 b91c9eff2a3..f62a715a102 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 @@ -1810,7 +1810,7 @@ public class Configuration implements Iterable>, TimeUnit defaultUnit, TimeUnit returnUnit) { String vStr = get(name); if (null == vStr) { - return defaultValue; + return returnUnit.convert(defaultValue, defaultUnit); } else { return getTimeDurationHelper(name, vStr, defaultUnit, returnUnit); } 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 a8bca131d4b..0703fe729e8 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 @@ -1402,6 +1402,10 @@ public class TestConfiguration { @Test public void testTimeDuration() { Configuration conf = new Configuration(false); + + assertEquals(7000L, + conf.getTimeDuration("test.time.a", 7L, SECONDS, MILLISECONDS)); + conf.setTimeDuration("test.time.a", 7L, SECONDS); assertEquals("7s", conf.get("test.time.a")); assertEquals(0L, conf.getTimeDuration("test.time.a", 30, MINUTES));