@Test
public void testSeek() throws IOException {

  int NUM_LINES = 1000;
  int LINE_LEN = 1000;
  generateData(file, Charsets.UTF_8, NUM_LINES, LINE_LEN);
  PositionTracker tracker = new DurablePositionTracker(meta, file.getPath());
  ResettableInputStream in = new ResettableFileInputStream(file, tracker,
      10 * LINE_LEN, Charsets.UTF_8, DecodeErrorPolicy.FAIL);
  String line = "";
  for (int i = 0; i < 9; i++) {
    line = readLine(in, LINE_LEN);
  }
  int lineNum = Integer.parseInt(line.substring(0, 10));
  assertEquals(8, lineNum);
  // seek back within our buffer
  long pos = in.tell();
  in.seek(pos - 2 * LINE_LEN); // jump back 2 lines
  line = readLine(in, LINE_LEN);
  lineNum = Integer.parseInt(line.substring(0, 10));
  assertEquals(7, lineNum);
  // seek forward within our buffer
  in.seek(in.tell() + LINE_LEN);
  line = readLine(in, LINE_LEN);
  lineNum = Integer.parseInt(line.substring(0, 10));
  assertEquals(9, lineNum);
  // seek forward outside our buffer
  in.seek(in.tell() + 20 * LINE_LEN);
  line = readLine(in, LINE_LEN);
  lineNum = Integer.parseInt(line.substring(0, 10));
  assertEquals(30, lineNum);
  // seek backward outside our buffer
  in.seek(in.tell() - 25 * LINE_LEN);
  line = readLine(in, LINE_LEN);
  lineNum = Integer.parseInt(line.substring(0, 10));
  assertEquals(6, lineNum);
  // test a corner-case seek which requires a buffer refill
  in.seek(100 * LINE_LEN);
  in.seek(0); // reset buffer
  in.seek(9 * LINE_LEN);
  assertEquals(9, Integer.parseInt(readLine(in, LINE_LEN).substring(0, 10)));
  assertEquals(10, Integer.parseInt(readLine(in, LINE_LEN).substring(0, 10)));
  assertEquals(11, Integer.parseInt(readLine(in, LINE_LEN).substring(0, 10)));
}