HADOOP-16265. Fix bug causing Configuration#getTimeDuration to use incorrect units when the default value is used. Contributed by starphin.

(cherry-picked from 1ddb48872f)
This commit is contained in:
Erik Krogen 2019-04-22 08:16:57 -07:00 committed by Erik Krogen
parent ac85aa80d9
commit 28ff96f367
2 changed files with 5 additions and 1 deletions

View File

@ -1810,7 +1810,7 @@ public class Configuration implements Iterable<Map.Entry<String,String>>,
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);
}

View File

@ -1401,6 +1401,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));