From 0feb14418030ff98b49880f1fc762a7b13374944 Mon Sep 17 00:00:00 2001 From: xujiaqiang <54771125+xujiaqiang@users.noreply.github.com> Date: Tue, 12 Dec 2023 17:11:27 +0800 Subject: [PATCH] [Improvement-15260][dolphinscheduler-datasource-hana] add hana related dependencies (#15260) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 --- dolphinscheduler-bom/pom.xml | 9 ++++ .../common/constants/DataSourceConstants.java | 2 +- .../dolphinscheduler-datasource-all/pom.xml | 5 ++ .../dolphinscheduler-datasource-hana/pom.xml | 49 +++++++++++++++++++ ...nt.java => HanaAdHocDataSourceClient.java} | 7 ++- .../hana/HanaDataSourceChannel.java | 12 +++-- .../hana/HanaPooledDataSourceClient.java | 30 ++++++++++++ .../hana/param/HanaDataSourceProcessor.java | 9 ++-- .../HanaDataSourceChannelFactoryTest.java | 5 +- .../hana/HanaDataSourceChannelTest.java | 12 +++-- .../param/HanaDataSourceProcessorTest.java | 23 ++++----- .../provider/JDBCDataSourceProviderTest.java | 14 +++--- .../hana/utils/DataSourceUtilsTest.java | 38 +++++++------- dolphinscheduler-datasource-plugin/pom.xml | 1 + 14 files changed, 159 insertions(+), 57 deletions(-) create mode 100644 dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hana/pom.xml rename dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hana/src/main/java/org/apache/dolphinscheduler/plugin/datasource/hana/{HanaDataSourceClient.java => HanaAdHocDataSourceClient.java} (84%) create mode 100644 dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hana/src/main/java/org/apache/dolphinscheduler/plugin/datasource/hana/HanaPooledDataSourceClient.java diff --git a/dolphinscheduler-bom/pom.xml b/dolphinscheduler-bom/pom.xml index 77b9d0c0c8..8829cdec3a 100644 --- a/dolphinscheduler-bom/pom.xml +++ b/dolphinscheduler-bom/pom.xml @@ -60,6 +60,7 @@ 12.0.4-0 21.5.0.0 8.1.2.79 + 2.4.51 1.7.36 4.1.2 3.1.0 @@ -418,6 +419,14 @@ h2 ${h2.version} + + + com.sap.cloud.db.jdbc + ngdbc + ${ngdbc.version} + test + + org.slf4j diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/constants/DataSourceConstants.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/constants/DataSourceConstants.java index d9afab2c47..568eb8c6f5 100644 --- a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/constants/DataSourceConstants.java +++ b/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 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 diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-all/pom.xml b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-all/pom.xml index d1f39e1ad7..effe3c9abb 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-all/pom.xml +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-all/pom.xml @@ -153,5 +153,10 @@ dolphinscheduler-datasource-k8s ${project.version} + + org.apache.dolphinscheduler + dolphinscheduler-datasource-hana + ${project.version} + diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hana/pom.xml b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hana/pom.xml new file mode 100644 index 0000000000..e35249d962 --- /dev/null +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hana/pom.xml @@ -0,0 +1,49 @@ + + + + 4.0.0 + + org.apache.dolphinscheduler + dolphinscheduler-datasource-plugin + dev-SNAPSHOT + + + dolphinscheduler-datasource-hana + jar + ${project.artifactId} + + + + org.apache.dolphinscheduler + dolphinscheduler-spi + provided + + + + org.apache.dolphinscheduler + dolphinscheduler-datasource-api + ${project.version} + + + + com.sap.cloud.db.jdbc + ngdbc + + + diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hana/src/main/java/org/apache/dolphinscheduler/plugin/datasource/hana/HanaDataSourceClient.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hana/src/main/java/org/apache/dolphinscheduler/plugin/datasource/hana/HanaAdHocDataSourceClient.java similarity index 84% rename from dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hana/src/main/java/org/apache/dolphinscheduler/plugin/datasource/hana/HanaDataSourceClient.java rename to dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hana/src/main/java/org/apache/dolphinscheduler/plugin/datasource/hana/HanaAdHocDataSourceClient.java index 72806e42df..0cdb8fb265 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hana/src/main/java/org/apache/dolphinscheduler/plugin/datasource/hana/HanaDataSourceClient.java +++ b/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; -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.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); } - } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hana/src/main/java/org/apache/dolphinscheduler/plugin/datasource/hana/HanaDataSourceChannel.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hana/src/main/java/org/apache/dolphinscheduler/plugin/datasource/hana/HanaDataSourceChannel.java index 9952ee4316..930d8b3bc5 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hana/src/main/java/org/apache/dolphinscheduler/plugin/datasource/hana/HanaDataSourceChannel.java +++ b/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; +import org.apache.dolphinscheduler.spi.datasource.AdHocDataSourceClient; import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam; 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; public class HanaDataSourceChannel implements DataSourceChannel { @Override - public DataSourceClient createDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { - return new HanaDataSourceClient(baseConnectionParam, dbType); + public AdHocDataSourceClient createAdHocDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + return new HanaAdHocDataSourceClient(baseConnectionParam, dbType); + } + + @Override + public PooledDataSourceClient createPooledDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { + return new HanaPooledDataSourceClient(baseConnectionParam, dbType); } } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hana/src/main/java/org/apache/dolphinscheduler/plugin/datasource/hana/HanaPooledDataSourceClient.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hana/src/main/java/org/apache/dolphinscheduler/plugin/datasource/hana/HanaPooledDataSourceClient.java new file mode 100644 index 0000000000..71da615431 --- /dev/null +++ b/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); + } + +} diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hana/src/main/java/org/apache/dolphinscheduler/plugin/datasource/hana/param/HanaDataSourceProcessor.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hana/src/main/java/org/apache/dolphinscheduler/plugin/datasource/hana/param/HanaDataSourceProcessor.java index 5c5da73aab..e6f59aece8 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hana/src/main/java/org/apache/dolphinscheduler/plugin/datasource/hana/param/HanaDataSourceProcessor.java +++ b/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.SQLException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.google.auto.service.AutoService; + @AutoService(DataSourceProcessor.class) public class HanaDataSourceProcessor extends AbstractDataSourceProcessor { - private final Logger logger = LoggerFactory.getLogger(HanaDataSourceProcessor.class); - private static final String APPEND_PARAMS = "reconnect=true"; + @Override public BaseDataSourceParamDTO castDatasourceParamDTO(String paramJson) { return JSONUtils.parseObject(paramJson, HanaDataSourceParamDTO.class); @@ -96,7 +93,7 @@ public class HanaDataSourceProcessor extends AbstractDataSourceProcessor { @Override public String getValidationQuery() { - return DataSourceConstants.COM_HANA_DB_JDBC_DRIVER; + return DataSourceConstants.HANA_VALIDATION_QUERY; } @Override diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hana/src/test/java/org/apache/dolphinscheduler/plugin/datasource/hana/HanaDataSourceChannelFactoryTest.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hana/src/test/java/org/apache/dolphinscheduler/plugin/datasource/hana/HanaDataSourceChannelFactoryTest.java index 089b203f50..dfcee56ab9 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hana/src/test/java/org/apache/dolphinscheduler/plugin/datasource/hana/HanaDataSourceChannelFactoryTest.java +++ b/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; import org.apache.dolphinscheduler.spi.datasource.DataSourceChannel; + import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -public class HanaDataSourceChannelFactoryTest { +class HanaDataSourceChannelFactoryTest { @Test - public void testCreate() { + void testCreate() { HanaDataSourceChannelFactory sourceChannelFactory = new HanaDataSourceChannelFactory(); DataSourceChannel dataSourceChannel = sourceChannelFactory.create(); Assertions.assertNotNull(dataSourceChannel); diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hana/src/test/java/org/apache/dolphinscheduler/plugin/datasource/hana/HanaDataSourceChannelTest.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hana/src/test/java/org/apache/dolphinscheduler/plugin/datasource/hana/HanaDataSourceChannelTest.java index e60e3bfc81..1c38ff2c65 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hana/src/test/java/org/apache/dolphinscheduler/plugin/datasource/hana/HanaDataSourceChannelTest.java +++ b/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.spi.enums.DbType; + import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -26,13 +27,14 @@ import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) -public class HanaDataSourceChannelTest { +class HanaDataSourceChannelTest { @Test - public void testCreateDataSourceClient() { + void testCreateDataSourceClient() { HanaDataSourceChannel sourceChannel = Mockito.mock(HanaDataSourceChannel.class); - HanaDataSourceClient dataSourceClient = Mockito.mock(HanaDataSourceClient.class); - Mockito.when(sourceChannel.createDataSourceClient(Mockito.any(), Mockito.any())).thenReturn(dataSourceClient); - Assertions.assertNotNull(sourceChannel.createDataSourceClient(new HanaConnectionParam(), DbType.HANA)); + HanaPooledDataSourceClient dataSourceClient = Mockito.mock(HanaPooledDataSourceClient.class); + Mockito.when(sourceChannel.createPooledDataSourceClient(Mockito.any(), Mockito.any())) + .thenReturn(dataSourceClient); + Assertions.assertNotNull(sourceChannel.createPooledDataSourceClient(new HanaConnectionParam(), DbType.HANA)); } } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hana/src/test/java/org/apache/dolphinscheduler/plugin/datasource/hana/param/HanaDataSourceProcessorTest.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hana/src/test/java/org/apache/dolphinscheduler/plugin/datasource/hana/param/HanaDataSourceProcessorTest.java index 8f6095b3b5..c457eb3e73 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hana/src/test/java/org/apache/dolphinscheduler/plugin/datasource/hana/param/HanaDataSourceProcessorTest.java +++ b/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.plugin.datasource.api.utils.PasswordUtils; 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.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -27,16 +31,13 @@ import org.mockito.MockedStatic; import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; -import java.util.HashMap; -import java.util.Map; - @ExtendWith(MockitoExtension.class) -public class HanaDataSourceProcessorTest { +class HanaDataSourceProcessorTest { private HanaDataSourceProcessor hanaDataSourceProcessor = new HanaDataSourceProcessor(); @Test - public void testCreateConnectionParams() { + void testCreateConnectionParams() { Map props = new HashMap<>(); HanaDataSourceParamDTO mysqlDatasourceParamDTO = new HanaDataSourceParamDTO(); mysqlDatasourceParamDTO.setUserName("root"); @@ -55,7 +56,7 @@ public class HanaDataSourceProcessorTest { } @Test - public void testCreateConnectionParams2() { + void testCreateConnectionParams2() { String connectionJson = "{\"user\":\"root\",\"password\":\"123456\",\"address\":\"jdbc:sap://localhost:30015\"" + ",\"database\":\"default\",\"jdbcUrl\":\"jdbc:sap://localhost:30015?currentschema=default\"}"; HanaConnectionParam connectionParams = (HanaConnectionParam) hanaDataSourceProcessor @@ -65,13 +66,13 @@ public class HanaDataSourceProcessorTest { } @Test - public void testGetDatasourceDriver() { + void testGetDatasourceDriver() { Assertions.assertEquals(DataSourceConstants.COM_HANA_DB_JDBC_DRIVER, hanaDataSourceProcessor.getDatasourceDriver()); } @Test - public void testGetJdbcUrl() { + void testGetJdbcUrl() { HanaConnectionParam hanaConnectionParam = new HanaConnectionParam(); hanaConnectionParam.setJdbcUrl("jdbc:sap://localhost:30015?currentschema=default"); Assertions.assertEquals( @@ -80,18 +81,18 @@ public class HanaDataSourceProcessorTest { } @Test - public void testGetDbType() { + void testGetDbType() { Assertions.assertEquals(DbType.HANA, hanaDataSourceProcessor.getDbType()); } @Test - public void testGetValidationQuery() { + void testGetValidationQuery() { Assertions.assertEquals(DataSourceConstants.HANA_VALIDATION_QUERY, hanaDataSourceProcessor.getValidationQuery()); } @Test - public void testGetDatasourceUniqueId() { + void testGetDatasourceUniqueId() { HanaConnectionParam mysqlConnectionParam = new HanaConnectionParam(); mysqlConnectionParam.setJdbcUrl("jdbc:sap://localhost:30015?currentschema=default"); mysqlConnectionParam.setUser("root"); diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hana/src/test/java/org/apache/dolphinscheduler/plugin/datasource/hana/provider/JDBCDataSourceProviderTest.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hana/src/test/java/org/apache/dolphinscheduler/plugin/datasource/hana/provider/JDBCDataSourceProviderTest.java index cea4282e75..43e042fb82 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hana/src/test/java/org/apache/dolphinscheduler/plugin/datasource/hana/provider/JDBCDataSourceProviderTest.java +++ b/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; -import com.zaxxer.hikari.HikariDataSource; import org.apache.dolphinscheduler.plugin.datasource.api.provider.JDBCDataSourceProvider; import org.apache.dolphinscheduler.plugin.datasource.hana.param.HanaConnectionParam; import org.apache.dolphinscheduler.spi.enums.DbType; + import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -28,25 +28,27 @@ import org.mockito.MockedStatic; import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; +import com.zaxxer.hikari.HikariDataSource; + @ExtendWith(MockitoExtension.class) -public class JDBCDataSourceProviderTest { +class JDBCDataSourceProviderTest { @Test - public void testCreateJdbcDataSource() { + void testCreateJdbcDataSource() { try ( MockedStatic mockedJDBCDataSourceProvider = Mockito.mockStatic(JDBCDataSourceProvider.class)) { HikariDataSource dataSource = Mockito.mock(HikariDataSource.class); mockedJDBCDataSourceProvider - .when(() -> JDBCDataSourceProvider.createJdbcDataSource(Mockito.any(), Mockito.any())) + .when(() -> JDBCDataSourceProvider.createOneSessionJdbcDataSource(Mockito.any(), Mockito.any())) .thenReturn(dataSource); Assertions.assertNotNull( - JDBCDataSourceProvider.createJdbcDataSource(new HanaConnectionParam(), DbType.HANA)); + JDBCDataSourceProvider.createOneSessionJdbcDataSource(new HanaConnectionParam(), DbType.HANA)); } } @Test - public void testCreateOneSessionJdbcDataSource() { + void testCreateOneSessionJdbcDataSource() { try ( MockedStatic mockedJDBCDataSourceProvider = Mockito.mockStatic(JDBCDataSourceProvider.class)) { diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hana/src/test/java/org/apache/dolphinscheduler/plugin/datasource/hana/utils/DataSourceUtilsTest.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hana/src/test/java/org/apache/dolphinscheduler/plugin/datasource/hana/utils/DataSourceUtilsTest.java index e7cf949e31..a11d746c87 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hana/src/test/java/org/apache/dolphinscheduler/plugin/datasource/hana/utils/DataSourceUtilsTest.java +++ b/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.spi.datasource.ConnectionParam; 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.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -34,16 +41,11 @@ import org.mockito.MockedStatic; import org.mockito.Mockito; 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) -public class DataSourceUtilsTest { +class DataSourceUtilsTest { @Test - public void testCheckDatasourceParam() { + void testCheckDatasourceParam() { HanaDataSourceParamDTO hanaDataSourceParamDTO = new HanaDataSourceParamDTO(); hanaDataSourceParamDTO.setHost("localhost"); hanaDataSourceParamDTO.setDatabase("default"); @@ -55,7 +57,7 @@ public class DataSourceUtilsTest { } @Test - public void testBuildConnectionParams() { + void testBuildConnectionParams() { HanaDataSourceParamDTO hanaDataSourceParamDTO = new HanaDataSourceParamDTO(); hanaDataSourceParamDTO.setHost("localhost"); hanaDataSourceParamDTO.setDatabase("default"); @@ -75,7 +77,7 @@ public class DataSourceUtilsTest { } @Test - public void testBuildConnectionParams2() { + void testBuildConnectionParams2() { HanaDataSourceParamDTO hanaDatasourceParamDTO = new HanaDataSourceParamDTO(); hanaDatasourceParamDTO.setHost("localhost"); hanaDatasourceParamDTO.setDatabase("default"); @@ -88,39 +90,37 @@ public class DataSourceUtilsTest { } @Test - public void testGetConnection() throws ExecutionException { + void testGetConnection() throws ExecutionException, SQLException { try ( MockedStatic mockedStaticPropertyUtils = Mockito.mockStatic(PropertyUtils.class); MockedStatic mockedStaticDataSourceClientProvider = Mockito.mockStatic(DataSourceClientProvider.class)) { 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); - Mockito.when(clientProvider.getConnection(Mockito.any(), Mockito.any())).thenReturn(connection); + Mockito.when(DataSourceClientProvider.getAdHocConnection(Mockito.any(), Mockito.any())) + .thenReturn(connection); HanaConnectionParam connectionParam = new HanaConnectionParam(); connectionParam.setUser("root"); connectionParam.setPassword("123456"); - connection = DataSourceClientProvider.getInstance().getConnection(DbType.HANA, connectionParam); Assertions.assertNotNull(connection); } } @Test - public void testGetJdbcUrl() { + void testGetJdbcUrl() { HanaConnectionParam hanaConnectionParam = new HanaConnectionParam(); hanaConnectionParam.setJdbcUrl("jdbc:sap://localhost:30015"); String jdbcUrl = DataSourceUtils.getJdbcUrl(DbType.HANA, hanaConnectionParam); Assertions.assertEquals( - "jdbc:sap://localhost:30015?reconnect=true", + "jdbc:sap://localhost:30015&reconnect=true", jdbcUrl); } @Test - public void testBuildDatasourceParamDTO() { + void testBuildDatasourceParamDTO() { HanaConnectionParam connectionParam = new HanaConnectionParam(); connectionParam.setJdbcUrl( "jdbc:sap://localhost:30015?reconnect=true"); @@ -134,12 +134,12 @@ public class DataSourceUtilsTest { } @Test - public void testGetDatasourceProcessor() { + void testGetDatasourceProcessor() { Assertions.assertNotNull(DataSourceUtils.getDatasourceProcessor(DbType.HANA)); } @Test - public void testGetDatasourceProcessorError() { + void testGetDatasourceProcessorError() { Assertions.assertThrows(Exception.class, () -> { DataSourceUtils.getDatasourceProcessor(null); }); diff --git a/dolphinscheduler-datasource-plugin/pom.xml b/dolphinscheduler-datasource-plugin/pom.xml index f5c59cfab5..c30a6b4258 100644 --- a/dolphinscheduler-datasource-plugin/pom.xml +++ b/dolphinscheduler-datasource-plugin/pom.xml @@ -55,6 +55,7 @@ dolphinscheduler-datasource-doris dolphinscheduler-datasource-sagemaker dolphinscheduler-datasource-k8s + dolphinscheduler-datasource-hana