From 4fcecfac0d9a31787068696a9a47efd623d5d5f2 Mon Sep 17 00:00:00 2001 From: Violeta Georgieva Date: Tue, 28 Jun 2022 10:57:02 +0300 Subject: [PATCH] [test] MessageToMessageEncoder now overrides encodeAndClose() instead of encode() (#2334) Related to #1873 --- .../java/reactor/netty/NettyOutboundTest.java | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/reactor-netty-core/src/test/java/reactor/netty/NettyOutboundTest.java b/reactor-netty-core/src/test/java/reactor/netty/NettyOutboundTest.java index 39a92e291b..690e179bc7 100644 --- a/reactor-netty-core/src/test/java/reactor/netty/NettyOutboundTest.java +++ b/reactor-netty-core/src/test/java/reactor/netty/NettyOutboundTest.java @@ -48,10 +48,8 @@ import io.netty5.handler.stream.ChunkedNioFile; import io.netty5.handler.stream.ChunkedWriteHandler; import io.netty5.util.CharsetUtil; -import io.netty5.util.ReferenceCountUtil; import io.netty5.util.concurrent.Future; import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.reactivestreams.Publisher; import reactor.core.publisher.Mono; @@ -76,7 +74,7 @@ void sendFileWithoutTlsUsesFileRegion() throws URISyntaxException { new MessageToMessageEncoder() { @Override - protected void encode(ChannelHandlerContext ctx, FileRegion msg, + protected void encodeAndClose(ChannelHandlerContext ctx, FileRegion msg, List out) throws Exception { ByteArrayOutputStream bais = new ByteArrayOutputStream(); WritableByteChannel wbc = Channels.newChannel(bais); @@ -87,10 +85,9 @@ protected void encode(ChannelHandlerContext ctx, FileRegion msg, }, new MessageToMessageEncoder<>() { @Override - protected void encode(ChannelHandlerContext ctx, Object msg, + protected void encodeAndClose(ChannelHandlerContext ctx, Object msg, List out) { messageClasses.add(msg.getClass()); - ReferenceCountUtil.retain(msg); out.add(msg); } }); @@ -149,7 +146,6 @@ public NettyOutbound withConnection(Consumer withConnection) } @Test - @Disabled void sendFileWithTlsUsesChunkedFile() throws URISyntaxException, SSLException { SslContext sslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build(); final SslHandler sslHandler = sslCtx.newHandler(preferredAllocator()); @@ -164,7 +160,7 @@ void sendFileWithTlsUsesChunkedFile() throws URISyntaxException, SSLException { //capture the chunks unencrypted, transform as Strings: new MessageToMessageEncoder() { @Override - protected void encode(ChannelHandlerContext ctx, Buffer msg, + protected void encodeAndClose(ChannelHandlerContext ctx, Buffer msg, List out) { clearMessages.add(msg.readCharSequence(msg.readableBytes(), CharsetUtil.UTF_8)); out.add(msg.split()); @@ -175,10 +171,8 @@ protected void encode(ChannelHandlerContext ctx, Buffer msg, //helps to ensure a ChunkedFile was written outs new MessageToMessageEncoder<>() { @Override - protected void encode(ChannelHandlerContext ctx, Object msg, List out) { + protected void encodeAndClose(ChannelHandlerContext ctx, Object msg, List out) { messageWritten.add(msg.getClass()); - //passing the ChunkedFile through this method releases it, which is undesired - ReferenceCountUtil.retain(msg); out.add(msg); } }); @@ -251,7 +245,6 @@ public NettyOutbound withConnection(Consumer withConnection) } @Test - @Disabled void sendFileWithForceChunkedFileUsesStrategyChunks() throws URISyntaxException, IOException { List> messageWritten = new ArrayList<>(2); @@ -260,7 +253,7 @@ void sendFileWithForceChunkedFileUsesStrategyChunks() //transform the Buffer chunks into Strings: new MessageToMessageEncoder() { @Override - protected void encode(ChannelHandlerContext ctx, Buffer msg, + protected void encodeAndClose(ChannelHandlerContext ctx, Buffer msg, List out) { out.add(msg.readCharSequence(msg.readableBytes(), CharsetUtil.UTF_8)); } @@ -270,7 +263,7 @@ protected void encode(ChannelHandlerContext ctx, Buffer msg, //helps to ensure a ChunkedFile was written outs new MessageToMessageEncoder<>() { @Override - protected void encode(ChannelHandlerContext ctx, Object msg, List out) { + protected void encodeAndClose(ChannelHandlerContext ctx, Object msg, List out) { messageWritten.add(msg.getClass()); out.add(msg); }