@Test
  public void messageReadSetIndexInputStreamTestException() throws Exception {
    ArrayList<ByteBuffer> listBuf = new ArrayList<ByteBuffer>();
    byte[] buf = new byte[1024];
    new Random().nextBytes(buf);
    listBuf.add(ByteBuffer.wrap(buf));
    ArrayList<StoreKey> storeKeys = new ArrayList<StoreKey>();
    storeKeys.add(new MockId("012345678910123223233456789012"));
    MessageReadSet readSet = new MockMessageReadSet(listBuf, storeKeys);
    MessageReadSetIndexInputStream stream = new MessageReadSetIndexInputStream(readSet, 0, 0);
    byte[] bufOutput = new byte[1024];
    Assert.assertEquals("Should return 0 if length requested is 0", 0, stream.read(bufOutput, 0, 0));
    Assert.assertEquals("Should return 0 if length requested is 0", 0, stream.read(bufOutput, 1, 0));
    try {
      stream.read(bufOutput, -1, 10);
      Assert.fail("IndexOutOfBoundsException is expected.");
    } catch (IndexOutOfBoundsException e) {
    }
    try {
      stream.read(bufOutput, 0, -1);
      Assert.fail("IndexOutOfBoundsException is expected.");
    } catch (IndexOutOfBoundsException e) {
    }
    try {
      stream.read(bufOutput, 1, 1024);
      Assert.fail("IndexOutOfBoundsException is expected.");
    } catch (IndexOutOfBoundsException e) {
    }
    stream.read(bufOutput, 0, 1024);
    Assert.assertArrayEquals("Output doesn't match", bufOutput, buf);
    Assert.assertEquals("Should return -1 if no more data", -1, stream.read());
    Assert.assertEquals("Should return -1 if no more data", -1, stream.read(bufOutput, 0, 1));
  }
Test Exceptions cases for {@link MessageReadSetIndexInputStream}
IndexOutOfBoundsException should be thrown if offset or length is invalid.
0 is expected if length requested is 0.
-1 is expected if no more data available.
ambry-messageformat/src/test/java/com/github/ambry/messageformat/MessageFormatSendTest.java