use of reactor.netty.tcp.TcpClient in project reactor-netty by reactor.
the class HttpServerTests method doTestDecodingFailureLastHttpContent.
private void doTestDecodingFailureLastHttpContent(String message, String... expectations) throws Exception {
TcpClient tcpClient = TcpClient.create().port(disposableServer.port()).wiretap(true);
Connection connection = tcpClient.connectNow();
CountDownLatch latch = new CountDownLatch(1);
connection.channel().closeFuture().addListener(f -> latch.countDown());
AtomicReference<String> result = new AtomicReference<>();
connection.inbound().receive().asString().doOnNext(result::set).subscribe();
connection.outbound().sendString(Mono.just(message)).then().subscribe();
assertThat(latch.await(30, TimeUnit.SECONDS)).isTrue();
assertThat(result.get()).contains(expectations);
assertThat(connection.channel().isActive()).isFalse();
}
use of reactor.netty.tcp.TcpClient in project reactor-netty by reactor.
the class HttpServerTests method doTest.
private void doTest(int port, String message) throws Exception {
TcpClient tcpClient = TcpClient.create().port(port).wiretap(true);
Connection connection = tcpClient.connectNow();
CountDownLatch latch = new CountDownLatch(2);
connection.channel().closeFuture().addListener(f -> latch.countDown());
AtomicReference<String> result = new AtomicReference<>();
connection.inbound().receive().asString().doOnNext(s -> {
result.set(s);
latch.countDown();
}).subscribe();
connection.outbound().sendString(Mono.just(message)).then().subscribe();
assertThat(latch.await(30, TimeUnit.SECONDS)).isTrue();
assertThat(result.get()).contains("test", "connection: close");
assertThat(connection.channel().isActive()).isFalse();
}
use of reactor.netty.tcp.TcpClient in project spring-boot by spring-projects.
the class NettyRSocketServerFactoryTests method createSecureTcpClient.
private TcpClient createSecureTcpClient() {
TcpClient tcpClient = createTcpClient();
Http11SslContextSpec sslContextSpec = Http11SslContextSpec.forClient().configure((builder) -> builder.sslProvider(SslProvider.JDK).trustManager(InsecureTrustManagerFactory.INSTANCE));
return tcpClient.secure((spec) -> spec.sslContext(sslContextSpec));
}
use of reactor.netty.tcp.TcpClient in project reactor-netty by reactor.
the class HttpClientTest method testApplyTcpClientSSLConfig.
@Test
void testApplyTcpClientSSLConfig() throws Exception {
SslContext sslContext = SslContextBuilder.forClient().build();
TcpClient tcpClient = TcpClient.create().secure(sslProviderBuilder -> sslProviderBuilder.sslContext(sslContext));
HttpClient httpClient = HttpClientConnect.applyTcpClientConfig(tcpClient.configuration());
assertThat(tcpClient.configuration().sslProvider()).isEqualTo(httpClient.configuration().sslProvider());
}
use of reactor.netty.tcp.TcpClient in project reactor-netty by reactor.
the class DefaultLoopResourcesTest method testClientTransportWarmup.
private void testClientTransportWarmup(boolean preferNative) throws Exception {
final DefaultLoopResources loop1 = (DefaultLoopResources) LoopResources.create("testClientTransportWarmup", 1, true);
final NioEventLoopGroup loop2 = new NioEventLoopGroup(1);
try {
TcpClient tcpClient = TcpClient.create().resolver(spec -> spec.runOn(loop2)).runOn(loop1, preferNative);
Mono<Void> warmupMono = tcpClient.warmup();
assertThat(loop1.cacheNativeClientLoops.get()).isNull();
assertThat(loop1.clientLoops.get()).isNull();
warmupMono.block(Duration.ofSeconds(5));
if (preferNative && LoopResources.hasNativeSupport()) {
assertThat(loop1.cacheNativeClientLoops.get()).isNotNull();
assertThat(loop1.clientLoops.get()).isNull();
} else {
assertThat(loop1.cacheNativeClientLoops.get()).isNull();
assertThat(loop1.clientLoops.get()).isNotNull();
}
} finally {
loop1.disposeLater().block(Duration.ofSeconds(5));
loop2.shutdownGracefully().get(5, TimeUnit.SECONDS);
}
}
Aggregations