Fix test failures n LocalTransportThreadModelTest

testConcurrentMessageBufferAccess() assumes the outbound/inbound byte buffers are unbounded.  Because PooledByteBuf is bounded, the test did not pass.

The fix makes an assumption that ctx.flush() or fireInboundBufferUpdated() will make the next buffer consumed immediately, which is not the case in the real world.  Under network congestion, a user will see IndexOutOfBoundsException if the user's handler implementation writes boundlessly into inbound/outbound buffers.
This commit is contained in:
Trustin Lee 2012-12-10 20:22:19 +09:00 committed by Norman Maurer
parent bf8345999c
commit 321b18d4d1

View File

@ -436,8 +436,13 @@ public class LocalTransportThreadModelTest {
int expected = inCnt ++; int expected = inCnt ++;
Assert.assertEquals(expected, msg.intValue()); Assert.assertEquals(expected, msg.intValue());
if (out.maxCapacity() - out.writerIndex() < 4) {
// Next inbound buffer is full - attempt to flush some data.
ctx.fireInboundBufferUpdated();
}
out.writeInt(msg); out.writeInt(msg);
} }
ctx.fireInboundBufferUpdated(); ctx.fireInboundBufferUpdated();
} }
@ -534,7 +539,7 @@ public class LocalTransportThreadModelTest {
} }
@Override @Override
public void flush(ChannelHandlerContext ctx, public void flush(final ChannelHandlerContext ctx,
ChannelFuture future) throws Exception { ChannelFuture future) throws Exception {
Assert.assertSame(t, Thread.currentThread()); Assert.assertSame(t, Thread.currentThread());
@ -549,8 +554,15 @@ public class LocalTransportThreadModelTest {
int expected = outCnt ++; int expected = outCnt ++;
Assert.assertEquals(expected, msg.intValue()); Assert.assertEquals(expected, msg.intValue());
if (out.maxCapacity() - out.writerIndex() < 4) {
// Next outbound buffer is full - attempt to flush some data.
ctx.flush();
}
out.writeInt(msg); out.writeInt(msg);
} }
ctx.flush(future); ctx.flush(future);
} }