public void testProduceOutputLongMessageSaturatedChannel() throws Exception {
final BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", "/");
final NStringEntity entity = new NStringEntity("a lot of various stuff");
request.setEntity(entity);
final WritableByteChannelMock wchannel = Mockito.spy(new WritableByteChannelMock(64, 24));
final ByteChannelMock channel = new ByteChannelMock(null, wchannel);
Mockito.when(session.channel()).thenReturn(channel);
Mockito.doAnswer(new RequestReadyAnswer(request)).when(
handler).requestReady(Mockito.<NHttpClientConnection>any());
Mockito.doAnswer(new ProduceContentAnswer(entity)).when(
handler).outputReady(Mockito.<NHttpClientConnection>any(), Mockito.<ContentEncoder>any());
conn.produceOutput(handler);
Assert.assertNull(conn.getHttpRequest());
Assert.assertNull(conn.contentEncoder);
Assert.assertEquals("POST / HTTP/1.1\r\n\r\na lot", wchannel.dump(Consts.ASCII));
Assert.assertEquals(17, conn.outbuf.length());
Mockito.verify(session, Mockito.never()).clearEvent(SelectionKey.OP_WRITE);
Mockito.verify(wchannel, Mockito.times(2)).write(Matchers.<ByteBuffer>any());
}