Skip to content

Commit 18161ea

Browse files
committed
Use MySQL instead of H2Database in ShardingSphere integration
1 parent 5840c1b commit 18161ea

25 files changed

Lines changed: 322 additions & 205 deletions

File tree

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
cache: 'maven'
2626
- name: Build all test with Maven
2727
run: |
28-
./mvnw -T1C -B -e clean test
28+
./mvnw -T1C -e clean test
2929
test-minimum-hotspot-jdk-ci:
3030
name: Test CI - JDK ${{ matrix.java-version }} on ${{ matrix.os }}
3131
runs-on: ${{ matrix.os }}
@@ -50,6 +50,6 @@ jobs:
5050
./mvnw -am -pl orm-samples/mybatis-sample -T1C -B -e clean test
5151
- name: Build third-part test with Maven
5252
run: |
53-
./mvnw -am -pl third-part-samples/shardingsphere-sample/shardingsphere-jdbc-4.x-spring-sample -T1C -B -e clean test
54-
./mvnw -am -pl third-part-samples/shardingsphere-sample/shardingsphere-jdbc-5.x-core-sample -T1C -B -e clean test
55-
./mvnw -am -pl third-part-samples/shardingsphere-sample/shardingsphere-jdbc-5.x-spring-sample -T1C -B -e clean test
53+
./mvnw -am -pl third-part-samples/shardingsphere-sample/shardingsphere-jdbc-4.x-spring-sample -T1C -e clean test
54+
./mvnw -am -pl third-part-samples/shardingsphere-sample/shardingsphere-jdbc-5.x-core-sample -T1C -e clean test
55+
./mvnw -am -pl third-part-samples/shardingsphere-sample/shardingsphere-jdbc-5.x-spring-sample -T1C -e clean test
Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,3 @@
1-
# Licensed to the Apache Software Foundation (ASF) under one
2-
# or more contributor license agreements. See the NOTICE file
3-
# distributed with this work for additional information
4-
# regarding copyright ownership. The ASF licenses this file
5-
# to you under the Apache License, Version 2.0 (the
6-
# "License"); you may not use this file except in compliance
7-
# with the License. You may obtain a copy of the License at
8-
#
9-
# http://www.apache.org/licenses/LICENSE-2.0
10-
#
11-
# Unless required by applicable law or agreed to in writing,
12-
# software distributed under the License is distributed on an
13-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14-
# KIND, either express or implied. See the License for the
15-
# specific language governing permissions and limitations
16-
# under the License.
17-
wrapperVersion=3.3.2
1+
wrapperVersion=3.3.4
182
distributionType=only-script
19-
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip
3+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.11/apache-maven-3.9.11-bin.zip

README.md

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# 演示例子
22

3-
大部分数据库连接为 H2Database,仅供测试。
3+
大部分数据库连接为 `h2database` 或通过 `testcontainers-java` 启动的 `mysql-server`,仅供测试。讨论不同情况,
44

5-
除开 `com.baomidou:springboot3-sample`, 其他子模块均可在 [OpenJDK 8, OpenJDK 21] 的 JDK 范围及其下游发行版下执行单元测试。
5+
1. `com.baomidou:springboot3-sample` 可在 [OpenJDK 17, OpenJDK 21] 的 JDK 范围及其下游发行版下执行单元测试
6+
2. 除开 `com.baomidou:springboot3-sample`, 其他子模块均可在 [OpenJDK 8, OpenJDK 21] 的 JDK 范围及其下游发行版下执行单元测试
67

78
所有单元测试在 Github Actions 完成验证。你可能希望参考 [位于 Github Actions 的 CI 文件](./.github/workflows/ci.yml)
89

@@ -29,10 +30,15 @@
2930
## Contributing
3031

3132
我们欢迎社区的贡献。围绕此 git 的讨论与协作应通过 https://github.com/baomidou/dynamic-datasource/issues 进行。
32-
33-
针对 IDE,项目的语言级别应设置为 JDK 8,对于单独的 `com.baomidou:springboot3-sample` 子模块,语言级别应设置为 JDK 17 。
3433
在提交 Pull Request 之前, 请在本地通过 [OpenJDK 17, OpenJDK 21] 的 JDK 范围下完成此命令的验证。
35-
我们鼓励通过 `SDKMAN!` 切换到 `21.0.2-graalce` 来验证。
34+
我们鼓励通过 `SDKMAN!``version-fox/vfox` 切换到 `21.0.2-graalce` 来验证。
35+
36+
针对 IntelliJ IDEA 等 IDE,项目的语言级别应设置为 JDK 8,对于单独的 `com.baomidou:springboot3-sample` 子模块,语言级别应设置为 JDK 17。
37+
下文讨论不同情况下可能的测试流程,
38+
39+
### Ubuntu 24.04
40+
41+
假设 `SDKMAN!``Docker Engine` 已安装,在 Bash 执行如下命令,
3642

