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:
parent
ac85aa80d9
commit
28ff96f367
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
|
|
Loading…
Reference in New Issue