use of reactor.netty.http.Http2SslContextSpec in project reactor-netty by reactor.
the class PooledConnectionProviderDefaultMetricsTest method testConnectionProviderMetricsEnableAndHttpClientMetricsDisabledHttp2.
@Test
void testConnectionProviderMetricsEnableAndHttpClientMetricsDisabledHttp2() throws Exception {
Http2SslContextSpec serverCtx = Http2SslContextSpec.forServer(ssc.certificate(), ssc.privateKey());
Http2SslContextSpec clientCtx = Http2SslContextSpec.forClient().configure(builder -> builder.trustManager(InsecureTrustManagerFactory.INSTANCE));
ConnectionProvider provider = ConnectionProvider.builder("test4").maxConnections(1).pendingAcquireMaxCount(10).metrics(true).lifo().build();
try {
doTest(createServer().protocol(HttpProtocol.H2).secure(spec -> spec.sslContext(serverCtx)), createClient(provider, () -> disposableServer.address()).protocol(HttpProtocol.H2).secure(spec -> spec.sslContext(clientCtx)), "test4", false, 1, 10);
} finally {
provider.disposeLater().block(Duration.ofSeconds(5));
}
}
use of reactor.netty.http.Http2SslContextSpec in project reactor-netty by reactor.
the class PooledConnectionProviderDefaultMetricsTest method testConnectionProviderMetricsDisabledAndHttpClientMetricsEnabledHttp2.
@Test
void testConnectionProviderMetricsDisabledAndHttpClientMetricsEnabledHttp2() throws Exception {
// by default, when the max number of pending acquire is not specified, it will bet set to 2 * max-connection
// (see PoolFactory from PoolConnectionProvider.java)
Http2SslContextSpec serverCtx = Http2SslContextSpec.forServer(ssc.certificate(), ssc.privateKey());
Http2SslContextSpec clientCtx = Http2SslContextSpec.forClient().configure(builder -> builder.trustManager(InsecureTrustManagerFactory.INSTANCE));
ConnectionProvider provider = ConnectionProvider.create("test2", 1);
try {
doTest(createServer().protocol(HttpProtocol.H2).secure(spec -> spec.sslContext(serverCtx)), createClient(provider, () -> disposableServer.address()).protocol(HttpProtocol.H2).secure(spec -> spec.sslContext(clientCtx)), "test2", true, 1, 2);
} finally {
provider.disposeLater().block(Duration.ofSeconds(5));
}
}
use of reactor.netty.http.Http2SslContextSpec in project reactor-netty by reactor.
the class DefaultPooledConnectionProviderTest method testIssue1982H2.
@ParameterizedTest
@MethodSource("h2CompatibleCombinations")
void testIssue1982H2(HttpProtocol[] serverProtocols, HttpProtocol[] clientProtocols) throws Exception {
Http2SslContextSpec serverCtx = Http2SslContextSpec.forServer(ssc.certificate(), ssc.privateKey());
Http2SslContextSpec clientCtx = Http2SslContextSpec.forClient().configure(builder -> builder.trustManager(InsecureTrustManagerFactory.INSTANCE));
doTestIssue1982(serverProtocols, clientProtocols, serverCtx, clientCtx);
}
use of reactor.netty.http.Http2SslContextSpec in project reactor-netty by reactor.
the class DefaultPooledConnectionProviderTest method testConnectionReturnedToParentPoolWhenNoActiveStreams.
@Test
void testConnectionReturnedToParentPoolWhenNoActiveStreams() throws Exception {
Http2SslContextSpec serverCtx = Http2SslContextSpec.forServer(ssc.certificate(), ssc.privateKey());
Http2SslContextSpec clientCtx = Http2SslContextSpec.forClient().configure(builder -> builder.trustManager(InsecureTrustManagerFactory.INSTANCE));
disposableServer = createServer().wiretap(false).protocol(HttpProtocol.H2).secure(spec -> spec.sslContext(serverCtx)).route(routes -> routes.post("/", (req, res) -> res.send(req.receive().retain()))).bindNow();
int requestsNum = 10;
CountDownLatch latch = new CountDownLatch(1);
DefaultPooledConnectionProvider provider = (DefaultPooledConnectionProvider) ConnectionProvider.create("testConnectionReturnedToParentPoolWhenNoActiveStreams", 5);
AtomicInteger counter = new AtomicInteger();
HttpClient client = createClient(provider, disposableServer.port()).wiretap(false).protocol(HttpProtocol.H2).secure(spec -> spec.sslContext(clientCtx)).observe((conn, state) -> {
if (state == ConnectionObserver.State.CONNECTED) {
counter.incrementAndGet();
}
if (state == ConnectionObserver.State.RELEASED && counter.decrementAndGet() == 0) {
latch.countDown();
}
});
try {
Flux.range(0, requestsNum).flatMap(i -> client.post().uri("/").send(ByteBufMono.fromString(Mono.just("testConnectionReturnedToParentPoolWhenNoActiveStreams"))).responseContent().aggregate().asString()).blockLast(Duration.ofSeconds(5));
assertThat(latch.await(5, TimeUnit.SECONDS)).isTrue();
assertThat(provider.channelPools).hasSize(1);
@SuppressWarnings({ "unchecked", "rawtypes" }) InstrumentedPool<DefaultPooledConnectionProvider.PooledConnection> channelPool = provider.channelPools.values().toArray(new InstrumentedPool[0])[0];
InstrumentedPool.PoolMetrics metrics = channelPool.metrics();
assertThat(metrics.acquiredSize()).isEqualTo(0);
assertThat(metrics.allocatedSize()).isEqualTo(metrics.idleSize());
} finally {
provider.disposeLater().block(Duration.ofSeconds(5));
}
}
use of reactor.netty.http.Http2SslContextSpec in project reactor-netty by reactor.
the class HttpClientTest method testConnectionLifeTimeFixedPoolHttp2_1.
@Test
void testConnectionLifeTimeFixedPoolHttp2_1() throws Exception {
Http2SslContextSpec serverCtx = Http2SslContextSpec.forServer(ssc.certificate(), ssc.privateKey());
Http2SslContextSpec clientCtx = Http2SslContextSpec.forClient().configure(builder -> builder.trustManager(InsecureTrustManagerFactory.INSTANCE));
ConnectionProvider provider = ConnectionProvider.builder("testConnectionLifeTimeFixedPoolHttp2_1").maxConnections(1).pendingAcquireTimeout(Duration.ofMillis(100)).maxLifeTime(Duration.ofMillis(30)).build();
try {
ChannelId[] ids = doTestConnectionLifeTime(createServer().protocol(HttpProtocol.H2).secure(spec -> spec.sslContext(serverCtx)), createClient(provider, () -> disposableServer.address()).protocol(HttpProtocol.H2).secure(spec -> spec.sslContext(clientCtx)));
assertThat(ids[0]).isNotEqualTo(ids[1]);
} finally {
provider.disposeLater().block(Duration.ofSeconds(5));
}
}
Aggregations