net.ttddyy.dsproxy.listener.ChainListener Java Examples

The following examples show how to use net.ttddyy.dsproxy.listener.ChainListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SleuthProxyDataSourceListenerAutoConfigurationTests.java    From spring-boot-data-source-decorator with Apache License 2.0 5 votes vote down vote up
@Test
void testAddsDatasourceProxyListener() {
    contextRunner.run(context -> {
        DataSource dataSource = context.getBean(DataSource.class);
        ProxyDataSource proxyDataSource = (ProxyDataSource) ((DecoratedDataSource) dataSource).getDecoratedDataSource();
        ChainListener chainListener = proxyDataSource.getProxyConfig().getQueryListener();
        assertThat(chainListener.getListeners()).extracting("class").contains(TracingQueryExecutionListener.class);
    });
}
 
Example #2
Source File: SleuthProxyDataSourceListenerAutoConfigurationTests.java    From spring-boot-data-source-decorator with Apache License 2.0 5 votes vote down vote up
@Test
void testDoesNotAddDatasourceProxyListenerIfNoTracer() {
    ApplicationContextRunner contextRunner = this.contextRunner.withPropertyValues("spring.sleuth.enabled:false");

    contextRunner.run(context -> {
        DataSource dataSource = context.getBean(DataSource.class);
        ProxyDataSource proxyDataSource = (ProxyDataSource) ((DecoratedDataSource) dataSource).getDecoratedDataSource();
        ChainListener chainListener = proxyDataSource.getProxyConfig().getQueryListener();
        assertThat(chainListener.getListeners()).extracting("class").doesNotContain(TracingQueryExecutionListener.class);
    });
}
 
Example #3
Source File: ProxyDataSourceConfigurationTests.java    From spring-boot-data-source-decorator with Apache License 2.0 5 votes vote down vote up
@Test
void testRegisterLogAndSlowQueryLogByDefaultToSlf4j() {
    contextRunner.run(context -> {
        DataSource dataSource = context.getBean(DataSource.class);
        ProxyDataSource proxyDataSource = (ProxyDataSource) ((DecoratedDataSource) dataSource).getDecoratedDataSource();
        ChainListener chainListener = proxyDataSource.getProxyConfig().getQueryListener();
        assertThat(chainListener.getListeners()).extracting("class").contains(SLF4JSlowQueryListener.class);
        assertThat(chainListener.getListeners()).extracting("class").contains(SLF4JQueryLoggingListener.class);
    });
}
 
Example #4
Source File: ProxyDataSourceConfigurationTests.java    From spring-boot-data-source-decorator with Apache License 2.0 5 votes vote down vote up
@Test
void testRegisterLogAndSlowQueryLogByUsingSlf4j() {
    ApplicationContextRunner contextRunner = this.contextRunner.withPropertyValues("decorator.datasource.datasource-proxy.logging:slf4j");

    contextRunner.run(context -> {
        DataSource dataSource = context.getBean(DataSource.class);
        ProxyDataSource proxyDataSource = (ProxyDataSource) ((DecoratedDataSource) dataSource).getDecoratedDataSource();
        ChainListener chainListener = proxyDataSource.getProxyConfig().getQueryListener();
        assertThat(chainListener.getListeners()).extracting("class").contains(SLF4JSlowQueryListener.class);
        assertThat(chainListener.getListeners()).extracting("class").contains(SLF4JQueryLoggingListener.class);
    });
}
 
Example #5
Source File: ProxyDataSourceConfigurationTests.java    From spring-boot-data-source-decorator with Apache License 2.0 5 votes vote down vote up
@Test
void testRegisterLogAndSlowQueryLogUsingSystemOut() {
    ApplicationContextRunner contextRunner = this.contextRunner.withPropertyValues("decorator.datasource.datasource-proxy.logging:sysout");

    contextRunner.run(context -> {
        DataSource dataSource = context.getBean(DataSource.class);
        ProxyDataSource proxyDataSource = (ProxyDataSource) ((DecoratedDataSource) dataSource).getDecoratedDataSource();
        ChainListener chainListener = proxyDataSource.getProxyConfig().getQueryListener();
        assertThat(chainListener.getListeners()).extracting("class").contains(SystemOutSlowQueryListener.class);
        assertThat(chainListener.getListeners()).extracting("class").contains(SystemOutQueryLoggingListener.class);
    });
}
 
