| <?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/test-manual/module-test/</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/test-manual/module-test/index.xml" rel="self" type="application/rss+xml" /> |
| |
| |
| <item> |
| <title>SQL 解析测试</title> |
| <link>https://shardingsphere.apache.org/document/current/cn/test-manual/module-test/parser-test/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/document/current/cn/test-manual/module-test/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 条件等进行断言,例如如下的配置: |
| &lt;parser-result-sets&gt; &lt;parser-result sql-case-id=&#34;insert_with_multiple_values&#34;&gt; &lt;tables&gt; &lt;table name=&#34;t_order&#34; /&gt; &lt;/tables&gt; &lt;tokens&gt; &lt;table-token start-index=&#34;12&#34; table-name=&#34;t_order&#34; length=&#34;7&#34; /&gt; &lt;/tokens&gt; &lt;sharding-conditions&gt; &lt;and-condition&gt; &lt;condition column-name=&#34;order_id&#34; table-name=&#34;t_order&#34; operator=&#34;EQUAL&#34;&gt; &lt;value literal=&#34;1&#34; type=&#34;int&#34; /&gt; &lt;/condition&gt; &lt;condition column-name=&#34;user_id&#34; table-name=&#34;t_order&#34; operator=&#34;EQUAL&#34;&gt; &lt;value literal=&#34;1&#34; type=&#34;int&#34; /&gt; &lt;/condition&gt; &lt;/and-condition&gt; &lt;and-condition&gt; &lt;condition column-name=&#34;order_id&#34; table-name=&#34;t_order&#34; operator=&#34;EQUAL&#34;&gt; &lt;value literal=&#34;2&#34; type=&#34;int&#34; /&gt; &lt;/condition&gt; &lt;condition column-name=&#34;user_id&#34; table-name=&#34;t_order&#34; operator=&#34;EQUAL&#34;&gt; &lt;value literal=&#34;2&#34; type=&#34;int&#34; /&gt; &lt;/condition&gt; &lt;/and-condition&gt; &lt;/sharding-conditions&gt; &lt;/parser-result&gt; &lt;/parser-result-sets&gt; 设置好上面两类数据,开发者就可以通过 shardingsphere-sql-parser/shardingsphere-sql-parser-test 下对应的测试引擎启动 SQL 解析的测试了。</description> |
| </item> |
| |
| <item> |
| <title>SQL 改写测试</title> |
| <link>https://shardingsphere.apache.org/document/current/cn/test-manual/module-test/rewrite-test/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/document/current/cn/test-manual/module-test/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.</description> |
| </item> |
| |
| </channel> |
| </rss> |