From 6b10785857de5b19d72f1da6fea6e78b6968f24a Mon Sep 17 00:00:00 2001 From: Violeta Georgieva Date: Wed, 8 Jan 2025 12:14:35 +0200 Subject: [PATCH] Polish Signed-off-by: Violeta Georgieva --- .../netty/resources/ConnectionProvider.java | 8 +- .../resources/PooledConnectionProvider.java | 4 +- .../netty/http/client/HttpClientTest.java | 85 ++++++++----------- 3 files changed, 40 insertions(+), 57 deletions(-) diff --git a/reactor-netty-core/src/main/java/reactor/netty/resources/ConnectionProvider.java b/reactor-netty-core/src/main/java/reactor/netty/resources/ConnectionProvider.java index a135340403..c3de26bdbe 100644 --- a/reactor-netty-core/src/main/java/reactor/netty/resources/ConnectionProvider.java +++ b/reactor-netty-core/src/main/java/reactor/netty/resources/ConnectionProvider.java @@ -396,12 +396,11 @@ final class Builder extends ConnectionPoolSpec { static final Duration DISPOSE_INACTIVE_POOLS_IN_BACKGROUND_DISABLED = Duration.ZERO; static final int MAX_CONNECTION_POOLS = -1; - int maxConnectionPools = MAX_CONNECTION_POOLS; - String name; Duration inactivePoolDisposeInterval = DISPOSE_INACTIVE_POOLS_IN_BACKGROUND_DISABLED; Duration poolInactivity; Duration disposeTimeout; + int maxConnectionPools = MAX_CONNECTION_POOLS; final Map> confPerRemoteHost = new HashMap<>(); /** @@ -497,8 +496,9 @@ public final Builder forRemoteHost(SocketAddress remoteHost, Consumer acquire( log.debug("Creating a new [{}] client pool [{}] for [{}]", name, poolFactory, remoteAddress); } - if (maxConnectionPools > Builder.MAX_CONNECTION_POOLS && connectionPoolCount.incrementAndGet() > maxConnectionPools) { - if (log.isWarnEnabled()) { + if (log.isWarnEnabled()) { + if (maxConnectionPools > Builder.MAX_CONNECTION_POOLS && connectionPoolCount.incrementAndGet() > maxConnectionPools) { log.warn("Connection pool creation limit exceeded: {} pools created, maximum expected is {}", connectionPoolCount.get(), maxConnectionPools); } diff --git a/reactor-netty-http/src/test/java/reactor/netty/http/client/HttpClientTest.java b/reactor-netty-http/src/test/java/reactor/netty/http/client/HttpClientTest.java index c6e6b7c2b3..f488272869 100644 --- a/reactor-netty-http/src/test/java/reactor/netty/http/client/HttpClientTest.java +++ b/reactor-netty-http/src/test/java/reactor/netty/http/client/HttpClientTest.java @@ -625,79 +625,62 @@ void testMaxConnectionPools(boolean withMaxConnectionPools) throws SSLException Logger spyLogger = Mockito.spy(log); Loggers.useCustomLoggers(s -> spyLogger); - ConnectionProvider connectionProvider = withMaxConnectionPools ? ConnectionProvider - .builder("max-connection-pools") - .maxConnectionPools(1) - .build() : ConnectionProvider - .builder("max-connection-pools") - .build(); + ConnectionProvider connectionProvider = withMaxConnectionPools ? + ConnectionProvider.builder("max-connection-pools").maxConnectionPools(1).build() : + ConnectionProvider.builder("max-connection-pools").build(); try { ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(String.class); - SslContext sslServer = SslContextBuilder - .forServer(ssc.certificate(), ssc.privateKey()) - .build(); - - disposableServer = createServer() - .secure(ssl -> ssl.sslContext(sslServer)) - .handle((req, resp) -> resp.sendString(Flux.just("hello ", req.uri()))) - .bindNow(); - - - - StepVerifier - .create(Flux - .range(1, 2) - .flatMap(i -> createClient(connectionProvider, disposableServer::address) - .secure(ssl -> ssl.sslContext(createClientSslContext())) - .get() - .uri("/foo") - .responseContent() - .aggregate() - .asString())) - .thenConsumeWhile(s -> true) - .verifyComplete(); + SslContext sslServer = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build(); + + disposableServer = + createServer().secure(ssl -> ssl.sslContext(sslServer)) + .handle((req, resp) -> resp.sendString(Flux.just("hello ", req.uri()))) + .bindNow(); + + Flux.range(1, 2) + .flatMap(i -> + createClient(connectionProvider, disposableServer::address) + .secure(ssl -> ssl.sslContext(createClientSslContext())) + .get() + .uri("/foo") + .responseContent() + .aggregate() + .asString()) + .as(StepVerifier::create) + .thenConsumeWhile(s -> true) + .expectComplete() + .verify(Duration.ofSeconds(5)); if (withMaxConnectionPools) { - Mockito - .verify(spyLogger) - .warn(argumentCaptor.capture(), Mockito.eq(2), Mockito.eq(1)); - assertThat(argumentCaptor.getValue()).isEqualTo( - "Connection pool creation limit exceeded: {} pools created, maximum expected is {}"); + Mockito.verify(spyLogger) + .warn(argumentCaptor.capture(), Mockito.eq(2), Mockito.eq(1)); + assertThat(argumentCaptor.getValue()) + .isEqualTo("Connection pool creation limit exceeded: {} pools created, maximum expected is {}"); } else { - Mockito - .verify(spyLogger, times(0)) - .warn(Mockito.eq( - "Connection pool creation limit exceeded: {} pools created, maximum expected is {}"), - Mockito.eq(2), - Mockito.eq(1)); - + Mockito.verify(spyLogger, times(0)) + .warn(Mockito.eq("Connection pool creation limit exceeded: {} pools created, maximum expected is {}"), + Mockito.eq(2), Mockito.eq(1)); } } finally { Loggers.resetLoggerFactory(); connectionProvider.dispose(); } - } @ParameterizedTest @ValueSource(ints = {0, -2}) void testInvalidMaxConnectionPoolsSetting(int maxConnectionPools) { - - assertThatIllegalArgumentException().isThrownBy(() -> ConnectionProvider - .builder("max-connection-pools") - .maxConnectionPools(maxConnectionPools)); - + assertThatIllegalArgumentException() + .isThrownBy(() -> ConnectionProvider.builder("max-connection-pools").maxConnectionPools(maxConnectionPools)); } - private SslContext createClientSslContext() { + private static SslContext createClientSslContext() { try { - return SslContextBuilder.forClient() - .trustManager(InsecureTrustManagerFactory.INSTANCE) - .build(); + return SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build(); } catch (SSLException e) { throw new RuntimeException(e);