|
|
|
|
@@ -29,6 +29,7 @@ import net.ttddyy.dsproxy.listener.logging.CommonsQueryLoggingListener;
|
|
|
|
|
import net.ttddyy.dsproxy.listener.logging.CommonsSlowQueryListener;
|
|
|
|
|
import net.ttddyy.dsproxy.listener.logging.JULQueryLoggingListener;
|
|
|
|
|
import net.ttddyy.dsproxy.listener.logging.JULSlowQueryListener;
|
|
|
|
|
import net.ttddyy.dsproxy.listener.logging.SLF4JLogLevel;
|
|
|
|
|
import net.ttddyy.dsproxy.listener.logging.SLF4JQueryLoggingListener;
|
|
|
|
|
import net.ttddyy.dsproxy.listener.logging.SLF4JSlowQueryListener;
|
|
|
|
|
import net.ttddyy.dsproxy.listener.logging.SystemOutQueryLoggingListener;
|
|
|
|
|
@@ -53,6 +54,7 @@ import org.springframework.context.annotation.Configuration;
|
|
|
|
|
import org.springframework.context.annotation.Primary;
|
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
|
import static org.assertj.core.api.Assertions.filter;
|
|
|
|
|
|
|
|
|
|
class ProxyDataSourceConfigurationTests {
|
|
|
|
|
|
|
|
|
|
@@ -65,7 +67,24 @@ class ProxyDataSourceConfigurationTests {
|
|
|
|
|
.withClassLoader(new FilteredClassLoader("com.p6spy"));
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void testRegisterLogAndSlowQueryLogByDefaultToSlf4j() {
|
|
|
|
|
void testNotRegisterLogAndSlowQueryLogByDefaultToSlf4j() {
|
|
|
|
|
contextRunner.run(context -> {
|
|
|
|
|
DataSource dataSource = context.getBean(DataSource.class);
|
|
|
|
|
ProxyDataSource proxyDataSource = (ProxyDataSource) ((DataSourceWrapper) dataSource)
|
|
|
|
|
.getDecoratedDataSource();
|
|
|
|
|
ChainListener chainListener = proxyDataSource.getProxyConfig().getQueryListener();
|
|
|
|
|
assertThat(chainListener.getListeners()).extracting("class").doesNotContain(SLF4JSlowQueryListener.class);
|
|
|
|
|
assertThat(chainListener.getListeners()).extracting("class")
|
|
|
|
|
.doesNotContain(SLF4JQueryLoggingListener.class);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void testRegisterLogAndSlowQueryLogByDefaultToSlf4jWhenLoggingIsEnabled() {
|
|
|
|
|
ApplicationContextRunner contextRunner = this.contextRunner.withPropertyValues(
|
|
|
|
|
"spring.sleuth.jdbc.datasource-proxy.slow-query.enable-logging=true",
|
|
|
|
|
"spring.sleuth.jdbc.datasource-proxy.query.enable-logging=true");
|
|
|
|
|
|
|
|
|
|
contextRunner.run(context -> {
|
|
|
|
|
DataSource dataSource = context.getBean(DataSource.class);
|
|
|
|
|
ProxyDataSource proxyDataSource = (ProxyDataSource) ((DataSourceWrapper) dataSource)
|
|
|
|
|
@@ -78,8 +97,10 @@ class ProxyDataSourceConfigurationTests {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void testRegisterLogAndSlowQueryLogByUsingSlf4j() {
|
|
|
|
|
ApplicationContextRunner contextRunner = this.contextRunner
|
|
|
|
|
.withPropertyValues("spring.sleuth.jdbc.datasource-proxy.logging=slf4j");
|
|
|
|
|
ApplicationContextRunner contextRunner = this.contextRunner.withPropertyValues(
|
|
|
|
|
"spring.sleuth.jdbc.datasource-proxy.logging=slf4j",
|
|
|
|
|
"spring.sleuth.jdbc.datasource-proxy.slow-query.enable-logging=true",
|
|
|
|
|
"spring.sleuth.jdbc.datasource-proxy.query.enable-logging=true");
|
|
|
|
|
|
|
|
|
|
contextRunner.run(context -> {
|
|
|
|
|
DataSource dataSource = context.getBean(DataSource.class);
|
|
|
|
|
@@ -93,8 +114,10 @@ class ProxyDataSourceConfigurationTests {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void testRegisterLogAndSlowQueryLogUsingSystemOut() {
|
|
|
|
|
ApplicationContextRunner contextRunner = this.contextRunner
|
|
|
|
|
.withPropertyValues("spring.sleuth.jdbc.datasource-proxy.logging=sysout");
|
|
|
|
|
ApplicationContextRunner contextRunner = this.contextRunner.withPropertyValues(
|
|
|
|
|
"spring.sleuth.jdbc.datasource-proxy.logging=sysout",
|
|
|
|
|
"spring.sleuth.jdbc.datasource-proxy.slow-query.enable-logging=true",
|
|
|
|
|
"spring.sleuth.jdbc.datasource-proxy.query.enable-logging=true");
|
|
|
|
|
|
|
|
|
|
contextRunner.run(context -> {
|
|
|
|
|
DataSource dataSource = context.getBean(DataSource.class);
|
|
|
|
|
@@ -108,8 +131,10 @@ class ProxyDataSourceConfigurationTests {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void testRegisterLogAndSlowQueryLogUsingJUL() {
|
|
|
|
|
ApplicationContextRunner contextRunner = this.contextRunner
|
|
|
|
|
.withPropertyValues("spring.sleuth.jdbc.datasourceProxy.logging=jul");
|
|
|
|
|
ApplicationContextRunner contextRunner = this.contextRunner.withPropertyValues(
|
|
|
|
|
"spring.sleuth.jdbc.datasourceProxy.logging=jul",
|
|
|
|
|
"spring.sleuth.jdbc.datasource-proxy.slow-query.enable-logging=true",
|
|
|
|
|
"spring.sleuth.jdbc.datasource-proxy.query.enable-logging=true");
|
|
|
|
|
|
|
|
|
|
contextRunner.run(context -> {
|
|
|
|
|
DataSource dataSource = context.getBean(DataSource.class);
|
|
|
|
|
@@ -123,8 +148,10 @@ class ProxyDataSourceConfigurationTests {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void testRegisterLogAndSlowQueryLogUsingApacheCommons() {
|
|
|
|
|
ApplicationContextRunner contextRunner = this.contextRunner
|
|
|
|
|
.withPropertyValues("spring.sleuth.jdbc.datasourceProxy.logging=commons");
|
|
|
|
|
ApplicationContextRunner contextRunner = this.contextRunner.withPropertyValues(
|
|
|
|
|
"spring.sleuth.jdbc.datasourceProxy.logging=commons",
|
|
|
|
|
"spring.sleuth.jdbc.datasource-proxy.slow-query.enable-logging=true",
|
|
|
|
|
"spring.sleuth.jdbc.datasource-proxy.query.enable-logging=true");
|
|
|
|
|
|
|
|
|
|
contextRunner.run(context -> {
|
|
|
|
|
DataSource dataSource = context.getBean(DataSource.class);
|
|
|
|
|
@@ -193,6 +220,27 @@ class ProxyDataSourceConfigurationTests {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void testLogLevelIsCustomizableForLogAndSlowQueryInSlf4j() {
|
|
|
|
|
ApplicationContextRunner contextRunner = this.contextRunner.withPropertyValues(
|
|
|
|
|
"spring.sleuth.jdbc.datasource-proxy.logging=slf4j",
|
|
|
|
|
"spring.sleuth.jdbc.datasource-proxy.query.enable-logging=true",
|
|
|
|
|
"spring.sleuth.jdbc.datasource-proxy.slow-query.enable-logging=true",
|
|
|
|
|
"spring.sleuth.jdbc.datasource-proxy.slow-query.log-level=INFO",
|
|
|
|
|
"spring.sleuth.jdbc.datasource-proxy.query.log-level=INFO");
|
|
|
|
|
|
|
|
|
|
contextRunner.run(context -> {
|
|
|
|
|
DataSource dataSource = context.getBean(DataSource.class);
|
|
|
|
|
ProxyDataSource proxyDataSource = (ProxyDataSource) ((DataSourceWrapper) dataSource)
|
|
|
|
|
.getDecoratedDataSource();
|
|
|
|
|
ChainListener chainListener = proxyDataSource.getProxyConfig().getQueryListener();
|
|
|
|
|
assertThat(filter(chainListener.getListeners()).with("class").equalsTo(SLF4JQueryLoggingListener.class)
|
|
|
|
|
.with("logLevel").equalsTo(SLF4JLogLevel.INFO).get()).hasSize(1);
|
|
|
|
|
assertThat(filter(chainListener.getListeners()).with("class").equalsTo(SLF4JSlowQueryListener.class)
|
|
|
|
|
.with("logLevel").equalsTo(SLF4JLogLevel.INFO).get()).hasSize(1);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
|
static class CustomDataSourceProxyConfiguration {
|
|
|
|
|
|
|
|
|
|
|