Browse Source

[Improvement-15260][dolphinscheduler-datasource-hana] add hana related dependencies (#15260)

* add hana related dependencies

* optimizing HANA data source bugs

* run mvn spotless:apply

* Fix hana datasource getValidationQuery()

* Fix hana datasource testGetJdbcUrl()

---------

Co-authored-by: xujiaqiang <“xujiaqiangwz@163.com”>
Co-authored-by: David Zollo <dailidong66@gmail.com>
3.2.1-prepare
xujiaqiang 12 months ago committed by GitHub
parent
commit
0feb144180
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      dolphinscheduler-bom/pom.xml
  2. 2
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/constants/DataSourceConstants.java
  3. 5
      dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-all/pom.xml
  4. 49
      dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hana/pom.xml
  5. 7
      dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hana/src/main/java/org/apache/dolphinscheduler/plugin/datasource/hana/HanaAdHocDataSourceClient.java
  6. 12
      dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hana/src/main/java/org/apache/dolphinscheduler/plugin/datasource/hana/HanaDataSourceChannel.java
  7. 30
      dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hana/src/main/java/org/apache/dolphinscheduler/plugin/datasource/hana/HanaPooledDataSourceClient.java
  8. 9
      dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hana/src/main/java/org/apache/dolphinscheduler/plugin/datasource/hana/param/HanaDataSourceProcessor.java
  9. 5
      dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hana/src/test/java/org/apache/dolphinscheduler/plugin/datasource/hana/HanaDataSourceChannelFactoryTest.java
  10. 12
      dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hana/src/test/java/org/apache/dolphinscheduler/plugin/datasource/hana/HanaDataSourceChannelTest.java
  11. 23
      dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hana/src/test/java/org/apache/dolphinscheduler/plugin/datasource/hana/param/HanaDataSourceProcessorTest.java
  12. 14
      dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hana/src/test/java/org/apache/dolphinscheduler/plugin/datasource/hana/provider/JDBCDataSourceProviderTest.java
  13. 38
      dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hana/src/test/java/org/apache/dolphinscheduler/plugin/datasource/hana/utils/DataSourceUtilsTest.java
  14. 1
      dolphinscheduler-datasource-plugin/pom.xml

9
dolphinscheduler-bom/pom.xml

@ -60,6 +60,7 @@
<vertica-jdbc.version>12.0.4-0</vertica-jdbc.version> <vertica-jdbc.version>12.0.4-0</vertica-jdbc.version>
<oracle-jdbc.version>21.5.0.0</oracle-jdbc.version> <oracle-jdbc.version>21.5.0.0</oracle-jdbc.version>
<dameng-jdbc.version>8.1.2.79</dameng-jdbc.version> <dameng-jdbc.version>8.1.2.79</dameng-jdbc.version>
<ngdbc.version>2.4.51</ngdbc.version>
<slf4j.version>1.7.36</slf4j.version> <slf4j.version>1.7.36</slf4j.version>
<poi.version>4.1.2</poi.version> <poi.version>4.1.2</poi.version>
<javax.servlet-api.version>3.1.0</javax.servlet-api.version> <javax.servlet-api.version>3.1.0</javax.servlet-api.version>
@ -418,6 +419,14 @@
<artifactId>h2</artifactId> <artifactId>h2</artifactId>
<version>${h2.version}</version> <version>${h2.version}</version>
</dependency> </dependency>
<dependency>
<groupId>com.sap.cloud.db.jdbc</groupId>
<artifactId>ngdbc</artifactId>
<version>${ngdbc.version}</version>
<scope>test</scope>
</dependency>
<!-- sl4j --> <!-- sl4j -->
<dependency> <dependency>
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>

2
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/constants/DataSourceConstants.java

@ -65,7 +65,7 @@ public class DataSourceConstants {
public static final String KYUUBI_VALIDATION_QUERY = "select 1"; public static final String KYUUBI_VALIDATION_QUERY = "select 1";
public static final String VERTICA_VALIDATION_QUERY = "select 1"; public static final String VERTICA_VALIDATION_QUERY = "select 1";
public static final String HANA_VALIDATION_QUERY = "select 1"; public static final String HANA_VALIDATION_QUERY = "select 1 from DUMMY";
/** /**
* jdbc url * jdbc url

5
dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-all/pom.xml

@ -153,5 +153,10 @@
<artifactId>dolphinscheduler-datasource-k8s</artifactId> <artifactId>dolphinscheduler-datasource-k8s</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.apache.dolphinscheduler</groupId>
<artifactId>dolphinscheduler-datasource-hana</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies> </dependencies>
</project> </project>

49
dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hana/pom.xml

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one or more
~ contributor license agreements. See the NOTICE file distributed with
~ this work for additional information regarding copyright ownership.
~ The ASF licenses this file to You under the Apache License, Version 2.0
~ (the "License"); you may not use this file except in compliance with
~ the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.dolphinscheduler</groupId>
<artifactId>dolphinscheduler-datasource-plugin</artifactId>
<version>dev-SNAPSHOT</version>
</parent>
<artifactId>dolphinscheduler-datasource-hana</artifactId>
<packaging>jar</packaging>
<name>${project.artifactId}</name>
<dependencies>
<dependency>
<groupId>org.apache.dolphinscheduler</groupId>
<artifactId>dolphinscheduler-spi</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.dolphinscheduler</groupId>
<artifactId>dolphinscheduler-datasource-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.sap.cloud.db.jdbc</groupId>
<artifactId>ngdbc</artifactId>
</dependency>
</dependencies>
</project>

7
dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hana/src/main/java/org/apache/dolphinscheduler/plugin/datasource/hana/HanaDataSourceClient.java → dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hana/src/main/java/org/apache/dolphinscheduler/plugin/datasource/hana/HanaAdHocDataSourceClient.java

@ -17,14 +17,13 @@
package org.apache.dolphinscheduler.plugin.datasource.hana; package org.apache.dolphinscheduler.plugin.datasource.hana;
import org.apache.dolphinscheduler.plugin.datasource.api.client.CommonDataSourceClient; import org.apache.dolphinscheduler.plugin.datasource.api.client.BaseAdHocDataSourceClient;
import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam; import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam;
import org.apache.dolphinscheduler.spi.enums.DbType; import org.apache.dolphinscheduler.spi.enums.DbType;
public class HanaDataSourceClient extends CommonDataSourceClient { public class HanaAdHocDataSourceClient extends BaseAdHocDataSourceClient {
public HanaDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { public HanaAdHocDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) {
super(baseConnectionParam, dbType); super(baseConnectionParam, dbType);
} }
} }

12
dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hana/src/main/java/org/apache/dolphinscheduler/plugin/datasource/hana/HanaDataSourceChannel.java

@ -17,15 +17,21 @@
package org.apache.dolphinscheduler.plugin.datasource.hana; package org.apache.dolphinscheduler.plugin.datasource.hana;
import org.apache.dolphinscheduler.spi.datasource.AdHocDataSourceClient;
import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam; import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam;
import org.apache.dolphinscheduler.spi.datasource.DataSourceChannel; import org.apache.dolphinscheduler.spi.datasource.DataSourceChannel;
import org.apache.dolphinscheduler.spi.datasource.DataSourceClient; import org.apache.dolphinscheduler.spi.datasource.PooledDataSourceClient;
import org.apache.dolphinscheduler.spi.enums.DbType; import org.apache.dolphinscheduler.spi.enums.DbType;
public class HanaDataSourceChannel implements DataSourceChannel { public class HanaDataSourceChannel implements DataSourceChannel {
@Override @Override
public DataSourceClient createDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { public AdHocDataSourceClient createAdHocDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) {
return new HanaDataSourceClient(baseConnectionParam, dbType); return new HanaAdHocDataSourceClient(baseConnectionParam, dbType);
}
@Override
public PooledDataSourceClient createPooledDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) {
return new HanaPooledDataSourceClient(baseConnectionParam, dbType);
} }
} }

30
dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hana/src/main/java/org/apache/dolphinscheduler/plugin/datasource/hana/HanaPooledDataSourceClient.java

@ -0,0 +1,30 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dolphinscheduler.plugin.datasource.hana;
import org.apache.dolphinscheduler.plugin.datasource.api.client.BasePooledDataSourceClient;
import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam;
import org.apache.dolphinscheduler.spi.enums.DbType;
public class HanaPooledDataSourceClient extends BasePooledDataSourceClient {
public HanaPooledDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) {
super(baseConnectionParam, dbType);
}
}

9
dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hana/src/main/java/org/apache/dolphinscheduler/plugin/datasource/hana/param/HanaDataSourceProcessor.java

@ -34,16 +34,13 @@ import java.sql.Connection;
import java.sql.DriverManager; import java.sql.DriverManager;
import java.sql.SQLException; import java.sql.SQLException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.auto.service.AutoService; import com.google.auto.service.AutoService;
@AutoService(DataSourceProcessor.class) @AutoService(DataSourceProcessor.class)
public class HanaDataSourceProcessor extends AbstractDataSourceProcessor { public class HanaDataSourceProcessor extends AbstractDataSourceProcessor {
private final Logger logger = LoggerFactory.getLogger(HanaDataSourceProcessor.class);
private static final String APPEND_PARAMS = "reconnect=true"; private static final String APPEND_PARAMS = "reconnect=true";
@Override @Override
public BaseDataSourceParamDTO castDatasourceParamDTO(String paramJson) { public BaseDataSourceParamDTO castDatasourceParamDTO(String paramJson) {
return JSONUtils.parseObject(paramJson, HanaDataSourceParamDTO.class); return JSONUtils.parseObject(paramJson, HanaDataSourceParamDTO.class);
@ -96,7 +93,7 @@ public class HanaDataSourceProcessor extends AbstractDataSourceProcessor {
@Override @Override
public String getValidationQuery() { public String getValidationQuery() {
return DataSourceConstants.COM_HANA_DB_JDBC_DRIVER; return DataSourceConstants.HANA_VALIDATION_QUERY;
} }
@Override @Override

5
dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hana/src/test/java/org/apache/dolphinscheduler/plugin/datasource/hana/HanaDataSourceChannelFactoryTest.java

@ -18,13 +18,14 @@
package org.apache.dolphinscheduler.plugin.datasource.hana; package org.apache.dolphinscheduler.plugin.datasource.hana;
import org.apache.dolphinscheduler.spi.datasource.DataSourceChannel; import org.apache.dolphinscheduler.spi.datasource.DataSourceChannel;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
public class HanaDataSourceChannelFactoryTest { class HanaDataSourceChannelFactoryTest {
@Test @Test
public void testCreate() { void testCreate() {
HanaDataSourceChannelFactory sourceChannelFactory = new HanaDataSourceChannelFactory(); HanaDataSourceChannelFactory sourceChannelFactory = new HanaDataSourceChannelFactory();
DataSourceChannel dataSourceChannel = sourceChannelFactory.create(); DataSourceChannel dataSourceChannel = sourceChannelFactory.create();
Assertions.assertNotNull(dataSourceChannel); Assertions.assertNotNull(dataSourceChannel);

12
dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hana/src/test/java/org/apache/dolphinscheduler/plugin/datasource/hana/HanaDataSourceChannelTest.java

@ -19,6 +19,7 @@ package org.apache.dolphinscheduler.plugin.datasource.hana;
import org.apache.dolphinscheduler.plugin.datasource.hana.param.HanaConnectionParam; import org.apache.dolphinscheduler.plugin.datasource.hana.param.HanaConnectionParam;
import org.apache.dolphinscheduler.spi.enums.DbType; import org.apache.dolphinscheduler.spi.enums.DbType;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
@ -26,13 +27,14 @@ import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoExtension;
@ExtendWith(MockitoExtension.class) @ExtendWith(MockitoExtension.class)
public class HanaDataSourceChannelTest { class HanaDataSourceChannelTest {
@Test @Test
public void testCreateDataSourceClient() { void testCreateDataSourceClient() {
HanaDataSourceChannel sourceChannel = Mockito.mock(HanaDataSourceChannel.class); HanaDataSourceChannel sourceChannel = Mockito.mock(HanaDataSourceChannel.class);
HanaDataSourceClient dataSourceClient = Mockito.mock(HanaDataSourceClient.class); HanaPooledDataSourceClient dataSourceClient = Mockito.mock(HanaPooledDataSourceClient.class);
Mockito.when(sourceChannel.createDataSourceClient(Mockito.any(), Mockito.any())).thenReturn(dataSourceClient); Mockito.when(sourceChannel.createPooledDataSourceClient(Mockito.any(), Mockito.any()))
Assertions.assertNotNull(sourceChannel.createDataSourceClient(new HanaConnectionParam(), DbType.HANA)); .thenReturn(dataSourceClient);
Assertions.assertNotNull(sourceChannel.createPooledDataSourceClient(new HanaConnectionParam(), DbType.HANA));
} }
} }

23
dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hana/src/test/java/org/apache/dolphinscheduler/plugin/datasource/hana/param/HanaDataSourceProcessorTest.java

@ -20,6 +20,10 @@ package org.apache.dolphinscheduler.plugin.datasource.hana.param;
import org.apache.dolphinscheduler.common.constants.DataSourceConstants; import org.apache.dolphinscheduler.common.constants.DataSourceConstants;
import org.apache.dolphinscheduler.plugin.datasource.api.utils.PasswordUtils; import org.apache.dolphinscheduler.plugin.datasource.api.utils.PasswordUtils;
import org.apache.dolphinscheduler.spi.enums.DbType; import org.apache.dolphinscheduler.spi.enums.DbType;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
@ -27,16 +31,13 @@ import org.mockito.MockedStatic;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoExtension;
import java.util.HashMap;
import java.util.Map;
@ExtendWith(MockitoExtension.class) @ExtendWith(MockitoExtension.class)
public class HanaDataSourceProcessorTest { class HanaDataSourceProcessorTest {
private HanaDataSourceProcessor hanaDataSourceProcessor = new HanaDataSourceProcessor(); private HanaDataSourceProcessor hanaDataSourceProcessor = new HanaDataSourceProcessor();
@Test @Test
public void testCreateConnectionParams() { void testCreateConnectionParams() {
Map<String, String> props = new HashMap<>(); Map<String, String> props = new HashMap<>();
HanaDataSourceParamDTO mysqlDatasourceParamDTO = new HanaDataSourceParamDTO(); HanaDataSourceParamDTO mysqlDatasourceParamDTO = new HanaDataSourceParamDTO();
mysqlDatasourceParamDTO.setUserName("root"); mysqlDatasourceParamDTO.setUserName("root");
@ -55,7 +56,7 @@ public class HanaDataSourceProcessorTest {
} }
@Test @Test
public void testCreateConnectionParams2() { void testCreateConnectionParams2() {
String connectionJson = "{\"user\":\"root\",\"password\":\"123456\",\"address\":\"jdbc:sap://localhost:30015\"" String connectionJson = "{\"user\":\"root\",\"password\":\"123456\",\"address\":\"jdbc:sap://localhost:30015\""
+ ",\"database\":\"default\",\"jdbcUrl\":\"jdbc:sap://localhost:30015?currentschema=default\"}"; + ",\"database\":\"default\",\"jdbcUrl\":\"jdbc:sap://localhost:30015?currentschema=default\"}";
HanaConnectionParam connectionParams = (HanaConnectionParam) hanaDataSourceProcessor HanaConnectionParam connectionParams = (HanaConnectionParam) hanaDataSourceProcessor
@ -65,13 +66,13 @@ public class HanaDataSourceProcessorTest {
} }
@Test @Test
public void testGetDatasourceDriver() { void testGetDatasourceDriver() {
Assertions.assertEquals(DataSourceConstants.COM_HANA_DB_JDBC_DRIVER, Assertions.assertEquals(DataSourceConstants.COM_HANA_DB_JDBC_DRIVER,
hanaDataSourceProcessor.getDatasourceDriver()); hanaDataSourceProcessor.getDatasourceDriver());
} }
@Test @Test
public void testGetJdbcUrl() { void testGetJdbcUrl() {
HanaConnectionParam hanaConnectionParam = new HanaConnectionParam(); HanaConnectionParam hanaConnectionParam = new HanaConnectionParam();
hanaConnectionParam.setJdbcUrl("jdbc:sap://localhost:30015?currentschema=default"); hanaConnectionParam.setJdbcUrl("jdbc:sap://localhost:30015?currentschema=default");
Assertions.assertEquals( Assertions.assertEquals(
@ -80,18 +81,18 @@ public class HanaDataSourceProcessorTest {
} }
@Test @Test
public void testGetDbType() { void testGetDbType() {
Assertions.assertEquals(DbType.HANA, hanaDataSourceProcessor.getDbType()); Assertions.assertEquals(DbType.HANA, hanaDataSourceProcessor.getDbType());
} }
@Test @Test
public void testGetValidationQuery() { void testGetValidationQuery() {
Assertions.assertEquals(DataSourceConstants.HANA_VALIDATION_QUERY, Assertions.assertEquals(DataSourceConstants.HANA_VALIDATION_QUERY,
hanaDataSourceProcessor.getValidationQuery()); hanaDataSourceProcessor.getValidationQuery());
} }
@Test @Test
public void testGetDatasourceUniqueId() { void testGetDatasourceUniqueId() {
HanaConnectionParam mysqlConnectionParam = new HanaConnectionParam(); HanaConnectionParam mysqlConnectionParam = new HanaConnectionParam();
mysqlConnectionParam.setJdbcUrl("jdbc:sap://localhost:30015?currentschema=default"); mysqlConnectionParam.setJdbcUrl("jdbc:sap://localhost:30015?currentschema=default");
mysqlConnectionParam.setUser("root"); mysqlConnectionParam.setUser("root");

14
dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hana/src/test/java/org/apache/dolphinscheduler/plugin/datasource/hana/provider/JDBCDataSourceProviderTest.java

@ -17,10 +17,10 @@
package org.apache.dolphinscheduler.plugin.datasource.hana.provider; package org.apache.dolphinscheduler.plugin.datasource.hana.provider;
import com.zaxxer.hikari.HikariDataSource;
import org.apache.dolphinscheduler.plugin.datasource.api.provider.JDBCDataSourceProvider; import org.apache.dolphinscheduler.plugin.datasource.api.provider.JDBCDataSourceProvider;
import org.apache.dolphinscheduler.plugin.datasource.hana.param.HanaConnectionParam; import org.apache.dolphinscheduler.plugin.datasource.hana.param.HanaConnectionParam;
import org.apache.dolphinscheduler.spi.enums.DbType; import org.apache.dolphinscheduler.spi.enums.DbType;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
@ -28,25 +28,27 @@ import org.mockito.MockedStatic;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoExtension;
import com.zaxxer.hikari.HikariDataSource;
@ExtendWith(MockitoExtension.class) @ExtendWith(MockitoExtension.class)
public class JDBCDataSourceProviderTest { class JDBCDataSourceProviderTest {
@Test @Test
public void testCreateJdbcDataSource() { void testCreateJdbcDataSource() {
try ( try (
MockedStatic<JDBCDataSourceProvider> mockedJDBCDataSourceProvider = MockedStatic<JDBCDataSourceProvider> mockedJDBCDataSourceProvider =
Mockito.mockStatic(JDBCDataSourceProvider.class)) { Mockito.mockStatic(JDBCDataSourceProvider.class)) {
HikariDataSource dataSource = Mockito.mock(HikariDataSource.class); HikariDataSource dataSource = Mockito.mock(HikariDataSource.class);
mockedJDBCDataSourceProvider mockedJDBCDataSourceProvider
.when(() -> JDBCDataSourceProvider.createJdbcDataSource(Mockito.any(), Mockito.any())) .when(() -> JDBCDataSourceProvider.createOneSessionJdbcDataSource(Mockito.any(), Mockito.any()))
.thenReturn(dataSource); .thenReturn(dataSource);
Assertions.assertNotNull( Assertions.assertNotNull(
JDBCDataSourceProvider.createJdbcDataSource(new HanaConnectionParam(), DbType.HANA)); JDBCDataSourceProvider.createOneSessionJdbcDataSource(new HanaConnectionParam(), DbType.HANA));
} }
} }
@Test @Test
public void testCreateOneSessionJdbcDataSource() { void testCreateOneSessionJdbcDataSource() {
try ( try (
MockedStatic<JDBCDataSourceProvider> mockedJDBCDataSourceProvider = MockedStatic<JDBCDataSourceProvider> mockedJDBCDataSourceProvider =
Mockito.mockStatic(JDBCDataSourceProvider.class)) { Mockito.mockStatic(JDBCDataSourceProvider.class)) {

38
dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hana/src/test/java/org/apache/dolphinscheduler/plugin/datasource/hana/utils/DataSourceUtilsTest.java

@ -27,6 +27,13 @@ import org.apache.dolphinscheduler.plugin.datasource.hana.param.HanaConnectionPa
import org.apache.dolphinscheduler.plugin.datasource.hana.param.HanaDataSourceParamDTO; import org.apache.dolphinscheduler.plugin.datasource.hana.param.HanaDataSourceParamDTO;
import org.apache.dolphinscheduler.spi.datasource.ConnectionParam; import org.apache.dolphinscheduler.spi.datasource.ConnectionParam;
import org.apache.dolphinscheduler.spi.enums.DbType; import org.apache.dolphinscheduler.spi.enums.DbType;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
@ -34,16 +41,11 @@ import org.mockito.MockedStatic;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoExtension;
import java.sql.Connection;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutionException;
@ExtendWith(MockitoExtension.class) @ExtendWith(MockitoExtension.class)
public class DataSourceUtilsTest { class DataSourceUtilsTest {
@Test @Test
public void testCheckDatasourceParam() { void testCheckDatasourceParam() {
HanaDataSourceParamDTO hanaDataSourceParamDTO = new HanaDataSourceParamDTO(); HanaDataSourceParamDTO hanaDataSourceParamDTO = new HanaDataSourceParamDTO();
hanaDataSourceParamDTO.setHost("localhost"); hanaDataSourceParamDTO.setHost("localhost");
hanaDataSourceParamDTO.setDatabase("default"); hanaDataSourceParamDTO.setDatabase("default");
@ -55,7 +57,7 @@ public class DataSourceUtilsTest {
} }
@Test @Test
public void testBuildConnectionParams() { void testBuildConnectionParams() {
HanaDataSourceParamDTO hanaDataSourceParamDTO = new HanaDataSourceParamDTO(); HanaDataSourceParamDTO hanaDataSourceParamDTO = new HanaDataSourceParamDTO();
hanaDataSourceParamDTO.setHost("localhost"); hanaDataSourceParamDTO.setHost("localhost");
hanaDataSourceParamDTO.setDatabase("default"); hanaDataSourceParamDTO.setDatabase("default");
@ -75,7 +77,7 @@ public class DataSourceUtilsTest {
} }
@Test @Test
public void testBuildConnectionParams2() { void testBuildConnectionParams2() {
HanaDataSourceParamDTO hanaDatasourceParamDTO = new HanaDataSourceParamDTO(); HanaDataSourceParamDTO hanaDatasourceParamDTO = new HanaDataSourceParamDTO();
hanaDatasourceParamDTO.setHost("localhost"); hanaDatasourceParamDTO.setHost("localhost");
hanaDatasourceParamDTO.setDatabase("default"); hanaDatasourceParamDTO.setDatabase("default");
@ -88,39 +90,37 @@ public class DataSourceUtilsTest {
} }
@Test @Test
public void testGetConnection() throws ExecutionException { void testGetConnection() throws ExecutionException, SQLException {
try ( try (
MockedStatic<PropertyUtils> mockedStaticPropertyUtils = Mockito.mockStatic(PropertyUtils.class); MockedStatic<PropertyUtils> mockedStaticPropertyUtils = Mockito.mockStatic(PropertyUtils.class);
MockedStatic<DataSourceClientProvider> mockedStaticDataSourceClientProvider = MockedStatic<DataSourceClientProvider> mockedStaticDataSourceClientProvider =
Mockito.mockStatic(DataSourceClientProvider.class)) { Mockito.mockStatic(DataSourceClientProvider.class)) {
mockedStaticPropertyUtils.when(() -> PropertyUtils.getLong("kerberos.expire.time", 24L)).thenReturn(24L); mockedStaticPropertyUtils.when(() -> PropertyUtils.getLong("kerberos.expire.time", 24L)).thenReturn(24L);
DataSourceClientProvider clientProvider = Mockito.mock(DataSourceClientProvider.class);
mockedStaticDataSourceClientProvider.when(DataSourceClientProvider::getInstance).thenReturn(clientProvider);
Connection connection = Mockito.mock(Connection.class); Connection connection = Mockito.mock(Connection.class);
Mockito.when(clientProvider.getConnection(Mockito.any(), Mockito.any())).thenReturn(connection);
Mockito.when(DataSourceClientProvider.getAdHocConnection(Mockito.any(), Mockito.any()))
.thenReturn(connection);
HanaConnectionParam connectionParam = new HanaConnectionParam(); HanaConnectionParam connectionParam = new HanaConnectionParam();
connectionParam.setUser("root"); connectionParam.setUser("root");
connectionParam.setPassword("123456"); connectionParam.setPassword("123456");
connection = DataSourceClientProvider.getInstance().getConnection(DbType.HANA, connectionParam);
Assertions.assertNotNull(connection); Assertions.assertNotNull(connection);
} }
} }
@Test @Test
public void testGetJdbcUrl() { void testGetJdbcUrl() {
HanaConnectionParam hanaConnectionParam = new HanaConnectionParam(); HanaConnectionParam hanaConnectionParam = new HanaConnectionParam();
hanaConnectionParam.setJdbcUrl("jdbc:sap://localhost:30015"); hanaConnectionParam.setJdbcUrl("jdbc:sap://localhost:30015");
String jdbcUrl = DataSourceUtils.getJdbcUrl(DbType.HANA, hanaConnectionParam); String jdbcUrl = DataSourceUtils.getJdbcUrl(DbType.HANA, hanaConnectionParam);
Assertions.assertEquals( Assertions.assertEquals(
"jdbc:sap://localhost:30015?reconnect=true", "jdbc:sap://localhost:30015&reconnect=true",
jdbcUrl); jdbcUrl);
} }
@Test @Test
public void testBuildDatasourceParamDTO() { void testBuildDatasourceParamDTO() {
HanaConnectionParam connectionParam = new HanaConnectionParam(); HanaConnectionParam connectionParam = new HanaConnectionParam();
connectionParam.setJdbcUrl( connectionParam.setJdbcUrl(
"jdbc:sap://localhost:30015?reconnect=true"); "jdbc:sap://localhost:30015?reconnect=true");
@ -134,12 +134,12 @@ public class DataSourceUtilsTest {
} }
@Test @Test
public void testGetDatasourceProcessor() { void testGetDatasourceProcessor() {
Assertions.assertNotNull(DataSourceUtils.getDatasourceProcessor(DbType.HANA)); Assertions.assertNotNull(DataSourceUtils.getDatasourceProcessor(DbType.HANA));
} }
@Test @Test
public void testGetDatasourceProcessorError() { void testGetDatasourceProcessorError() {
Assertions.assertThrows(Exception.class, () -> { Assertions.assertThrows(Exception.class, () -> {
DataSourceUtils.getDatasourceProcessor(null); DataSourceUtils.getDatasourceProcessor(null);
}); });

1
dolphinscheduler-datasource-plugin/pom.xml

@ -55,6 +55,7 @@
<module>dolphinscheduler-datasource-doris</module> <module>dolphinscheduler-datasource-doris</module>
<module>dolphinscheduler-datasource-sagemaker</module> <module>dolphinscheduler-datasource-sagemaker</module>
<module>dolphinscheduler-datasource-k8s</module> <module>dolphinscheduler-datasource-k8s</module>
<module>dolphinscheduler-datasource-hana</module>
</modules> </modules>
<dependencyManagement> <dependencyManagement>

Loading…
Cancel
Save