Skip to content

Commit 2350775

Browse files
authored
Add IT for mysql5/postgresql16 initialize/upgrade (#15063)
1 parent c59b2d5 commit 2350775

17 files changed

+588
-176
lines changed

dolphinscheduler-tools/src/test/java/org/apache/dolphinscheduler/tools/datasource/BaseDolphinSchedulerManagerIT.java renamed to dolphinscheduler-tools/src/test/java/org/apache/dolphinscheduler/tools/datasource/jupiter/DatabaseContainerProvider.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,14 @@
1515
* limitations under the License.
1616
*/
1717

18-
package org.apache.dolphinscheduler.tools.datasource;
18+
package org.apache.dolphinscheduler.tools.datasource.jupiter;
1919

20-
import org.apache.dolphinscheduler.dao.DaoConfiguration;
20+
import org.testcontainers.containers.GenericContainer;
2121

22-
import org.springframework.boot.test.context.SpringBootTest;
23-
import org.testcontainers.containers.Network;
22+
public interface DatabaseContainerProvider {
2423

25-
@SpringBootTest(classes = {UpgradeDolphinScheduler.class, DaoConfiguration.class})
26-
public abstract class BaseDolphinSchedulerManagerIT {
24+
GenericContainer<?> getContainer(DolphinSchedulerDatabaseContainer dataSourceContainer);
2725

28-
protected static final Network NETWORK = Network.newNetwork();
26+
String getType();
2927

3028
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.dolphinscheduler.tools.datasource.jupiter;
19+
20+
import java.lang.annotation.ElementType;
21+
import java.lang.annotation.Inherited;
22+
import java.lang.annotation.Retention;
23+
import java.lang.annotation.RetentionPolicy;
24+
import java.lang.annotation.Target;
25+
26+
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
27+
import org.junit.jupiter.api.TestMethodOrder;
28+
import org.junit.jupiter.api.extension.ExtendWith;
29+
30+
@Inherited
31+
@Target(ElementType.TYPE)
32+
@Retention(RetentionPolicy.RUNTIME)
33+
@TestMethodOrder(OrderAnnotation.class)
34+
@ExtendWith(DolphinSchedulerDatabaseContainerExtension.class)
35+
public @interface DolphinSchedulerDatabaseContainer {
36+
37+
String imageName();
38+
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.dolphinscheduler.tools.datasource.jupiter;
19+
20+
import java.util.HashMap;
21+
import java.util.Map;
22+
import java.util.ServiceLoader;
23+
import java.util.stream.Stream;
24+
25+
import lombok.extern.slf4j.Slf4j;
26+
27+
import org.junit.jupiter.api.extension.AfterAllCallback;
28+
import org.junit.jupiter.api.extension.BeforeAllCallback;
29+
import org.junit.jupiter.api.extension.ExtensionContext;
30+
import org.testcontainers.containers.GenericContainer;
31+
import org.testcontainers.lifecycle.Startables;
32+
import org.testcontainers.utility.DockerImageName;
33+
34+
@Slf4j
35+
public class DolphinSchedulerDatabaseContainerExtension implements BeforeAllCallback, AfterAllCallback {
36+
37+
private static GenericContainer<?> databaseContainer;
38+
39+
@Override
40+
public void beforeAll(ExtensionContext context) {
41+
databaseContainer = getDataSourceContainer(context);
42+
log.info("Create {} successfully.", databaseContainer.getDockerImageName());
43+
databaseContainer.start();
44+
45+
log.info("Starting {}...", databaseContainer.getDockerImageName());
46+
Startables.deepStart(Stream.of(databaseContainer)).join();
47+
log.info("{} started", databaseContainer.getDockerImageName());
48+
49+
}
50+
51+
private GenericContainer<?> getDataSourceContainer(ExtensionContext context) {
52+
Class<?> requiredTestClass = context.getRequiredTestClass();
53+
DolphinSchedulerDatabaseContainer annotation =
54+
requiredTestClass.getAnnotation(DolphinSchedulerDatabaseContainer.class);
55+
if (annotation == null) {
56+
throw new IllegalArgumentException("@DolphinSchedulerDataSourceContainer annotation not found");
57+
}
58+
Map<String, DatabaseContainerProvider> dataSourceContainerProviderMap = new HashMap<>();
59+
ServiceLoader.load(DatabaseContainerProvider.class)
60+
.forEach(databaseContainerProvider -> dataSourceContainerProviderMap
61+
.put(databaseContainerProvider.getType(), databaseContainerProvider));
62+
63+
DockerImageName dockerImageName = DockerImageName.parse(annotation.imageName());
64+
65+
if (!dataSourceContainerProviderMap.containsKey(dockerImageName.getRepository())) {
66+
throw new IllegalArgumentException(
67+
"DataSourceContainerProvider not found for type: " + annotation.imageName());
68+
}
69+
DatabaseContainerProvider databaseContainerProvider =
70+
dataSourceContainerProviderMap.get(dockerImageName.getRepository());
71+
return databaseContainerProvider.getContainer(annotation);
72+
}
73+
74+
@Override
75+
public void afterAll(ExtensionContext context) {
76+
if (databaseContainer != null) {
77+
databaseContainer.stop();
78+
}
79+
}
80+
}

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

Lines changed: 0 additions & 81 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.dolphinscheduler.tools.datasource.mysql;
19+
20+
import org.apache.dolphinscheduler.dao.DaoConfiguration;
21+
import org.apache.dolphinscheduler.tools.datasource.UpgradeDolphinScheduler;
22+
23+
import java.lang.annotation.ElementType;
24+
import java.lang.annotation.Inherited;
25+
import java.lang.annotation.Retention;
26+
import java.lang.annotation.RetentionPolicy;
27+
import java.lang.annotation.Target;
28+
29+
import org.springframework.boot.test.context.SpringBootTest;
30+
import org.springframework.test.context.ActiveProfiles;
31+
32+
@Inherited
33+
@Target(ElementType.TYPE)
34+
@Retention(RetentionPolicy.RUNTIME)
35+
@ActiveProfiles("mysql")
36+
@SpringBootTest(classes = {UpgradeDolphinScheduler.class, DaoConfiguration.class})
37+
public @interface DolphinSchedulerMysqlProfile {
38+
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.dolphinscheduler.tools.datasource.mysql;
19+
20+
import org.apache.dolphinscheduler.tools.datasource.jupiter.DatabaseContainerProvider;
21+
import org.apache.dolphinscheduler.tools.datasource.jupiter.DolphinSchedulerDatabaseContainer;
22+
23+
import org.testcontainers.containers.GenericContainer;
24+
import org.testcontainers.containers.MySQLContainer;
25+
import org.testcontainers.containers.Network;
26+
import org.testcontainers.containers.wait.strategy.Wait;
27+
import org.testcontainers.utility.DockerImageName;
28+
29+
import com.google.auto.service.AutoService;
30+
import com.google.common.collect.Lists;
31+
32+
@AutoService(DatabaseContainerProvider.class)
33+
public class MysqlDatabaseContainerProvider implements DatabaseContainerProvider {
34+
35+
private static final Network NETWORK = Network.newNetwork();
36+
37+
@Override
38+
public GenericContainer<?> getContainer(DolphinSchedulerDatabaseContainer dataSourceContainer) {
39+
GenericContainer mysqlContainer = new MySQLContainer(DockerImageName.parse(dataSourceContainer.imageName()))
40+
.withUsername("root")
41+
.withPassword("root")
42+
.withDatabaseName("dolphinscheduler")
43+
.withNetwork(NETWORK)
44+
.withExposedPorts(3306)
45+
.waitingFor(Wait.forHealthcheck());
46+
mysqlContainer.setPortBindings(Lists.newArrayList("3306:3306"));
47+
return mysqlContainer;
48+
}
49+
50+
@Override
51+
public String getType() {
52+
return "mysql";
53+
}
54+
55+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.dolphinscheduler.tools.datasource.mysql.v5;
19+
20+
import org.apache.dolphinscheduler.tools.datasource.DolphinSchedulerManager;
21+
import org.apache.dolphinscheduler.tools.datasource.jupiter.DolphinSchedulerDatabaseContainer;
22+
import org.apache.dolphinscheduler.tools.datasource.mysql.DolphinSchedulerMysqlProfile;
23+
24+
import lombok.extern.slf4j.Slf4j;
25+
26+
import org.junit.jupiter.api.Assertions;
27+
import org.junit.jupiter.api.DisplayName;
28+
import org.junit.jupiter.api.Test;
29+
import org.junit.jupiter.api.condition.EnabledOnOs;
30+
import org.junit.jupiter.api.condition.OS;
31+
import org.springframework.beans.factory.annotation.Autowired;
32+
33+
@Slf4j
34+
@EnabledOnOs(OS.LINUX)
35+
@DolphinSchedulerMysqlProfile
36+
@DolphinSchedulerDatabaseContainer(imageName = "mysql:5.7")
37+
class InitializeWithMysqlIT {
38+
39+
@Autowired
40+
private DolphinSchedulerManager dolphinSchedulerManager;
41+
42+
@Test
43+
@DisplayName("Test Initialize DolphinScheduler database in MySQL")
44+
void testInitializeWithMysqlProfile() {
45+
Assertions.assertDoesNotThrow(() -> dolphinSchedulerManager.initDolphinScheduler());
46+
// todo: Assert table count
47+
48+
}
49+
50+
}

0 commit comments

Comments
 (0)