diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7957a2cf..d4b347ff 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 @@ -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 @@ -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 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8ef0abc6..ee215903 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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 @@ -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 @@ -48,20 +47,33 @@ sudo apt-get install build-essential libz-dev zlib1g-dev -y git clone git@github.com: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 对应分支执行对应的单元测试。 diff --git a/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/SPELTest.java b/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/SPELTest.java index 5813c1dd..c74f45b2 100644 --- a/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/SPELTest.java +++ b/dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/fixture/v3/SPELTest.java @@ -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 + * Explore how to make + * StandardBeanExpressionResolver not reachable in AOT mode */ -@SpringBootTest(classes = SPELApplication.class, webEnvironment = RANDOM_PORT) @DisabledInNativeImage +@SpringBootTest(classes = SPELApplication.class, webEnvironment = RANDOM_PORT) public class SPELTest { MockMvc mockMvc; diff --git a/dynamic-datasource-spring-boot3-starter/src/test/resources/META-INF/native-image/com.baomidou/dynamic-datasource-spring-boot3-starter/reflect-config.json b/dynamic-datasource-spring-boot3-starter/src/test/resources/META-INF/native-image/com.baomidou/dynamic-datasource-spring-boot3-starter/reflect-config.json index 5a357503..9d194a8f 100644 --- a/dynamic-datasource-spring-boot3-starter/src/test/resources/META-INF/native-image/com.baomidou/dynamic-datasource-spring-boot3-starter/reflect-config.json +++ b/dynamic-datasource-spring-boot3-starter/src/test/resources/META-INF/native-image/com.baomidou/dynamic-datasource-spring-boot3-starter/reflect-config.json @@ -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" }, @@ -121,19 +53,10 @@ "name":"com.baomidou.dynamic.datasource.strategy.LoadBalanceDynamicDataSourceStrategy", "methods":[{"name":"","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" }, diff --git a/native-image/access-filter.json b/native-image/access-filter.json index 0d7dc012..16d5f721 100644 --- a/native-image/access-filter.json +++ b/native-image/access-filter.json @@ -1,7 +1,10 @@ { "rules": [ - {"includeClasses": "**"} + {"includeClasses": "**"}, + {"excludeClasses": "com.baomidou.mybatisplus.core.override.**"}, + {"excludeClasses": "org.apache.ibatis.binding.**"} ], "regexRules": [ + {"excludeClasses": ".*fixture*.*"} ] } diff --git a/pom.xml b/pom.xml index 80031aa2..ec541d3d 100644 --- a/pom.xml +++ b/pom.xml @@ -271,24 +271,6 @@ - - jdk11+ - - [11,) - - - - - - maven-surefire-plugin - - --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED - - - - - - release @@ -362,26 +344,20 @@ generateMetadata + + 17 + - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - 17 - 17 - - + org.apache.maven.plugins maven-surefire-plugin ${maven-surefire-plugin.version} - - com.baomidou.dynamic.datasource.fixture.v3.** - - --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED + + com.baomidou.dynamic.datasource.fixture.v1.** + @@ -411,7 +387,9 @@ Direct - config-output-dir=${project.basedir}/src/test/resources/META-INF/native-image/${project.groupId}/${project.artifactId} + + config-output-dir=${project.basedir}/src/test/resources/META-INF/native-image/${project.groupId}/${project.artifactId} + @@ -429,28 +407,11 @@ nativeTestInSpringBoot + + 17 + - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - 17 - 17 - - - - org.apache.maven.plugins - maven-surefire-plugin - ${maven-surefire-plugin.version} - - - com.baomidou.dynamic.datasource.fixture.v1.** - - --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED - - org.springframework.boot spring-boot-maven-plugin