3743
```shell
3844
sdk install java 21.0.2-graalce
@@ -42,3 +48,19 @@ git clone git@github.com:dynamic-datasource/dynamic-datasource-samples.git
4248
cd ./dynamic-datasource-samples/
4349
./mvnw -T1C -e clean test
4450
```
51+
52+
### Windows 11
53+
54+
假设 `PowerShell/PowerShell`, `version-fox/vfox`, `git-for-windows/git``rancher-sandbox/rancher-desktop` 已安装,
55+
`PowerShell 7` 执行如下命令,
56+
57+
```shell
58+
rdctl start --application.start-in-background --container-engine.name=moby --kubernetes.enabled=false
59+
vfox add java
60+
vfox install java@21.0.2-graalce
61+
vfox use --global java@21.0.2-graalce
62+
63+
git clone git@github.com:dynamic-datasource/dynamic-datasource-samples.git
64+
cd ./dynamic-datasource-samples/
65+
./mvnw -T1C -e clean test
66+
```

mvnw

Lines changed: 43 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mvnw.cmd

Lines changed: 48 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<h2.version>2.2.224</h2.version>
2222
<spring-boot-dependencies.version>2.7.18</spring-boot-dependencies.version>
2323
<lombok.version>1.18.30</lombok.version>
24+
<testcontainers-bom.version>1.21.3</testcontainers-bom.version>
2425
</properties>
2526

2627
<modules>
@@ -53,6 +54,13 @@
5354
<type>pom</type>
5455
<scope>import</scope>
5556
</dependency>
57+
<dependency>
58+
<groupId>org.testcontainers</groupId>
59+
<artifactId>testcontainers-bom</artifactId>
60+
<version>${testcontainers-bom.version}</version>
61+
<type>pom</type>
62+
<scope>import</scope>
63+
</dependency>
5664
<dependency>
5765
<groupId>org.springdoc</groupId>
5866
<artifactId>springdoc-openapi-ui</artifactId>

third-part-samples/shardingsphere-sample/shardingsphere-jdbc-4.x-spring-sample/src/test/java/com/baomidou/samples/shardingsphere/jdbc/v4/spring/MapperLayerTests.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333

3434
/**
3535
* TODO Unit tests for ShardingSphere 5.4.0 need to be synchronized.
36-
* Tracked on <a href="https://github.com/apache/shardingsphere/issues/27955">When a logic database uses both `SHARDING` and `READWRITE_SPLITTING` features, CRUD operations on table throw `NoSuchTableException`</a>
3736
*/
3837
@SpringBootTest
3938
@Disabled("TODO wait for com.baomidou:dynamic-datasource-spring-boot-starter:4.2.0 release")
@@ -54,21 +53,21 @@ void after() {
5453

5554
@Test
5655
void whenRequestToFindAll() {
57-
assertEquals(tOrderMapper.findAll().size(), 0);
56+
assertEquals(0, tOrderMapper.findAll().size());
5857
}
5958

6059
@Test
6160
void whenRequestToAddByNameAndUserId() {
6261
int firstNumberOfAffectedRows = tOrderMapper.addAll(101L, "Bright", 114514L);
6362
int secondNumberOfAffectedRows = tOrderMapper.addAll(102L, "Jordan", 114515L);
64-
assertEquals(firstNumberOfAffectedRows + secondNumberOfAffectedRows, 2);
65-
assertEquals(tOrderMapper.findAll().size(), 2);
63+
assertEquals(2, firstNumberOfAffectedRows + secondNumberOfAffectedRows);
64+
assertEquals(2, tOrderMapper.findAll().size());
6665
}
6766

6867
@Test
6968
void whenRequestToAddByNameAndUserIdWithPrimaryKey() {
7069
List<TOrder> emptyState = tOrderMapper.findAll();
71-
assertEquals(emptyState.size(), 0);
70+
assertEquals(0, emptyState.size());
7271
assertThrows(UncategorizedSQLException.class, () -> {
7372
tOrderMapper.addByNameAndUserId("Bright", 114514L);
7473
tOrderMapper.addByNameAndUserId("Jordan", 114515L);
@@ -84,8 +83,8 @@ void whenRequestToDeleteByIdTest() {
8483
tOrderMapper.addAll(105L, "Michael", 114518L);
8584
tOrderMapper.addAll(106L, "Tony", 114519L);
8685
int numberOfAffectedRows = tOrderMapper.deleteById(114514L);
87-
assertEquals(numberOfAffectedRows, 1);
88-
assertEquals(tOrderMapper.findAll().size(), 5);
86+
assertEquals(1, numberOfAffectedRows);
87+
assertEquals(5, tOrderMapper.findAll().size());
8988
}
9089

9190
@Test
@@ -97,7 +96,7 @@ void whenRequestToDeleteAll() {
9796
tOrderMapper.addAll(105L, "Michael", 114518L);
9897
tOrderMapper.addAll(106L, "Tony", 114519L);
9998
int numberOfAffectedRows = tOrderMapper.deleteAll();
100-
assertEquals(numberOfAffectedRows, 6);
101-
assertEquals(tOrderMapper.findAll().size(), 0);
99+
assertEquals(6, numberOfAffectedRows);
100+
assertEquals(0, tOrderMapper.findAll().size());
102101
}
103102
}

0 commit comments

Comments
 (0)