HDFS-7818. OffsetParam should return the default value instead of throwing NPE when the value is unspecified. Contributed by Eric Payne.

This commit is contained in:
Haohui Mai 2015-03-06 14:26:23 -08:00
parent 21101c01f2
commit c79710302e
4 changed files with 28 additions and 1 deletions

View File

@ -1107,6 +1107,9 @@ Release 2.7.0 - UNRELEASED
HDFS-7885. Datanode should not trust the generation stamp provided by HDFS-7885. Datanode should not trust the generation stamp provided by
client. (Tsz Wo Nicholas Sze via jing9) client. (Tsz Wo Nicholas Sze via jing9)
HDFS-7818. OffsetParam should return the default value instead of throwing
NPE when the value is unspecified. (Eric Payne via wheat9)
BREAKDOWN OF HDFS-7584 SUBTASKS AND RELATED JIRAS BREAKDOWN OF HDFS-7584 SUBTASKS AND RELATED JIRAS
HDFS-7720. Quota by Storage Type API, tools and ClientNameNode HDFS-7720. Quota by Storage Type API, tools and ClientNameNode

View File

@ -62,7 +62,7 @@ class ParameterParser {
} }
long offset() { long offset() {
return new OffsetParam(param(OffsetParam.NAME)).getValue(); return new OffsetParam(param(OffsetParam.NAME)).getOffset();
} }
String namenodeId() { String namenodeId() {

View File

@ -46,4 +46,9 @@ public class OffsetParam extends LongParam {
public String getName() { public String getName() {
return NAME; return NAME;
} }
public Long getOffset() {
Long offset = getValue();
return (offset == null) ? Long.valueOf(0) : offset;
}
} }

View File

@ -23,6 +23,7 @@ import org.apache.hadoop.hdfs.HAUtil;
import org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenIdentifier; import org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenIdentifier;
import org.apache.hadoop.hdfs.web.resources.DelegationParam; import org.apache.hadoop.hdfs.web.resources.DelegationParam;
import org.apache.hadoop.hdfs.web.resources.NamenodeAddressParam; import org.apache.hadoop.hdfs.web.resources.NamenodeAddressParam;
import org.apache.hadoop.hdfs.web.resources.OffsetParam;
import org.apache.hadoop.security.token.Token; import org.apache.hadoop.security.token.Token;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
@ -65,4 +66,22 @@ public class TestParameterParser {
ParameterParser testParser = new ParameterParser(decoder, conf); ParameterParser testParser = new ParameterParser(decoder, conf);
Assert.assertEquals(EXPECTED_PATH, testParser.path()); Assert.assertEquals(EXPECTED_PATH, testParser.path());
} }
@Test
public void testOffset() throws IOException {
final long X = 42;
long offset = new OffsetParam(Long.toString(X)).getOffset();
Assert.assertEquals("OffsetParam: ", X, offset);
offset = new OffsetParam((String) null).getOffset();
Assert.assertEquals("OffsetParam with null should have defaulted to 0", 0, offset);
try {
offset = new OffsetParam("abc").getValue();
Assert.fail("OffsetParam with nondigit value should have thrown IllegalArgumentException");
} catch (IllegalArgumentException iae) {
// Ignore
}
}
} }