|
|
@ -29,7 +29,6 @@ import io.r2dbc.pool.ConnectionPool;
|
|
|
|
import io.r2dbc.pool.PoolMetrics;
|
|
|
|
import io.r2dbc.pool.PoolMetrics;
|
|
|
|
import io.r2dbc.spi.ConnectionFactory;
|
|
|
|
import io.r2dbc.spi.ConnectionFactory;
|
|
|
|
import io.r2dbc.spi.Option;
|
|
|
|
import io.r2dbc.spi.Option;
|
|
|
|
import io.r2dbc.spi.ValidationDepth;
|
|
|
|
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.BeanCreationException;
|
|
|
|
import org.springframework.beans.factory.BeanCreationException;
|
|
|
@ -63,27 +62,25 @@ class R2dbcAutoConfigurationTests {
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void configureWithUrlAndPoolPropertiesApplyProperties() {
|
|
|
|
void configureWithUrlAndPoolPropertiesApplyProperties() {
|
|
|
|
this.contextRunner
|
|
|
|
this.contextRunner.withPropertyValues("spring.r2dbc.url:r2dbc:h2:mem:///" + randomDatabaseName(),
|
|
|
|
.withPropertyValues("spring.r2dbc.url:r2dbc:h2:mem:///" + randomDatabaseName(),
|
|
|
|
"spring.r2dbc.pool.max-size=15", "spring.r2dbc.pool.max-acquire-time=3m").run((context) -> {
|
|
|
|
"spring.r2dbc.pool.initial-size=5", "spring.r2dbc.pool.max-size=15",
|
|
|
|
|
|
|
|
"spring.r2dbc.pool.max-idle-time=1ms", "spring.r2dbc.pool.max-life-time=2s",
|
|
|
|
|
|
|
|
"spring.r2dbc.pool.max-acquire-time=3m", "spring.r2dbc.pool.max-create-connection-time=4h",
|
|
|
|
|
|
|
|
"spring.r2dbc.pool.validation-query=SELECT 1", "spring.r2dbc.pool.validation-depth=remote")
|
|
|
|
|
|
|
|
.run((context) -> {
|
|
|
|
|
|
|
|
assertThat(context).hasSingleBean(ConnectionFactory.class).hasSingleBean(ConnectionPool.class)
|
|
|
|
assertThat(context).hasSingleBean(ConnectionFactory.class).hasSingleBean(ConnectionPool.class)
|
|
|
|
.hasSingleBean(R2dbcProperties.class);
|
|
|
|
.hasSingleBean(R2dbcProperties.class);
|
|
|
|
PoolMetrics poolMetrics = context.getBean(ConnectionPool.class).getMetrics().get();
|
|
|
|
ConnectionPool connectionPool = context.getBean(ConnectionPool.class);
|
|
|
|
|
|
|
|
PoolMetrics poolMetrics = connectionPool.getMetrics().get();
|
|
|
|
assertThat(poolMetrics.getMaxAllocatedSize()).isEqualTo(15);
|
|
|
|
assertThat(poolMetrics.getMaxAllocatedSize()).isEqualTo(15);
|
|
|
|
|
|
|
|
assertThat(connectionPool).hasFieldOrPropertyWithValue("maxAcquireTime", Duration.ofMinutes(3));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
R2dbcProperties properties = context.getBean(R2dbcProperties.class);
|
|
|
|
@Test
|
|
|
|
assertThat(properties.getPool().getInitialSize()).isEqualTo(5);
|
|
|
|
void configureWithUrlAndDefaultDoNotOverrideDefaultTimeouts() {
|
|
|
|
assertThat(properties.getPool().getMaxSize()).isEqualTo(15);
|
|
|
|
this.contextRunner.withPropertyValues("spring.r2dbc.url:r2dbc:h2:mem:///" + randomDatabaseName())
|
|
|
|
assertThat(properties.getPool().getMaxIdleTime()).isEqualTo(Duration.ofMillis(1));
|
|
|
|
.run((context) -> {
|
|
|
|
assertThat(properties.getPool().getMaxLifeTime()).isEqualTo(Duration.ofSeconds(2));
|
|
|
|
assertThat(context).hasSingleBean(ConnectionFactory.class).hasSingleBean(ConnectionPool.class)
|
|
|
|
assertThat(properties.getPool().getMaxAcquireTime()).isEqualTo(Duration.ofMinutes(3));
|
|
|
|
.hasSingleBean(R2dbcProperties.class);
|
|
|
|
assertThat(properties.getPool().getMaxCreateConnectionTime()).isEqualTo(Duration.ofHours(4));
|
|
|
|
ConnectionPool connectionPool = context.getBean(ConnectionPool.class);
|
|
|
|
assertThat(properties.getPool().getValidationQuery()).isEqualTo("SELECT 1");
|
|
|
|
assertThat(connectionPool).hasFieldOrPropertyWithValue("maxAcquireTime", Duration.ZERO);
|
|
|
|
assertThat(properties.getPool().getValidationDepth()).isEqualTo(ValidationDepth.REMOTE);
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|