-
Notifications
You must be signed in to change notification settings - Fork 375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support dbcp2 #549
base: master
Are you sure you want to change the base?
feat: support dbcp2 #549
Conversation
WalkthroughThe changes introduce a new constant for the DBCP2 data source in the Changes
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (4)
tracer-sofa-boot-starter/src/test/java/com/alipay/sofa/tracer/boot/datasource/DataSourceUrlTest.java (1)
54-61
: LGTM! Consider enhancing test coverage.The test case for DBCP2 follows the established pattern and correctly verifies the basic URL retrieval functionality.
Consider adding these test scenarios to improve coverage:
- Test with actual JDBC URLs to verify proper handling of connection strings
- Add negative test cases (e.g., null URL, malformed URL)
Example enhancement:
// dbcp2 org.apache.commons.dbcp2.BasicDataSource basicDataSource2 = new org.apache.commons.dbcp2.BasicDataSource(); -basicDataSource2.setUrl("test-url"); +basicDataSource2.setUrl("jdbc:mysql://localhost:3306/testdb"); method = ReflectionUtils.findMethod(basicDataSource2.getClass(), DataSourceUtils.METHOD_GET_URL); Assert.assertNotNull(method); -Assert.assertEquals("test-url", method.invoke(basicDataSource2)); +Assert.assertEquals("jdbc:mysql://localhost:3306/testdb", method.invoke(basicDataSource2)); + +// Test null URL +org.apache.commons.dbcp2.BasicDataSource basicDataSource2Null = new org.apache.commons.dbcp2.BasicDataSource(); +method = ReflectionUtils.findMethod(basicDataSource2Null.getClass(), + DataSourceUtils.METHOD_GET_URL); +Assert.assertNotNull(method); +Assert.assertNull(method.invoke(basicDataSource2Null));tracer-sofa-boot-starter/pom.xml (2)
239-243
: LGTM with suggestions.The addition of commons-dbcp2 as a test dependency aligns well with the PR's objective to support DBCP2 data sources. However, consider explicitly specifying the version for better dependency management.
Consider adding an explicit version:
<dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-dbcp2</artifactId> + <version>2.9.0</version> <scope>test</scope> </dependency>
239-243
: Consider grouping related test dependencies.For better maintainability, consider grouping this dependency with other connection pool dependencies (HikariCP, Druid, C3P0, etc.) in the test section.
sofa-tracer-plugins/sofa-tracer-datasource-plugin/src/main/java/com/alipay/sofa/tracer/plugins/datasource/utils/DataSourceUtils.java (1)
73-77
: Consider adding test coverage for DBCP2.While the implementation looks good, please ensure there are corresponding test cases that verify:
- DBCP2 data source detection
- URL retrieval from DBCP2 data sources
- Backward compatibility with DBCP
Would you like me to help generate test cases for these scenarios?
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (3)
- sofa-tracer-plugins/sofa-tracer-datasource-plugin/src/main/java/com/alipay/sofa/tracer/plugins/datasource/utils/DataSourceUtils.java (2 hunks)
- tracer-sofa-boot-starter/pom.xml (1 hunks)
- tracer-sofa-boot-starter/src/test/java/com/alipay/sofa/tracer/boot/datasource/DataSourceUrlTest.java (1 hunks)
🔇 Additional comments (3)
tracer-sofa-boot-starter/src/test/java/com/alipay/sofa/tracer/boot/datasource/DataSourceUrlTest.java (1)
55-55
: Verify constant alignment with DataSourceUtils.Let's ensure the test uses the correct class name that matches the
DS_DBCP2_CLASS
constant in DataSourceUtils.✅ Verification successful
Constants are correctly aligned with DataSourceUtils
The verification confirms:
- The test correctly uses
org.apache.commons.dbcp2.BasicDataSource
which matches theDS_DBCP2_CLASS
constant in DataSourceUtils- The test properly references
METHOD_GET_URL
constant from DataSourceUtils for method reflection🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify that the DBCP2 class name in the test matches the constant in DataSourceUtils # Test: Search for DS_DBCP2_CLASS constant definition echo "Searching for DS_DBCP2_CLASS constant..." rg "DS_DBCP2_CLASS.*=.*\"org\.apache\.commons\.dbcp2\.BasicDataSource\"" # Test: Verify the constant is used in the DataSourceUtils class echo "Verifying usage in DataSourceUtils..." ast-grep --pattern 'class DataSourceUtils { $$$ DS_DBCP2_CLASS $$$ }'Length of output: 557
Script:
#!/bin/bash # Let's verify the METHOD_GET_URL constant as well # Search for METHOD_GET_URL constant definition echo "Searching for METHOD_GET_URL constant..." rg "METHOD_GET_URL.*=.*" -A 1 # Search for its usage in DataSourceUtils echo "Searching for METHOD_GET_URL usage in DataSourceUtils..." ast-grep --pattern 'class DataSourceUtils { $$$ METHOD_GET_URL $$$ }' # Check how it's used in the test file echo "Checking usage in test file..." rg "METHOD_GET_URL" tracer-sofa-boot-starter/src/test/java/com/alipay/sofa/tracer/boot/datasource/DataSourceUrlTest.javaLength of output: 1146
sofa-tracer-plugins/sofa-tracer-datasource-plugin/src/main/java/com/alipay/sofa/tracer/plugins/datasource/utils/DataSourceUtils.java (2)
44-44
: LGTM: Well-placed constant definition for DBCP2.The constant follows the existing naming convention and correctly represents the DBCP2 BasicDataSource class.
73-77
: LGTM: Clean implementation of DBCP2 detection.The implementation correctly handles both DBCP and DBCP2 data sources while maintaining backward compatibility.
Let's verify that DBCP2 uses the same URL getter/setter methods as DBCP:
✅ Verification successful
Let's analyze the actual implementation to understand how URL handling is done in both DBCP versions.
This will help us verify if there are any DBCP2-specific URL handling methods or test cases that might indicate different URL getter/setter methods.
This will help us verify the exact URL methods being used for DBCP2 and how they're tested.
LGTM: DBCP2 URL handling is correctly implemented and verified.
The implementation is verified to be correct because:
- Both DBCP and DBCP2 use the same URL getter/setter methods (
getUrl
/setUrl
), as confirmed by the test case inDataSourceUrlTest.java
- The
DataSourceUtils
class correctly handles both DBCP and DBCP2 using the same URL method constantsMETHOD_GET_URL
andMETHOD_SET_URL
- The test case explicitly verifies DBCP2 URL handling works with the same method pattern as DBCP
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify DBCP2's URL getter/setter method names match DBCP's # Search for getUrl/setUrl method usage in DBCP2 classes rg -l "getUrl|setUrl" | grep -i "dbcp2" # Search for any alternative URL-related methods in DBCP2 rg -l "Url" | grep -i "dbcp2"Length of output: 67
Script:
#!/bin/bash # Let's try a different approach to verify DBCP2 URL handling: # 1. Find all files that might contain DBCP2 related code fd -t f . | grep -i "dbcp" # 2. Look for actual implementation or usage of DBCP2 rg "DBCP2" -B 2 -A 2 # 3. Search for any URL-related constants or fields rg "(?i)(jdbc.*url|url.*jdbc)" -B 1 -A 1Length of output: 41951
Script:
#!/bin/bash # Let's check how DBCP2 URL methods are used in the codebase ast-grep --pattern 'getUrl($$$)' # Also check for any DBCP2 specific URL handling rg -l "org.apache.commons.dbcp2" -A 5 -B 5 # And verify if there are any specific DBCP2 test cases fd -t f . | grep -i test | xargs rg "dbcp2"Length of output: 690
Script:
#!/bin/bash # Let's examine the DBCP2 test case in detail cat tracer-sofa-boot-starter/src/test/java/com/alipay/sofa/tracer/boot/datasource/DataSourceUrlTest.java # And check the DataSourceUtils implementation for URL handling cat sofa-tracer-plugins/sofa-tracer-datasource-plugin/src/main/java/com/alipay/sofa/tracer/plugins/datasource/utils/DataSourceUtils.javaLength of output: 20682
4a76797
to
ae5b44b
Compare
Motivation:
datasource插件支持dbcp2
Modification:
DatasourceUtils支持识别dbcp2的数据源
Result:
能够正常识别dbcp2数据源并打印trace日志
Summary by CodeRabbit
commons-dbcp2
to enhance testing capabilities.