Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
e424dfbe
Commit
e424dfbe
authored
Nov 23, 2018
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish "Perform best effort to retrieve DataSourceProxy"
Closes gh-15206
parent
26f9a928
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
271 additions
and
120 deletions
+271
-120
DataSourceJmxConfiguration.java
...k/boot/autoconfigure/jdbc/DataSourceJmxConfiguration.java
+3
-35
DataSourceJmxConfigurationTests.java
...t/autoconfigure/jdbc/DataSourceJmxConfigurationTests.java
+8
-85
DataSourceUnwrapper.java
...va/org/springframework/boot/jdbc/DataSourceUnwrapper.java
+97
-0
DataSourceUnwrapperNoSpringJdbcTests.java
...ework/boot/jdbc/DataSourceUnwrapperNoSpringJdbcTests.java
+61
-0
DataSourceUnwrapperTests.java
...g/springframework/boot/jdbc/DataSourceUnwrapperTests.java
+102
-0
No files found.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceJmxConfiguration.java
View file @
e424dfbe
...
@@ -26,23 +26,20 @@ import org.apache.commons.logging.Log;
...
@@ -26,23 +26,20 @@ import org.apache.commons.logging.Log;
import
org.apache.commons.logging.LogFactory
;
import
org.apache.commons.logging.LogFactory
;
import
org.apache.tomcat.jdbc.pool.DataSourceProxy
;
import
org.apache.tomcat.jdbc.pool.DataSourceProxy
;
import
org.springframework.aop.framework.AopProxyUtils
;
import
org.springframework.aop.support.AopUtils
;
import
org.springframework.beans.factory.ObjectProvider
;
import
org.springframework.beans.factory.ObjectProvider
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate
;
import
org.springframework.boot.jdbc.DataSourceUnwrapper
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.jdbc.datasource.DelegatingDataSource
;
import
org.springframework.jmx.export.MBeanExporter
;
import
org.springframework.jmx.export.MBeanExporter
;
/**
/**
* Configures DataSource related MBeans.
* Configures DataSource related MBeans.
*
*
* @author Stephane Nicoll
* @author Stephane Nicoll
* @author Tadaya Tsuyukubo
*/
*/
@Configuration
@Configuration
@ConditionalOnProperty
(
prefix
=
"spring.jmx"
,
name
=
"enabled"
,
havingValue
=
"true"
,
matchIfMissing
=
true
)
@ConditionalOnProperty
(
prefix
=
"spring.jmx"
,
name
=
"enabled"
,
havingValue
=
"true"
,
matchIfMissing
=
true
)
...
@@ -93,7 +90,8 @@ class DataSourceJmxConfiguration {
...
@@ -93,7 +90,8 @@ class DataSourceJmxConfiguration {
@Bean
@Bean
@ConditionalOnMissingBean
(
name
=
"dataSourceMBean"
)
@ConditionalOnMissingBean
(
name
=
"dataSourceMBean"
)
public
Object
dataSourceMBean
(
DataSource
dataSource
)
{
public
Object
dataSourceMBean
(
DataSource
dataSource
)
{
DataSourceProxy
dataSourceProxy
=
extractDataSourceProxy
(
dataSource
);
DataSourceProxy
dataSourceProxy
=
DataSourceUnwrapper
.
unwrap
(
dataSource
,
DataSourceProxy
.
class
);
if
(
dataSourceProxy
!=
null
)
{
if
(
dataSourceProxy
!=
null
)
{
try
{
try
{
return
dataSourceProxy
.
createPool
().
getJmxPool
();
return
dataSourceProxy
.
createPool
().
getJmxPool
();
...
@@ -105,36 +103,6 @@ class DataSourceJmxConfiguration {
...
@@ -105,36 +103,6 @@ class DataSourceJmxConfiguration {
return
null
;
return
null
;
}
}
/**
* Perform best effort to retrieve tomcat's {@link DataSourceProxy}.
*
* Since {@link DataSourceProxy#unwrap(Class)} always return {@code null}, it
* cannot directly retrieve {@link DataSourceProxy}. This method tries best effort
* to find {@link DataSourceProxy} if the given {@link DataSource} is wrapped or
* proxied by spring.
* @param dataSource candidate datasource
* @return found DataSourceProxy or null
*/
private
DataSourceProxy
extractDataSourceProxy
(
DataSource
dataSource
)
{
if
(
dataSource
instanceof
DataSourceProxy
)
{
return
(
DataSourceProxy
)
dataSource
;
// found
}
else
if
(
dataSource
instanceof
DelegatingDataSource
)
{
// check delegating target
return
extractDataSourceProxy
(
((
DelegatingDataSource
)
dataSource
).
getTargetDataSource
());
}
else
if
(
AopUtils
.
isAopProxy
(
dataSource
))
{
// for proxy by spring, try target(advised) instance
Object
target
=
AopProxyUtils
.
getSingletonTarget
(
dataSource
);
if
(
target
instanceof
DataSource
)
{
return
extractDataSourceProxy
((
DataSource
)
target
);
}
}
return
null
;
}
}
}
}
}
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceJmxConfigurationTests.java
View file @
e424dfbe
...
@@ -31,9 +31,7 @@ import org.apache.tomcat.jdbc.pool.DataSourceProxy;
...
@@ -31,9 +31,7 @@ import org.apache.tomcat.jdbc.pool.DataSourceProxy;
import
org.apache.tomcat.jdbc.pool.jmx.ConnectionPool
;
import
org.apache.tomcat.jdbc.pool.jmx.ConnectionPool
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.springframework.aop.framework.AopProxyUtils
;
import
org.springframework.aop.framework.ProxyFactory
;
import
org.springframework.aop.framework.ProxyFactory
;
import
org.springframework.aop.support.AopUtils
;
import
org.springframework.beans.factory.config.BeanPostProcessor
;
import
org.springframework.beans.factory.config.BeanPostProcessor
;
import
org.springframework.boot.autoconfigure.AutoConfigurations
;
import
org.springframework.boot.autoconfigure.AutoConfigurations
;
import
org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration
;
import
org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration
;
...
@@ -159,6 +157,7 @@ public class DataSourceJmxConfigurationTests {
...
@@ -159,6 +157,7 @@ public class DataSourceJmxConfigurationTests {
this
.
contextRunner
.
withPropertyValues
(
this
.
contextRunner
.
withPropertyValues
(
"spring.datasource.type="
+
DataSource
.
class
.
getName
(),
"spring.datasource.type="
+
DataSource
.
class
.
getName
(),
"spring.datasource.jmx-enabled=true"
).
run
((
context
)
->
{
"spring.datasource.jmx-enabled=true"
).
run
((
context
)
->
{
assertThat
(
context
).
hasBean
(
"dataSourceMBean"
);
assertThat
(
context
).
hasSingleBean
(
ConnectionPool
.
class
);
assertThat
(
context
).
hasSingleBean
(
ConnectionPool
.
class
);
assertThat
(
context
.
getBean
(
DataSourceProxy
.
class
).
createPool
()
assertThat
(
context
.
getBean
(
DataSourceProxy
.
class
).
createPool
()
.
getJmxPool
())
.
getJmxPool
())
...
@@ -173,12 +172,9 @@ public class DataSourceJmxConfigurationTests {
...
@@ -173,12 +172,9 @@ public class DataSourceJmxConfigurationTests {
"spring.datasource.type="
+
DataSource
.
class
.
getName
(),
"spring.datasource.type="
+
DataSource
.
class
.
getName
(),
"spring.datasource.jmx-enabled=true"
)
"spring.datasource.jmx-enabled=true"
)
.
run
((
context
)
->
{
.
run
((
context
)
->
{
assertThat
(
context
).
hasSingleBean
(
ConnectionPool
.
class
);
assertThat
(
context
).
hasBean
(
"dataSourceMBean"
);
DataSourceProxy
dataSourceProxy
=
(
DataSourceProxy
)
AopProxyUtils
assertThat
(
context
).
getBean
(
"dataSourceMBean"
)
.
getSingletonTarget
(
.
isInstanceOf
(
ConnectionPool
.
class
);
context
.
getBean
(
javax
.
sql
.
DataSource
.
class
));
assertThat
(
dataSourceProxy
.
createPool
().
getJmxPool
())
.
isSameAs
(
context
.
getBean
(
ConnectionPool
.
class
));
});
});
}
}
...
@@ -189,55 +185,12 @@ public class DataSourceJmxConfigurationTests {
...
@@ -189,55 +185,12 @@ public class DataSourceJmxConfigurationTests {
"spring.datasource.type="
+
DataSource
.
class
.
getName
(),
"spring.datasource.type="
+
DataSource
.
class
.
getName
(),
"spring.datasource.jmx-enabled=true"
)
"spring.datasource.jmx-enabled=true"
)
.
run
((
context
)
->
{
.
run
((
context
)
->
{
assertThat
(
context
).
hasSingleBean
(
ConnectionPool
.
class
);
assertThat
(
context
).
hasBean
(
"dataSourceMBean"
);
DataSourceProxy
dataSourceProxy
=
(
DataSourceProxy
)
context
assertThat
(
context
).
getBean
(
"dataSourceMBean"
)
.
getBean
(
DelegatingDataSource
.
class
).
getTargetDataSource
();
.
isInstanceOf
(
ConnectionPool
.
class
);
assertThat
(
dataSourceProxy
.
createPool
().
getJmxPool
())
.
isSameAs
(
context
.
getBean
(
ConnectionPool
.
class
));
});
});
}
}
@Test
public
void
tomcatProxyAndDelegateCanExposeMBeanPool
()
{
this
.
contextRunner
.
withUserConfiguration
(
DataSourceMixWrapAndProxyConfiguration
.
class
)
.
withPropertyValues
(
"spring.datasource.type="
+
DataSource
.
class
.
getName
(),
"spring.datasource.jmx-enabled=true"
)
.
run
((
context
)
->
{
assertThat
(
context
).
hasSingleBean
(
ConnectionPool
.
class
);
DataSourceProxy
dataSourceProxy
=
extractTomcatDataSource
(
context
.
getBean
(
javax
.
sql
.
DataSource
.
class
));
assertThat
(
dataSourceProxy
.
createPool
().
getJmxPool
())
.
isSameAs
(
context
.
getBean
(
ConnectionPool
.
class
));
});
}
private
static
javax
.
sql
.
DataSource
wrap
(
javax
.
sql
.
DataSource
dataSource
)
{
return
(
javax
.
sql
.
DataSource
)
new
ProxyFactory
(
dataSource
).
getProxy
();
}
private
static
javax
.
sql
.
DataSource
delegate
(
javax
.
sql
.
DataSource
dataSource
)
{
return
new
DelegatingDataSource
(
dataSource
);
}
private
static
DataSource
extractTomcatDataSource
(
javax
.
sql
.
DataSource
dataSource
)
{
if
(
dataSource
instanceof
DataSource
)
{
return
(
DataSource
)
dataSource
;
}
else
if
(
dataSource
instanceof
DelegatingDataSource
)
{
return
extractTomcatDataSource
(
((
DelegatingDataSource
)
dataSource
).
getTargetDataSource
());
}
else
if
(
AopUtils
.
isAopProxy
(
dataSource
))
{
return
extractTomcatDataSource
(
(
javax
.
sql
.
DataSource
)
AopProxyUtils
.
getSingletonTarget
(
dataSource
));
}
throw
new
RuntimeException
(
"Not proxied or delegated tomcat DataSource: "
+
dataSource
);
}
@Configuration
@Configuration
static
class
DataSourceProxyConfiguration
{
static
class
DataSourceProxyConfiguration
{
...
@@ -253,7 +206,7 @@ public class DataSourceJmxConfigurationTests {
...
@@ -253,7 +206,7 @@ public class DataSourceJmxConfigurationTests {
@Override
@Override
public
Object
postProcessAfterInitialization
(
Object
bean
,
String
beanName
)
{
public
Object
postProcessAfterInitialization
(
Object
bean
,
String
beanName
)
{
if
(
bean
instanceof
javax
.
sql
.
DataSource
)
{
if
(
bean
instanceof
javax
.
sql
.
DataSource
)
{
return
wrap
((
javax
.
sql
.
DataSource
)
bean
);
return
new
ProxyFactory
(
bean
).
getProxy
(
);
}
}
return
bean
;
return
bean
;
}
}
...
@@ -279,34 +232,4 @@ public class DataSourceJmxConfigurationTests {
...
@@ -279,34 +232,4 @@ public class DataSourceJmxConfigurationTests {
}
}
@Configuration
static
class
DataSourceMixWrapAndProxyConfiguration
{
@Bean
public
static
DataSourceBeanPostProcessor
dataSourceBeanPostProcessor
()
{
return
new
DataSourceBeanPostProcessor
()
{
@Override
public
Object
postProcessAfterInitialization
(
Object
bean
,
String
beanName
)
{
if
(
bean
instanceof
javax
.
sql
.
DataSource
)
{
javax
.
sql
.
DataSource
dataSource
=
(
javax
.
sql
.
DataSource
)
bean
;
// delegate/wrap multiple times
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
if
(
i
%
2
==
0
)
{
dataSource
=
wrap
(
dataSource
);
}
else
{
dataSource
=
delegate
(
dataSource
);
}
}
return
dataSource
;
}
return
bean
;
}
};
}
}
}
}
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/DataSourceUnwrapper.java
0 → 100644
View file @
e424dfbe
/*
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
jdbc
;
import
java.sql.Wrapper
;
import
javax.sql.DataSource
;
import
org.springframework.aop.framework.AopProxyUtils
;
import
org.springframework.aop.support.AopUtils
;
import
org.springframework.jdbc.datasource.DelegatingDataSource
;
import
org.springframework.util.ClassUtils
;
/**
* Unwraps a {@link DataSource} that may have been proxied or wrapped in a custom
* {@link Wrapper} such as {@link DelegatingDataSource}.
*
* @author Tadaya Tsuyukubo
* @author Stephane Nicoll
* @since 2.0.7
*/
public
final
class
DataSourceUnwrapper
{
private
static
final
boolean
DELEGATING_DATA_SOURCE_PRESENT
=
ClassUtils
.
isPresent
(
"org.springframework.jdbc.datasource.DelegatingDataSource"
,
DataSourceUnwrapper
.
class
.
getClassLoader
());
private
DataSourceUnwrapper
()
{
}
/**
* Return an object that implements the given {@code target} type, unwrapping delegate
* or proxy if necessary.
* @param dataSource the datasource to handle
* @param target the type that the result must implement
* @param <T> the target type
* @return an object that implements the target type or {@code null}
*/
public
static
<
T
>
T
unwrap
(
DataSource
dataSource
,
Class
<
T
>
target
)
{
if
(
target
.
isInstance
(
dataSource
))
{
return
target
.
cast
(
dataSource
);
}
T
unwrapped
=
safeUnwrap
(
dataSource
,
target
);
if
(
unwrapped
!=
null
)
{
return
unwrapped
;
}
if
(
DELEGATING_DATA_SOURCE_PRESENT
)
{
DataSource
targetDataSource
=
DelegatingDataSourceUnwrapper
.
getTargetDataSource
(
dataSource
);
if
(
targetDataSource
!=
null
)
{
return
unwrap
(
targetDataSource
,
target
);
}
}
if
(
AopUtils
.
isAopProxy
(
dataSource
))
{
Object
proxyTarget
=
AopProxyUtils
.
getSingletonTarget
(
dataSource
);
if
(
proxyTarget
instanceof
DataSource
)
{
return
unwrap
((
DataSource
)
proxyTarget
,
target
);
}
}
return
null
;
}
private
static
<
S
>
S
safeUnwrap
(
Wrapper
wrapper
,
Class
<
S
>
target
)
{
try
{
return
wrapper
.
unwrap
(
target
);
}
catch
(
Exception
ex
)
{
return
null
;
}
}
private
static
class
DelegatingDataSourceUnwrapper
{
private
static
DataSource
getTargetDataSource
(
DataSource
dataSource
)
{
if
(
dataSource
instanceof
DelegatingDataSource
)
{
return
((
DelegatingDataSource
)
dataSource
).
getTargetDataSource
();
}
return
null
;
}
}
}
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jdbc/DataSourceUnwrapperNoSpringJdbcTests.java
0 → 100644
View file @
e424dfbe
/*
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
jdbc
;
import
javax.sql.DataSource
;
import
com.zaxxer.hikari.HikariDataSource
;
import
org.apache.tomcat.jdbc.pool.DataSourceProxy
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.aop.framework.ProxyFactory
;
import
org.springframework.boot.testsupport.runner.classpath.ClassPathExclusions
;
import
org.springframework.boot.testsupport.runner.classpath.ModifiedClassPathRunner
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Integration tests for {@link DataSourceUnwrapper} when spring-jdbc is not available.
*
* @author Stephane Nicoll
*/
@RunWith
(
ModifiedClassPathRunner
.
class
)
@ClassPathExclusions
(
"spring-jdbc-*.jar"
)
public
class
DataSourceUnwrapperNoSpringJdbcTests
{
@Test
public
void
unwrapWithProxy
()
{
DataSource
dataSource
=
new
HikariDataSource
();
DataSource
actual
=
wrapInProxy
(
wrapInProxy
(
dataSource
));
assertThat
(
DataSourceUnwrapper
.
unwrap
(
actual
,
HikariDataSource
.
class
))
.
isSameAs
(
dataSource
);
}
@Test
public
void
unwrapDataSourceProxy
()
{
org
.
apache
.
tomcat
.
jdbc
.
pool
.
DataSource
dataSource
=
new
org
.
apache
.
tomcat
.
jdbc
.
pool
.
DataSource
();
DataSource
actual
=
wrapInProxy
(
wrapInProxy
(
dataSource
));
assertThat
(
DataSourceUnwrapper
.
unwrap
(
actual
,
DataSourceProxy
.
class
))
.
isSameAs
(
dataSource
);
}
private
DataSource
wrapInProxy
(
DataSource
dataSource
)
{
return
(
DataSource
)
new
ProxyFactory
(
dataSource
).
getProxy
();
}
}
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jdbc/DataSourceUnwrapperTests.java
0 → 100644
View file @
e424dfbe
/*
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
jdbc
;
import
javax.sql.DataSource
;
import
com.zaxxer.hikari.HikariDataSource
;
import
org.apache.tomcat.jdbc.pool.DataSourceProxy
;
import
org.junit.Test
;
import
org.springframework.aop.framework.ProxyFactory
;
import
org.springframework.jdbc.datasource.DelegatingDataSource
;
import
org.springframework.jdbc.datasource.SingleConnectionDataSource
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link DataSourceUnwrapper}.
*
* @author Stephane Nicoll
*/
public
class
DataSourceUnwrapperTests
{
@Test
public
void
unwrapWithTarget
()
{
DataSource
dataSource
=
new
HikariDataSource
();
assertThat
(
DataSourceUnwrapper
.
unwrap
(
dataSource
,
HikariDataSource
.
class
))
.
isSameAs
(
dataSource
);
}
@Test
public
void
unwrapWithWrongTarget
()
{
DataSource
dataSource
=
new
HikariDataSource
();
assertThat
(
DataSourceUnwrapper
.
unwrap
(
dataSource
,
SingleConnectionDataSource
.
class
))
.
isNull
();
}
@Test
public
void
unwrapWithDelegate
()
{
DataSource
dataSource
=
new
HikariDataSource
();
DataSource
actual
=
wrapInDelegate
(
wrapInDelegate
(
dataSource
));
assertThat
(
DataSourceUnwrapper
.
unwrap
(
actual
,
HikariDataSource
.
class
))
.
isSameAs
(
dataSource
);
}
@Test
public
void
unwrapWithProxy
()
{
DataSource
dataSource
=
new
HikariDataSource
();
DataSource
actual
=
wrapInProxy
(
wrapInProxy
(
dataSource
));
assertThat
(
DataSourceUnwrapper
.
unwrap
(
actual
,
HikariDataSource
.
class
))
.
isSameAs
(
dataSource
);
}
@Test
public
void
unwrapWithProxyAndDelegate
()
{
DataSource
dataSource
=
new
HikariDataSource
();
DataSource
actual
=
wrapInProxy
(
wrapInDelegate
(
dataSource
));
assertThat
(
DataSourceUnwrapper
.
unwrap
(
actual
,
HikariDataSource
.
class
))
.
isSameAs
(
dataSource
);
}
@Test
public
void
unwrapWithSeveralLevelOfWrapping
()
{
DataSource
dataSource
=
new
HikariDataSource
();
DataSource
actual
=
wrapInProxy
(
wrapInDelegate
(
wrapInDelegate
((
wrapInProxy
(
wrapInDelegate
(
dataSource
))))));
assertThat
(
DataSourceUnwrapper
.
unwrap
(
actual
,
HikariDataSource
.
class
))
.
isSameAs
(
dataSource
);
}
@Test
public
void
unwrapDataSourceProxy
()
{
org
.
apache
.
tomcat
.
jdbc
.
pool
.
DataSource
dataSource
=
new
org
.
apache
.
tomcat
.
jdbc
.
pool
.
DataSource
();
DataSource
actual
=
wrapInDelegate
(
wrapInProxy
(
dataSource
));
assertThat
(
DataSourceUnwrapper
.
unwrap
(
actual
,
DataSourceProxy
.
class
))
.
isSameAs
(
dataSource
);
}
private
DataSource
wrapInProxy
(
DataSource
dataSource
)
{
return
(
DataSource
)
new
ProxyFactory
(
dataSource
).
getProxy
();
}
private
DataSource
wrapInDelegate
(
DataSource
dataSource
)
{
return
new
DelegatingDataSource
(
dataSource
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment