|
@@ -44,6 +44,26 @@ public class TestWritableUtils extends TestCase {
|
|
assertEquals(vintlen, WritableUtils.getVIntSize(val));
|
|
assertEquals(vintlen, WritableUtils.getVIntSize(val));
|
|
assertEquals(vintlen, WritableUtils.decodeVIntSize(buf.getData()[0]));
|
|
assertEquals(vintlen, WritableUtils.decodeVIntSize(buf.getData()[0]));
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ public static void testReadInRange(long val, int lower,
|
|
|
|
+ int upper, boolean expectSuccess) throws IOException {
|
|
|
|
+ DataOutputBuffer buf = new DataOutputBuffer();
|
|
|
|
+ DataInputBuffer inbuf = new DataInputBuffer();
|
|
|
|
+ WritableUtils.writeVLong(buf, val);
|
|
|
|
+ try {
|
|
|
|
+ inbuf.reset(buf.getData(), 0, buf.getLength());
|
|
|
|
+ long val2 = WritableUtils.readVIntInRange(inbuf, lower, upper);
|
|
|
|
+ if (!expectSuccess) {
|
|
|
|
+ fail("expected readVIntInRange to throw an exception");
|
|
|
|
+ }
|
|
|
|
+ assertEquals(val, val2);
|
|
|
|
+ } catch(IOException e) {
|
|
|
|
+ if (expectSuccess) {
|
|
|
|
+ LOG.error("unexpected exception:", e);
|
|
|
|
+ fail("readVIntInRange threw an unexpected exception");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
public static void testVInt() throws Exception {
|
|
public static void testVInt() throws Exception {
|
|
testValue(12, 1);
|
|
testValue(12, 1);
|
|
@@ -61,5 +81,10 @@ public class TestWritableUtils extends TestCase {
|
|
testValue(-65536, 3);
|
|
testValue(-65536, 3);
|
|
testValue(65536, 4);
|
|
testValue(65536, 4);
|
|
testValue(-65537, 4);
|
|
testValue(-65537, 4);
|
|
|
|
+ testReadInRange(123, 122, 123, true);
|
|
|
|
+ testReadInRange(123, 0, 100, false);
|
|
|
|
+ testReadInRange(0, 0, 100, true);
|
|
|
|
+ testReadInRange(-1, 0, 100, false);
|
|
|
|
+ testReadInRange(1099511627776L, 0, Integer.MAX_VALUE, false);
|
|
}
|
|
}
|
|
}
|
|
}
|