use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelOutboundHandlerAdapter in project netty by netty.
the class ChunkedWriteHandlerTest method checkFirstFailed.
private static void checkFirstFailed(Object input) {
ChannelOutboundHandlerAdapter noOpWrites = new ChannelOutboundHandlerAdapter() {
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) {
ReferenceCountUtil.release(msg);
promise.tryFailure(new RuntimeException());
}
};
EmbeddedChannel ch = new EmbeddedChannel(noOpWrites, new ChunkedWriteHandler());
ChannelFuture r = ch.writeAndFlush(input);
// Should be `false` as we do not expect any messages to be written
assertFalse(ch.finish());
assertTrue(r.cause() instanceof RuntimeException);
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelOutboundHandlerAdapter in project netty by netty.
the class ChunkedWriteHandlerTest method testEndOfInputWhenChannelIsClosedwhenWrite.
@Test
public void testEndOfInputWhenChannelIsClosedwhenWrite() {
ChunkedInput<ByteBuf> input = new ChunkedInput<ByteBuf>() {
@Override
public boolean isEndOfInput() {
return true;
}
@Override
public void close() {
}
@Deprecated
@Override
public ByteBuf readChunk(ChannelHandlerContext ctx) {
return null;
}
@Override
public ByteBuf readChunk(ByteBufAllocator allocator) {
return null;
}
@Override
public long length() {
return -1;
}
@Override
public long progress() {
return 1;
}
};
EmbeddedChannel ch = new EmbeddedChannel(new ChannelOutboundHandlerAdapter() {
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
ReferenceCountUtil.release(msg);
// Calling close so we will drop all queued messages in the ChunkedWriteHandler.
ctx.close();
promise.setSuccess();
}
}, new ChunkedWriteHandler());
ch.writeAndFlush(input).syncUninterruptibly();
assertFalse(ch.finishAndReleaseAll());
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelOutboundHandlerAdapter in project netty by netty.
the class Http2StreamFrameToHttpObjectCodecTest method testEncodeHttpsSchemeWhenSslHandlerExists.
@Test
public void testEncodeHttpsSchemeWhenSslHandlerExists() throws Exception {
final Queue<Http2StreamFrame> frames = new ConcurrentLinkedQueue<Http2StreamFrame>();
final SslContext ctx = SslContextBuilder.forClient().sslProvider(SslProvider.JDK).build();
EmbeddedChannel ch = new EmbeddedChannel(ctx.newHandler(ByteBufAllocator.DEFAULT), new ChannelOutboundHandlerAdapter() {
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
if (msg instanceof Http2StreamFrame) {
frames.add((Http2StreamFrame) msg);
ctx.write(Unpooled.EMPTY_BUFFER, promise);
} else {
ctx.write(msg, promise);
}
}
}, new Http2StreamFrameToHttpObjectCodec(false));
try {
FullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/hello/world");
assertTrue(ch.writeOutbound(req));
ch.finishAndReleaseAll();
Http2HeadersFrame headersFrame = (Http2HeadersFrame) frames.poll();
Http2Headers headers = headersFrame.headers();
assertThat(headers.scheme().toString(), is("https"));
assertThat(headers.method().toString(), is("GET"));
assertThat(headers.path().toString(), is("/hello/world"));
assertTrue(headersFrame.isEndStream());
assertNull(frames.poll());
} finally {
ch.finishAndReleaseAll();
}
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelOutboundHandlerAdapter in project netty by netty.
the class WebSocketProtocolHandlerTest method testTimeout.
@Test
public void testTimeout() throws Exception {
final AtomicReference<ChannelPromise> ref = new AtomicReference<ChannelPromise>();
WebSocketProtocolHandler handler = new WebSocketProtocolHandler(false, WebSocketCloseStatus.NORMAL_CLOSURE, 1) {
};
EmbeddedChannel channel = new EmbeddedChannel(new ChannelOutboundHandlerAdapter() {
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) {
ref.set(promise);
ReferenceCountUtil.release(msg);
}
}, handler);
ChannelFuture future = channel.writeAndFlush(new CloseWebSocketFrame());
ChannelHandlerContext ctx = channel.pipeline().context(WebSocketProtocolHandler.class);
handler.close(ctx, ctx.newPromise());
do {
Thread.sleep(10);
channel.runPendingTasks();
} while (!future.isDone());
assertThat(future.cause(), Matchers.instanceOf(WebSocketHandshakeException.class));
assertFalse(ref.get().isDone());
assertFalse(channel.finish());
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelOutboundHandlerAdapter in project netty by netty.
the class EmbeddedChannelTest method testWriteLater.
@Test
public void testWriteLater() {
EmbeddedChannel channel = new EmbeddedChannel(new ChannelOutboundHandlerAdapter() {
@Override
public void write(final ChannelHandlerContext ctx, final Object msg, final ChannelPromise promise) throws Exception {
ctx.executor().execute(new Runnable() {
@Override
public void run() {
ctx.write(msg, promise);
}
});
}
});
Object msg = new Object();
assertTrue(channel.writeOutbound(msg));
assertTrue(channel.finish());
assertSame(msg, channel.readOutbound());
assertNull(channel.readOutbound());
}
Aggregations