You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by ke...@apache.org on 2022/01/27 11:15:18 UTC
[dolphinscheduler] branch dev updated: [Improvement][E2E] use testcontainers host (#8224)
This is an automated email from the ASF dual-hosted git repository.
kezhenxu94 pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git
The following commit(s) were added to refs/heads/dev by this push:
new 756ea11 [Improvement][E2E] use testcontainers host (#8224)
756ea11 is described below
commit 756ea1181eb60329510257141f29f0d815735a9b
Author: wind <ca...@users.noreply.github.com>
AuthorDate: Thu Jan 27 19:15:05 2022 +0800
[Improvement][E2E] use testcontainers host (#8224)
---
.../e2e/core/DolphinSchedulerExtension.java | 80 +++++++++++-----------
1 file changed, 41 insertions(+), 39 deletions(-)
diff --git a/dolphinscheduler-e2e/dolphinscheduler-e2e-core/src/main/java/org/apache/dolphinscheduler/e2e/core/DolphinSchedulerExtension.java b/dolphinscheduler-e2e/dolphinscheduler-e2e-core/src/main/java/org/apache/dolphinscheduler/e2e/core/DolphinSchedulerExtension.java
index 76c5be3..a1da5f8 100644
--- a/dolphinscheduler-e2e/dolphinscheduler-e2e-core/src/main/java/org/apache/dolphinscheduler/e2e/core/DolphinSchedulerExtension.java
+++ b/dolphinscheduler-e2e/dolphinscheduler-e2e-core/src/main/java/org/apache/dolphinscheduler/e2e/core/DolphinSchedulerExtension.java
@@ -47,6 +47,7 @@ import org.junit.runners.model.Statement;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.RemoteWebDriver;
+import org.testcontainers.Testcontainers;
import org.testcontainers.containers.BrowserWebDriverContainer;
import org.testcontainers.containers.ContainerState;
import org.testcontainers.containers.DockerComposeContainer;
@@ -69,6 +70,9 @@ final class DolphinSchedulerExtension
private RemoteWebDriver driver;
private DockerComposeContainer<?> compose;
private BrowserWebDriverContainer<?> browser;
+ private Network network;
+ private HostAndPort address;
+ private String rootPath;
@Override
@SuppressWarnings("UnstableApiUsage")
@@ -76,33 +80,10 @@ final class DolphinSchedulerExtension
Awaitility.setDefaultTimeout(Duration.ofSeconds(60));
Awaitility.setDefaultPollInterval(Duration.ofSeconds(10));
- Network network = null;
- HostAndPort address = null;
- String rootPath = "/";
- if (!LOCAL_MODE) {
- compose = createDockerCompose(context);
- compose.start();
-
- final ContainerState dsContainer = compose.getContainerByServiceName("dolphinscheduler_1")
- .orElseThrow(() -> new RuntimeException("Failed to find a container named 'dolphinscheduler'"));
- final String networkId = dsContainer.getContainerInfo().getNetworkSettings().getNetworks().keySet().iterator().next();
- network = new Network() {
- @Override
- public String getId() {
- return networkId;
- }
-
- @Override
- public void close() {
- }
-
- @Override
- public Statement apply(Statement base, Description description) {
- return null;
- }
- };
- address = HostAndPort.fromParts("dolphinscheduler", 12345);
- rootPath = "/dolphinscheduler";
+ if (LOCAL_MODE) {
+ runInLocal();
+ } else {
+ runInDockerContainer(context);
}
final Path record;
@@ -135,18 +116,7 @@ final class DolphinSchedulerExtension
.pageLoadTimeout(5, TimeUnit.SECONDS);
driver.manage().window()
.maximize();
- if (address == null) {
- try {
- address = HostAndPort.fromParts(browser.getTestHostIpAddress(), 8888);
- } catch (UnsupportedOperationException ignored) {
- if (SystemUtils.IS_OS_MAC || SystemUtils.IS_OS_MAC_OSX) {
- address = HostAndPort.fromParts("host.docker.internal", 8888);
- }
- }
- }
- if (address == null) {
- throw new UnsupportedOperationException("Unsupported operation system");
- }
+
driver.get(new URL("http", address.getHost(), address.getPort(), rootPath).toString());
browser.beforeTest(new TestDescription(context));
@@ -158,6 +128,38 @@ final class DolphinSchedulerExtension
.forEach(it -> setDriver(clazz, it));
}
+ private void runInLocal() {
+ Testcontainers.exposeHostPorts(8888);
+ address = HostAndPort.fromParts("host.testcontainers.internal", 8888);
+ rootPath = "/";
+ }
+
+ private void runInDockerContainer(ExtensionContext context) {
+ compose = createDockerCompose(context);
+ compose.start();
+
+ final ContainerState dsContainer = compose.getContainerByServiceName("dolphinscheduler_1")
+ .orElseThrow(() -> new RuntimeException("Failed to find a container named 'dolphinscheduler'"));
+ final String networkId = dsContainer.getContainerInfo().getNetworkSettings().getNetworks().keySet().iterator().next();
+ network = new Network() {
+ @Override
+ public String getId() {
+ return networkId;
+ }
+
+ @Override
+ public void close() {
+ }
+
+ @Override
+ public Statement apply(Statement base, Description description) {
+ return null;
+ }
+ };
+ address = HostAndPort.fromParts("dolphinscheduler", 12345);
+ rootPath = "/dolphinscheduler";
+ }
+
@Override
public void afterAll(ExtensionContext context) {
browser.afterTest(new TestDescription(context), Optional.empty());