Assert.assertEquals("stuff-much more stuff", s);
}
@Test
public void testCodingFragmentBufferingChannelSaturated() throws Exception {
final WritableByteChannelMock channel = Mockito.spy(new WritableByteChannelMock(64, 8));
final SessionOutputBuffer outbuf = Mockito.spy(new SessionOutputBufferImpl(1024, 128));
final HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
final IdentityEncoder encoder = new IdentityEncoder(channel, outbuf, metrics, 3);
Assert.assertEquals(5, encoder.write(CodecTestUtils.wrap("stuff")));
Assert.assertEquals(1, encoder.write(CodecTestUtils.wrap("-")));
Assert.assertEquals(1, encoder.write(CodecTestUtils.wrap("-")));
Assert.assertEquals(1, encoder.write(CodecTestUtils.wrap("-")));
Assert.assertEquals(1, encoder.write(CodecTestUtils.wrap("-")));
Assert.assertEquals(1, encoder.write(CodecTestUtils.wrap("-")));
Assert.assertEquals(1, encoder.write(CodecTestUtils.wrap("-")));
Assert.assertEquals(0, encoder.write(CodecTestUtils.wrap("-")));
Assert.assertEquals(0, encoder.write(CodecTestUtils.wrap("more stuff")));
Mockito.verify(channel, Mockito.times(5)).write(Mockito.<ByteBuffer>any());
Mockito.verify(outbuf, Mockito.times(6)).write(Mockito.<ByteBuffer>any());
Mockito.verify(outbuf, Mockito.times(4)).flush(channel);
Assert.assertEquals(8, metrics.getBytesTransferred());
outbuf.flush(channel);
final String s = channel.dump(Consts.ASCII);
Assert.assertEquals("stuff---", s);
Assert.assertEquals(3, outbuf.length());
}