use of io.r2dbc.spi.ConnectionFactoryOptions 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.spi.ConnectionFactoryOptions in project spring-boot by spring-projects.
the class ConnectionFactoryBuilderTests method buildOptionsWithSpecificSettingsShouldOverrideUrlOptions.
@Test
void buildOptionsWithSpecificSettingsShouldOverrideUrlOptions() {
ConnectionFactoryOptions options = ConnectionFactoryBuilder.withUrl("r2dbc:simple://user:password@myhost/mydatabase").username("another-user").password("another-password").hostname("another-host").port(1234).database("another-database").buildOptions();
assertThat(options.getRequiredValue(ConnectionFactoryOptions.USER)).isEqualTo("another-user");
assertThat(options.getRequiredValue(ConnectionFactoryOptions.PASSWORD)).isEqualTo("another-password");
assertThat(options.getRequiredValue(ConnectionFactoryOptions.HOST)).isEqualTo("another-host");
assertThat(options.getRequiredValue(ConnectionFactoryOptions.PORT)).isEqualTo(1234);
assertThat(options.getRequiredValue(ConnectionFactoryOptions.DATABASE)).isEqualTo("another-database");
}
use of io.r2dbc.spi.ConnectionFactoryOptions in project spring-boot by spring-projects.
the class ConnectionFactoryBuilderTests method buildOptionsWithCompleteUrlShouldExposeOptions.
@Test
void buildOptionsWithCompleteUrlShouldExposeOptions() {
ConnectionFactoryOptions options = ConnectionFactoryBuilder.withUrl("r2dbc:simple:proto://user:password@myhost:4711/mydatabase").buildOptions();
assertThat(options.getRequiredValue(ConnectionFactoryOptions.DRIVER)).isEqualTo("simple");
assertThat(options.getRequiredValue(ConnectionFactoryOptions.PROTOCOL)).isEqualTo("proto");
assertThat(options.getRequiredValue(ConnectionFactoryOptions.USER)).isEqualTo("user");
assertThat(options.getRequiredValue(ConnectionFactoryOptions.PASSWORD)).isEqualTo("password");
assertThat(options.getRequiredValue(ConnectionFactoryOptions.HOST)).isEqualTo("myhost");
assertThat(options.getRequiredValue(ConnectionFactoryOptions.PORT)).isEqualTo(4711);
assertThat(options.getRequiredValue(ConnectionFactoryOptions.DATABASE)).isEqualTo("mydatabase");
}
use of io.r2dbc.spi.ConnectionFactoryOptions in project spring-boot by spring-projects.
the class ConnectionFactoryBuilderTests method buildWhenDerivedWithNewDatabaseReturnsNewConnectionFactory.
@Test
void buildWhenDerivedWithNewDatabaseReturnsNewConnectionFactory() {
String intialDatabaseName = UUID.randomUUID().toString();
ConnectionFactory connectionFactory = ConnectionFactoryBuilder.withUrl(EmbeddedDatabaseConnection.H2.getUrl(intialDatabaseName)).build();
ConnectionFactoryOptions initialOptions = ((OptionsCapableConnectionFactory) connectionFactory).getOptions();
String derivedDatabaseName = UUID.randomUUID().toString();
ConnectionFactory derived = ConnectionFactoryBuilder.derivedFrom(connectionFactory).database(derivedDatabaseName).build();
ConnectionFactoryOptions derivedOptions = ((OptionsCapableConnectionFactory) derived).getOptions();
assertThat(derivedOptions.getRequiredValue(ConnectionFactoryOptions.DATABASE)).isEqualTo(derivedDatabaseName);
assertMatchingOptions(derivedOptions, initialOptions, ConnectionFactoryOptions.CONNECT_TIMEOUT, ConnectionFactoryOptions.DRIVER, ConnectionFactoryOptions.HOST, ConnectionFactoryOptions.PASSWORD, ConnectionFactoryOptions.PORT, ConnectionFactoryOptions.PROTOCOL, ConnectionFactoryOptions.SSL, ConnectionFactoryOptions.USER);
}
use of io.r2dbc.spi.ConnectionFactoryOptions in project spring-boot by spring-projects.
the class ConnectionFactoryBuilderTests method buildOptionsWithEmbeddedConnectionH2ShouldExposeOptions.
@Test
void buildOptionsWithEmbeddedConnectionH2ShouldExposeOptions() {
ConnectionFactoryOptions options = ConnectionFactoryBuilder.withUrl(EmbeddedDatabaseConnection.H2.getUrl("testdb")).buildOptions();
assertThat(options.getRequiredValue(ConnectionFactoryOptions.DRIVER)).isEqualTo("h2");
assertThat(options.getRequiredValue(ConnectionFactoryOptions.PROTOCOL)).isEqualTo("mem");
assertThat(options.getRequiredValue(ConnectionFactoryOptions.DATABASE)).isEqualTo("testdb");
assertThat(options.hasOption(ConnectionFactoryOptions.HOST)).isFalse();
assertThat(options.hasOption(ConnectionFactoryOptions.PORT)).isFalse();
assertThat(options.hasOption(ConnectionFactoryOptions.USER)).isFalse();
assertThat(options.hasOption(ConnectionFactoryOptions.PASSWORD)).isFalse();
assertThat(options.getValue(Option.<String>valueOf("options"))).isEqualTo("DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE");
}
Aggregations