HADOOP-16265. Fix bug causing Configuration#getTimeDuration to use incorrect units when the default value is used. Contributed by starphin.
(cherry-picked from1ddb48872f
) (cherry-picked from28ff96f367
)
This commit is contained in:
parent
8b228a42e9
commit
9da70a1b4b
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
|
|
Loading…
Reference in New Issue