Skip to content

Commit

Permalink
Revert "Add another test case for channelReadComplete() suppression"
Browse files Browse the repository at this point in the history
This reverts commit 8f4ead0.
  • Loading branch information
normanmaurer committed Apr 20, 2015
1 parent b63fe25 commit 55afb90
Showing 1 changed file with 8 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ private static void testSupressChannelReadComplete0(boolean executors) throws Ex
EmbeddedChannel ch = new EmbeddedChannel(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) throws Exception {
ch.pipeline().addLast(group, new ChannelHandlerAdapter() {
ch.pipeline().addLast(group, new ChannelInboundHandlerAdapter() {
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
if (read1.incrementAndGet() == 1) {
Expand All @@ -593,7 +593,7 @@ public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
ctx.fireChannelReadComplete();
}
});
ch.pipeline().addLast(group, new ChannelHandlerAdapter() {
ch.pipeline().addLast(group, new ChannelInboundHandlerAdapter() {
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
read2.incrementAndGet();
Expand Down Expand Up @@ -634,44 +634,6 @@ public void channelInactive(ChannelHandlerContext ctx) throws Exception {
}
}

/**
* {@link ChannelHandler#channelReadComplete(ChannelHandlerContext)} should not be suppressed
* when a handler has just been added and thus had no chance to get the previous
* {@link ChannelHandler#channelRead(ChannelHandlerContext, Object)}.
*/
@Test
public void testProhibitChannelReadCompleteSuppression() throws Exception {
final AtomicInteger readComplete = new AtomicInteger();

EmbeddedChannel ch = new EmbeddedChannel(new ChannelHandlerAdapter() {
@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 ChannelHandlerAdapter() {
@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
public void testChannelReadTriggered() {
final AtomicInteger read1 = new AtomicInteger();
Expand All @@ -684,7 +646,7 @@ public void testChannelReadTriggered() {
final AtomicInteger channelRead3 = new AtomicInteger();
final AtomicInteger channelReadComplete3 = new AtomicInteger();

EmbeddedChannel ch = new EmbeddedChannel(new ChannelHandlerAdapter() {
EmbeddedChannel ch = new EmbeddedChannel(new ChannelDuplexHandler() {
@Override
public void read(ChannelHandlerContext ctx) throws Exception {
read1.incrementAndGet();
Expand All @@ -702,7 +664,7 @@ public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
channelReadComplete1.incrementAndGet();
ctx.fireChannelReadComplete();
}
}, new ChannelHandlerAdapter() {
}, new ChannelDuplexHandler() {
@Override
public void read(ChannelHandlerContext ctx) throws Exception {
read2.incrementAndGet();
Expand All @@ -720,7 +682,7 @@ public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
channelReadComplete2.incrementAndGet();
ctx.fireChannelReadComplete();
}
}, new ChannelHandlerAdapter() {
}, new ChannelDuplexHandler() {
@Override
public void read(ChannelHandlerContext ctx) throws Exception {
read3.incrementAndGet();
Expand Down Expand Up @@ -770,15 +732,15 @@ public void testChannelReadNotTriggeredWhenLast() throws Exception {
final AtomicInteger channelRead2 = new AtomicInteger();
final AtomicInteger channelReadComplete2 = new AtomicInteger();

EmbeddedChannel ch = new EmbeddedChannel(new ChannelHandlerAdapter());
EmbeddedChannel ch = new EmbeddedChannel(new ChannelInboundHandlerAdapter());

// Ensure pipeline is really empty
ChannelPipeline pipeline = ch.pipeline();
while (pipeline.first() != null) {
pipeline.removeFirst();
}

pipeline.addLast(new ChannelHandlerAdapter() {
pipeline.addLast(new ChannelDuplexHandler() {
@Override
public void read(ChannelHandlerContext ctx) throws Exception {
read1.incrementAndGet();
Expand All @@ -796,7 +758,7 @@ public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
channelReadComplete1.incrementAndGet();
ctx.fireChannelReadComplete();
}
}, new ChannelHandlerAdapter() {
}, new ChannelDuplexHandler() {
@Override
public void read(ChannelHandlerContext ctx) throws Exception {
read2.incrementAndGet();
Expand Down

0 comments on commit 55afb90

Please sign in to comment.