-
Notifications
You must be signed in to change notification settings - Fork 92
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
Add support for com.baomidou:dynamic-datasource-spring-boot-starter:3.6.1
#154
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
metadata/com.baomidou/dynamic-datasource-spring-boot-starter/3.6.1/index.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[ | ||
"jni-config.json", | ||
"proxy-config.json", | ||
"reflect-config.json", | ||
"resource-config.json", | ||
"serialization-config.json" | ||
] |
1 change: 1 addition & 0 deletions
1
metadata/com.baomidou/dynamic-datasource-spring-boot-starter/3.6.1/jni-config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[] |
1 change: 1 addition & 0 deletions
1
metadata/com.baomidou/dynamic-datasource-spring-boot-starter/3.6.1/proxy-config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[] |
1 change: 1 addition & 0 deletions
1
metadata/com.baomidou/dynamic-datasource-spring-boot-starter/3.6.1/reflect-config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[] |
1 change: 1 addition & 0 deletions
1
metadata/com.baomidou/dynamic-datasource-spring-boot-starter/3.6.1/resource-config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
4 changes: 4 additions & 0 deletions
4
metadata/com.baomidou/dynamic-datasource-spring-boot-starter/3.6.1/serialization-config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"lambdaCapturingTypes": [], | ||
"types": [] | ||
} |
10 changes: 10 additions & 0 deletions
10
metadata/com.baomidou/dynamic-datasource-spring-boot-starter/index.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[ | ||
{ | ||
"latest": true, | ||
"metadata-version": "3.6.1", | ||
"module": "com.baomidou:dynamic-datasource-spring-boot-starter", | ||
"tested-versions": [ | ||
"3.6.1" | ||
] | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
tests/src/com.baomidou/dynamic-datasource-spring-boot-starter/3.6.1/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
gradlew.bat | ||
gradlew | ||
gradle/ | ||
build/ |
44 changes: 44 additions & 0 deletions
44
tests/src/com.baomidou/dynamic-datasource-spring-boot-starter/3.6.1/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright and related rights waived via CC0 | ||
* | ||
* You should have received a copy of the CC0 legalcode along with this | ||
* work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>. | ||
*/ | ||
|
||
plugins { | ||
id "org.graalvm.internal.tck" | ||
id 'org.springframework.boot' version '3.0.1' | ||
id 'io.spring.dependency-management' version '1.1.0' | ||
} | ||
|
||
String libraryVersion = tck.testedLibraryVersion.get() | ||
|
||
dependencies { | ||
testImplementation "com.baomidou:dynamic-datasource-spring-boot-starter:$libraryVersion" | ||
testImplementation 'org.assertj:assertj-core:3.22.0' | ||
testImplementation 'org.springframework.boot:spring-boot-starter-web' | ||
testRuntimeOnly 'com.h2database:h2:2.1.214' | ||
testImplementation 'org.springframework.boot:spring-boot-starter-test' | ||
} | ||
|
||
group 'com_baomidou.dynamic_datasource_spring_boot_starter' | ||
|
||
springBoot { | ||
mainClass = 'com_baomidou.dynamic_datasource_spring_boot_starter.AddRemoveDatasourceApplication' | ||
} | ||
|
||
graalvmNative { | ||
agent { | ||
defaultMode = "conditional" | ||
modes { | ||
conditional { | ||
userCodeFilterPath = "user-code-filter.json" | ||
} | ||
} | ||
metadataCopy { | ||
mergeWithExisting = true | ||
inputTaskNames.add("test") | ||
outputDirectories.add("src/test/resources/META-INF/native-image/com.baomidou/dynamic-datasource-spring-boot-starter") | ||
} | ||
} | ||
} | ||
2 changes: 2 additions & 0 deletions
2
tests/src/com.baomidou/dynamic-datasource-spring-boot-starter/3.6.1/gradle.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
library.version = 3.6.1 | ||
metadata.dir = com.baomidou/dynamic-datasource-spring-boot-starter/3.6.1/ |
13 changes: 13 additions & 0 deletions
13
tests/src/com.baomidou/dynamic-datasource-spring-boot-starter/3.6.1/settings.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
pluginManagement { | ||
def tckPath = Objects.requireNonNullElse( | ||
System.getenv("GVM_TCK_TCKDIR"), | ||
"../../../../tck-build-logic" | ||
) | ||
includeBuild(tckPath) | ||
} | ||
|
||
plugins { | ||
id "org.graalvm.internal.tck-settings" version "1.0.0-SNAPSHOT" | ||
} | ||
|
||
rootProject.name = 'com.baomidou.dynamic-datasource-spring-boot-starter_tests' |
51 changes: 51 additions & 0 deletions
51
...est/java/com_baomidou/dynamic_datasource_spring_boot_starter/AddRemoveDatasourceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright and related rights waived via CC0 | ||
* | ||
* You should have received a copy of the CC0 legalcode along with this | ||
* work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>. | ||
*/ | ||
package com_baomidou.dynamic_datasource_spring_boot_starter; | ||
|
||
import com.baomidou.dynamic.datasource.DynamicRoutingDataSource; | ||
import com.baomidou.dynamic.datasource.creator.DefaultDataSourceCreator; | ||
import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DataSourceProperty; | ||
import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.hikari.HikariCpConfig; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
import javax.sql.DataSource; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; | ||
|
||
@SpringBootTest(classes = AddRemoveDatasourceApplication.class, webEnvironment = RANDOM_PORT) | ||
public class AddRemoveDatasourceTest { | ||
@Autowired | ||
DataSource dataSource; | ||
@Autowired | ||
DefaultDataSourceCreator dataSourceCreator; | ||
|
||
@Test | ||
void testAddAndRemoveDataSource() { | ||
HikariCpConfig hikariCpConfig = new HikariCpConfig(); | ||
hikariCpConfig.setConnectionTestQuery("select 1"); | ||
DataSourceProperty dataSourceProperty = new DataSourceProperty() | ||
.setPoolName("slave_1").setDriverClassName("org.h2.Driver").setUrl("jdbc:h2:mem:test1;MODE=MySQL") | ||
.setUsername("sa").setPassword("").setHikari(hikariCpConfig); | ||
DynamicRoutingDataSource ds = (DynamicRoutingDataSource) dataSource; | ||
ds.addDataSource(dataSourceProperty.getPoolName(), dataSourceCreator.createDataSource(dataSourceProperty)); | ||
assertThat(ds.getDataSources().keySet()).contains("slave_1"); | ||
ds.removeDataSource("slave_1"); | ||
assertThat(ds.getDataSources().keySet()).doesNotContain("slave_1"); | ||
} | ||
} | ||
|
||
@SpringBootApplication | ||
class AddRemoveDatasourceApplication { | ||
public static void main(String[] args) { | ||
SpringApplication.run(AddRemoveDatasourceApplication.class, args); | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
.../java/com_baomidou/dynamic_datasource_spring_boot_starter/LoadDatasourceFromJDBCTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright and related rights waived via CC0 | ||
* | ||
* You should have received a copy of the CC0 legalcode along with this | ||
* work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>. | ||
*/ | ||
package com_baomidou.dynamic_datasource_spring_boot_starter; | ||
|
||
import com.baomidou.dynamic.datasource.DynamicRoutingDataSource; | ||
import com.baomidou.dynamic.datasource.provider.AbstractJdbcDataSourceProvider; | ||
import com.baomidou.dynamic.datasource.provider.DynamicDataSourceProvider; | ||
import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DataSourceProperty; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.context.annotation.Bean; | ||
|
||
import javax.sql.DataSource; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.sql.Statement; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; | ||
|
||
@SpringBootTest(classes = LoadDatasourceFromJDBCApplication.class, webEnvironment = RANDOM_PORT) | ||
public class LoadDatasourceFromJDBCTest { | ||
@Autowired | ||
DataSource dataSource; | ||
|
||
@Test | ||
void testExistDataSource() { | ||
DynamicRoutingDataSource ds = (DynamicRoutingDataSource) dataSource; | ||
assertThat(ds.getDataSources().keySet()).contains("master", "db1", "db2", "db3"); | ||
} | ||
} | ||
|
||
@SuppressWarnings({"SqlDialectInspection", "SqlNoDataSourceInspection"}) | ||
@SpringBootApplication | ||
class LoadDatasourceFromJDBCApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(LoadDatasourceFromJDBCApplication.class, args); | ||
} | ||
|
||
@Bean | ||
public DynamicDataSourceProvider dynamicDataSourceProvider() { | ||
return new AbstractJdbcDataSourceProvider("org.h2.Driver", "jdbc:h2:mem:test;MODE=MySQL", "sa", "") { | ||
@Override | ||
protected Map<String, DataSourceProperty> executeStmt(Statement statement) throws SQLException { | ||
statement.execute(""" | ||
CREATE TABLE IF NOT EXISTS `DB` | ||
( | ||
`name` VARCHAR(30) NULL DEFAULT NULL, | ||
`username` VARCHAR(30) NULL DEFAULT NULL, | ||
`password` VARCHAR(30) NULL DEFAULT NULL, | ||
`url` VARCHAR(30) NULL DEFAULT NULL, | ||
`driver` VARCHAR(30) NULL DEFAULT NULL | ||
)"""); | ||
statement.executeUpdate("insert into DB values ('master','sa','','jdbc:h2:mem:test;MODE=MySQL','org.h2.Driver')"); | ||
statement.executeUpdate("insert into DB values ('db1','sa','','jdbc:h2:mem:test2','org.h2.Driver')"); | ||
statement.executeUpdate("insert into DB values ('db2','sa','','jdbc:h2:mem:test3','org.h2.Driver')"); | ||
statement.executeUpdate("insert into DB values ('db3','sa','','jdbc:h2:mem:test4','org.h2.Driver')"); | ||
Map<String, DataSourceProperty> map = new HashMap<>(); | ||
ResultSet rs = statement.executeQuery("select * from DB"); | ||
while (rs.next()) { | ||
map.put(rs.getString("name"), new DataSourceProperty() | ||
.setUsername(rs.getString("username")).setPassword(rs.getString("password")) | ||
.setUrl(rs.getString("url")).setDriverClassName(rs.getString("driver"))); | ||
} | ||
return map; | ||
} | ||
}; | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
...src/test/java/com_baomidou/dynamic_datasource_spring_boot_starter/NestDataSourceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright and related rights waived via CC0 | ||
* | ||
* You should have received a copy of the CC0 legalcode along with this | ||
* work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>. | ||
*/ | ||
package com_baomidou.dynamic_datasource_spring_boot_starter; | ||
|
||
import com.baomidou.dynamic.datasource.DynamicRoutingDataSource; | ||
import com.baomidou.dynamic.datasource.creator.DefaultDataSourceCreator; | ||
import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DataSourceProperty; | ||
import com_baomidou.dynamic_datasource_spring_boot_starter.service.nest.*; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
import javax.sql.DataSource; | ||
import java.util.List; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; | ||
|
||
@SpringBootTest(classes = NestApplication.class, webEnvironment = RANDOM_PORT) | ||
public class NestDataSourceTest { | ||
@Autowired | ||
DataSource dataSource; | ||
@Autowired | ||
DefaultDataSourceCreator dataSourceCreator; | ||
@Autowired | ||
private TeacherService teacherService; | ||
@Autowired | ||
private StudentService studentService; | ||
@Autowired | ||
private SchoolService schoolService; | ||
|
||
@Test | ||
void testNest() { | ||
DataSourceProperty masterDataSourceProperty = new DataSourceProperty() | ||
.setPoolName("master").setDriverClassName("org.h2.Driver") | ||
.setUrl("jdbc:h2:mem:test;MODE=MySQL;DB_CLOSE_ON_EXIT=FALSE;INIT=RUNSCRIPT FROM 'classpath:db/add-remove-datasource.sql'") | ||
.setUsername("sa").setPassword(""); | ||
DataSourceProperty teacherDataSourceProperty = new DataSourceProperty() | ||
.setPoolName("teacher").setDriverClassName("org.h2.Driver").setUrl("jdbc:h2:mem:test;MODE=MySQL;DB_CLOSE_ON_EXIT=FALSE") | ||
.setUsername("sa").setPassword(""); | ||
DataSourceProperty studentDataSourceProperty = new DataSourceProperty() | ||
.setPoolName("student").setDriverClassName("org.h2.Driver").setUrl("jdbc:h2:mem:test;MODE=MySQL;DB_CLOSE_ON_EXIT=FALSE") | ||
.setUsername("sa").setPassword(""); | ||
DynamicRoutingDataSource ds = (DynamicRoutingDataSource) dataSource; | ||
ds.addDataSource(masterDataSourceProperty.getPoolName(), dataSourceCreator.createDataSource(masterDataSourceProperty)); | ||
ds.addDataSource(teacherDataSourceProperty.getPoolName(), dataSourceCreator.createDataSource(teacherDataSourceProperty)); | ||
ds.addDataSource(studentDataSourceProperty.getPoolName(), dataSourceCreator.createDataSource(studentDataSourceProperty)); | ||
assertThat(ds.getDataSources().keySet()).contains("master", "teacher", "student"); | ||
assertThat(teacherService.addTeacherWithTx("ss", 1)).isEqualTo(1); | ||
assertThat(studentService.addStudentWithTx("tt", 2)).isEqualTo(1); | ||
assertThat(teacherService.selectTeachers()).isEqualTo(List.of(new Teacher(1, "tt", 2))); | ||
assertThat(studentService.selectStudents()).isEqualTo(List.of(new Student(1, "tt", 2))); | ||
assertThat(schoolService.addTeacherAndStudentWithTx()).isEqualTo(2); | ||
assertThat(teacherService.selectTeachers()).isEqualTo(List.of(new Teacher(1, "tt", 2), new Teacher(2, "bb", 4))); | ||
assertThat(studentService.selectStudents()).isEqualTo(List.of(new Student(1, "tt", 2), new Student(2, "bb", 4))); | ||
} | ||
} | ||
|
||
@SpringBootApplication | ||
class NestApplication { | ||
public static void main(String[] args) { | ||
SpringApplication.run(NestApplication.class, args); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sdeleuze
./gradlew -Pagent clean test
../gradlew clean test
, everything works fine, but cannot useuser-code-filter.json
to generate GraalVM reachability metadata in Conditional Agent Mode.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@linghengqian Looks like Native Build Tools sets
org.graalvm.nativeimage.imagecode
system property when the agent profile is enabled (expected) but that impacts the code running in the Gradle plugin JVM potentially because the JVM is not forked and in term of lifecycle that maybe happens too early.@bclozel @sbrannen Any thoughts ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Running in agent mode with the NBT will set
org.graalvm.nativeimage.imagecode=agent
.And
AotDetector.useGeneratedArtifacts()
returnstrue
if that's the case.So that would explain the cause of the
IllegalStateException
inTestContextAotGenerator
.That may be problematic in and of itself.
In any case, why is
TestContextAotGenerator
used when executing./gradlew -Pagent clean test
?Is that command supposed to trigger AOT processing of the test suite?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sbrannen
This involves an idea that I want to use GraalVM Tracing Agent to collect GraalVM Reachability Metadata in Conditional form for the corresponding unit tests for some third-party Spring Boot Starters that must use Spring Boot's unique classes.
I've been involved with too many deadlines lately, and haven't had time to investigate this PR.
Do you want me to open a new issue with a minimal reproducible example on the Spring Boot side?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@linghengqian, yes that would be great!
Though it may be better to file the issue against the Spring Framework, since changes will likely need to be made in Framework -- even if the example you provide uses Boot and its plugins.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.