Skip to content

Commit

Permalink
Simplify redundant configurations caused by Spring Boot version chang…
Browse files Browse the repository at this point in the history
…es (#566)
  • Loading branch information
linghengqian authored Sep 7, 2023
1 parent 0d96393 commit 563522d
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 152 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ env:
MAVEN_OPTS: -Dhttps.protocols=TLSv1.2 -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=WARN -Dorg.slf4j.simpleLogger.showDateTime=true -Djava.awt.headless=true

jobs:
# We only execute nativeTest on `dynamic-datasource-spring-boot3-starter`, since only Spring Boot OSS 3 support provides support for GraalVM Native Image
test-graalvm-ce-ci:
name: NativeTest CI - GraalVM CE ${{ matrix.java-version }} on ${{ matrix.os }} (This CI failure is reasonable)
name: NativeTest CI - GraalVM CE ${{ matrix.java-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
timeout-minutes: 90
continue-on-error: true
Expand All @@ -43,16 +44,15 @@ jobs:
cache: 'maven'
- name: Build Spring Boot Starter 3 test with Maven
run: |
./mvnw -T1C -B -PgenerateMetadata -DskipNativeTests clean test
./mvnw -am -pl dynamic-datasource-spring-boot3-starter -PnativeTestInSpringBoot -T1C -B clean test
test-maximum-jdk-ci:
test-hotspot-jdk-ci:
name: Test CI - JDK ${{ matrix.java-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
timeout-minutes: 60
strategy:
matrix:
os: [ ubuntu-latest ]
java-version: [ '17' ]
java-version: [ '17', '20' ]
steps:
- uses: actions/checkout@v3
- name: Setup java
Expand Down Expand Up @@ -82,7 +82,7 @@ jobs:
cache: 'maven'
- name: Build test with Maven
run: |
./mvnw -am -pl dynamic-datasource-creator -T1C -B clean package
./mvnw -am -pl dynamic-datasource-spring -T1C -B clean package
./mvnw -am -pl dynamic-datasource-spring-boot-common -T1C -B clean package
./mvnw -am -pl dynamic-datasource-creator -T1C -B clean test
./mvnw -am -pl dynamic-datasource-spring -T1C -B clean test
./mvnw -am -pl dynamic-datasource-spring-boot-common -T1C -B clean test
./mvnw -am -pl dynamic-datasource-spring-boot-starter -T1C -B clean test
38 changes: 25 additions & 13 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Git Mirror 位于 https://github.com/baomidou/dynamic-datasource 。

提交 PR 前,应在 OpenJDK 17 下执行 `./mvnw -T1C -B clean test` 以验证更改是否未破坏单元测试。若有需要请补充或更改单元测试。

假设贡献者处于新的 Ubuntu 22.04.3 LTS 实例下,其可通过如下 bash 命令来执行单元测试
假设贡献者处于新的 Ubuntu 22.04.3 LTS 实例下,其可通过如下 bash 命令来通过 SDKMAN! 管理 JDK 和工具链,并执行单元测试

```bash
sudo apt install unzip zip curl sed -y
Expand All @@ -28,15 +28,14 @@ cd ./dynamic-datasource/
## 2.1. Execute NativeTest under GraalVM Native Image

项目的输出产物对在 GraalVM Native Image 下的可用性的验证,是通过 GraalVM Native Build Tools 的 Maven Plugin 子项目来完成的。
通过在 JVM 下运行单元测试,为单元测试打上 unique Id,此后构建为 GraalVM Native Image 进行 nativeTest 来测试在 GraalVM Native Image
下的单元测试覆盖率。

项目定义了 `generateMetadata` 的 Maven Profile 用于在普通 JVM 下携带 GraalVM Tracing Agent 执行单元测试,并在特定目录下生成或合并
已有的 GraalVM Reachability Metadata 文件。
通过在 JVM 下运行单元测试,为单元测试打上 `junit-platform-unique-ids*`,此后构建为 GraalVM Native Image 进行 nativeTest 来测试在
GraalVM Native Image 下的单元测试覆盖率。请不要使用 `io.kotest:kotest-runner-junit5-jvm:5.5.4` 等在 `test listener` mode 下
failed to discover tests 的测试库。

项目定义了 `nativeTestInSpringBoot` 的 Maven Profile 用于为 `dynamic-datasource-spring-boot3-starter` 模块执行 nativeTest。

假设贡献者处于新的 Ubuntu 22.04.3 LTS 实例下,其可通过如下 bash 命令为 `dynamic-datasource-spring-boot3-starter` 子模块执行 nativeTest。
假设贡献者处于新的 Ubuntu 22.04.3 LTS 实例下,其可通过如下 bash 命令通过 SDKMAN! 管理 JDK 和工具链,
并为 `dynamic-datasource-spring-boot3-starter` 子模块执行 nativeTest。

```bash
sudo apt install unzip zip curl sed -y
Expand All @@ -48,20 +47,33 @@ sudo apt-get install build-essential libz-dev zlib1g-dev -y

git clone [email protected]:baomidou/dynamic-datasource.git
cd ./dynamic-datasource/
./mvnw -T1C -B -PgenerateMetadata -DskipNativeTests clean test
./mvnw -am -pl dynamic-datasource-spring-boot3-starter -PnativeTestInSpringBoot -T1C -B clean test
```

贡献者在提交 PR 后,位于 Github Actions 的 CI 将进行此验证。

请不要为 SPEL 功能编写可能的 nativeTest,参考 https://github.com/spring-projects/spring-framework/issues/29548 。如有需要,
请使用 `org.graalvm.nativeimage.imagecode` 的 System Property 屏蔽相关测试在 GraalVM Native Image 下运行。
贡献者在提交 PR 后,位于 Github Actions 的 CI 将进行此验证。如果 nativeTest 执行失败,请跳转到[本文的 2.2一节](./CONTRIBUTING.md)

当贡献者发现缺少与 `dynamic-datasource` 无关的第三方库的 GraalVM Reachability Metadata 时,应当在
https://github.com/oracle/graalvm-reachability-metadata 打开新的 issue, 并提交包含依赖的第三方库缺失的 GraalVM Reachability
Metadata 的 PR。

## 2.2 Generate or merge GraalVM Reachability Metadata for unit tests

如果 nativeTest 执行失败, 应为单元测试生成初步的 GraalVM Reachability Metadata,并手动调整以修复 nativeTest。
如有需要,请使用 `org.junit.jupiter.api.condition.DisabledInNativeImage` 注解屏蔽部分单元测试。

请不要为 SpEL 功能编写可能的 nativeTest,参考 https://github.com/spring-projects/spring-framework/issues/29548 。如有需要,
请使用 `org.graalvm.nativeimage.imagecode` 的 System Property 屏蔽相关测试在 GraalVM Native Image 下运行。

项目定义了 `generateMetadata` 的 Maven Profile 用于在普通 JVM 下携带 GraalVM Tracing Agent 执行单元测试,并在特定目录下生成或合并
已有的 GraalVM Reachability Metadata 文件。可通过如下 bash 命令简单处理此流程。贡献者仍可能需要手动调整具体的 JSON 条目,并在适当的时候
调整 Maven Profile 和 GraalVM Tracing Agent 的 Filter 链。

```bash
./mvnw -T1C -B -PgenerateMetadata -DskipNativeTests clean test
./mvnw -am -pl dynamic-datasource-spring-boot3-starter -PnativeTestInSpringBoot -T1C -B clean test
```

# 3. PR

PR 应提交到位于 Github 的 Git Mirror,即 https://github.com/baomidou/dynamic-datasource
位于 Github Actions 的 CI 将在 OpenJDK 8 和 OpenJDK 17 下对 PR 对应分支执行对应的单元测试。
位于 Github Actions 的 CI 将在 OpenJDK 8+ 下对 PR 对应分支执行对应的单元测试。
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppContextSetup;

/**
* TODO It looks like SPEL is not available under the test with GraalVM Tracing Agent.
* SpEL is not available under the nativeTest due to
* <a href="https://github.com/spring-projects/spring-framework/issues/29548">Explore how to make
* StandardBeanExpressionResolver not reachable in AOT mode</a>
*/
@SpringBootTest(classes = SPELApplication.class, webEnvironment = RANDOM_PORT)
@DisabledInNativeImage
@SpringBootTest(classes = SPELApplication.class, webEnvironment = RANDOM_PORT)
public class SPELTest {

MockMvc mockMvc;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,74 +11,6 @@
"name":"com.baomidou.dynamic.datasource.creator.druid.DruidConfig",
"methods":[{"name":"getAsyncInit","parameterTypes":[] }, {"name":"getBreakAfterAcquireFailure","parameterTypes":[] }, {"name":"getClearFiltersEnable","parameterTypes":[] }, {"name":"getConnectTimeout","parameterTypes":[] }, {"name":"getConnectionErrorRetryAttempts","parameterTypes":[] }, {"name":"getDefaultAutoCommit","parameterTypes":[] }, {"name":"getDefaultCatalog","parameterTypes":[] }, {"name":"getDefaultReadOnly","parameterTypes":[] }, {"name":"getDefaultTransactionIsolation","parameterTypes":[] }, {"name":"getFailFast","parameterTypes":[] }, {"name":"getFilters","parameterTypes":[] }, {"name":"getInitConnectionSqls","parameterTypes":[] }, {"name":"getInitGlobalVariants","parameterTypes":[] }, {"name":"getInitVariants","parameterTypes":[] }, {"name":"getInitialSize","parameterTypes":[] }, {"name":"getKeepAlive","parameterTypes":[] }, {"name":"getKeepAliveBetweenTimeMillis","parameterTypes":[] }, {"name":"getKillWhenSocketReadTimeout","parameterTypes":[] }, {"name":"getLogAbandoned","parameterTypes":[] }, {"name":"getMaxActive","parameterTypes":[] }, {"name":"getMaxEvictableIdleTimeMillis","parameterTypes":[] }, {"name":"getMaxPoolPreparedStatementPerConnectionSize","parameterTypes":[] }, {"name":"getMaxWait","parameterTypes":[] }, {"name":"getMaxWaitThreadCount","parameterTypes":[] }, {"name":"getMinEvictableIdleTimeMillis","parameterTypes":[] }, {"name":"getMinIdle","parameterTypes":[] }, {"name":"getNotFullTimeoutRetryCount","parameterTypes":[] }, {"name":"getPhyMaxUseCount","parameterTypes":[] }, {"name":"getPhyTimeoutMillis","parameterTypes":[] }, {"name":"getPoolPreparedStatements","parameterTypes":[] }, {"name":"getPublicKey","parameterTypes":[] }, {"name":"getQueryTimeout","parameterTypes":[] }, {"name":"getRemoveAbandoned","parameterTypes":[] }, {"name":"getRemoveAbandonedTimeoutMillis","parameterTypes":[] }, {"name":"getResetStatEnable","parameterTypes":[] }, {"name":"getSharePreparedStatements","parameterTypes":[] }, {"name":"getSocketTimeout","parameterTypes":[] }, {"name":"getStatSqlMaxSize","parameterTypes":[] }, {"name":"getTestOnBorrow","parameterTypes":[] }, {"name":"getTestOnReturn","parameterTypes":[] }, {"name":"getTestWhileIdle","parameterTypes":[] }, {"name":"getTimeBetweenConnectErrorMillis","parameterTypes":[] }, {"name":"getTimeBetweenEvictionRunsMillis","parameterTypes":[] }, {"name":"getTimeBetweenLogStatsMillis","parameterTypes":[] }, {"name":"getTransactionQueryTimeout","parameterTypes":[] }, {"name":"getUseGlobalDataSourceStat","parameterTypes":[] }, {"name":"getUseUnfairLock","parameterTypes":[] }, {"name":"getValidationQuery","parameterTypes":[] }, {"name":"getValidationQueryTimeout","parameterTypes":[] }]
},
{
"name":"com.baomidou.dynamic.datasource.fixture.v3.AddRemoveDatasourceApplication$$SpringCGLIB$$0"
},
{
"name":"com.baomidou.dynamic.datasource.fixture.v3.LoadDatasourceFromJDBCApplication",
"queryAllDeclaredMethods":true
},
{
"name":"com.baomidou.dynamic.datasource.fixture.v3.LoadDatasourceFromJDBCApplication$$SpringCGLIB$$0"
},
{
"name":"com.baomidou.dynamic.datasource.fixture.v3.NestApplication$$SpringCGLIB$$0"
},
{
"name":"com.baomidou.dynamic.datasource.fixture.v3.SPELApplication$$SpringCGLIB$$0"
},
{
"name":"com.baomidou.dynamic.datasource.fixture.v3.service.nest.SchoolService",
"queryAllDeclaredMethods":true
},
{
"name":"com.baomidou.dynamic.datasource.fixture.v3.service.nest.SchoolService$$SpringCGLIB$$0"
},
{
"name":"com.baomidou.dynamic.datasource.fixture.v3.service.nest.SchoolService$$SpringCGLIB$$1"
},
{
"name":"com.baomidou.dynamic.datasource.fixture.v3.service.nest.SchoolService$$SpringCGLIB$$2"
},
{
"name":"com.baomidou.dynamic.datasource.fixture.v3.service.nest.StudentService",
"queryAllDeclaredMethods":true
},
{
"name":"com.baomidou.dynamic.datasource.fixture.v3.service.nest.StudentService$$SpringCGLIB$$0"
},
{
"name":"com.baomidou.dynamic.datasource.fixture.v3.service.nest.StudentService$$SpringCGLIB$$1"
},
{
"name":"com.baomidou.dynamic.datasource.fixture.v3.service.nest.StudentService$$SpringCGLIB$$2"
},
{
"name":"com.baomidou.dynamic.datasource.fixture.v3.service.nest.TeacherService",
"queryAllDeclaredMethods":true
},
{
"name":"com.baomidou.dynamic.datasource.fixture.v3.service.nest.TeacherService$$SpringCGLIB$$0"
},
{
"name":"com.baomidou.dynamic.datasource.fixture.v3.service.nest.TeacherService$$SpringCGLIB$$1"
},
{
"name":"com.baomidou.dynamic.datasource.fixture.v3.service.nest.TeacherService$$SpringCGLIB$$2"
},
{
"name":"com.baomidou.dynamic.datasource.fixture.v3.service.spel.UserService",
"queryAllDeclaredMethods":true
},
{
"name":"com.baomidou.dynamic.datasource.fixture.v3.service.spel.UserService$$SpringCGLIB$$0"
},
{
"name":"com.baomidou.dynamic.datasource.fixture.v3.service.spel.UserService$$SpringCGLIB$$1"
},
{
"name":"com.baomidou.dynamic.datasource.fixture.v3.service.spel.UserService$$SpringCGLIB$$2"
},
{
"name":"com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DruidDynamicDataSourceConfiguration$$SpringCGLIB$$0"
},
Expand Down Expand Up @@ -121,19 +53,10 @@
"name":"com.baomidou.dynamic.datasource.strategy.LoadBalanceDynamicDataSourceStrategy",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"com.baomidou.mybatisplus.core.override.MybatisMapperProxy"
},
{
"name":"com.baomidou.mybatisplus.core.override.PageMapperProxy"
},
{
"name":"java.lang.Object",
"queryAllDeclaredMethods":true
},
{
"name":"org.apache.ibatis.binding.MapperProxy"
},
{
"name":"org.h2.Driver"
},
Expand Down
5 changes: 4 additions & 1 deletion native-image/access-filter.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"rules": [
{"includeClasses": "**"}
{"includeClasses": "**"},
{"excludeClasses": "com.baomidou.mybatisplus.core.override.**"},
{"excludeClasses": "org.apache.ibatis.binding.**"}
],
"regexRules": [
{"excludeClasses": ".*fixture*.*"}
]
}
65 changes: 13 additions & 52 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -271,24 +271,6 @@
</build>

<profiles>
<profile>
<id>jdk11+</id>
<activation>
<jdk>[11,)</jdk>
</activation>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>--add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED</argLine>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
<profile>
<id>release</id>
<distributionManagement>
Expand Down Expand Up @@ -362,26 +344,20 @@
</profile>
<profile>
<id>generateMetadata</id>
<properties>
<java.version>17</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
<!-- We do not collect GraalVM Reachability Metadata from `dynamic-datasource-spring-boot-starter` because only Spring Boot OSS 3 support provides support for GraalVM Native Image-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<includes>
<exclude>com.baomidou.dynamic.datasource.fixture.v3.**</exclude>
</includes>
<argLine>--add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED</argLine>
<excludes>
<exclude>com.baomidou.dynamic.datasource.fixture.v1.**</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
Expand Down Expand Up @@ -411,7 +387,9 @@
<defaultMode>Direct</defaultMode>
<modes>
<!--TODO For the foreseeable future, the generated GraalVM Reachability Metadata will go directly to the Release product rather than staying under test packages -->
<direct>config-output-dir=${project.basedir}/src/test/resources/META-INF/native-image/${project.groupId}/${project.artifactId}</direct>
<direct>
config-output-dir=${project.basedir}/src/test/resources/META-INF/native-image/${project.groupId}/${project.artifactId}
</direct>
</modes>
<options>
<callerFilterFiles>
Expand All @@ -429,28 +407,11 @@
</profile>
<profile>
<id>nativeTestInSpringBoot</id>
<properties>
<java.version>17</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<excludes>
<exclude>com.baomidou.dynamic.datasource.fixture.v1.**</exclude>
</excludes>
<argLine>--add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
Expand Down

0 comments on commit 563522d

Please sign in to comment.