@Test
public void testDropUntilNewLine() {

  long maxSz = FlumeConfiguration.get().getEventMaxSizeBytes();
  ByteBuffer buf = ByteBuffer.allocate((int) maxSz * 4);
  // Empty Case
  boolean ret = ExecNioSource.dropUntilNewLine(buf);
  assertTrue(ret); // not new line yet
  assertEquals(0, buf.position());
  // Overflow Case
  // this should fill the buffer and but progress should be made.
  for (int i = 0; i < maxSz; i++) {
    buf.put((byte) 'a');
  }
  ret = ExecNioSource.dropUntilNewLine(buf);
  assertTrue(ret);
  assertEquals(0, buf.position()); // should have buffer cleared
  buf.put((byte) '\n');
  buf.put((byte) 'd');
  ret = ExecNioSource.dropUntilNewLine(buf);
  assertFalse(ret);
  assertEquals(1, buf.position()); // should have buffer cleared
  buf.clear();
  // Normal Case
  for (int i = 0; i < maxSz; i++) {
    if (i % 1024 == 1023) {
      buf.put((byte) '\n');
    } else {
      buf.put((byte) 'b');
    }
  }
  ret = ExecNioSource.dropUntilNewLine(buf);
  assertFalse(ret);
  // cleared until first '\n' then and leaves remaining data
  assertEquals(maxSz - 1024, buf.position());
}