This closes #3252
This commit is contained in:
commit
3152521864
|
@ -63,5 +63,7 @@ public class WebSocketFrameEncoder extends ChannelOutboundHandlerAdapter {
|
|||
byteBuf.readBytes(fragment, length);
|
||||
ctx.writeAndFlush(new ContinuationWebSocketFrame(finalFragment, 0, fragment), promise);
|
||||
}
|
||||
|
||||
byteBuf.release();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ import static org.mockito.Mockito.verifyZeroInteractions;
|
|||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
|
||||
import io.netty.buffer.ByteBufUtil;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
@ -75,6 +76,28 @@ public class WebSocketFrameEncoderTest {
|
|||
verifyZeroInteractions(promise);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteReleaseBuffer() throws Exception {
|
||||
String content = "Buffer should be released";
|
||||
|
||||
int utf8Bytes = ByteBufUtil.utf8Bytes(content);
|
||||
ByteBuf msg = Unpooled.directBuffer(utf8Bytes);
|
||||
ByteBufUtil.reserveAndWriteUtf8(msg, content, utf8Bytes);
|
||||
|
||||
ArgumentCaptor<WebSocketFrame> frameCaptor = ArgumentCaptor.forClass(WebSocketFrame.class);
|
||||
|
||||
spy.write(ctx, msg, promise); //test
|
||||
|
||||
assertEquals(0, msg.refCnt());
|
||||
assertEquals(0, msg.readableBytes());
|
||||
verify(ctx).writeAndFlush(frameCaptor.capture(), eq(promise));
|
||||
WebSocketFrame frame = frameCaptor.getValue();
|
||||
assertTrue(frame instanceof BinaryWebSocketFrame);
|
||||
assertTrue(frame.isFinalFragment());
|
||||
assertEquals(content, frame.content().toString(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testWriteSingleFrame() throws Exception {
|
||||
String content = "Content MSG length less than max frame payload length: " + maxFramePayloadLength;
|
||||
|
|
Loading…
Reference in New Issue