use of io.r2dbc.pool.ConnectionPool in project spring-boot by spring-projects.
the class ConnectionPoolMetricsTests method connectionFactoryIsInstrumented.
@Test
void connectionFactoryIsInstrumented() {
SimpleMeterRegistry registry = new SimpleMeterRegistry();
ConnectionPool connectionPool = new ConnectionPool(ConnectionPoolConfiguration.builder(this.connectionFactory).initialSize(3).maxSize(7).build());
ConnectionPoolMetrics metrics = new ConnectionPoolMetrics(connectionPool, "test-pool", Tags.of(testTag, regionTag));
metrics.bindTo(registry);
// acquire two connections
connectionPool.create().as(StepVerifier::create).expectNextCount(1).verifyComplete();
connectionPool.create().as(StepVerifier::create).expectNextCount(1).verifyComplete();
assertGauge(registry, "r2dbc.pool.acquired", 2);
assertGauge(registry, "r2dbc.pool.allocated", 3);
assertGauge(registry, "r2dbc.pool.idle", 1);
assertGauge(registry, "r2dbc.pool.pending", 0);
assertGauge(registry, "r2dbc.pool.max.allocated", 7);
assertGauge(registry, "r2dbc.pool.max.pending", Integer.MAX_VALUE);
}
use of io.r2dbc.pool.ConnectionPool in project spring-boot by spring-projects.
the class R2dbcAutoConfigurationTests method configureWithUrlAndDefaultDoNotOverrideDefaultTimeouts.
@Test
void configureWithUrlAndDefaultDoNotOverrideDefaultTimeouts() {
this.contextRunner.withPropertyValues("spring.r2dbc.url:r2dbc:h2:mem:///" + randomDatabaseName()).run((context) -> {
assertThat(context).hasSingleBean(ConnectionFactory.class).hasSingleBean(ConnectionPool.class).hasSingleBean(R2dbcProperties.class);
ConnectionPool connectionPool = context.getBean(ConnectionPool.class);
assertThat(connectionPool).hasFieldOrPropertyWithValue("maxAcquireTime", Duration.ofNanos(-1));
});
}
use of io.r2dbc.pool.ConnectionPool in project spring-boot by spring-projects.
the class R2dbcAutoConfigurationTests method configureWithUrlPoolAndNoPoolPropertiesCreatesPool.
@Test
void configureWithUrlPoolAndNoPoolPropertiesCreatesPool() {
this.contextRunner.withPropertyValues("spring.r2dbc.url:r2dbc:pool:h2:mem:///" + randomDatabaseName() + "?maxSize=12").run((context) -> {
assertThat(context).hasSingleBean(ConnectionFactory.class).hasSingleBean(ConnectionPool.class);
ConnectionPool connectionPool = context.getBean(ConnectionPool.class);
assertThat(connectionPool.getMetrics().get().getMaxAllocatedSize()).isEqualTo(12);
});
}
use of io.r2dbc.pool.ConnectionPool in project spring-boot by spring-projects.
the class R2dbcAutoConfigurationTests method configureWithPoolInvokeOptionCustomizer.
@Test
void configureWithPoolInvokeOptionCustomizer() {
this.contextRunner.withPropertyValues("spring.r2dbc.url:r2dbc:simple://host/database").withUserConfiguration(CustomizerConfiguration.class).run((context) -> {
assertThat(context).hasSingleBean(ConnectionFactory.class).hasSingleBean(ConnectionPool.class);
ConnectionFactory pool = context.getBean(ConnectionFactory.class);
ConnectionFactory connectionFactory = ((ConnectionPool) pool).unwrap();
assertThat(connectionFactory).asInstanceOf(type(OptionsCapableConnectionFactory.class)).extracting(OptionsCapableConnectionFactory::getOptions).satisfies((options) -> assertThat(options.getRequiredValue(Option.valueOf("customized"))).isEqualTo(Boolean.TRUE));
});
}
use of io.r2dbc.pool.ConnectionPool 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);
}
Aggregations