From a17923a62b036537d2b21c5100e1038468c56e1d Mon Sep 17 00:00:00 2001 From: rickchengx <38122586+rickchengx@users.noreply.github.com> Date: Wed, 19 Oct 2022 16:58:42 +0800 Subject: [PATCH] [Improvement-12333][Test] Migrate all UT cases from jUnit 4 to jUnit 5 in microbench and e2e module (#12348) --- .../e2e/pages/common/CodeEditor.java | 1 - .../e2e/core/DolphinSchedulerExtension.java | 31 +++---------------- .../e2e/core/TestDescription.java | 4 +-- dolphinscheduler-microbench/pom.xml | 5 ++- .../base/AbstractBaseBenchmark.java | 2 +- 5 files changed, 9 insertions(+), 34 deletions(-) diff --git a/dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/pages/common/CodeEditor.java b/dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/pages/common/CodeEditor.java index fa9b269657..8e610fb8d5 100644 --- a/dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/pages/common/CodeEditor.java +++ b/dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/pages/common/CodeEditor.java @@ -19,7 +19,6 @@ */ package org.apache.dolphinscheduler.e2e.pages.common; -import org.junit.rules.ExpectedException; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; 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 b8683ca93e..fefc68795c 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 @@ -42,16 +42,12 @@ import org.junit.jupiter.api.extension.AfterAllCallback; import org.junit.jupiter.api.extension.BeforeAllCallback; import org.junit.jupiter.api.extension.BeforeEachCallback; import org.junit.jupiter.api.extension.ExtensionContext; -import org.junit.runner.Description; -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; -import org.testcontainers.containers.Network; import org.testcontainers.containers.wait.strategy.Wait; import org.testcontainers.shaded.org.awaitility.Awaitility; @@ -72,7 +68,6 @@ final class DolphinSchedulerExtension implements BeforeAllCallback, AfterAllCall private RemoteWebDriver driver; private DockerComposeContainer compose; private BrowserWebDriverContainer browser; - private Network network; private HostAndPort address; private String rootPath; @@ -94,8 +89,9 @@ final class DolphinSchedulerExtension implements BeforeAllCallback, AfterAllCall setBrowserContainerByOsName(); - if (network != null) { - browser.withNetwork(network); + if (compose != null) { + Testcontainers.exposeHostPorts(compose.getServicePort("dolphinscheduler_1", 12345)); + browser.withAccessToHost(true); } browser.start(); @@ -128,25 +124,7 @@ final class DolphinSchedulerExtension implements BeforeAllCallback, AfterAllCall 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); + address = HostAndPort.fromParts("host.testcontainers.internal", compose.getServicePort("dolphinscheduler_1", 12345)); rootPath = "/dolphinscheduler/ui/"; } @@ -223,6 +201,7 @@ final class DolphinSchedulerExtension implements BeforeAllCallback, AfterAllCall compose = new DockerComposeContainer<>(files) .withPull(true) .withTailChildContainers(true) + .withExposedService("dolphinscheduler_1", 12345) .withLogConsumer("dolphinscheduler_1", outputFrame -> LOGGER.info(outputFrame.getUtf8String())) .waitingFor("dolphinscheduler_1", Wait.forHealthcheck().withStartupTimeout(Duration.ofSeconds(180))); diff --git a/dolphinscheduler-e2e/dolphinscheduler-e2e-core/src/main/java/org/apache/dolphinscheduler/e2e/core/TestDescription.java b/dolphinscheduler-e2e/dolphinscheduler-e2e-core/src/main/java/org/apache/dolphinscheduler/e2e/core/TestDescription.java index 16f366cd83..59ef66b7f6 100644 --- a/dolphinscheduler-e2e/dolphinscheduler-e2e-core/src/main/java/org/apache/dolphinscheduler/e2e/core/TestDescription.java +++ b/dolphinscheduler-e2e/dolphinscheduler-e2e-core/src/main/java/org/apache/dolphinscheduler/e2e/core/TestDescription.java @@ -21,8 +21,6 @@ package org.apache.dolphinscheduler.e2e.core; import static java.nio.charset.StandardCharsets.UTF_8; -import static org.junit.platform.commons.util.StringUtils.isBlank; - import java.io.UnsupportedEncodingException; import java.net.URLEncoder; @@ -45,7 +43,7 @@ final class TestDescription implements org.testcontainers.lifecycle.TestDescript public String getFilesystemFriendlyName() { final String contextId = context.getUniqueId(); try { - return (isBlank(contextId)) + return (contextId == null || contextId.trim().isEmpty()) ? UNKNOWN_NAME : URLEncoder.encode(contextId, UTF_8.toString()); } catch (UnsupportedEncodingException e) { diff --git a/dolphinscheduler-microbench/pom.xml b/dolphinscheduler-microbench/pom.xml index f3447b319c..59f71c50d5 100644 --- a/dolphinscheduler-microbench/pom.xml +++ b/dolphinscheduler-microbench/pom.xml @@ -62,9 +62,8 @@ - junit - junit - compile + org.junit.jupiter + junit-jupiter-api diff --git a/dolphinscheduler-microbench/src/main/java/org/apache/dolphinscheduler/microbench/base/AbstractBaseBenchmark.java b/dolphinscheduler-microbench/src/main/java/org/apache/dolphinscheduler/microbench/base/AbstractBaseBenchmark.java index 392ad3e100..3fc0b67ef7 100644 --- a/dolphinscheduler-microbench/src/main/java/org/apache/dolphinscheduler/microbench/base/AbstractBaseBenchmark.java +++ b/dolphinscheduler-microbench/src/main/java/org/apache/dolphinscheduler/microbench/base/AbstractBaseBenchmark.java @@ -20,7 +20,7 @@ package org.apache.dolphinscheduler.microbench.base; import java.io.File; import java.io.IOException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openjdk.jmh.annotations.Fork; import org.openjdk.jmh.annotations.Measurement; import org.openjdk.jmh.annotations.Scope;