blob: c1066b6b3333adc424219f3c65be0272879f4dff [file] [log] [blame]
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>测试引擎 on ShardingSphere</title>
<link>https://shardingsphere.apache.org/document/current/cn/features/test-engine/</link>
<description>Recent content in 测试引擎 on ShardingSphere</description>
<generator>Hugo -- gohugo.io</generator>
<language>en-us</language>
<atom:link href="https://shardingsphere.apache.org/document/current/cn/features/test-engine/index.xml" rel="self" type="application/rss+xml" />
<item>
<title>集成测试</title>
<link>https://shardingsphere.apache.org/document/current/cn/features/test-engine/integration-test/</link>
<pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
<guid>https://shardingsphere.apache.org/document/current/cn/features/test-engine/integration-test/</guid>
<description>设计 集成测试包括 3 个模块:测试用例、测试环境以及测试引擎。
测试用例 用于定义待测试的 SQL 以及测试结果的断言数据。 每个用例定义一条 SQL,SQL 可定义多种数据库执行类型。
测试环境 用于搭建运行测试用例的数据库和 ShardingSphere-Proxy 环境。 环境又具体分为环境准备方式,数据库类型和场景。
环境准备方式分为 Native 和 Docker,未来还将增加 Embed 类型的支持。
Native 环境用于测试用例直接运行在开发者提供的测试环境中,适于调试场景; Docker 环境由 Maven 运行 Docker-Compose 插件直接搭建,适用于云编译环境和测试 ShardingSphere-Proxy 的场景,如:GitHub Action; Embed 环境由测试框架自动搭建嵌入式 MySQL,适用于 ShardingSphere-JDBC 的本地环境测试。 当前默认采用 Native 环境,使用 ShardingSphere-JDBC + H2 数据库运行测试用例。 通过 Maven 的 -P -Pit.env.docker 参数可以指定 Docker 环境的运行方式。 未来将采用 Embed 环境的 ShardingSphere-JDBC + MySQL,替换 Native 执行测试用例的默认环境类型。
数据库类型目前支持 MySQL、PostgreSQL、SQLServer 和 Oracle,并且可以支持使用 ShardingSphere-JDBC 或是使用 ShardingSphere-Proxy 执行测试用例。</description>
</item>
<item>
<title>SQL 解析测试</title>
<link>https://shardingsphere.apache.org/document/current/cn/features/test-engine/parser-test/</link>
<pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
<guid>https://shardingsphere.apache.org/document/current/cn/features/test-engine/parser-test/</guid>
<description>数据准备 SQL 解析无需真实的测试环境,开发者只需定义好待测试的 SQL,以及解析后的断言数据即可:
SQL数据 在集成测试的部分提到过sql-case-id,其对应的SQL,可以在不同模块共享。开发者只需要在shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/sql/supported/${SQL-TYPE}/*.xml 添加待测试的 SQL 即可。
断言数据 断言的解析数据保存在 shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/case/${SQL-TYPE}/*.xml 在xml文件中,可以针对表名,token,SQL条件等进行断言,例如如下的配置:
&amp;lt;parser-result-sets&amp;gt; &amp;lt;parser-result sql-case-id=&amp;#34;insert_with_multiple_values&amp;#34;&amp;gt; &amp;lt;tables&amp;gt; &amp;lt;table name=&amp;#34;t_order&amp;#34; /&amp;gt; &amp;lt;/tables&amp;gt; &amp;lt;tokens&amp;gt; &amp;lt;table-token start-index=&amp;#34;12&amp;#34; table-name=&amp;#34;t_order&amp;#34; length=&amp;#34;7&amp;#34; /&amp;gt; &amp;lt;/tokens&amp;gt; &amp;lt;sharding-conditions&amp;gt; &amp;lt;and-condition&amp;gt; &amp;lt;condition column-name=&amp;#34;order_id&amp;#34; table-name=&amp;#34;t_order&amp;#34; operator=&amp;#34;EQUAL&amp;#34;&amp;gt; &amp;lt;value literal=&amp;#34;1&amp;#34; type=&amp;#34;int&amp;#34; /&amp;gt; &amp;lt;/condition&amp;gt; &amp;lt;condition column-name=&amp;#34;user_id&amp;#34; table-name=&amp;#34;t_order&amp;#34; operator=&amp;#34;EQUAL&amp;#34;&amp;gt; &amp;lt;value literal=&amp;#34;1&amp;#34; type=&amp;#34;int&amp;#34; /&amp;gt; &amp;lt;/condition&amp;gt; &amp;lt;/and-condition&amp;gt; &amp;lt;and-condition&amp;gt; &amp;lt;condition column-name=&amp;#34;order_id&amp;#34; table-name=&amp;#34;t_order&amp;#34; operator=&amp;#34;EQUAL&amp;#34;&amp;gt; &amp;lt;value literal=&amp;#34;2&amp;#34; type=&amp;#34;int&amp;#34; /&amp;gt; &amp;lt;/condition&amp;gt; &amp;lt;condition column-name=&amp;#34;user_id&amp;#34; table-name=&amp;#34;t_order&amp;#34; operator=&amp;#34;EQUAL&amp;#34;&amp;gt; &amp;lt;value literal=&amp;#34;2&amp;#34; type=&amp;#34;int&amp;#34; /&amp;gt; &amp;lt;/condition&amp;gt; &amp;lt;/and-condition&amp;gt; &amp;lt;/sharding-conditions&amp;gt; &amp;lt;/parser-result&amp;gt; &amp;lt;/parser-result-sets&amp;gt; 设置好上面两类数据,开发者就可以通过 shardingsphere-sql-parser/shardingsphere-sql-parser-test 下对应的测试引擎启动 SQL 解析的测试了。</description>
</item>
<item>
<title>SQL 改写测试</title>
<link>https://shardingsphere.apache.org/document/current/cn/features/test-engine/rewrite-test/</link>
<pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
<guid>https://shardingsphere.apache.org/document/current/cn/features/test-engine/rewrite-test/</guid>
<description>目标 面向逻辑库与逻辑表书写的SQL,并不能够直接在真实的数据库中执行,SQL改写用于将逻辑SQL改写为在真实数据库中可以正确执行的SQL。 它包括正确性改写和优化改写两部分,所以 SQL 改写的测试都是基于这些改写方向进行校验的。
测试 SQL 改写测试用例位于 sharding-core/sharding-core-rewrite 下的 test 中。SQL 改写的测试主要依赖如下几个部分:
测试引擎 环境配置 验证数据 测试引擎是 SQL 改写测试的入口,跟其他引擎一样,通过 Junit 的 Parameterized 逐条读取 test\resources 目录中测试类型下对应的 xml 文件,然后按读取顺序一一进行验证。
环境配置存放在 test\resources\yaml 路径中测试类型下对应的 yaml 中。配置了dataSources,shardingRule,encryptRule 等信息,例子如下:
dataSources: db: !!com.zaxxer.hikari.HikariDataSource driverClassName: org.h2.Driver jdbcUrl: jdbc:h2:mem:db;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL username: sa password: ## sharding 规则 rules: - !SHARDING tables: t_account: actualDataNodes: db.t_account_${0..1} tableStrategy: standard: shardingColumn: account_id shardingAlgorithmName: account_table_inline keyGenerateStrategy: column: account_id keyGeneratorName: snowflake t_account_detail: actualDataNodes: db.t_account_detail_${0..1} tableStrategy: standard: shardingColumn: order_id shardingAlgorithmName: account_detail_table_inline bindingTables: - t_account, t_account_detail shardingAlgorithms: account_table_inline: type: INLINE props: algorithm-expression: t_account_${account_id % 2} account_detail_table_inline: type: INLINE props: algorithm-expression: t_account_detail_${account_id % 2} keyGenerators: snowflake: type: SNOWFLAKE props: worker-id: 123 验证数据存放在 test\resources 路径中测试类型下对应的 xml 文件中。验证数据中, yaml-rule 指定了环境以及 rule 的配置文件,input 指定了待测试的 SQL 以及参数,output 指定了期待的 SQL 以及参数。 其中 db-type 决定了 SQL 解析的类型,默认为 SQL92, 例如:</description>
</item>
<item>
<title>性能测试</title>
<link>https://shardingsphere.apache.org/document/current/cn/features/test-engine/performance-test/</link>
<pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
<guid>https://shardingsphere.apache.org/document/current/cn/features/test-engine/performance-test/</guid>
<description>目标 对ShardingSphere-JDBC,ShardingSphere-Proxy及MySQL进行性能对比。从业务角度考虑,在基本应用场景(单路由,主从+加密+分库分表,全路由)下,INSERT+UPDATE+DELETE通常用作一个完整的关联操作,用于性能评估,而SELECT关注分片优化可用作性能评估的另一个操作;而主从模式下,可将INSERT+SELECT+DELETE作为一组评估性能的关联操作。 为了更好的观察效果,设计在一定数据量的基础上,使用jmeter 20并发线程持续压测半小时,进行增删改查性能测试,且每台机器部署一个MySQL实例,而对比MySQL场景为单机单实例部署。
测试场景 单路由 在1000数据量的基础上分库分表,根据id分为4个库,部署在同一台机器上,根据k分为1024个表,查询操作路由到单库单表; 作为对比,MySQL运行在1000数据量的基础上,使用INSERT+UPDATE+DELETE和单路由查询语句。
主从 基本主从场景,设置一主库一从库,部署在两台不同的机器上,在10000数据量的基础上,观察读写性能; 作为对比,MySQL运行在10000数据量的基础上,使用INSERT+SELECT+DELETE语句。
主从+加密+分库分表 在1000数据量的基础上,根据id分为4个库,部署在四台不同的机器上,根据k分为1024个表,c使用aes加密,pad使用md5加密,查询操作路由到单库单表; 作为对比,MySQL运行在1000数据量的基础上,使用INSERT+UPDATE+DELETE和单路由查询语句。
全路由 在1000数据量的基础上,分库分表,根据id分为4个库,部署在四台不同的机器上,根据k分为1个表,查询操作使用全路由。 作为对比,MySQL运行在1000数据量的基础上,使用INSERT+UPDATE+DELETE和全路由查询语句。
测试环境搭建 数据库表结构 此处表结构参考sysbench的sbtest表
CREATE TABLE `tbl` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `k` int(11) NOT NULL DEFAULT 0, `c` char(120) NOT NULL DEFAULT &amp;#39;&amp;#39;, `pad` char(60) NOT NULL DEFAULT &amp;#39;&amp;#39;, PRIMARY KEY (`id`) ); 测试场景配置 ShardingSphere-JDBC使用与ShardingSphere-Proxy一致的配置,MySQL直连一个库用作性能对比,下面为四个场景的具体配置:
单路由配置 schemaName: sharding_db dataSources: ds_0: url: jdbc:mysql://***.***.***.***:****/ds?serverTimezone=UTC&amp;amp;useSSL=false username: test password: connectionTimeoutMilliseconds: 30000 idleTimeoutMilliseconds: 60000 maxLifetimeMilliseconds: 1800000 maxPoolSize: 200 ds_1: url: jdbc:mysql://***.</description>
</item>
<item>
<title>性能测试(sysbench)</title>
<link>https://shardingsphere.apache.org/document/current/cn/features/test-engine/performance-test-sysbench/</link>
<pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
<guid>https://shardingsphere.apache.org/document/current/cn/features/test-engine/performance-test-sysbench/</guid>
<description>环境 推荐硬件环境 CPU: 32 Cores RAM: 128 GB NIC: 10Gb Ethernet 至少需要5台机器:
Jenkins * 1: ${host-jenkins} Sysbench * 1: ${host-sysbench} ShardingSphere-Proxy * 1: ${host-proxy} MySQL Server * 2: ${host-mysql-1}, ${host-mysql-2} 可以适当降低Jenkins和Sysbench机器的硬件标准
软件环境 Jenins: 最新版本 Sysbench: 1.0.20 ShardingSphere-Proxy: master分支代码打包 MySQL Server: 5.7.28 测试方案 根据以上的硬件环境,配置参数如下,参数应根据硬件环境改变而调整
ShardingSphere-Proxy配置 Proxy运行在${host-proxy}机器 版本包括:Master分支版本、4.1.1版本、3.0.0版本 场景包括:config-sharding、config-replica-query、config-sharding-replica-query、config-encrypt 配置文件详细内容:见附录1 MySQL Server配置 两个MySQL实例分别运行在${host-mysql-1}和${host-mysql-2}机器
需要提前在两个实例上创建sbtest数据库 设置参数max_prepared_stmt_count = 500000 设置参数max_connections = 2000 Jenkins配置 创建6个Jenkins任务,每个任务依次调用下一个任务:(运行在${host-jenkins}机器)
1. sysbench_install: 拉取最新代码,打包Proxy压缩包 以下任务通过Jenkins slave运行在单独的Sysbench发压机器:(运行在${host-sysbench}机器)
2. sysbench_sharding: a. 远程部署各版本Proxy的分片场景 b. 执行Sysbench命令压测Proxy c.</description>
</item>
</channel>
</rss>