Skip to content

Commit

Permalink
made maxconnectionpools setting strictly positive.
Browse files Browse the repository at this point in the history
  • Loading branch information
jchenga committed Jan 8, 2025
1 parent 420dd1c commit 5b037f9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -495,12 +495,15 @@ public final Builder forRemoteHost(SocketAddress remoteHost, Consumer<HostSpecif
/**
* Specifies the maximum number of connection pools that the provider can create.
* If the number of connection pools created exceeds this value, a warning message is logged.
* The value must be positive or zero; otherwise, the connection pools check is ignored.
*
* @param maxConnectionPools the number of connection pools expected to be created.
* 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.
*/
public Builder maxConnectionPools(int maxConnectionPools) {
if (maxConnectionPools != MAX_CONNECTION_POOLS && maxConnectionPools <= 0) {
throw new IllegalArgumentException("Maximum connection pools setting must be strictly positive.");
}
this.maxConnectionPools = maxConnectionPools;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
import static io.netty.handler.codec.http.HttpHeaderValues.GZIP;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assumptions.assumeThat;
import static org.mockito.Mockito.times;

Expand Down Expand Up @@ -620,7 +621,14 @@ void sslExchangeRelativeGet() throws SSLException {

@ParameterizedTest
@ValueSource(booleans = {true, false})
void maxConnectionPools(boolean withMaxConnectionPools) throws SSLException {
void testMaxConnectionPools(boolean withMaxConnectionPools) throws SSLException {

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);
Expand All @@ -636,12 +644,7 @@ void maxConnectionPools(boolean withMaxConnectionPools) throws SSLException {
.handle((req, resp) -> resp.sendString(Flux.just("hello ", req.uri())))
.bindNow();

ConnectionProvider connectionProvider = withMaxConnectionPools ? ConnectionProvider
.builder("max-connection-pools")
.maxConnectionPools(1)
.build() : ConnectionProvider
.builder("max-connection-pools")
.build();


StepVerifier
.create(Flux
Expand Down Expand Up @@ -674,12 +677,22 @@ void maxConnectionPools(boolean withMaxConnectionPools) throws SSLException {
}
}
finally {
disposableServer.dispose();
connectionProvider.dispose();
Loggers.resetLoggerFactory();
}

}

@ParameterizedTest
@ValueSource(ints = {0, -2})
void testInvalidMaxConnectionPoolsSetting(int maxConnectionPools) {

assertThatIllegalArgumentException().isThrownBy(() -> ConnectionProvider
.builder("max-connection-pools")
.maxConnectionPools(maxConnectionPools));

}

private SslContext createClientSslContext() {
try {
return SslContextBuilder.forClient()
Expand Down

0 comments on commit 5b037f9

Please sign in to comment.