Skip to content

Commit

Permalink
[test] MessageToMessageEncoder now overrides encodeAndClose() instead…
Browse files Browse the repository at this point in the history
… of encode() (#2334)

Related to #1873
  • Loading branch information
violetagg committed Jun 28, 2022
1 parent b1dfc8a commit 4fcecfa
Showing 1 changed file with 6 additions and 13 deletions.
Expand Up @@ -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;
Expand All @@ -76,7 +74,7 @@ void sendFileWithoutTlsUsesFileRegion() throws URISyntaxException {
new MessageToMessageEncoder<FileRegion>() {

@Override
protected void encode(ChannelHandlerContext ctx, FileRegion msg,
protected void encodeAndClose(ChannelHandlerContext ctx, FileRegion msg,
List<Object> out) throws Exception {
ByteArrayOutputStream bais = new ByteArrayOutputStream();
WritableByteChannel wbc = Channels.newChannel(bais);
Expand All @@ -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<Object> out) {
messageClasses.add(msg.getClass());
ReferenceCountUtil.retain(msg);
out.add(msg);
}
});
Expand Down Expand Up @@ -149,7 +146,6 @@ public NettyOutbound withConnection(Consumer<? super Connection> withConnection)
}

@Test
@Disabled
void sendFileWithTlsUsesChunkedFile() throws URISyntaxException, SSLException {
SslContext sslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build();
final SslHandler sslHandler = sslCtx.newHandler(preferredAllocator());
Expand All @@ -164,7 +160,7 @@ void sendFileWithTlsUsesChunkedFile() throws URISyntaxException, SSLException {
//capture the chunks unencrypted, transform as Strings:
new MessageToMessageEncoder<Buffer>() {
@Override
protected void encode(ChannelHandlerContext ctx, Buffer msg,
protected void encodeAndClose(ChannelHandlerContext ctx, Buffer msg,
List<Object> out) {
clearMessages.add(msg.readCharSequence(msg.readableBytes(), CharsetUtil.UTF_8));
out.add(msg.split());
Expand All @@ -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<Object> out) {
protected void encodeAndClose(ChannelHandlerContext ctx, Object msg, List<Object> out) {
messageWritten.add(msg.getClass());
//passing the ChunkedFile through this method releases it, which is undesired
ReferenceCountUtil.retain(msg);
out.add(msg);
}
});
Expand Down Expand Up @@ -251,7 +245,6 @@ public NettyOutbound withConnection(Consumer<? super Connection> withConnection)
}

@Test
@Disabled
void sendFileWithForceChunkedFileUsesStrategyChunks()
throws URISyntaxException, IOException {
List<Class<?>> messageWritten = new ArrayList<>(2);
Expand All @@ -260,7 +253,7 @@ void sendFileWithForceChunkedFileUsesStrategyChunks()
//transform the Buffer chunks into Strings:
new MessageToMessageEncoder<Buffer>() {
@Override
protected void encode(ChannelHandlerContext ctx, Buffer msg,
protected void encodeAndClose(ChannelHandlerContext ctx, Buffer msg,
List<Object> out) {
out.add(msg.readCharSequence(msg.readableBytes(), CharsetUtil.UTF_8));
}
Expand All @@ -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<Object> out) {
protected void encodeAndClose(ChannelHandlerContext ctx, Object msg, List<Object> out) {
messageWritten.add(msg.getClass());
out.add(msg);
}
Expand Down

0 comments on commit 4fcecfa

Please sign in to comment.