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);
}
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);
}
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);
}
Aggregations