Browse Source

Add IT for mysql5/postgresql16 initialize/upgrade (#15063)

augit-log
Wenjun Ruan 7 months ago committed by GitHub
parent
commit
2350775272
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      dolphinscheduler-tools/src/test/java/org/apache/dolphinscheduler/tools/datasource/jupiter/DatabaseContainerProvider.java
  2. 39
      dolphinscheduler-tools/src/test/java/org/apache/dolphinscheduler/tools/datasource/jupiter/DolphinSchedulerDatabaseContainer.java
  3. 80
      dolphinscheduler-tools/src/test/java/org/apache/dolphinscheduler/tools/datasource/jupiter/DolphinSchedulerDatabaseContainerExtension.java
  4. 81
      dolphinscheduler-tools/src/test/java/org/apache/dolphinscheduler/tools/datasource/mysql/BaseDolphinSchedulerDatabaseWithMysqlIT.java
  5. 39
      dolphinscheduler-tools/src/test/java/org/apache/dolphinscheduler/tools/datasource/mysql/DolphinSchedulerMysqlProfile.java
  6. 55
      dolphinscheduler-tools/src/test/java/org/apache/dolphinscheduler/tools/datasource/mysql/MysqlDatabaseContainerProvider.java
  7. 50
      dolphinscheduler-tools/src/test/java/org/apache/dolphinscheduler/tools/datasource/mysql/v5/InitializeWithMysqlIT.java
  8. 65
      dolphinscheduler-tools/src/test/java/org/apache/dolphinscheduler/tools/datasource/mysql/v5/UpgradeWithMysqlIT.java
  9. 16
      dolphinscheduler-tools/src/test/java/org/apache/dolphinscheduler/tools/datasource/mysql/v8/InitializeWithMysqlIT.java
  10. 18
      dolphinscheduler-tools/src/test/java/org/apache/dolphinscheduler/tools/datasource/mysql/v8/UpgradeWithMysqlIT.java
  11. 78
      dolphinscheduler-tools/src/test/java/org/apache/dolphinscheduler/tools/datasource/postgresql/BaseDolphinSchedulerManagerWithPostgresqlIT.java
  12. 38
      dolphinscheduler-tools/src/test/java/org/apache/dolphinscheduler/tools/datasource/postgresql/DolphinSchedulerPostgresqlProfile.java
  13. 58
      dolphinscheduler-tools/src/test/java/org/apache/dolphinscheduler/tools/datasource/postgresql/PostgresqlDatabaseContainerProvider.java
  14. 14
      dolphinscheduler-tools/src/test/java/org/apache/dolphinscheduler/tools/datasource/postgresql/v11/InitializeWithPostgresqlIT.java
  15. 17
      dolphinscheduler-tools/src/test/java/org/apache/dolphinscheduler/tools/datasource/postgresql/v11/UpgradeWithPostgresqlIT.java
  16. 47
      dolphinscheduler-tools/src/test/java/org/apache/dolphinscheduler/tools/datasource/postgresql/v16/InitializeWithPostgresql16IT.java
  17. 57
      dolphinscheduler-tools/src/test/java/org/apache/dolphinscheduler/tools/datasource/postgresql/v16/UpgradeWithPostgresql16IT.java

12
dolphinscheduler-tools/src/test/java/org/apache/dolphinscheduler/tools/datasource/BaseDolphinSchedulerManagerIT.java → dolphinscheduler-tools/src/test/java/org/apache/dolphinscheduler/tools/datasource/jupiter/DatabaseContainerProvider.java

@ -15,16 +15,14 @@
* limitations under the License.
*/
package org.apache.dolphinscheduler.tools.datasource;
package org.apache.dolphinscheduler.tools.datasource.jupiter;
import org.apache.dolphinscheduler.dao.DaoConfiguration;
import org.testcontainers.containers.GenericContainer;
import org.springframework.boot.test.context.SpringBootTest;
import org.testcontainers.containers.Network;
public interface DatabaseContainerProvider {
@SpringBootTest(classes = {UpgradeDolphinScheduler.class, DaoConfiguration.class})
public abstract class BaseDolphinSchedulerManagerIT {
GenericContainer<?> getContainer(DolphinSchedulerDatabaseContainer dataSourceContainer);
protected static final Network NETWORK = Network.newNetwork();
String getType();
}

39
dolphinscheduler-tools/src/test/java/org/apache/dolphinscheduler/tools/datasource/jupiter/DolphinSchedulerDatabaseContainer.java

@ -0,0 +1,39 @@
/*
* 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.tools.datasource.jupiter;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.extension.ExtendWith;
@Inherited
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@TestMethodOrder(OrderAnnotation.class)
@ExtendWith(DolphinSchedulerDatabaseContainerExtension.class)
public @interface DolphinSchedulerDatabaseContainer {
String imageName();
}

80
dolphinscheduler-tools/src/test/java/org/apache/dolphinscheduler/tools/datasource/jupiter/DolphinSchedulerDatabaseContainerExtension.java

@ -0,0 +1,80 @@
/*
* 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.tools.datasource.jupiter;
import java.util.HashMap;
import java.util.Map;
import java.util.ServiceLoader;
import java.util.stream.Stream;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.extension.AfterAllCallback;
import org.junit.jupiter.api.extension.BeforeAllCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.lifecycle.Startables;
import org.testcontainers.utility.DockerImageName;
@Slf4j
public class DolphinSchedulerDatabaseContainerExtension implements BeforeAllCallback, AfterAllCallback {
private static GenericContainer<?> databaseContainer;
@Override
public void beforeAll(ExtensionContext context) {
databaseContainer = getDataSourceContainer(context);
log.info("Create {} successfully.", databaseContainer.getDockerImageName());
databaseContainer.start();
log.info("Starting {}...", databaseContainer.getDockerImageName());
Startables.deepStart(Stream.of(databaseContainer)).join();
log.info("{} started", databaseContainer.getDockerImageName());
}
private GenericContainer<?> getDataSourceContainer(ExtensionContext context) {
Class<?> requiredTestClass = context.getRequiredTestClass();
DolphinSchedulerDatabaseContainer annotation =
requiredTestClass.getAnnotation(DolphinSchedulerDatabaseContainer.class);
if (annotation == null) {
throw new IllegalArgumentException("@DolphinSchedulerDataSourceContainer annotation not found");
}
Map<String, DatabaseContainerProvider> dataSourceContainerProviderMap = new HashMap<>();
ServiceLoader.load(DatabaseContainerProvider.class)
.forEach(databaseContainerProvider -> dataSourceContainerProviderMap
.put(databaseContainerProvider.getType(), databaseContainerProvider));
DockerImageName dockerImageName = DockerImageName.parse(annotation.imageName());
if (!dataSourceContainerProviderMap.containsKey(dockerImageName.getRepository())) {
throw new IllegalArgumentException(
"DataSourceContainerProvider not found for type: " + annotation.imageName());
}
DatabaseContainerProvider databaseContainerProvider =
dataSourceContainerProviderMap.get(dockerImageName.getRepository());
return databaseContainerProvider.getContainer(annotation);
}
@Override
public void afterAll(ExtensionContext context) {
if (databaseContainer != null) {
databaseContainer.stop();
}
}
}

81
dolphinscheduler-tools/src/test/java/org/apache/dolphinscheduler/tools/datasource/mysql/BaseDolphinSchedulerDatabaseWithMysqlIT.java

@ -1,81 +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.tools.datasource.mysql;
import org.apache.dolphinscheduler.tools.datasource.BaseDolphinSchedulerManagerIT;
import org.apache.dolphinscheduler.tools.datasource.DolphinSchedulerManager;
import java.util.stream.Stream;
import javax.sql.DataSource;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ActiveProfiles;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.MySQLContainer;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.lifecycle.Startables;
import org.testcontainers.utility.DockerImageName;
import com.google.common.collect.Lists;
// todo: use TestTemplate to test multiple mysql version
@Slf4j
@ActiveProfiles("mysql")
public class BaseDolphinSchedulerDatabaseWithMysqlIT extends BaseDolphinSchedulerManagerIT {
@Autowired
protected DolphinSchedulerManager dolphinSchedulerManager;
@Autowired
protected DataSource dataSource;
protected static GenericContainer databaseContainer;
@BeforeAll
public static void initializeContainer() {
// todo: test with multiple mysql version
databaseContainer = new MySQLContainer(DockerImageName.parse("mysql:8.0"))
.withUsername("root")
.withPassword("root")
.withDatabaseName("dolphinscheduler")
.withNetwork(NETWORK)
.withExposedPorts(3306)
.waitingFor(Wait.forHealthcheck());
databaseContainer.setPortBindings(Lists.newArrayList("3306:3306"));
log.info("Create MySQLContainer successfully.");
databaseContainer.start();
log.info("Starting MySQLContainer...");
Startables.deepStart(Stream.of(databaseContainer)).join();
log.info("MySQLContainer started");
}
@AfterAll
public static void closeContainer() {
if (databaseContainer != null) {
databaseContainer.stop();
}
}
}

39
dolphinscheduler-tools/src/test/java/org/apache/dolphinscheduler/tools/datasource/mysql/DolphinSchedulerMysqlProfile.java

@ -0,0 +1,39 @@
/*
* 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.tools.datasource.mysql;
import org.apache.dolphinscheduler.dao.DaoConfiguration;
import org.apache.dolphinscheduler.tools.datasource.UpgradeDolphinScheduler;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
@Inherited
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@ActiveProfiles("mysql")
@SpringBootTest(classes = {UpgradeDolphinScheduler.class, DaoConfiguration.class})
public @interface DolphinSchedulerMysqlProfile {
}

55
dolphinscheduler-tools/src/test/java/org/apache/dolphinscheduler/tools/datasource/mysql/MysqlDatabaseContainerProvider.java

@ -0,0 +1,55 @@
/*
* 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.tools.datasource.mysql;
import org.apache.dolphinscheduler.tools.datasource.jupiter.DatabaseContainerProvider;
import org.apache.dolphinscheduler.tools.datasource.jupiter.DolphinSchedulerDatabaseContainer;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.MySQLContainer;
import org.testcontainers.containers.Network;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.utility.DockerImageName;
import com.google.auto.service.AutoService;
import com.google.common.collect.Lists;
@AutoService(DatabaseContainerProvider.class)
public class MysqlDatabaseContainerProvider implements DatabaseContainerProvider {
private static final Network NETWORK = Network.newNetwork();
@Override
public GenericContainer<?> getContainer(DolphinSchedulerDatabaseContainer dataSourceContainer) {
GenericContainer mysqlContainer = new MySQLContainer(DockerImageName.parse(dataSourceContainer.imageName()))
.withUsername("root")
.withPassword("root")
.withDatabaseName("dolphinscheduler")
.withNetwork(NETWORK)
.withExposedPorts(3306)
.waitingFor(Wait.forHealthcheck());
mysqlContainer.setPortBindings(Lists.newArrayList("3306:3306"));
return mysqlContainer;
}
@Override
public String getType() {
return "mysql";
}
}

50
dolphinscheduler-tools/src/test/java/org/apache/dolphinscheduler/tools/datasource/mysql/v5/InitializeWithMysqlIT.java

@ -0,0 +1,50 @@
/*
* 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.tools.datasource.mysql.v5;
import org.apache.dolphinscheduler.tools.datasource.DolphinSchedulerManager;
import org.apache.dolphinscheduler.tools.datasource.jupiter.DolphinSchedulerDatabaseContainer;
import org.apache.dolphinscheduler.tools.datasource.mysql.DolphinSchedulerMysqlProfile;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledOnOs;
import org.junit.jupiter.api.condition.OS;
import org.springframework.beans.factory.annotation.Autowired;
@Slf4j
@EnabledOnOs(OS.LINUX)
@DolphinSchedulerMysqlProfile
@DolphinSchedulerDatabaseContainer(imageName = "mysql:5.7")
class InitializeWithMysqlIT {
@Autowired
private DolphinSchedulerManager dolphinSchedulerManager;
@Test
@DisplayName("Test Initialize DolphinScheduler database in MySQL")
void testInitializeWithMysqlProfile() {
Assertions.assertDoesNotThrow(() -> dolphinSchedulerManager.initDolphinScheduler());
// todo: Assert table count
}
}

65
dolphinscheduler-tools/src/test/java/org/apache/dolphinscheduler/tools/datasource/mysql/v5/UpgradeWithMysqlIT.java

@ -0,0 +1,65 @@
/*
* 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.tools.datasource.mysql.v5;
import org.apache.dolphinscheduler.common.sql.SqlScriptRunner;
import org.apache.dolphinscheduler.tools.datasource.DolphinSchedulerManager;
import org.apache.dolphinscheduler.tools.datasource.jupiter.DolphinSchedulerDatabaseContainer;
import org.apache.dolphinscheduler.tools.datasource.mysql.DolphinSchedulerMysqlProfile;
import java.io.IOException;
import java.sql.SQLException;
import javax.sql.DataSource;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledOnOs;
import org.junit.jupiter.api.condition.OS;
import org.springframework.beans.factory.annotation.Autowired;
@Slf4j
@EnabledOnOs(OS.LINUX)
@DolphinSchedulerMysqlProfile
@DolphinSchedulerDatabaseContainer(imageName = "mysql:5.7")
class UpgradeWithMysqlIT {
@Autowired
private DolphinSchedulerManager dolphinSchedulerManager;
@Autowired
private DataSource dataSource;
@Test
@DisplayName("Test Upgrade DolphinScheduler database in MySQL")
void testUpgradeWithMysqlProfile() throws SQLException, IOException {
// initialize the 3.0.0 schema
SqlScriptRunner sqlScriptRunner = new SqlScriptRunner(dataSource, "3.0.0_schema/mysql_3.0.0.sql");
sqlScriptRunner.execute();
log.info("Initialize the 3.0.0 schema successfully.");
Assertions.assertDoesNotThrow(() -> dolphinSchedulerManager.upgradeDolphinScheduler());
// todo: Assert table count
}
}

16
dolphinscheduler-tools/src/test/java/org/apache/dolphinscheduler/tools/datasource/mysql/DolphinSchedulerDatabaseInitializeWithMysqlIT.java → dolphinscheduler-tools/src/test/java/org/apache/dolphinscheduler/tools/datasource/mysql/v8/InitializeWithMysqlIT.java

@ -15,18 +15,26 @@
* limitations under the License.
*/
package org.apache.dolphinscheduler.tools.datasource.mysql;
package org.apache.dolphinscheduler.tools.datasource.mysql.v8;
import org.apache.dolphinscheduler.tools.datasource.DolphinSchedulerManager;
import org.apache.dolphinscheduler.tools.datasource.jupiter.DolphinSchedulerDatabaseContainer;
import org.apache.dolphinscheduler.tools.datasource.mysql.DolphinSchedulerMysqlProfile;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.beans.factory.annotation.Autowired;
@Slf4j
@ActiveProfiles("mysql")
class DolphinSchedulerDatabaseInitializeWithMysqlIT extends BaseDolphinSchedulerDatabaseWithMysqlIT {
@DolphinSchedulerMysqlProfile
@DolphinSchedulerDatabaseContainer(imageName = "mysql:8.0")
class InitializeWithMysqlIT {
@Autowired
private DolphinSchedulerManager dolphinSchedulerManager;
@Test
@DisplayName("Test Initialize DolphinScheduler database in MySQL")

18
dolphinscheduler-tools/src/test/java/org/apache/dolphinscheduler/tools/datasource/mysql/DolphinSchedulerDatabaseUpgradeWithMysqlIT.java → dolphinscheduler-tools/src/test/java/org/apache/dolphinscheduler/tools/datasource/mysql/v8/UpgradeWithMysqlIT.java

@ -15,21 +15,35 @@
* limitations under the License.
*/
package org.apache.dolphinscheduler.tools.datasource.mysql;
package org.apache.dolphinscheduler.tools.datasource.mysql.v8;
import org.apache.dolphinscheduler.common.sql.SqlScriptRunner;
import org.apache.dolphinscheduler.tools.datasource.DolphinSchedulerManager;
import org.apache.dolphinscheduler.tools.datasource.jupiter.DolphinSchedulerDatabaseContainer;
import org.apache.dolphinscheduler.tools.datasource.mysql.DolphinSchedulerMysqlProfile;
import java.io.IOException;
import java.sql.SQLException;
import javax.sql.DataSource;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
@Slf4j
class DolphinSchedulerDatabaseUpgradeWithMysqlIT extends BaseDolphinSchedulerDatabaseWithMysqlIT {
@DolphinSchedulerMysqlProfile
@DolphinSchedulerDatabaseContainer(imageName = "mysql:8.0")
class UpgradeWithMysqlIT {
@Autowired
private DolphinSchedulerManager dolphinSchedulerManager;
@Autowired
private DataSource dataSource;
@Test
@DisplayName("Test Upgrade DolphinScheduler database in MySQL")

78
dolphinscheduler-tools/src/test/java/org/apache/dolphinscheduler/tools/datasource/postgresql/BaseDolphinSchedulerManagerWithPostgresqlIT.java

@ -1,78 +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.tools.datasource.postgresql;
import org.apache.dolphinscheduler.tools.datasource.BaseDolphinSchedulerManagerIT;
import org.apache.dolphinscheduler.tools.datasource.DolphinSchedulerManager;
import java.util.stream.Stream;
import javax.sql.DataSource;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ActiveProfiles;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.lifecycle.Startables;
import org.testcontainers.utility.DockerImageName;
import com.google.common.collect.Lists;
// todo: use TestTemplate to test multiple PG version
@Slf4j
@ActiveProfiles("postgresql")
public class BaseDolphinSchedulerManagerWithPostgresqlIT extends BaseDolphinSchedulerManagerIT {
@Autowired
protected DolphinSchedulerManager dolphinSchedulerManager;
@Autowired
protected DataSource dataSource;
protected static GenericContainer databaseContainer;
@BeforeAll
public static void initializeContainer() {
// todo: test with multiple pg version
databaseContainer = new PostgreSQLContainer(DockerImageName.parse("postgres:11.1"))
.withUsername("root")
.withPassword("root")
.withDatabaseName("dolphinscheduler")
.withNetwork(NETWORK)
.withExposedPorts(5432);
databaseContainer.setPortBindings(Lists.newArrayList("5432:5432"));
log.info("Create PostgreSQLContainer successfully.");
databaseContainer.start();
log.info("Starting PostgreSQLContainer...");
Startables.deepStart(Stream.of(databaseContainer)).join();
log.info("PostgreSQLContainer started");
}
@AfterAll
public static void closeContainer() {
if (databaseContainer != null) {
databaseContainer.stop();
}
}
}

38
dolphinscheduler-tools/src/test/java/org/apache/dolphinscheduler/tools/datasource/postgresql/DolphinSchedulerPostgresqlProfile.java

@ -0,0 +1,38 @@
/*
* 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.tools.datasource.postgresql;
import org.apache.dolphinscheduler.dao.DaoConfiguration;
import org.apache.dolphinscheduler.tools.datasource.UpgradeDolphinScheduler;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
@Inherited
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@ActiveProfiles("postgresql")
@SpringBootTest(classes = {UpgradeDolphinScheduler.class, DaoConfiguration.class})
public @interface DolphinSchedulerPostgresqlProfile {
}

58
dolphinscheduler-tools/src/test/java/org/apache/dolphinscheduler/tools/datasource/postgresql/PostgresqlDatabaseContainerProvider.java

@ -0,0 +1,58 @@
/*
* 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.tools.datasource.postgresql;
import org.apache.dolphinscheduler.tools.datasource.jupiter.DatabaseContainerProvider;
import org.apache.dolphinscheduler.tools.datasource.jupiter.DolphinSchedulerDatabaseContainer;
import lombok.extern.slf4j.Slf4j;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.Network;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.utility.DockerImageName;
import com.google.auto.service.AutoService;
import com.google.common.collect.Lists;
@Slf4j
@AutoService(DatabaseContainerProvider.class)
public class PostgresqlDatabaseContainerProvider implements DatabaseContainerProvider {
private static final Network NETWORK = Network.newNetwork();
@SuppressWarnings("unchecked")
@Override
public GenericContainer<?> getContainer(DolphinSchedulerDatabaseContainer dataSourceContainer) {
// todo: test with multiple pg version
GenericContainer<?> postgresqlContainer = new PostgreSQLContainer(DockerImageName.parse("postgres:11.1"))
.withUsername("root")
.withPassword("root")
.withDatabaseName("dolphinscheduler")
.withNetwork(NETWORK)
.withExposedPorts(5432);
postgresqlContainer.setPortBindings(Lists.newArrayList("5432:5432"));
return postgresqlContainer;
}
@Override
public String getType() {
return "postgres";
}
}

14
dolphinscheduler-tools/src/test/java/org/apache/dolphinscheduler/tools/datasource/postgresql/DolphinSchedulerInitializeWithPostgresqlIT.java → dolphinscheduler-tools/src/test/java/org/apache/dolphinscheduler/tools/datasource/postgresql/v11/InitializeWithPostgresqlIT.java

@ -15,16 +15,26 @@
* limitations under the License.
*/
package org.apache.dolphinscheduler.tools.datasource.postgresql;
package org.apache.dolphinscheduler.tools.datasource.postgresql.v11;
import org.apache.dolphinscheduler.tools.datasource.DolphinSchedulerManager;
import org.apache.dolphinscheduler.tools.datasource.jupiter.DolphinSchedulerDatabaseContainer;
import org.apache.dolphinscheduler.tools.datasource.postgresql.DolphinSchedulerPostgresqlProfile;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
@Slf4j
class DolphinSchedulerInitializeWithPostgresqlIT extends BaseDolphinSchedulerManagerWithPostgresqlIT {
@DolphinSchedulerPostgresqlProfile
@DolphinSchedulerDatabaseContainer(imageName = "postgres:11.1")
class InitializeWithPostgresqlIT {
@Autowired
private DolphinSchedulerManager dolphinSchedulerManager;
@Test
@DisplayName("Test initDolphinScheduler database in PostgreSQL")

17
dolphinscheduler-tools/src/test/java/org/apache/dolphinscheduler/tools/datasource/postgresql/DolphinSchedulerDatabaseUpgradeWithPostgresqlIT.java → dolphinscheduler-tools/src/test/java/org/apache/dolphinscheduler/tools/datasource/postgresql/v11/UpgradeWithPostgresqlIT.java

@ -15,9 +15,14 @@
* limitations under the License.
*/
package org.apache.dolphinscheduler.tools.datasource.postgresql;
package org.apache.dolphinscheduler.tools.datasource.postgresql.v11;
import org.apache.dolphinscheduler.common.sql.SqlScriptRunner;
import org.apache.dolphinscheduler.tools.datasource.DolphinSchedulerManager;
import org.apache.dolphinscheduler.tools.datasource.jupiter.DolphinSchedulerDatabaseContainer;
import org.apache.dolphinscheduler.tools.datasource.postgresql.DolphinSchedulerPostgresqlProfile;
import javax.sql.DataSource;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
@ -25,9 +30,17 @@ import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
@Slf4j
class DolphinSchedulerDatabaseUpgradeWithPostgresqlIT extends BaseDolphinSchedulerManagerWithPostgresqlIT {
@DolphinSchedulerPostgresqlProfile
@DolphinSchedulerDatabaseContainer(imageName = "postgres:11.1")
class UpgradeWithPostgresqlIT {
@Autowired
private DolphinSchedulerManager dolphinSchedulerManager;
@Autowired
private DataSource dataSource;
@Test
@SneakyThrows

47
dolphinscheduler-tools/src/test/java/org/apache/dolphinscheduler/tools/datasource/postgresql/v16/InitializeWithPostgresql16IT.java

@ -0,0 +1,47 @@
/*
* 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.tools.datasource.postgresql.v16;
import org.apache.dolphinscheduler.tools.datasource.DolphinSchedulerManager;
import org.apache.dolphinscheduler.tools.datasource.jupiter.DolphinSchedulerDatabaseContainer;
import org.apache.dolphinscheduler.tools.datasource.postgresql.DolphinSchedulerPostgresqlProfile;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
@Slf4j
@DolphinSchedulerPostgresqlProfile
@DolphinSchedulerDatabaseContainer(imageName = "postgres:16.0")
class InitializeWithPostgresql16IT {
@Autowired
private DolphinSchedulerManager dolphinSchedulerManager;
@Test
@DisplayName("Test initDolphinScheduler database in PostgreSQL")
void testInitializeWithPostgreSQLProfile() {
Assertions.assertDoesNotThrow(() -> {
dolphinSchedulerManager.initDolphinScheduler();
});
// todo: Assert table count
}
}

57
dolphinscheduler-tools/src/test/java/org/apache/dolphinscheduler/tools/datasource/postgresql/v16/UpgradeWithPostgresql16IT.java

@ -0,0 +1,57 @@
/*
* 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.tools.datasource.postgresql.v16;
import org.apache.dolphinscheduler.common.sql.SqlScriptRunner;
import org.apache.dolphinscheduler.tools.datasource.DolphinSchedulerManager;
import org.apache.dolphinscheduler.tools.datasource.jupiter.DolphinSchedulerDatabaseContainer;
import org.apache.dolphinscheduler.tools.datasource.postgresql.DolphinSchedulerPostgresqlProfile;
import javax.sql.DataSource;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
@Slf4j
@DolphinSchedulerPostgresqlProfile
@DolphinSchedulerDatabaseContainer(imageName = "postgres:16.0")
class UpgradeWithPostgresql16IT {
@Autowired
private DolphinSchedulerManager dolphinSchedulerManager;
@Autowired
private DataSource dataSource;
@Test
@SneakyThrows
@DisplayName("Test Upgrade DolphinScheduler database in PostgreSQL")
void testUpgradeWithPostgreSQLProfile() {
// initialize the 3.0.0 schema
SqlScriptRunner sqlScriptRunner = new SqlScriptRunner(dataSource, "3.0.0_schema/postgresql_3.0.0.sql");
sqlScriptRunner.execute();
log.info("Initialize the 3.0.0 schema successfully.");
Assertions.assertDoesNotThrow(() -> dolphinSchedulerManager.upgradeDolphinScheduler());
// todo: Assert table count
}
}
Loading…
Cancel
Save