Skip to content

Commit

Permalink
Polish
Browse files Browse the repository at this point in the history
Signed-off-by: Violeta Georgieva <[email protected]>
  • Loading branch information
violetagg committed Jan 8, 2025
1 parent 963dd20 commit 6b10785
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -396,12 +396,11 @@ final class Builder extends ConnectionPoolSpec<Builder> {
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<SocketAddress, ConnectionPoolSpec<?>> confPerRemoteHost = new HashMap<>();

/**
Expand Down Expand Up @@ -497,8 +496,9 @@ public final Builder forRemoteHost(SocketAddress remoteHost, Consumer<HostSpecif
* If the number of connection pools created exceeds this value, a warning message is logged.
* The value must be strictly positive or -1; otherwise, the connection pools check is ignored.
* Setting the configuration to -1 disables the setting.
* @param maxConnectionPools the maximum number of connection pools that can be created.
* @return the current {@link Builder} instance with the updated configuration.
*
* @param maxConnectionPools the maximum number of connection pools that can be created
* @return the current {@link Builder} instance with the updated configuration
*/
public Builder maxConnectionPools(int maxConnectionPools) {
if (maxConnectionPools != MAX_CONNECTION_POOLS && maxConnectionPools <= 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ public final Mono<? extends Connection> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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);
Expand Down

0 comments on commit 6b10785

Please sign in to comment.