You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by GitBox <gi...@apache.org> on 2021/10/22 04:26:41 UTC
[GitHub] [dolphinscheduler] kezhenxu94 commented on a change in pull request #6500: [Improvement-5807][Dao] Use h2 in UT
kezhenxu94 commented on a change in pull request #6500:
URL: https://github.com/apache/dolphinscheduler/pull/6500#discussion_r734225714
##########
File path: dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/datasource/SpringConnectionFactory.java
##########
@@ -106,17 +115,30 @@ public DruidDataSource dataSource() throws SQLException {
//auto commit
druidDataSource.setDefaultAutoCommit(PropertyUtils.getBoolean(Constants.SPRING_DATASOURCE_DEFAULT_AUTO_COMMIT, true));
druidDataSource.init();
+ logger.info("Initialize Druid DataSource success");
return druidDataSource;
}
+ @Bean(name = "datasource")
+ @Profile(value = {ProfileType.UNIT_TEST})
+ public DataSource h2DataSource() {
+ EmbeddedDatabaseBuilder embeddedDatabaseBuilder = new EmbeddedDatabaseBuilder(new FileSystemResourceLoader());
+ EmbeddedDatabase datasource = embeddedDatabaseBuilder.setType(EmbeddedDatabaseType.H2)
+ .setName("DolphinSchedulerUT;MODE=MySQL")
+ .addScript("file:../sql/dolphinscheduler_h2.sql")
+ .build();
+ logger.info("Initialize H2 DataSource success");
+ return datasource;
+ }
Review comment:
> @kezhenxu94 @CalvinKirs I have try to add multiple datasources properties, such like `datasource-mysql.properties`, `datasource-postgresql.properties`, but it seems not easy, some modules like `Alert` which use datasource is not a spring project, this may require significant changes. Do you have any good ideas?
That's the same pain point when I tried to do the same thing ~1 month ago, mixing Spring and non-Spring modules forces us to do many verbose and inconsistent codes, if there is no special reasons @CalvinKirs , why not consider applying the Spring style to other modules if they are not applied yet? Making them consistent we can reduce a lot of codes and configurations.
But for now as an intermediate phase @ruanwenjun , maybe we have to read the Spring profile name ourselves (e.g. named `h2`) and inject the correct datasource properties (e.g. named `datasource-{profile-name}.properties`)? Is it OK to you?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org