Wenjun Ruan
7 months ago
committed by
GitHub
17 changed files with 588 additions and 176 deletions
@ -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(); |
||||
|
||||
} |
@ -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(); |
||||
} |
||||
} |
||||
} |
@ -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(); |
||||
} |
||||
} |
||||
|
||||
} |
@ -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 { |
||||
|
||||
} |
@ -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"; |
||||
} |
||||
|
||||
} |
@ -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
|
||||
|
||||
} |
||||
|
||||
} |
@ -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
|
||||
|
||||
} |
||||
|
||||
} |
@ -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(); |
||||
} |
||||
} |
||||
} |
@ -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 { |
||||
|
||||
} |
@ -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"; |
||||
} |
||||
} |
@ -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
|
||||
} |
||||
} |
@ -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…
Reference in new issue