已开启
add: DBCP 连接池适配 openGauss B 兼容模式示例与测试 #104
add: DBCP 连接池适配 openGauss B 兼容模式示例与测试 #104
已开启
liuhongwei创建于 8月7日
liuhongwei
liuhongwei
8月7日

关联任务

https://atomgit.com/opengauss/opensource-intership/issues/52

变更内容

  • 新增 DBCP2 2.9.0 + MySQL Connector/J 8.0.28 连接 openGauss B 兼容库的示例。
  • 新增数据库初始化脚本、连接池配置、DAO 和 CRUD 示例。
  • 新增测试思维导图和自测报告。
  • 测试覆盖连接池参数、满池等待、CRUD、事务、并发、断连恢复和 DDL/DML/DQL/DCL/TCL。

连接链路

dbcp.properties
  → BasicDataSourceFactory
  → BasicDataSource.getConnection()
  → GenericObjectPool.borrowObject()
  → PoolableConnectionFactory.makeObject()(无空闲连接时)
  → DriverConnectionFactory.createConnection()
  → com.mysql.cj.jdbc.Driver.connect()
  → com.mysql.cj.jdbc.ConnectionImpl
  → TCP / Dolphin MySQL 协议端口
  → openGauss B 兼容库
  → ResultSet 或 updateCount
  → PoolableConnection.close()
  → GenericObjectPool.returnObject()

DBCP 负责逻辑连接的借出、校验和归还;池中没有可复用连接且未达到 maxTotal 时,才调用 Connector/J 创建物理连接。Connector/J 负责 MySQL 协议通信,Dolphin 将请求交给 openGauss 执行。

测试清单

测试类 用例数 主要内容
DbcpDataSourceTest 5 配置装配、驱动加载、初始连接和错误连接参数
ConnectionPoolTest 10 借出归还、池参数、并发、满池等待与恢复
ConnectionValidationTest 3 连接校验、失效连接淘汰和重建
CrudTest 8 查询、插入、更新、删除、分页和批处理
TransactionTest 5 自动提交、提交、回滚、隔离级别和池化连接事务
SqlCategoryTest 5 DDL、DML、DQL、DCL、TCL
DataTypeCharsetTest 3 中文、emoji、常用类型和 NULL
ConstraintTest 3 多语句限制、游标参数和非 SSL 连接
StabilityTest 4 重复建池、并发事务、长连接和池状态
合计 46 Failures=0,Errors=0,Skipped=0

重点边界

  • dbcp.properties → TestConfig → BasicDataSourceFactory → BasicDataSource 参数逐项断言。
  • maxTotal=8 时,8 条连接分别完成事务 CRUD 并保持占用;第 9 条请求等待且不突破上限,不释放时超时,释放后恢复。
  • 16 线程各持有独立连接执行 INSERT → SELECT → UPDATE → SELECT → DELETE → COMMIT,结束 active=0
  • 固定 maxTotal=128 的高负载验证完成 128 条同时持有连接和最多 5000 个排队业务请求;5000 表示请求数,不是物理连接数。
  • commit 后数据跨连接可见,rollback 后不可见。
  • DDL/DML/DQL/DCL/TCL 分别校验对象状态、影响行数、查询结果、授权状态和事务结果。\n- 46 项回归使用具备 CREATEROLE 权限的 opengauss 测试账号;生产部署应替换为专用业务账号。
  • 服务端会话失效后,testOnBorrowtestWhileIdle 能淘汰失效连接并恢复查询。

验证结果

测试环境:openEuler 24.03 x86_64、openGauss 7.0.0 master 转测包、Dolphin 127.0.0.1:36443(隔离自测端口;README 默认部署端口为 3308)、BiSheng JDK 8u472、Maven 3.6.3、DBCP2 2.9.0、Pool2 2.10.0、Connector/J 8.0.28。

Tests run: 46, Failures: 0, Errors: 0, Skipped: 0
BUILD SUCCESS

另使用 Spring Boot 3.5.7 + HikariCP 6.3.3 + Connector/J 8.0.28 验证默认数据源链路,确认 HikariDataSource → HikariProxyConnection → ConnectionImpl → Dolphin → openGaussJdbcTemplate CRUD、TransactionTemplate 提交/回滚及连接归还均通过。该结果用于说明 Spring Boot 默认 HikariCP 链路,不计入 DBCP 的 46 个测试方法。

运行方式

mvn clean test \
  -Ddbcp.url='jdbc:mysql://127.0.0.1:36443/mysql_test_db?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC&characterEncoding=utf-8&zeroDateTimeBehavior=CONVERT_TO_NULL' \
  -Ddbcp.username=opengauss \
  -Ddbcp.password="$DBCP_PASSWORD"

完整初始化、配置和验证说明见本 PR 的 README.mddocs/初始化步骤.mddocs/自测报告.md

关联 PR

likedislike
合并受阻
liuhongweiliuhongwei
8月7日 创建了 pull request,commit 33d24b23
opengauss_botopengauss_bot成员
8月7日 添加了label:sig/Infra
opengauss_bot
opengauss_bot成员
8月7日 评论:

Welcome To openGauss Community

Hey @liuhongwei-2026 , thanks for your contribution to the community.

Bot Usage Manual

I'm the Bot here serving you. You can find the instructions on how to interact with me at Here . That means you can comment below every pull request or issue to trigger Bot Commands.

Contact Guide

If you have any questions, please contact the SIG: Infra ,
and any of the maintainers: @CarrotGo, @chendong76, @chenxiaobin19, @congzhou2603, @dodders, @hwworkholic, @jemappellehc, @muyulinzhong, @quemingjian, @shenzheng4, @shirley_zhengx, @superlchf, @totaj, @wlff234, @wofanzheng, @ywzq1161327784 ,
and any of the committers: @ailoooong, @gzbang, @libiao2024, @zhangxubo .

likedislike
opengauss_botopengauss_bot成员
8月7日 添加了label:opengauss-cla/no
liuhongweiliuhongwei
8月7日 修改标题为 “add: DBCP 连接池适配 openGauss B 兼容模式示例与测试”,原标题为“add: DBCP ���ӳ����� openGauss B ����ģʽʾ�������”
此处折叠了112条消息 查看更多
opengauss_botopengauss_bot成员
6 天前 删除了label:stat/needs-squash
opengauss_bot
opengauss_bot成员
6 天前 评论:

Notification

This pull request has been changed(code update) or closed, so removes the following label(s): stat/needs-squash.

likedislike
opengauss_botopengauss_bot成员
6 天前 添加了label:opengauss-cla/yes
opengauss_bot
opengauss_bot成员
6 天前 评论:

CLA Signature Pass

liuhongwei-2026, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
liyangx成员
4 天前 评论:

/retest

likedislike