Search in sources :

Example 1 with ConnectionPoolConfiguration

use of io.r2dbc.pool.ConnectionPoolConfiguration in project spring-boot by spring-projects.

the class ConnectionFactoryBuilderTests method buildWhenDerivedFromPoolReturnsNewNonPooledConnectionFactory.

@Test
void buildWhenDerivedFromPoolReturnsNewNonPooledConnectionFactory() {
    ConnectionFactory connectionFactory = ConnectionFactoryBuilder.withUrl(EmbeddedDatabaseConnection.H2.getUrl(UUID.randomUUID().toString())).build();
    ConnectionFactoryOptions initialOptions = ((OptionsCapableConnectionFactory) connectionFactory).getOptions();
    ConnectionPoolConfiguration poolConfiguration = ConnectionPoolConfiguration.builder(connectionFactory).build();
    ConnectionPool pool = new ConnectionPool(poolConfiguration);
    ConnectionFactory derived = ConnectionFactoryBuilder.derivedFrom(pool).username("admin").password("secret").build();
    assertThat(derived).isNotInstanceOf(ConnectionPool.class).isInstanceOf(OptionsCapableConnectionFactory.class);
    ConnectionFactoryOptions derivedOptions = ((OptionsCapableConnectionFactory) derived).getOptions();
    assertThat(derivedOptions.getRequiredValue(ConnectionFactoryOptions.USER)).isEqualTo("admin");
    assertThat(derivedOptions.getRequiredValue(ConnectionFactoryOptions.PASSWORD)).isEqualTo("secret");
    assertMatchingOptions(derivedOptions, initialOptions, ConnectionFactoryOptions.CONNECT_TIMEOUT, ConnectionFactoryOptions.DATABASE, ConnectionFactoryOptions.DRIVER, ConnectionFactoryOptions.HOST, ConnectionFactoryOptions.PORT, ConnectionFactoryOptions.PROTOCOL, ConnectionFactoryOptions.SSL);
}
Also used : ConnectionPool(io.r2dbc.pool.ConnectionPool) ConnectionFactory(io.r2dbc.spi.ConnectionFactory) ConnectionFactoryOptions(io.r2dbc.spi.ConnectionFactoryOptions) ConnectionPoolConfiguration(io.r2dbc.pool.ConnectionPoolConfiguration) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with ConnectionPoolConfiguration

use of io.r2dbc.pool.ConnectionPoolConfiguration 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 3 with ConnectionPoolConfiguration

use of io.r2dbc.pool.ConnectionPoolConfiguration 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

ConnectionPool (io.r2dbc.pool.ConnectionPool)3 ConnectionPoolConfiguration (io.r2dbc.pool.ConnectionPoolConfiguration)3 ConnectionFactory (io.r2dbc.spi.ConnectionFactory)3 ConnectionFactoryOptions (io.r2dbc.spi.ConnectionFactoryOptions)3 Test (org.junit.jupiter.api.Test)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 H2ConnectionFactoryMetadata (io.r2dbc.h2.H2ConnectionFactoryMetadata)2 PoolingConnectionFactoryProvider (io.r2dbc.pool.PoolingConnectionFactoryProvider)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 Arguments (org.junit.jupiter.params.provider.Arguments)2 MethodSource (org.junit.jupiter.params.provider.MethodSource)2 Mockito.mock (org.mockito.Mockito.mock)2