com.p6spy.engine.spy.P6DataSource Java Examples
The following examples show how to use
com.p6spy.engine.spy.P6DataSource.
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: DataSourceDecoratorAutoConfigurationTests.java From spring-boot-data-source-decorator with Apache License 2.0 | 6 votes |
@Test void testCustomDataSourceDecoratorApplied() { ApplicationContextRunner contextRunner = this.contextRunner.withUserConfiguration(TestDataSourceDecoratorConfiguration.class); contextRunner.run(context -> { DataSource dataSource = context.getBean(DataSource.class); assertThat(dataSource).isNotNull(); DataSource customDataSource = ((DecoratedDataSource) dataSource).getDecoratedDataSource(); assertThat(customDataSource).isInstanceOf(CustomDataSourceProxy.class); DataSource realDataSource = ((DecoratedDataSource) dataSource).getRealDataSource(); assertThat(realDataSource).isInstanceOf(HikariDataSource.class); assertThatDataSourceDecoratingChain(dataSource).containsExactly(CustomDataSourceProxy.class, P6DataSource.class, ProxyDataSource.class, FlexyPoolDataSource.class); }); }
Example #2
Source File: P6DataSourceBeanPostProcessor.java From summerframework with Apache License 2.0 | 5 votes |
@Override public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { if (bean instanceof DataSource && !(bean instanceof P6DataSource)) { P6DataSource dataSource = new P6DataSource((DataSource)bean); dataSource.setRealDataSource(beanName); return dataSource; } else { return bean; } }
Example #3
Source File: P6SpyConfigurationTests.java From spring-boot-data-source-decorator with Apache License 2.0 | 5 votes |
@Test void testCustomListeners() { ApplicationContextRunner contextRunner = this.contextRunner.withUserConfiguration(CustomListenerConfiguration.class); contextRunner.run(context -> { DataSource dataSource = context.getBean(DataSource.class); JdbcEventListenerFactory jdbcEventListenerFactory = context.getBean(JdbcEventListenerFactory.class); GetCountingListener getCountingListener = context.getBean(GetCountingListener.class); ClosingCountingListener closingCountingListener = context.getBean(ClosingCountingListener.class); P6DataSource p6DataSource = (P6DataSource) ((DecoratedDataSource) dataSource).getDecoratedDataSource(); assertThat(p6DataSource).extracting("jdbcEventListenerFactory").isEqualTo(jdbcEventListenerFactory); CompoundJdbcEventListener jdbcEventListener = (CompoundJdbcEventListener) jdbcEventListenerFactory.createJdbcEventListener(); assertThat(jdbcEventListener.getEventListeners()).contains(getCountingListener, closingCountingListener); assertThat(getCountingListener.connectionCount).isEqualTo(0); Connection connection1 = p6DataSource.getConnection(); assertThat(getCountingListener.connectionCount).isEqualTo(1); assertThat(closingCountingListener.connectionCount).isEqualTo(0); Connection connection2 = p6DataSource.getConnection(); assertThat(getCountingListener.connectionCount).isEqualTo(2); connection1.close(); assertThat(closingCountingListener.connectionCount).isEqualTo(1); connection2.close(); assertThat(closingCountingListener.connectionCount).isEqualTo(2); }); }
Example #4
Source File: DataSourceDecoratorAutoConfigurationTests.java From spring-boot-data-source-decorator with Apache License 2.0 | 5 votes |
@Test void testDecoratingInDefaultOrder() { contextRunner.run(context -> { DataSource dataSource = context.getBean(DataSource.class); assertThatDataSourceDecoratingChain(dataSource).containsExactly(P6DataSource.class, ProxyDataSource.class, FlexyPoolDataSource.class); }); }
Example #5
Source File: DataSourceDecoratorAutoConfigurationTests.java From spring-boot-data-source-decorator with Apache License 2.0 | 5 votes |
@Test void testDecoratingWhenDefaultProxyProviderNotAvailable() { ApplicationContextRunner contextRunner = this.contextRunner.withClassLoader(new HidePackagesClassLoader("com.vladmihalcea.flexypool")); contextRunner.run(context -> { DataSource dataSource = context.getBean(DataSource.class); assertThat(((DecoratedDataSource) dataSource).getRealDataSource()).isInstanceOf(HikariDataSource.class); assertThatDataSourceDecoratingChain(dataSource).containsExactly(P6DataSource.class, ProxyDataSource.class); }); }
Example #6
Source File: DataSourceDecoratorAutoConfigurationTests.java From spring-boot-data-source-decorator with Apache License 2.0 | 5 votes |
@Test void testDecoratingChainBuiltCorrectly() { contextRunner.run(context -> { DataSource dataSource = context.getBean(DataSource.class); DecoratedDataSource dataSource1 = context.getBean(DecoratedDataSource.class); assertThat(dataSource1).isNotNull(); DataSource p6DataSource = dataSource1.getDecoratedDataSource(); assertThat(p6DataSource).isNotNull(); assertThat(p6DataSource).isInstanceOf(P6DataSource.class); DataSource proxyDataSource = (DataSource) new DirectFieldAccessor(p6DataSource) .getPropertyValue("realDataSource"); assertThat(proxyDataSource).isNotNull(); assertThat(proxyDataSource).isInstanceOf(ProxyDataSource.class); DataSource flexyDataSource = (DataSource) new DirectFieldAccessor(proxyDataSource) .getPropertyValue("dataSource"); assertThat(flexyDataSource).isNotNull(); assertThat(flexyDataSource).isInstanceOf(FlexyPoolDataSource.class); DataSource realDataSource = (DataSource) new DirectFieldAccessor(flexyDataSource) .getPropertyValue("targetDataSource"); assertThat(realDataSource).isNotNull(); assertThat(realDataSource).isInstanceOf(HikariDataSource.class); assertThatDataSourceDecoratingChain(dataSource).containsExactly(P6DataSource.class, ProxyDataSource.class, FlexyPoolDataSource.class); assertThat(dataSource.toString()).isEqualTo( "p6SpyDataSourceDecorator [com.p6spy.engine.spy.P6DataSource] -> " + "proxyDataSourceDecorator [net.ttddyy.dsproxy.support.ProxyDataSource] -> " + "flexyPoolDataSourceDecorator [com.vladmihalcea.flexypool.FlexyPoolDataSource] -> " + "dataSource [com.zaxxer.hikari.HikariDataSource]"); }); }
Example #7
Source File: P6SpyDataSourceDecorator.java From spring-boot-data-source-decorator with Apache License 2.0 | 4 votes |
@Override public DataSource decorate(String beanName, DataSource dataSource) { P6DataSource p6DataSource = new P6DataSource(dataSource); p6DataSource.setJdbcEventListenerFactory(jdbcEventListenerFactory); return p6DataSource; }