@@ -218,7 +218,7 @@ public void testReadMultiFourBytesLimit() throws IOException {
218218 assertThat (is .read (read ), equalTo (-1 ));
219219 }
220220
221- public void testMarkRest () throws Exception {
221+ public void testMarkReset () throws Exception {
222222 Directory dir = new ByteBuffersDirectory ();
223223 IndexOutput output = dir .createOutput ("test" , IOContext .DEFAULT );
224224 for (int i = 0 ; i < 3 ; i ++) {
@@ -243,6 +243,41 @@ public void testMarkRest() throws Exception {
243243 assertThat (is .read (), equalTo (2 ));
244244 }
245245
246+ public void testSkipBytes () throws Exception {
247+ Directory dir = new ByteBuffersDirectory ();
248+ IndexOutput output = dir .createOutput ("test" , IOContext .DEFAULT );
249+ int bytes = randomIntBetween (10 , 100 );
250+ for (int i = 0 ; i < bytes ; i ++) {
251+ output .writeByte ((byte ) i );
252+ }
253+ output .close ();
254+
255+ int limit = randomIntBetween (0 , bytes * 2 );
256+ int initialReadBytes = randomIntBetween (0 , limit );
257+ int skipBytes = randomIntBetween (0 , limit );
258+ int seekExpected = Math .min (Math .min (initialReadBytes + skipBytes , limit ), bytes );
259+ int skipBytesExpected = Math .max (seekExpected - initialReadBytes , 0 );
260+ logger .debug (
261+ "bytes: {}, limit: {}, initialReadBytes: {}, skipBytes: {}, seekExpected: {}, skipBytesExpected: {}" ,
262+ bytes ,
263+ limit ,
264+ initialReadBytes ,
265+ skipBytes ,
266+ seekExpected ,
267+ skipBytesExpected
268+ );
269+
270+ IndexInput input = dir .openInput ("test" , IOContext .DEFAULT );
271+ InputStreamIndexInput is = new InputStreamIndexInput (input , limit );
272+ is .readNBytes (initialReadBytes );
273+ assertThat (is .skip (skipBytes ), equalTo ((long ) skipBytesExpected ));
274+
275+ int remainingBytes = Math .min (bytes , limit ) - seekExpected ;
276+ for (int i = seekExpected ; i < seekExpected + remainingBytes ; i ++) {
277+ assertThat (is .read (), equalTo (i ));
278+ }
279+ }
280+
246281 public void testReadZeroShouldReturnZero () throws IOException {
247282 try (Directory dir = new ByteBuffersDirectory ()) {
248283 try (IndexOutput output = dir .createOutput ("test" , IOContext .DEFAULT )) {
0 commit comments