Add the unit test of ChannelOutboundBuffer (#10180)
Motivation: Parameter maxCount needs the unit test. Modifications: 1. Change the conditional statement to avoid the ineffective maxCount (enhance the robustness of the code merely). 2. Add the unit test for maxCount. Result: Enable this parameter to be tested.
This commit is contained in:
parent
b996bf2151
commit
2d4d64dc42
@ -452,7 +452,7 @@ public final class ChannelOutboundBuffer {
|
||||
// branch is not very likely to get hit very frequently.
|
||||
nioBufferCount = nioBuffers(entry, buf, nioBuffers, nioBufferCount, maxCount);
|
||||
}
|
||||
if (nioBufferCount == maxCount) {
|
||||
if (nioBufferCount >= maxCount) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -124,6 +124,31 @@ public class ChannelOutboundBufferTest {
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNioBuffersMaxCount() {
|
||||
TestChannel channel = new TestChannel();
|
||||
|
||||
ChannelOutboundBuffer buffer = new ChannelOutboundBuffer(channel);
|
||||
|
||||
CompositeByteBuf comp = compositeBuffer(256);
|
||||
ByteBuf buf = directBuffer().writeBytes("buf1".getBytes(CharsetUtil.US_ASCII));
|
||||
for (int i = 0; i < 65; i++) {
|
||||
comp.addComponent(true, buf.copy());
|
||||
}
|
||||
assertEquals(65, comp.nioBufferCount());
|
||||
buffer.addMessage(comp, comp.readableBytes(), channel.voidPromise());
|
||||
assertEquals("Should still be 0 as not flushed yet", 0, buffer.nioBufferCount());
|
||||
buffer.addFlush();
|
||||
final int maxCount = 10; // less than comp.nioBufferCount()
|
||||
ByteBuffer[] buffers = buffer.nioBuffers(maxCount, Integer.MAX_VALUE);
|
||||
assertTrue("Should not be greater than maxCount", buffer.nioBufferCount() <= maxCount);
|
||||
for (int i = 0; i < buffer.nioBufferCount(); i++) {
|
||||
assertEquals(buffers[i], buf.internalNioBuffer(buf.readerIndex(), buf.readableBytes()));
|
||||
}
|
||||
release(buffer);
|
||||
buf.release();
|
||||
}
|
||||
|
||||
private static void release(ChannelOutboundBuffer buffer) {
|
||||
for (;;) {
|
||||
if (!buffer.remove()) {
|
||||
|
Loading…
Reference in New Issue
Block a user