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

(cherry-picked from 1ddb48872f)
(cherry-picked from 28ff96f367)
This commit is contained in:
Erik Krogen 2019-04-22 08:16:57 -07:00 committed by Erik Krogen
parent 8b228a42e9
commit 9da70a1b4b
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

@ -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));