diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/main/java/org/apache/dolphinscheduler/plugin/datasource/api/plugin/DataSourceClientProvider.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/main/java/org/apache/dolphinscheduler/plugin/datasource/api/plugin/DataSourceClientProvider.java index 417af00b3de7..caae549f0369 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/main/java/org/apache/dolphinscheduler/plugin/datasource/api/plugin/DataSourceClientProvider.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/main/java/org/apache/dolphinscheduler/plugin/datasource/api/plugin/DataSourceClientProvider.java @@ -30,7 +30,6 @@ import java.sql.Connection; import java.sql.SQLException; -import java.util.Map; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; @@ -69,8 +68,7 @@ public static DataSourceClient getPooledDataSourceClient(DbType dbType, BaseConnectionParam baseConnectionParam = (BaseConnectionParam) connectionParam; String datasourceUniqueId = DataSourceUtils.getDatasourceUniqueId(baseConnectionParam, dbType); return POOLED_DATASOURCE_CLIENT_CACHE.get(datasourceUniqueId, () -> { - Map dataSourceChannelMap = dataSourcePluginManager.getDataSourceChannelMap(); - DataSourceChannel dataSourceChannel = dataSourceChannelMap.get(dbType.getName()); + DataSourceChannel dataSourceChannel = dataSourcePluginManager.getDataSourceChannel(dbType); if (null == dataSourceChannel) { throw new RuntimeException(String.format("datasource plugin '%s' is not found", dbType.getName())); } @@ -85,8 +83,7 @@ public static Connection getPooledConnection(DbType dbType, public static AdHocDataSourceClient getAdHocDataSourceClient(DbType dbType, ConnectionParam connectionParam) { BaseConnectionParam baseConnectionParam = (BaseConnectionParam) connectionParam; - Map dataSourceChannelMap = dataSourcePluginManager.getDataSourceChannelMap(); - DataSourceChannel dataSourceChannel = dataSourceChannelMap.get(dbType.getName()); + DataSourceChannel dataSourceChannel = dataSourcePluginManager.getDataSourceChannel(dbType); if (null == dataSourceChannel) { throw new RuntimeException(String.format("datasource plugin '%s' is not found", dbType.getName())); } diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/main/java/org/apache/dolphinscheduler/plugin/datasource/api/plugin/DataSourcePluginManager.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/main/java/org/apache/dolphinscheduler/plugin/datasource/api/plugin/DataSourcePluginManager.java index 7c4b61d82914..1bf4e7c5cc6e 100644 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/main/java/org/apache/dolphinscheduler/plugin/datasource/api/plugin/DataSourcePluginManager.java +++ b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/main/java/org/apache/dolphinscheduler/plugin/datasource/api/plugin/DataSourcePluginManager.java @@ -21,9 +21,9 @@ import org.apache.dolphinscheduler.spi.datasource.DataSourceChannel; import org.apache.dolphinscheduler.spi.datasource.DataSourceChannelFactory; +import org.apache.dolphinscheduler.spi.enums.DbType; import org.apache.dolphinscheduler.spi.plugin.PrioritySPIFactory; -import java.util.Collections; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -34,8 +34,8 @@ public class DataSourcePluginManager { private final Map datasourceChannelMap = new ConcurrentHashMap<>(); - public Map getDataSourceChannelMap() { - return Collections.unmodifiableMap(datasourceChannelMap); + public DataSourceChannel getDataSourceChannel(final DbType dbType) { + return datasourceChannelMap.get(dbType.getName()); } public void installPlugin() { diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/main/java/org/apache/dolphinscheduler/plugin/datasource/api/provider/JDBCDataSourceProvider.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/main/java/org/apache/dolphinscheduler/plugin/datasource/api/provider/JDBCDataSourceProvider.java deleted file mode 100644 index 7aae4ec5af63..000000000000 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/main/java/org/apache/dolphinscheduler/plugin/datasource/api/provider/JDBCDataSourceProvider.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * 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.api.provider; - -import org.apache.dolphinscheduler.common.utils.PropertyUtils; -import org.apache.dolphinscheduler.plugin.datasource.api.constants.DataSourceConstants; -import org.apache.dolphinscheduler.plugin.datasource.api.utils.DataSourceUtils; -import org.apache.dolphinscheduler.plugin.datasource.api.utils.PasswordUtils; -import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam; -import org.apache.dolphinscheduler.spi.enums.DbType; - -import org.apache.commons.collections4.MapUtils; -import org.apache.commons.lang3.StringUtils; - -import java.sql.Driver; - -import lombok.extern.slf4j.Slf4j; - -import com.zaxxer.hikari.HikariDataSource; - -/** - * Jdbc Data Source Provider - */ -@Slf4j -public class JDBCDataSourceProvider { - - /** - * @return One Session Jdbc DataSource - */ - public static HikariDataSource createOneSessionJdbcDataSource(BaseConnectionParam properties, DbType dbType) { - log.info("Creating OneSession HikariDataSource pool for maxActive:{}", - PropertyUtils.getInt(DataSourceConstants.SPRING_DATASOURCE_MAX_ACTIVE, 50)); - - HikariDataSource dataSource = new HikariDataSource(); - - dataSource.setDriverClassName(properties.getDriverClassName()); - dataSource.setJdbcUrl(DataSourceUtils.getJdbcUrl(dbType, properties)); - dataSource.setUsername(properties.getUser()); - dataSource.setPassword(PasswordUtils.decodePassword(properties.getPassword())); - - Boolean isOneSession = PropertyUtils.getBoolean(DataSourceConstants.SUPPORT_HIVE_ONE_SESSION, false); - dataSource.setMinimumIdle( - isOneSession ? 1 : PropertyUtils.getInt(DataSourceConstants.SPRING_DATASOURCE_MIN_IDLE, 5)); - dataSource.setMaximumPoolSize( - isOneSession ? 1 : PropertyUtils.getInt(DataSourceConstants.SPRING_DATASOURCE_MAX_ACTIVE, 50)); - dataSource.setConnectionTestQuery(properties.getValidationQuery()); - - if (MapUtils.isNotEmpty(properties.getOther())) { - properties.getOther().forEach(dataSource::addDataSourceProperty); - } - - log.info("Creating OneSession HikariDataSource pool success."); - return dataSource; - } - - protected static void loaderJdbcDriver(ClassLoader classLoader, BaseConnectionParam properties, DbType dbType) { - String drv = StringUtils.isBlank(properties.getDriverClassName()) - ? DataSourceUtils.getDatasourceProcessor(dbType).getDatasourceDriver() - : properties.getDriverClassName(); - try { - final Class clazz = Class.forName(drv, true, classLoader); - final Driver driver = (Driver) clazz.newInstance(); - if (!driver.acceptsURL(properties.getJdbcUrl())) { - log.warn("Jdbc driver loading error. Driver {} cannot accept url.", drv); - throw new RuntimeException("Jdbc driver loading error."); - } - if (dbType.equals(DbType.MYSQL)) { - if (driver.getMajorVersion() >= 8) { - properties.setDriverClassName(drv); - } else { - properties.setDriverClassName(DataSourceConstants.COM_MYSQL_JDBC_DRIVER); - } - } - } catch (final Exception e) { - log.warn("The specified driver not suitable."); - } - } - -} diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-doris/src/test/java/org/apache/dolphinscheduler/plugin/doris/provider/JDBCDataSourceProviderTest.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-doris/src/test/java/org/apache/dolphinscheduler/plugin/doris/provider/JDBCDataSourceProviderTest.java deleted file mode 100644 index e99096d7d03a..000000000000 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-doris/src/test/java/org/apache/dolphinscheduler/plugin/doris/provider/JDBCDataSourceProviderTest.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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.doris.provider; - -import org.apache.dolphinscheduler.plugin.datasource.api.provider.JDBCDataSourceProvider; -import org.apache.dolphinscheduler.plugin.doris.param.DorisConnectionParam; -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; -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 { - - @Test - public void testCreateOneSessionJdbcDataSource() { - try ( - MockedStatic mockedJDBCDataSourceProvider = - Mockito.mockStatic(JDBCDataSourceProvider.class)) { - HikariDataSource dataSource = Mockito.mock(HikariDataSource.class); - mockedJDBCDataSourceProvider - .when(() -> JDBCDataSourceProvider.createOneSessionJdbcDataSource(Mockito.any(), Mockito.any())) - .thenReturn(dataSource); - Assertions.assertNotNull( - JDBCDataSourceProvider.createOneSessionJdbcDataSource(new DorisConnectionParam(), DbType.DORIS)); - } - } - -} 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 deleted file mode 100644 index 43e042fb826c..000000000000 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-hana/src/test/java/org/apache/dolphinscheduler/plugin/datasource/hana/provider/JDBCDataSourceProviderTest.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * 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.provider; - -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; -import org.mockito.MockedStatic; -import org.mockito.Mockito; -import org.mockito.junit.jupiter.MockitoExtension; - -import com.zaxxer.hikari.HikariDataSource; - -@ExtendWith(MockitoExtension.class) -class JDBCDataSourceProviderTest { - - @Test - void testCreateJdbcDataSource() { - try ( - MockedStatic mockedJDBCDataSourceProvider = - Mockito.mockStatic(JDBCDataSourceProvider.class)) { - HikariDataSource dataSource = Mockito.mock(HikariDataSource.class); - mockedJDBCDataSourceProvider - .when(() -> JDBCDataSourceProvider.createOneSessionJdbcDataSource(Mockito.any(), Mockito.any())) - .thenReturn(dataSource); - Assertions.assertNotNull( - JDBCDataSourceProvider.createOneSessionJdbcDataSource(new HanaConnectionParam(), DbType.HANA)); - } - } - - @Test - void testCreateOneSessionJdbcDataSource() { - try ( - MockedStatic mockedJDBCDataSourceProvider = - Mockito.mockStatic(JDBCDataSourceProvider.class)) { - HikariDataSource dataSource = Mockito.mock(HikariDataSource.class); - mockedJDBCDataSourceProvider - .when(() -> JDBCDataSourceProvider.createOneSessionJdbcDataSource(Mockito.any(), Mockito.any())) - .thenReturn(dataSource); - Assertions.assertNotNull( - JDBCDataSourceProvider.createOneSessionJdbcDataSource(new HanaConnectionParam(), DbType.HANA)); - } - } - -} diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-kyuubi/src/test/java/org/apache/dolphinscheduler/plugin/datasource/kyuubi/provider/KyuubiJDBCDataSourceProviderTest.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-kyuubi/src/test/java/org/apache/dolphinscheduler/plugin/datasource/kyuubi/provider/KyuubiJDBCDataSourceProviderTest.java deleted file mode 100644 index 335eb6a92032..000000000000 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-kyuubi/src/test/java/org/apache/dolphinscheduler/plugin/datasource/kyuubi/provider/KyuubiJDBCDataSourceProviderTest.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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.kyuubi.provider; - -import org.apache.dolphinscheduler.plugin.datasource.api.provider.JDBCDataSourceProvider; -import org.apache.dolphinscheduler.plugin.datasource.kyuubi.param.KyuubiConnectionParam; -import org.apache.dolphinscheduler.spi.enums.DbType; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import org.mockito.MockedStatic; -import org.mockito.Mockito; - -import com.zaxxer.hikari.HikariDataSource; - -public class KyuubiJDBCDataSourceProviderTest { - - @Test - public void testCreateOneSessionJdbcDataSource() { - try ( - MockedStatic mockedJDBCDataSourceProvider = - Mockito.mockStatic(JDBCDataSourceProvider.class)) { - HikariDataSource dataSource = Mockito.mock(HikariDataSource.class); - mockedJDBCDataSourceProvider - .when(() -> JDBCDataSourceProvider.createOneSessionJdbcDataSource(Mockito.any(), Mockito.any())) - .thenReturn(dataSource); - Assertions.assertNotNull( - JDBCDataSourceProvider.createOneSessionJdbcDataSource(new KyuubiConnectionParam(), DbType.KYUUBI)); - } - } -} diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-mysql/src/test/java/org/apache/dolphinscheduler/plugin/datasource/mysql/provider/JDBCDataSourceProviderTest.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-mysql/src/test/java/org/apache/dolphinscheduler/plugin/datasource/mysql/provider/JDBCDataSourceProviderTest.java deleted file mode 100644 index a597ff6b1374..000000000000 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-mysql/src/test/java/org/apache/dolphinscheduler/plugin/datasource/mysql/provider/JDBCDataSourceProviderTest.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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.mysql.provider; - -import org.apache.dolphinscheduler.plugin.datasource.api.provider.JDBCDataSourceProvider; -import org.apache.dolphinscheduler.plugin.datasource.mysql.param.MySQLConnectionParam; -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; -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 { - - @Test - public void testCreateOneSessionJdbcDataSource() { - try ( - MockedStatic mockedJDBCDataSourceProvider = - Mockito.mockStatic(JDBCDataSourceProvider.class)) { - HikariDataSource dataSource = Mockito.mock(HikariDataSource.class); - mockedJDBCDataSourceProvider - .when(() -> JDBCDataSourceProvider.createOneSessionJdbcDataSource(Mockito.any(), Mockito.any())) - .thenReturn(dataSource); - Assertions.assertNotNull( - JDBCDataSourceProvider.createOneSessionJdbcDataSource(new MySQLConnectionParam(), DbType.MYSQL)); - } - } - -} diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-snowflake/src/test/java/org/apache/dolphinscheduler/plugin/datasource/snowflake/provider/SnowflakeJDBCDataSourceProviderTest.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-snowflake/src/test/java/org/apache/dolphinscheduler/plugin/datasource/snowflake/provider/SnowflakeJDBCDataSourceProviderTest.java deleted file mode 100644 index 2b3dffb7b215..000000000000 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-snowflake/src/test/java/org/apache/dolphinscheduler/plugin/datasource/snowflake/provider/SnowflakeJDBCDataSourceProviderTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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.snowflake.provider; - -import org.apache.dolphinscheduler.plugin.datasource.api.provider.JDBCDataSourceProvider; -import org.apache.dolphinscheduler.plugin.datasource.snowflake.param.SnowflakeConnectionParam; -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; -import org.mockito.MockedStatic; -import org.mockito.Mockito; -import org.mockito.junit.jupiter.MockitoExtension; - -import com.zaxxer.hikari.HikariDataSource; - -@ExtendWith(MockitoExtension.class) -public class SnowflakeJDBCDataSourceProviderTest { - - @Test - public void testCreateOneSessionJdbcDataSource() { - try ( - MockedStatic mockedJDBCDataSourceProvider = - Mockito.mockStatic(JDBCDataSourceProvider.class)) { - HikariDataSource dataSource = Mockito.mock(HikariDataSource.class); - mockedJDBCDataSourceProvider - .when(() -> JDBCDataSourceProvider.createOneSessionJdbcDataSource(Mockito.any(), Mockito.any())) - .thenReturn(dataSource); - Assertions.assertNotNull( - JDBCDataSourceProvider.createOneSessionJdbcDataSource(new SnowflakeConnectionParam(), - DbType.SNOWFLAKE)); - } - } - -} diff --git a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-vertica/src/test/java/org/apache/dolphinscheduler/plugin/datasource/vertica/provider/JDBCDataSourceProviderTest.java b/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-vertica/src/test/java/org/apache/dolphinscheduler/plugin/datasource/vertica/provider/JDBCDataSourceProviderTest.java deleted file mode 100644 index 85b7b8688bc7..000000000000 --- a/dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-vertica/src/test/java/org/apache/dolphinscheduler/plugin/datasource/vertica/provider/JDBCDataSourceProviderTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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.vertica.provider; - -import org.apache.dolphinscheduler.plugin.datasource.api.provider.JDBCDataSourceProvider; -import org.apache.dolphinscheduler.plugin.datasource.vertica.param.VerticaConnectionParam; -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; -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 { - - @Test - public void testCreateOneSessionJdbcDataSource() { - try ( - MockedStatic mockedJDBCDataSourceProvider = - Mockito.mockStatic(JDBCDataSourceProvider.class)) { - HikariDataSource dataSource = Mockito.mock(HikariDataSource.class); - mockedJDBCDataSourceProvider - .when(() -> JDBCDataSourceProvider.createOneSessionJdbcDataSource(Mockito.any(), Mockito.any())) - .thenReturn(dataSource); - Assertions.assertNotNull( - JDBCDataSourceProvider.createOneSessionJdbcDataSource(new VerticaConnectionParam(), - DbType.VERTICA)); - } - } - -}