use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelOutboundHandlerAdapter in project netty by netty.
the class EmbeddedChannelTest method testFlushOutbound.
@Test
public void testFlushOutbound() throws InterruptedException {
final CountDownLatch latch = new CountDownLatch(1);
EmbeddedChannel channel = new EmbeddedChannel(new ChannelOutboundHandlerAdapter() {
@Override
public void flush(ChannelHandlerContext ctx) throws Exception {
latch.countDown();
}
});
channel.flushOutbound();
if (!latch.await(1L, TimeUnit.SECONDS)) {
fail("Nobody called #flush() in time.");
}
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelOutboundHandlerAdapter in project netty by netty.
the class EmbeddedChannelTest method testWriteOneOutbound.
@Test
public void testWriteOneOutbound() throws InterruptedException {
final CountDownLatch latch = new CountDownLatch(1);
final AtomicInteger flushCount = new AtomicInteger(0);
EmbeddedChannel channel = new EmbeddedChannel(new ChannelOutboundHandlerAdapter() {
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
ctx.write(msg, promise);
latch.countDown();
}
@Override
public void flush(ChannelHandlerContext ctx) throws Exception {
flushCount.incrementAndGet();
}
});
// This shouldn't trigger a #flush()
channel.writeOneOutbound("Hello, Netty!");
if (!latch.await(1L, TimeUnit.SECONDS)) {
fail("Nobody called #write() in time.");
}
channel.close().syncUninterruptibly();
// There was no #flushOutbound() call so nobody should have called #flush()
assertEquals(0, flushCount.get());
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelOutboundHandlerAdapter in project netty by netty.
the class EmbeddedChannelTest method testHasNoDisconnectSkipDisconnect.
@Test
public void testHasNoDisconnectSkipDisconnect() throws InterruptedException {
EmbeddedChannel channel = new EmbeddedChannel(false, new ChannelOutboundHandlerAdapter() {
@Override
public void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
promise.tryFailure(new Throwable());
}
});
assertFalse(channel.disconnect().isSuccess());
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelOutboundHandlerAdapter in project grpc-java by grpc.
the class WriteBufferingAndExceptionHandlerTest method writesBuffered.
@Test
public void writesBuffered() throws Exception {
final AtomicBoolean handlerAdded = new AtomicBoolean();
final AtomicBoolean flush = new AtomicBoolean();
final AtomicReference<Object> write = new AtomicReference<>();
final WriteBufferingAndExceptionHandler handler = new WriteBufferingAndExceptionHandler(new ChannelOutboundHandlerAdapter() {
@Override
public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
assertFalse(handlerAdded.getAndSet(true));
super.handlerAdded(ctx);
}
@Override
public void flush(ChannelHandlerContext ctx) throws Exception {
assertFalse(flush.getAndSet(true));
super.flush(ctx);
}
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) {
assertNull(write.getAndSet(msg));
promise.setSuccess();
}
});
LocalAddress addr = new LocalAddress("local");
ChannelFuture cf = new Bootstrap().channel(LocalChannel.class).handler(handler).group(group).register();
chan = cf.channel();
cf.sync();
ChannelFuture sf = new ServerBootstrap().channel(LocalServerChannel.class).childHandler(new ChannelHandlerAdapter() {
}).group(group).bind(addr);
server = sf.channel();
sf.sync();
assertTrue(handlerAdded.get());
chan.write(new Object());
chan.connect(addr).sync();
assertNull(write.get());
chan.flush();
assertNull(write.get());
assertFalse(flush.get());
assertThat(chan.pipeline().context(handler)).isNotNull();
chan.eventLoop().submit(new Runnable() {
@Override
public void run() {
handler.writeBufferedAndRemove(chan.pipeline().context(handler));
}
}).sync();
assertThat(chan.pipeline().context(handler)).isNull();
assertThat(write.get().getClass()).isSameInstanceAs(Object.class);
assertTrue(flush.get());
assertThat(chan.pipeline().toMap().values()).doesNotContain(handler);
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelOutboundHandlerAdapter in project riposte by Nike-Inc.
the class VerifyCornerCasesComponentTest method invalid_http_call_that_causes_Netty_DecoderFailure_should_result_in_expected_400_error.
@Test
public void invalid_http_call_that_causes_Netty_DecoderFailure_should_result_in_expected_400_error() throws Exception {
// given
// Normal request, but fiddle with the first chunk as it's going out to remove the HTTP version and make it an
// invalid HTTP call. This will cause Netty to mark the HttpRequest with a DecoderFailure.
NettyHttpClientRequestBuilder request = request().withMethod(HttpMethod.GET).withUri(BasicEndpoint.MATCHING_PATH).withPipelineAdjuster(p -> p.addFirst(new ChannelOutboundHandlerAdapter() {
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
String msgAsString = ((ByteBuf) msg).toString(CharsetUtil.UTF_8);
if (msgAsString.contains("HTTP/1.1")) {
msg = Unpooled.copiedBuffer(msgAsString.replace("HTTP/1.1", ""), CharsetUtil.UTF_8);
}
super.write(ctx, msg, promise);
}
}));
// when
NettyHttpClientResponse response = request.execute(downstreamServerConfig.endpointsPort(), 3000);
// then
verifyErrorReceived(response.payload, response.statusCode, new ApiErrorWithMetadata(SampleCoreApiError.MALFORMED_REQUEST, Pair.of("cause", "Invalid HTTP request")));
}
Aggregations