public void testProduceOutputLongMessageSaturatedChannel() throws Exception {
final BasicHttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
final NStringEntity entity = new NStringEntity("a lot of various stuff");
response.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 ResponseReadyAnswer(response)).when(
handler).responseReady(Mockito.<NHttpServerConnection>any());
Mockito.doAnswer(new ProduceContentAnswer(entity)).when(
handler).outputReady(Mockito.<NHttpServerConnection>any(), Mockito.<ContentEncoder>any());
conn.produceOutput(handler);
Assert.assertNull(conn.getHttpResponse());
Assert.assertNull(conn.contentEncoder);
Assert.assertEquals("HTTP/1.1 200 OK\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());
}