use of io.r2dbc.spi.ConnectionFactory in project spring-framework by spring-projects.
the class MapConnectionFactoryLookupUnitTests method addingConnectionFactoryPermitsOverride.
@Test
public void addingConnectionFactoryPermitsOverride() {
Map<String, ConnectionFactory> connectionFactories = new HashMap<>();
DummyConnectionFactory overriddenConnectionFactory = new DummyConnectionFactory();
DummyConnectionFactory expectedConnectionFactory = new DummyConnectionFactory();
connectionFactories.put(CONNECTION_FACTORY_NAME, overriddenConnectionFactory);
MapConnectionFactoryLookup lookup = new MapConnectionFactoryLookup();
lookup.setConnectionFactories(connectionFactories);
lookup.addConnectionFactory(CONNECTION_FACTORY_NAME, expectedConnectionFactory);
ConnectionFactory connectionFactory = lookup.getConnectionFactory(CONNECTION_FACTORY_NAME);
assertThat(connectionFactory).isNotNull().isSameAs(expectedConnectionFactory);
}
use of io.r2dbc.spi.ConnectionFactory in project spring-boot by spring-projects.
the class ConnectionFactoryHealthIndicatorTests method healthIndicatorWhenDatabaseUpWithFailureValidationQuery.
@Test
void healthIndicatorWhenDatabaseUpWithFailureValidationQuery() {
CloseableConnectionFactory connectionFactory = createTestDatabase();
try {
String invalidValidationQuery = "SELECT COUNT(*) from DOES_NOT_EXIST";
ReactiveHealthIndicator healthIndicator = new ConnectionFactoryHealthIndicator(connectionFactory, invalidValidationQuery);
healthIndicator.health().as(StepVerifier::create).assertNext((actual) -> {
assertThat(actual.getStatus()).isEqualTo(Status.DOWN);
assertThat(actual.getDetails()).contains(entry("database", "H2"), entry("validationQuery", invalidValidationQuery));
assertThat(actual.getDetails()).containsOnlyKeys("database", "error", "validationQuery");
}).verifyComplete();
} finally {
StepVerifier.create(connectionFactory.close()).verifyComplete();
}
}
use of io.r2dbc.spi.ConnectionFactory in project spring-boot by spring-projects.
the class ConnectionFactoryHealthIndicatorTests method healthIndicatorWhenDatabaseDownWithConnectionValidation.
@Test
void healthIndicatorWhenDatabaseDownWithConnectionValidation() {
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
given(connectionFactory.getMetadata()).willReturn(() -> "mock");
RuntimeException exception = new RuntimeException("test");
given(connectionFactory.create()).willReturn(Mono.error(exception));
ConnectionFactoryHealthIndicator healthIndicator = new ConnectionFactoryHealthIndicator(connectionFactory);
healthIndicator.health().as(StepVerifier::create).assertNext((actual) -> {
assertThat(actual.getStatus()).isEqualTo(Status.DOWN);
assertThat(actual.getDetails()).containsOnly(entry("database", "mock"), entry("validationQuery", "validate(REMOTE)"), entry("error", "java.lang.RuntimeException: test"));
}).verifyComplete();
}
use of io.r2dbc.spi.ConnectionFactory in project spring-boot by spring-projects.
the class ConnectionFactoryBuilderTests method buildWhenDerivedWithNewCredentialsReturnsNewConnectionFactory.
@Test
void buildWhenDerivedWithNewCredentialsReturnsNewConnectionFactory() {
ConnectionFactory connectionFactory = ConnectionFactoryBuilder.withUrl(EmbeddedDatabaseConnection.H2.getUrl(UUID.randomUUID().toString())).build();
ConnectionFactoryOptions initialOptions = ((OptionsCapableConnectionFactory) connectionFactory).getOptions();
ConnectionFactory derived = ConnectionFactoryBuilder.derivedFrom(connectionFactory).username("admin").password("secret").build();
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.ConnectionFactory in project spring-boot by spring-projects.
the class ConnectionFactoryBuilderTests method buildShouldExposeConnectionFactory.
@Test
void buildShouldExposeConnectionFactory() {
String databaseName = UUID.randomUUID().toString();
ConnectionFactory connectionFactory = ConnectionFactoryBuilder.withUrl(EmbeddedDatabaseConnection.H2.getUrl(databaseName)).build();
assertThat(connectionFactory).isNotNull();
assertThat(connectionFactory.getMetadata().getName()).isEqualTo(H2ConnectionFactoryMetadata.NAME);
}
Aggregations