@Test
  public void badInputStreamTest() throws Exception {
    final String errMsg = "@@ExpectedExceptionMessage@@";
    InputStream stream = new InputStream() {
      @Override
      public int read() throws IOException {
        // this represents any exception - bad behavior or closure before being read completely.
        throw new IllegalStateException(errMsg);
      }
    };

    InputStreamReadableStreamChannel channel = new InputStreamReadableStreamChannel(stream, EXECUTOR_SERVICE);
    ReadIntoCallback callback = new ReadIntoCallback();
    try {
      channel.readInto(new BadAsyncWritableChannel(new IOException(errMsg)), callback).get();
      fail("Should have failed because the InputStream would have thrown exception");
    } catch (ExecutionException e) {
      Exception exception = (Exception) Utils.getRootCause(e);
      assertEquals("Exception message does not match expected (future)", errMsg, exception.getMessage());
      callback.awaitCallback();
      assertEquals("Exception message does not match expected (callback)", errMsg, callback.exception.getMessage());
    }
  }
Tests that the right exceptions are thrown when the provided {@link InputStream} has unexpected behavior.
@throws Exception
ambry-commons/src/test/java/com/github/ambry/commons/InputStreamReadableStreamChannelTest.java