HADOOP-16265. Fix bug causing Configuration#getTimeDuration to use incorrect units when the default value is used. Contributed by starphin.
This commit is contained in:
parent
adefd37105
commit
1ddb48872f
@ -1840,7 +1840,7 @@ public long getTimeDuration(String name, long defaultValue,
|
|||||||
TimeUnit defaultUnit, TimeUnit returnUnit) {
|
TimeUnit defaultUnit, TimeUnit returnUnit) {
|
||||||
String vStr = get(name);
|
String vStr = get(name);
|
||||||
if (null == vStr) {
|
if (null == vStr) {
|
||||||
return defaultValue;
|
return returnUnit.convert(defaultValue, defaultUnit);
|
||||||
} else {
|
} else {
|
||||||
return getTimeDurationHelper(name, vStr, defaultUnit, returnUnit);
|
return getTimeDurationHelper(name, vStr, defaultUnit, returnUnit);
|
||||||
}
|
}
|
||||||
|
@ -1401,6 +1401,10 @@ public void testEnumFromXml() throws IOException {
|
|||||||
@Test
|
@Test
|
||||||
public void testTimeDuration() {
|
public void testTimeDuration() {
|
||||||
Configuration conf = new Configuration(false);
|
Configuration conf = new Configuration(false);
|
||||||
|
|
||||||
|
assertEquals(7000L,
|
||||||
|
conf.getTimeDuration("test.time.a", 7L, SECONDS, MILLISECONDS));
|
||||||
|
|
||||||
conf.setTimeDuration("test.time.a", 7L, SECONDS);
|
conf.setTimeDuration("test.time.a", 7L, SECONDS);
|
||||||
assertEquals("7s", conf.get("test.time.a"));
|
assertEquals("7s", conf.get("test.time.a"));
|
||||||
assertEquals(0L, conf.getTimeDuration("test.time.a", 30, MINUTES));
|
assertEquals(0L, conf.getTimeDuration("test.time.a", 30, MINUTES));
|
||||||
|
Loading…
Reference in New Issue
Block a user