Merge branch '3.0.x'

Closes gh-35379
pull/35417/head
Moritz Halbritter 2 years ago
commit 0ebb32e7f0

@ -108,6 +108,8 @@ abstract class ConnectionFactoryConfigurations {
map.from(pool.getMaxSize()).to(builder::maxSize);
map.from(pool.getValidationQuery()).whenHasText().to(builder::validationQuery);
map.from(pool.getValidationDepth()).to(builder::validationDepth);
map.from(pool.getMinIdle()).to(builder::minIdle);
map.from(pool.getMaxValidationTime()).to(builder::maxValidationTime);
return new ConnectionPool(builder.build());
}

@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -136,6 +136,13 @@ public class R2dbcProperties {
public static class Pool {
/**
* Minimal number of idle connections.
*
* @since 2.7.12
*/
private int minIdle = 0;
/**
* Maximum amount of time that a connection is allowed to sit idle in the pool.
*/
@ -153,6 +160,14 @@ public class R2dbcProperties {
*/
private Duration maxAcquireTime;
/**
* Maximum time to validate a connection from the pool. By default, wait
* indefinitely.
*
* @since 2.7.12
*/
private Duration maxValidationTime;
/**
* Maximum time to wait to create a new connection. By default, wait indefinitely.
*/
@ -183,6 +198,14 @@ public class R2dbcProperties {
*/
private boolean enabled = true;
public int getMinIdle() {
return this.minIdle;
}
public void setMinIdle(int minIdle) {
this.minIdle = minIdle;
}
public Duration getMaxIdleTime() {
return this.maxIdleTime;
}
@ -199,6 +222,14 @@ public class R2dbcProperties {
this.maxLifeTime = maxLifeTime;
}
public Duration getMaxValidationTime() {
return this.maxValidationTime;
}
public void setMaxValidationTime(Duration maxValidationTime) {
this.maxValidationTime = maxValidationTime;
}
public Duration getMaxAcquireTime() {
return this.maxAcquireTime;
}

@ -81,15 +81,25 @@ class R2dbcAutoConfigurationTests {
void configureWithUrlAndPoolPropertiesApplyProperties() {
this.contextRunner
.withPropertyValues("spring.r2dbc.url:r2dbc:h2:mem:///" + randomDatabaseName(),
"spring.r2dbc.pool.max-size=15", "spring.r2dbc.pool.max-acquire-time=3m")
"spring.r2dbc.pool.max-size=15", "spring.r2dbc.pool.max-acquire-time=3m",
"spring.r2dbc.pool.min-idle=1", "spring.r2dbc.pool.max-validation-time=1s",
"spring.r2dbc.pool.initial-size=0")
.run((context) -> {
assertThat(context).hasSingleBean(ConnectionFactory.class)
.hasSingleBean(ConnectionPool.class)
.hasSingleBean(R2dbcProperties.class);
ConnectionPool connectionPool = context.getBean(ConnectionPool.class);
PoolMetrics poolMetrics = connectionPool.getMetrics().get();
assertThat(poolMetrics.getMaxAllocatedSize()).isEqualTo(15);
assertThat(connectionPool).hasFieldOrPropertyWithValue("maxAcquireTime", Duration.ofMinutes(3));
connectionPool.warmup().block();
try {
PoolMetrics poolMetrics = connectionPool.getMetrics().get();
assertThat(poolMetrics.idleSize()).isEqualTo(1);
assertThat(poolMetrics.getMaxAllocatedSize()).isEqualTo(15);
assertThat(connectionPool).hasFieldOrPropertyWithValue("maxAcquireTime", Duration.ofMinutes(3));
assertThat(connectionPool).hasFieldOrPropertyWithValue("maxValidationTime", Duration.ofSeconds(1));
}
finally {
connectionPool.close().block();
}
});
}

Loading…
Cancel
Save