@@ -21,4 +21,52 @@ protected StreamInput getStreamInput(BytesReference bytesReference) throws IOExc
2121 final BytesRef bytesRef = bytesReference .toBytesRef ();
2222 return new ByteBufferStreamInput (ByteBuffer .wrap (bytesRef .bytes , bytesRef .offset , bytesRef .length ));
2323 }
24+
25+ public void testReadVLongNegative () throws IOException {
26+ for (int i = 0 ; i < 1024 ; i ++) {
27+ long write = randomNegativeLong ();
28+ BytesStreamOutput out = new BytesStreamOutput ();
29+ out .writeVLongNoCheck (write );
30+ long read = getStreamInput (out .bytes ()).readVLong ();
31+ assertEquals (write , read );
32+ }
33+ }
34+
35+ public void testReadVLongBounds () throws IOException {
36+ long write = Long .MAX_VALUE ;
37+ BytesStreamOutput out = new BytesStreamOutput ();
38+ out .writeVLongNoCheck (write );
39+ long read = getStreamInput (out .bytes ()).readVLong ();
40+ assertEquals (write , read );
41+
42+ write = Long .MIN_VALUE ;
43+ out = new BytesStreamOutput ();
44+ out .writeVLongNoCheck (write );
45+ read = getStreamInput (out .bytes ()).readVLong ();
46+ assertEquals (write , read );
47+ }
48+
49+ public void testReadVIntNegative () throws IOException {
50+ for (int i = 0 ; i < 1024 ; i ++) {
51+ int write = randomNegativeInt ();
52+ BytesStreamOutput out = new BytesStreamOutput ();
53+ out .writeVInt (write );
54+ int read = getStreamInput (out .bytes ()).readVInt ();
55+ assertEquals (write , read );
56+ }
57+ }
58+
59+ public void testReadVIntBounds () throws IOException {
60+ int write = Integer .MAX_VALUE ;
61+ BytesStreamOutput out = new BytesStreamOutput ();
62+ out .writeVInt (write );
63+ long read = getStreamInput (out .bytes ()).readVInt ();
64+ assertEquals (write , read );
65+
66+ write = Integer .MIN_VALUE ;
67+ out = new BytesStreamOutput ();
68+ out .writeVInt (write );
69+ read = getStreamInput (out .bytes ()).readVInt ();
70+ assertEquals (write , read );
71+ }
2472}
0 commit comments