Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open and Fix NativeTest by Spring Framework under GraalVM CE #562

Merged
merged 1 commit into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ 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:
# TODO
test-graalvm-ce-ci:
name: NativeTest CI - GraalVM CE ${{ matrix.java-version }} on ${{ matrix.os }} (This CI failure is reasonable)
runs-on: ${{ matrix.os }}
Expand All @@ -45,7 +44,7 @@ jobs:
- 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
./mvnw -am -pl dynamic-datasource-spring-boot3-starter -PnativeTestInSpringBoot -T1C -B clean test
test-maximum-jdk-ci:
name: Test CI - JDK ${{ matrix.java-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ cd ./dynamic-datasource/
./mvnw -am -pl dynamic-datasource-spring-boot3-starter -PnativeTestInSpringBoot -T1C -B clean test
```

贡献者在提交 PR 后,位于 Github Actions 的 CI 将进行此验证。相关 CI 的失败行为是现阶段是可接受的。
贡献者在提交 PR 后,位于 Github Actions 的 CI 将进行此验证。

请不要为 SPEL 功能编写可能的 nativeTest,参考 https://github.com/spring-projects/spring-framework/issues/29548 。如有需要,
请使用 `org.graalvm.nativeimage.imagecode` 的 System Property 屏蔽相关测试在 GraalVM Native Image 下运行。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ public DynamicDataSourceAutoConfiguration(

@Bean
@ConditionalOnMissingBean
public DataSource dataSource() {
DynamicRoutingDataSource dataSource = new DynamicRoutingDataSource();
public DataSource dataSource(List<DynamicDataSourceProvider> providers) {
DynamicRoutingDataSource dataSource = new DynamicRoutingDataSource(providers);
dataSource.setPrimary(properties.getPrimary());
dataSource.setStrict(properties.getStrict());
dataSource.setStrategy(properties.getStrategy());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.baomidou.dynamic.datasource.spring.boot.autoconfigure;

import com.baomidou.dynamic.datasource.DynamicRoutingDataSource;
import com.baomidou.dynamic.datasource.provider.DynamicDataSourceProvider;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.ObjectProvider;
Expand Down Expand Up @@ -64,8 +65,8 @@ public DynamicDataSourceAutoConfiguration(

@Bean
@ConditionalOnMissingBean
public DataSource dataSource() {
DynamicRoutingDataSource dataSource = new DynamicRoutingDataSource();
public DataSource dataSource(List<DynamicDataSourceProvider> providers) {
DynamicRoutingDataSource dataSource = new DynamicRoutingDataSource(providers);
dataSource.setPrimary(properties.getPrimary());
dataSource.setStrict(properties.getStrict());
dataSource.setStrategy(properties.getStrategy());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.ReflectionUtils;
import org.springframework.util.StringUtils;

Expand All @@ -48,6 +48,7 @@
* @since 1.0.0
*/
@Slf4j
@Component
public class DynamicRoutingDataSource extends AbstractRoutingDataSource implements InitializingBean, DisposableBean {
linghengqian marked this conversation as resolved.
Show resolved Hide resolved

private static final String UNDERLINE = "_";
Expand All @@ -59,8 +60,7 @@ public class DynamicRoutingDataSource extends AbstractRoutingDataSource implemen
* 分组数据库
*/
private final Map<String, GroupDataSource> groupDataSources = new ConcurrentHashMap<>();
@Autowired
private List<DynamicDataSourceProvider> providers;
private final List<DynamicDataSourceProvider> providers;
@Setter
private Class<? extends DynamicDataSourceStrategy> strategy = LoadBalanceDynamicDataSourceStrategy.class;
@Setter
Expand All @@ -72,6 +72,10 @@ public class DynamicRoutingDataSource extends AbstractRoutingDataSource implemen
@Setter
private Boolean seata = false;

public DynamicRoutingDataSource(List<DynamicDataSourceProvider> providers) {
this.providers = providers;
}

@Override
protected String getPrimary() {
return primary;
Expand Down Expand Up @@ -207,7 +211,7 @@ public synchronized void removeDataSource(String ds) {
}

@Override
public void destroy() throws Exception {
public void destroy() {
log.info("dynamic-datasource start closing ....");
for (Map.Entry<String, DataSource> item : dataSourceMap.entrySet()) {
closeDataSource(item.getKey(), item.getValue());
Expand All @@ -216,7 +220,7 @@ public void destroy() throws Exception {
}

@Override
public void afterPropertiesSet() throws Exception {
public void afterPropertiesSet() {
// 检查开启了配置但没有相关依赖
checkEnv();
// 添加并分组数据源
Expand Down
13 changes: 3 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,9 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<excludes>
<exclude>com.baomidou.dynamic.datasource.fixture.v1.**</exclude>
</excludes>
<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>
</configuration>
</plugin>
Expand Down Expand Up @@ -429,13 +429,6 @@
</profile>
<profile>
<id>nativeTestInSpringBoot</id>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
Expand Down