Skip to content

Commit

Permalink
[Improvement-12333][Test] Migrate all UT cases from jUnit 4 to jUnit …
Browse files Browse the repository at this point in the history
…5 in microbench and e2e module
  • Loading branch information
rickchengx committed Oct 17, 2022
1 parent ac84504 commit 4836073
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,10 @@ public final class Constants {
* chrome download path in selenium/standalone-chrome-debug container
*/
public static final String SELENIUM_CONTAINER_CHROME_DOWNLOAD_PATH = "/home/seluser/Downloads";

public static final String DOLPHINSCHEDULER_STANDALONE_IMAGE_NAME = "apache/dolphinscheduler-standalone-server:ci";

public static final String DOLPHINSCHEDULER_STANDALONE_NETWORK_ALIAS = "dolphinscheduler";

public static final String WAITFOR_LOG_REGEX = ".*Started StandaloneServer.*";
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,14 @@
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.GenericContainer;
import org.testcontainers.containers.Network;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.shaded.org.awaitility.Awaitility;
Expand All @@ -68,7 +67,7 @@ final class DolphinSchedulerExtension implements BeforeAllCallback, AfterAllCall
private final boolean M1_CHIP_FLAG = Objects.equals(System.getProperty("m1_chip"), "true");

private RemoteWebDriver driver;
private DockerComposeContainer<?> compose;
private GenericContainer<?> dsContainer;
private BrowserWebDriverContainer<?> browser;
private Network network;
private HostAndPort address;
Expand All @@ -87,7 +86,7 @@ public void beforeAll(ExtensionContext context) throws IOException {
if (LOCAL_MODE) {
runInLocal();
} else {
runInDockerContainer(context);
runInDockerContainer();
}

setBrowserContainerByOsName();
Expand Down Expand Up @@ -122,29 +121,16 @@ private void runInLocal() {
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;
}
private void runInDockerContainer() {
network = Network.newNetwork();

@Override
public void close() {
}
dsContainer = new GenericContainer<>(Constants.DOLPHINSCHEDULER_STANDALONE_IMAGE_NAME)
.withNetwork(network)
.withNetworkAliases(Constants.DOLPHINSCHEDULER_STANDALONE_NETWORK_ALIAS)
.waitingFor(Wait.forLogMessage(Constants.WAITFOR_LOG_REGEX, 1));
dsContainer.start();

@Override
public Statement apply(Statement base, Description description) {
return null;
}
};
address = HostAndPort.fromParts("dolphinscheduler", 12345);
address = HostAndPort.fromParts(Constants.DOLPHINSCHEDULER_STANDALONE_NETWORK_ALIAS, 12345);
rootPath = "/dolphinscheduler/ui/";
}

Expand Down Expand Up @@ -187,8 +173,8 @@ record = Files.createTempDirectory("record-");
public void afterAll(ExtensionContext context) {
browser.afterTest(new TestDescription(context), Optional.empty());
browser.stop();
if (compose != null) {
compose.stop();
if (dsContainer != null) {
dsContainer.stop();
}
}

Expand All @@ -208,22 +194,4 @@ private void setDriver(Object object, Field field) {
LOGGER.error("Failed to inject web driver to field: {}", field.getName(), e);
}
}

private DockerComposeContainer<?> createDockerCompose(ExtensionContext context) {
final Class<?> clazz = context.getRequiredTestClass();
final DolphinScheduler annotation = clazz.getAnnotation(DolphinScheduler.class);
final List<File> files = Stream.of(annotation.composeFiles())
.map(it -> DolphinScheduler.class.getClassLoader().getResource(it))
.filter(Objects::nonNull)
.map(URL::getPath)
.map(File::new)
.collect(Collectors.toList());
compose = new DockerComposeContainer<>(files)
.withPull(true)
.withTailChildContainers(true)
.withLogConsumer("dolphinscheduler_1", outputFrame -> LOGGER.info(outputFrame.getUtf8String()))
.waitingFor("dolphinscheduler_1", Wait.forHealthcheck().withStartupTimeout(Duration.ofSeconds(180)));

return compose;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@

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;

Expand All @@ -45,7 +43,7 @@ public String getTestId() {
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) {
Expand Down
37 changes: 17 additions & 20 deletions dolphinscheduler-microbench/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>dolphinscheduler</artifactId>
<groupId>org.apache.dolphinscheduler</groupId>
<artifactId>dolphinscheduler</artifactId>
<version>dev-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>dolphinscheduler-microbench</artifactId>
<packaging>jar</packaging>
Expand All @@ -35,6 +34,18 @@
<uberjar.name>benchmarks</uberjar.name>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.dolphinscheduler</groupId>
<artifactId>dolphinscheduler-bom</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>

<dependency>
Expand All @@ -51,9 +62,8 @@
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>compile</scope>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
</dependency>

<dependency>
Expand All @@ -67,18 +77,6 @@

</dependencies>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.dolphinscheduler</groupId>
<artifactId>dolphinscheduler-bom</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<build>
<plugins>
<plugin>
Expand Down Expand Up @@ -112,5 +110,4 @@
</plugins>
</build>


</project>
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
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;
Expand Down Expand Up @@ -122,4 +122,3 @@ private static int getForks() {
}

}

0 comments on commit 4836073

Please sign in to comment.