Search in sources :

Example 1 with PoolingAwareOptionsCapableWrapper

use of org.springframework.boot.r2dbc.ConnectionFactoryBuilder.PoolingAwareOptionsCapableWrapper in project spring-boot by spring-projects.

the class ConnectionFactoryBuilderTests method stringlyTypedOptionIsMappedWhenCreatingPoolConfiguration.

@ParameterizedTest
@SuppressWarnings({ "rawtypes", "unchecked" })
@MethodSource("primitivePoolingConnectionProviderOptions")
void stringlyTypedOptionIsMappedWhenCreatingPoolConfiguration(Option option) {
    String url = "r2dbc:pool:h2:mem:///" + UUID.randomUUID();
    ExpectedOption expectedOption = ExpectedOption.get(option);
    ConnectionFactoryOptions options = ConnectionFactoryBuilder.withUrl(url).configure((builder) -> builder.option(PoolingConnectionFactoryProvider.POOL_NAME, "defaultName").option(option, expectedOption.value.toString())).buildOptions();
    ConnectionPoolConfiguration configuration = new PoolingAwareOptionsCapableWrapper().connectionPoolConfiguration(options, mock(ConnectionFactory.class));
    assertThat(configuration).extracting(expectedOption.property).isEqualTo(expectedOption.value);
}
Also used : ConnectionFactory(io.r2dbc.spi.ConnectionFactory) PoolingAwareOptionsCapableWrapper(org.springframework.boot.r2dbc.ConnectionFactoryBuilder.PoolingAwareOptionsCapableWrapper) H2ConnectionFactoryMetadata(io.r2dbc.h2.H2ConnectionFactoryMetadata) PoolingConnectionFactoryProvider(io.r2dbc.pool.PoolingConnectionFactoryProvider) ConnectionFactoryOptions(io.r2dbc.spi.ConnectionFactoryOptions) FieldFilter(org.springframework.util.ReflectionUtils.FieldFilter) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ConnectionPoolConfiguration(io.r2dbc.pool.ConnectionPoolConfiguration) UUID(java.util.UUID) ConnectionPool(io.r2dbc.pool.ConnectionPool) Arguments(org.junit.jupiter.params.provider.Arguments) Function(java.util.function.Function) Option(io.r2dbc.spi.Option) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ReflectionUtils(org.springframework.util.ReflectionUtils) Duration(java.time.Duration) Assertions.assertThatIllegalArgumentException(org.assertj.core.api.Assertions.assertThatIllegalArgumentException) ResolvableType(org.springframework.core.ResolvableType) ValidationDepth(io.r2dbc.spi.ValidationDepth) MethodSource(org.junit.jupiter.params.provider.MethodSource) Mockito.mock(org.mockito.Mockito.mock) ConnectionFactory(io.r2dbc.spi.ConnectionFactory) ConnectionFactoryOptions(io.r2dbc.spi.ConnectionFactoryOptions) PoolingAwareOptionsCapableWrapper(org.springframework.boot.r2dbc.ConnectionFactoryBuilder.PoolingAwareOptionsCapableWrapper) ConnectionPoolConfiguration(io.r2dbc.pool.ConnectionPoolConfiguration) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 2 with PoolingAwareOptionsCapableWrapper

use of org.springframework.boot.r2dbc.ConnectionFactoryBuilder.PoolingAwareOptionsCapableWrapper in project spring-boot by spring-projects.

the class ConnectionFactoryBuilderTests method optionIsMappedWhenCreatingPoolConfiguration.

@ParameterizedTest
@SuppressWarnings({ "rawtypes", "unchecked" })
@MethodSource("poolingConnectionProviderOptions")
void optionIsMappedWhenCreatingPoolConfiguration(Option option) {
    String url = "r2dbc:pool:h2:mem:///" + UUID.randomUUID();
    ExpectedOption expectedOption = ExpectedOption.get(option);
    ConnectionFactoryOptions options = ConnectionFactoryBuilder.withUrl(url).configure((builder) -> builder.option(PoolingConnectionFactoryProvider.POOL_NAME, "defaultName").option(option, expectedOption.value)).buildOptions();
    ConnectionPoolConfiguration configuration = new PoolingAwareOptionsCapableWrapper().connectionPoolConfiguration(options, mock(ConnectionFactory.class));
    assertThat(configuration).extracting(expectedOption.property).isEqualTo(expectedOption.value);
}
Also used : ConnectionFactory(io.r2dbc.spi.ConnectionFactory) PoolingAwareOptionsCapableWrapper(org.springframework.boot.r2dbc.ConnectionFactoryBuilder.PoolingAwareOptionsCapableWrapper) H2ConnectionFactoryMetadata(io.r2dbc.h2.H2ConnectionFactoryMetadata) PoolingConnectionFactoryProvider(io.r2dbc.pool.PoolingConnectionFactoryProvider) ConnectionFactoryOptions(io.r2dbc.spi.ConnectionFactoryOptions) FieldFilter(org.springframework.util.ReflectionUtils.FieldFilter) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ConnectionPoolConfiguration(io.r2dbc.pool.ConnectionPoolConfiguration) UUID(java.util.UUID) ConnectionPool(io.r2dbc.pool.ConnectionPool) Arguments(org.junit.jupiter.params.provider.Arguments) Function(java.util.function.Function) Option(io.r2dbc.spi.Option) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ReflectionUtils(org.springframework.util.ReflectionUtils) Duration(java.time.Duration) Assertions.assertThatIllegalArgumentException(org.assertj.core.api.Assertions.assertThatIllegalArgumentException) ResolvableType(org.springframework.core.ResolvableType) ValidationDepth(io.r2dbc.spi.ValidationDepth) MethodSource(org.junit.jupiter.params.provider.MethodSource) Mockito.mock(org.mockito.Mockito.mock) ConnectionFactory(io.r2dbc.spi.ConnectionFactory) ConnectionFactoryOptions(io.r2dbc.spi.ConnectionFactoryOptions) PoolingAwareOptionsCapableWrapper(org.springframework.boot.r2dbc.ConnectionFactoryBuilder.PoolingAwareOptionsCapableWrapper) ConnectionPoolConfiguration(io.r2dbc.pool.ConnectionPoolConfiguration) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

H2ConnectionFactoryMetadata (io.r2dbc.h2.H2ConnectionFactoryMetadata)2 ConnectionPool (io.r2dbc.pool.ConnectionPool)2 ConnectionPoolConfiguration (io.r2dbc.pool.ConnectionPoolConfiguration)2 PoolingConnectionFactoryProvider (io.r2dbc.pool.PoolingConnectionFactoryProvider)2 ConnectionFactory (io.r2dbc.spi.ConnectionFactory)2 ConnectionFactoryOptions (io.r2dbc.spi.ConnectionFactoryOptions)2 Option (io.r2dbc.spi.Option)2 ValidationDepth (io.r2dbc.spi.ValidationDepth)2 Duration (java.time.Duration)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 UUID (java.util.UUID)2 Function (java.util.function.Function)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Assertions.assertThatIllegalArgumentException (org.assertj.core.api.Assertions.assertThatIllegalArgumentException)2 Test (org.junit.jupiter.api.Test)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 Arguments (org.junit.jupiter.params.provider.Arguments)2 MethodSource (org.junit.jupiter.params.provider.MethodSource)2 Mockito.mock (org.mockito.Mockito.mock)2