Add another test case for channelReadComplete() suppression
Related commit:
- a41b46ff43
Motivation:
We need a test case for the commit above.
This commit is contained in:
parent
f7ccdd5d3b
commit
5fca3de098
@ -621,6 +621,44 @@ public class DefaultChannelPipelineTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link ChannelInboundHandler#channelReadComplete(ChannelHandlerContext)} should not be suppressed
|
||||||
|
* when a handler has just been added and thus had no chance to get the previous
|
||||||
|
* {@link ChannelInboundHandler#channelRead(ChannelHandlerContext, Object)}.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testProhibitChannelReadCompleteSuppression() throws Exception {
|
||||||
|
final AtomicInteger readComplete = new AtomicInteger();
|
||||||
|
|
||||||
|
EmbeddedChannel ch = new EmbeddedChannel(new ChannelInboundHandlerAdapter() {
|
||||||
|
@Override
|
||||||
|
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
|
||||||
|
ctx.fireChannelRead(msg);
|
||||||
|
|
||||||
|
// Add a new handler *after* channelRead() is triggered, so that
|
||||||
|
// the new handler does not handle channelRead() at all.
|
||||||
|
ctx.pipeline().addAfter(ctx.name(), "newHandler", new ChannelInboundHandlerAdapter() {
|
||||||
|
@Override
|
||||||
|
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
|
||||||
|
readComplete.incrementAndGet();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
|
||||||
|
ctx.fireChannelReadComplete();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ChannelPipeline p = ch.pipeline();
|
||||||
|
p.fireChannelRead(Boolean.TRUE);
|
||||||
|
p.fireChannelReadComplete();
|
||||||
|
ch.finish();
|
||||||
|
|
||||||
|
assertEquals(1, readComplete.get());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testChannelReadTriggered() {
|
public void testChannelReadTriggered() {
|
||||||
final AtomicInteger read1 = new AtomicInteger();
|
final AtomicInteger read1 = new AtomicInteger();
|
||||||
|
Loading…
Reference in New Issue
Block a user