diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DataSourceServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DataSourceServiceImpl.java index 6b1214dacce8..b7cd6f1518ac 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DataSourceServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DataSourceServiceImpl.java @@ -119,13 +119,7 @@ public Result createDataSource(User loginUser, BaseDataSourceParamDTO da putMsg(result, Status.DESCRIPTION_TOO_LONG_ERROR); return result; } - // check connect ConnectionParam connectionParam = DataSourceUtils.buildConnectionParams(datasourceParam); - Result isConnection = checkConnection(datasourceParam.getType(), connectionParam); - if (Status.SUCCESS.getCode() != isConnection.getCode()) { - putMsg(result, Status.DATASOURCE_CONNECT_FAILED); - return result; - } // build datasource DataSource dataSource = new DataSource(); @@ -202,11 +196,6 @@ public Result updateDataSource(int id, User loginUser, BaseDataSourcePar connectionParam.setPassword(oldParams.path(Constants.PASSWORD).asText()); } - Result isConnection = checkConnection(dataSource.getType(), connectionParam); - if (isConnection.isFailed()) { - return isConnection; - } - Date now = new Date(); dataSource.setName(dataSourceParam.getName().trim()); diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/DataSourceServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/DataSourceServiceTest.java index c5ba3c9fd20c..1a608df58df3 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/DataSourceServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/DataSourceServiceTest.java @@ -128,19 +128,12 @@ public void createDataSourceTest() throws ExecutionException { try ( MockedStatic mockedStaticDataSourceClientProvider = Mockito.mockStatic(DataSourceClientProvider.class)) { - // DATASOURCE_CONNECT_FAILED DataSourceClientProvider clientProvider = Mockito.mock(DataSourceClientProvider.class); mockedStaticDataSourceClientProvider.when(DataSourceClientProvider::getInstance).thenReturn(clientProvider); Mockito.when(dataSourceMapper.queryDataSourceByName(dataSourceName.trim())).thenReturn(null); - Mockito.when(clientProvider.getConnection(Mockito.any(), Mockito.any())).thenReturn(null); - Result connectFailedResult = dataSourceService.createDataSource(loginUser, postgreSqlDatasourceParam); - Assertions.assertEquals(Status.DATASOURCE_CONNECT_FAILED.getCode(), - connectFailedResult.getCode().intValue()); // SUCCESS - Connection connection = Mockito.mock(Connection.class); - Mockito.when(clientProvider.getConnection(Mockito.any(), Mockito.any())).thenReturn(connection); Result success = dataSourceService.createDataSource(loginUser, postgreSqlDatasourceParam); Assertions.assertEquals(Status.SUCCESS.getCode(), success.getCode().intValue()); } @@ -204,15 +197,9 @@ public void updateDataSourceTest() throws ExecutionException { DataSourceClientProvider clientProvider = Mockito.mock(DataSourceClientProvider.class); mockedStaticDataSourceClientProvider.when(DataSourceClientProvider::getInstance).thenReturn(clientProvider); - Mockito.when(clientProvider.getConnection(Mockito.any(), Mockito.any())).thenReturn(null); Mockito.when(dataSourceMapper.queryDataSourceByName(postgreSqlDatasourceParam.getName())).thenReturn(null); - Result connectFailed = - dataSourceService.updateDataSource(dataSourceId, loginUser, postgreSqlDatasourceParam); - Assertions.assertEquals(Status.CONNECTION_TEST_FAILURE.getCode(), connectFailed.getCode().intValue()); // SUCCESS - Connection connection = Mockito.mock(Connection.class); - Mockito.when(clientProvider.getConnection(Mockito.any(), Mockito.any())).thenReturn(connection); Result success = dataSourceService.updateDataSource(dataSourceId, loginUser, postgreSqlDatasourceParam); Assertions.assertEquals(Status.SUCCESS.getCode(), success.getCode().intValue()); }