Example #6
Source File: ProxyDataSourceConfigurationTests.java    From spring-boot-data-source-decorator with Apache License 2.0 5 votes vote down vote up
@Test
void testRegisterLogAndSlowQueryLogUsingJUL() {
    ApplicationContextRunner contextRunner = this.contextRunner.withPropertyValues("decorator.datasource.datasourceProxy.logging:jul");

    contextRunner.run(context -> {
        DataSource dataSource = context.getBean(DataSource.class);
        ProxyDataSource proxyDataSource = (ProxyDataSource) ((DecoratedDataSource) dataSource).getDecoratedDataSource();
        ChainListener chainListener = proxyDataSource.getProxyConfig().getQueryListener();
        assertThat(chainListener.getListeners()).extracting("class").contains(JULSlowQueryListener.class);
        assertThat(chainListener.getListeners()).extracting("class").contains(JULQueryLoggingListener.class);
    });
}
 
Example #7
Source File: ProxyDataSourceConfigurationTests.java    From spring-boot-data-source-decorator with Apache License 2.0 5 votes vote down vote up
@Test
void testRegisterLogAndSlowQueryLogUsingApacheCommons() {
    ApplicationContextRunner contextRunner = this.contextRunner.withPropertyValues("decorator.datasource.datasourceProxy.logging:commons");

    contextRunner.run(context -> {
        DataSource dataSource = context.getBean(DataSource.class);
        ProxyDataSource proxyDataSource = (ProxyDataSource) ((DecoratedDataSource) dataSource).getDecoratedDataSource();
        ChainListener chainListener = proxyDataSource.getProxyConfig().getQueryListener();
        assertThat(chainListener.getListeners()).extracting("class").contains(CommonsSlowQueryListener.class);
        assertThat(chainListener.getListeners()).extracting("class").contains(CommonsQueryLoggingListener.class);
    });
}
 
Example #8
Source File: ProxyDataSourceConfigurationTests.java    From spring-boot-data-source-decorator with Apache License 2.0 5 votes vote down vote up
@Test
void testCustomListeners() {
    ApplicationContextRunner contextRunner = this.contextRunner.withUserConfiguration(CustomListenerConfiguration.class);

    contextRunner.run(context -> {
        DataSource dataSource = context.getBean(DataSource.class);
        ProxyDataSource proxyDataSource = (ProxyDataSource) ((DecoratedDataSource) dataSource).getDecoratedDataSource();
        QueryExecutionListener queryExecutionListener = context.getBean(QueryExecutionListener.class);

        ChainListener chainListener = proxyDataSource.getProxyConfig().getQueryListener();
        assertThat(chainListener.getListeners()).contains(queryExecutionListener);
    });
}
 
Example #9
Source File: AbstractTest.java    From hibernate-master-class with Apache License 2.0 5 votes vote down vote up
protected DataSource newDataSource() {
    if (proxyDataSource()) {
        ChainListener listener = new ChainListener();
        SLF4JQueryLoggingListener loggingListener = new SLF4JQueryLoggingListener();
        loggingListener.setQueryLogEntryCreator(new AbstractTest.InlineQueryLogEntryCreator());
        listener.addListener(loggingListener);
        return ProxyDataSourceBuilder
                .create(getDataSourceProvider().dataSource())
                .name(getClass().getName())
                .listener(listener)
                .build();
    } else {
        return getDataSourceProvider().dataSource();
    }
}
 
Example #10
Source File: QuickPerfSqlDataSourceBuilder.java    From quickperf with Apache License 2.0 4 votes vote down vote up
public ProxyDataSource buildProxy(DataSource dataSource) {

        ProxyDataSource proxyDataSource = new ProxyDataSource();

        ChainListener chainListener = new ChainListener();

        DataSourceQuickPerfListener dataSourceQuickPerfListener = new DataSourceQuickPerfListener();
        chainListener.addListener(dataSourceQuickPerfListener);

        proxyDataSource.addListener(chainListener);

        proxyDataSource.setDataSource(dataSource);

        return proxyDataSource;

    }