This commit is contained in:
Clebert Suconic 2020-09-03 16:27:29 -04:00
commit 3152521864
2 changed files with 25 additions and 0 deletions

View File

@ -63,5 +63,7 @@ public class WebSocketFrameEncoder extends ChannelOutboundHandlerAdapter {
byteBuf.readBytes(fragment, length);
ctx.writeAndFlush(new ContinuationWebSocketFrame(finalFragment, 0, fragment), promise);
}
byteBuf.release();
}
}

View File

@ -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;