forked from apache/dolphinscheduler
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add IT for mysql5/postgresql16 initialize/upgrade (apache#15063)
- Loading branch information
1 parent
f8305f8
commit f212b8b
Showing
17 changed files
with
588 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...g/apache/dolphinscheduler/tools/datasource/jupiter/DolphinSchedulerDatabaseContainer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 changes: 80 additions & 0 deletions
80
...dolphinscheduler/tools/datasource/jupiter/DolphinSchedulerDatabaseContainerExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 changes: 0 additions & 81 deletions
81
...ache/dolphinscheduler/tools/datasource/mysql/BaseDolphinSchedulerDatabaseWithMysqlIT.java
This file was deleted.
Oops, something went wrong.
39 changes: 39 additions & 0 deletions
39
...java/org/apache/dolphinscheduler/tools/datasource/mysql/DolphinSchedulerMysqlProfile.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 changes: 55 additions & 0 deletions
55
...va/org/apache/dolphinscheduler/tools/datasource/mysql/MysqlDatabaseContainerProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 changes: 50 additions & 0 deletions
50
...est/java/org/apache/dolphinscheduler/tools/datasource/mysql/v5/InitializeWithMysqlIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.