|
|
|
@ -35,6 +35,7 @@ import org.mockito.ArgumentMatchers;
|
|
|
|
|
import org.springframework.boot.actuate.autoconfigure.metrics.test.MetricsRun;
|
|
|
|
|
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
|
|
|
|
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
|
|
|
|
import org.springframework.boot.autoconfigure.orm.jpa.EntityManagerFactoryBuilderCustomizer;
|
|
|
|
|
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
|
|
|
|
|
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
|
|
|
|
|
import org.springframework.boot.test.context.FilteredClassLoader;
|
|
|
|
@ -42,6 +43,8 @@ import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
|
import org.springframework.context.annotation.Primary;
|
|
|
|
|
import org.springframework.core.task.SimpleAsyncTaskExecutor;
|
|
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
|
|
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
|
|
|
|
|
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
|
|
|
|
|
|
|
|
|
@ -58,7 +61,7 @@ import static org.mockito.Mockito.mock;
|
|
|
|
|
*/
|
|
|
|
|
class HibernateMetricsAutoConfigurationTests {
|
|
|
|
|
|
|
|
|
|
private ApplicationContextRunner contextRunner = new ApplicationContextRunner().with(MetricsRun.simple())
|
|
|
|
|
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner().with(MetricsRun.simple())
|
|
|
|
|
.withConfiguration(AutoConfigurations.of(DataSourceAutoConfiguration.class,
|
|
|
|
|
HibernateJpaAutoConfiguration.class, HibernateMetricsAutoConfiguration.class))
|
|
|
|
|
.withUserConfiguration(BaseConfiguration.class);
|
|
|
|
@ -127,6 +130,21 @@ class HibernateMetricsAutoConfigurationTests {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void entityManagerFactoryInstrumentationDoesNotDeadlockWithDeferredInitialization() {
|
|
|
|
|
this.contextRunner
|
|
|
|
|
.withPropertyValues("spring.jpa.properties.hibernate.generate_statistics:true",
|
|
|
|
|
"spring.datasource.schema=city-schema.sql", "spring.datasource.data=city-data.sql")
|
|
|
|
|
.withBean(EntityManagerFactoryBuilderCustomizer.class,
|
|
|
|
|
() -> (builder) -> builder.setBootstrapExecutor(new SimpleAsyncTaskExecutor()))
|
|
|
|
|
.run((context) -> {
|
|
|
|
|
JdbcTemplate jdbcTemplate = new JdbcTemplate(context.getBean(DataSource.class));
|
|
|
|
|
assertThat(jdbcTemplate.queryForObject("SELECT COUNT(*) from CITY", Integer.class)).isEqualTo(1);
|
|
|
|
|
MeterRegistry registry = context.getBean(MeterRegistry.class);
|
|
|
|
|
registry.get("hibernate.statements").tags("entityManagerFactory", "entityManagerFactory").meter();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Configuration(proxyBeanMethods = false)
|
|
|
|
|
static class BaseConfiguration {
|
|
|
|
|
|
|
|
|
|