Search in sources :

Example 1 with ConnectionFactoryOptions

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

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");
}
Also used : ConnectionFactoryOptions(io.r2dbc.spi.ConnectionFactoryOptions) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with ConnectionFactoryOptions

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");
}
Also used : ConnectionFactoryOptions(io.r2dbc.spi.ConnectionFactoryOptions) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with ConnectionFactoryOptions

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);
}
Also used : ConnectionFactory(io.r2dbc.spi.ConnectionFactory) ConnectionFactoryOptions(io.r2dbc.spi.ConnectionFactoryOptions) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with ConnectionFactoryOptions

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");
}
Also used : ConnectionFactoryOptions(io.r2dbc.spi.ConnectionFactoryOptions) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

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