use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelOutboundHandlerAdapter in project netty by netty.
the class DynamicAddressConnectHandlerTest method testReplaceAddresses.
@Test
public void testReplaceAddresses() {
EmbeddedChannel channel = new EmbeddedChannel(new ChannelOutboundHandlerAdapter() {
@Override
public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) {
try {
assertSame(REMOTE_NEW, remoteAddress);
assertSame(LOCAL_NEW, localAddress);
promise.setSuccess();
} catch (Throwable cause) {
promise.setFailure(cause);
}
}
}, new DynamicAddressConnectHandler() {
@Override
protected SocketAddress localAddress(SocketAddress remoteAddress, SocketAddress localAddress) {
assertSame(REMOTE, remoteAddress);
assertSame(LOCAL, localAddress);
return LOCAL_NEW;
}
@Override
protected SocketAddress remoteAddress(SocketAddress remoteAddress, SocketAddress localAddress) {
assertSame(REMOTE, remoteAddress);
assertSame(LOCAL, localAddress);
return REMOTE_NEW;
}
});
channel.connect(REMOTE, LOCAL).syncUninterruptibly();
assertNull(channel.pipeline().get(DynamicAddressConnectHandler.class));
assertFalse(channel.finish());
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelOutboundHandlerAdapter in project zuul by Netflix.
the class SslHandshakeInfoHandlerTest method sslEarlyHandshakeFailure.
@Test
public void sslEarlyHandshakeFailure() throws Exception {
EmbeddedChannel clientChannel = new EmbeddedChannel();
SSLEngine clientEngine = SslContextBuilder.forClient().build().newEngine(clientChannel.alloc());
clientChannel.pipeline().addLast(new SslHandler(clientEngine));
EmbeddedChannel serverChannel = new EmbeddedChannel();
SelfSignedCertificate cert = new SelfSignedCertificate("localhorse");
SSLEngine serverEngine = SslContextBuilder.forServer(cert.key(), cert.cert()).build().newEngine(serverChannel.alloc());
serverChannel.pipeline().addLast(new ChannelOutboundHandlerAdapter() {
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) {
// Simulate an early closure form the client.
ReferenceCountUtil.safeRelease(msg);
promise.setFailure(new ClosedChannelException());
}
});
serverChannel.pipeline().addLast(new SslHandler(serverEngine));
serverChannel.pipeline().addLast(new SslHandshakeInfoHandler());
Object clientHello = clientChannel.readOutbound();
assertNotNull(clientHello);
ReferenceCountUtil.retain(clientHello);
serverChannel.writeInbound(clientHello);
// Assert that the handler removes itself from the pipeline, since it was torn down.
assertNull(serverChannel.pipeline().context(SslHandshakeInfoHandler.class));
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelOutboundHandlerAdapter in project reactor-netty by reactor.
the class DefaultPooledConnectionProviderTest method doTestSslEngineClosed.
private void doTestSslEngineClosed(HttpClient client, AtomicInteger closeCount, Class<? extends Throwable> expectedExc, String expectedMsg) {
Mono<String> response = client.doOnChannelInit((o, c, address) -> c.pipeline().addFirst(new ChannelOutboundHandlerAdapter() {
@Override
public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) throws Exception {
super.connect(ctx, remoteAddress, localAddress, new TestPromise(ctx.channel(), promise, closeCount));
}
})).get().uri("/").responseContent().aggregate().asString();
StepVerifier.create(response).expectErrorMatches(t -> t.getClass().isAssignableFrom(expectedExc) && t.getMessage().startsWith(expectedMsg)).verify(Duration.ofSeconds(30));
}
Aggregations