|
|
@ -59,13 +59,14 @@ import com.google.common.base.Strings; |
|
|
|
import com.google.common.net.HostAndPort; |
|
|
|
import com.google.common.net.HostAndPort; |
|
|
|
|
|
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
|
|
|
import org.testcontainers.utility.DockerImageName; |
|
|
|
|
|
|
|
|
|
|
|
@Slf4j |
|
|
|
@Slf4j |
|
|
|
final class DolphinSchedulerExtension |
|
|
|
final class DolphinSchedulerExtension implements BeforeAllCallback, AfterAllCallback, BeforeEachCallback { |
|
|
|
implements BeforeAllCallback, AfterAllCallback, |
|
|
|
|
|
|
|
BeforeEachCallback { |
|
|
|
|
|
|
|
private final boolean LOCAL_MODE = Objects.equals(System.getProperty("local"), "true"); |
|
|
|
private final boolean LOCAL_MODE = Objects.equals(System.getProperty("local"), "true"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final boolean M1_CHIP_FLAG = Objects.equals(System.getProperty("m1_chip"), "true"); |
|
|
|
|
|
|
|
|
|
|
|
private RemoteWebDriver driver; |
|
|
|
private RemoteWebDriver driver; |
|
|
|
private DockerComposeContainer<?> compose; |
|
|
|
private DockerComposeContainer<?> compose; |
|
|
|
private BrowserWebDriverContainer<?> browser; |
|
|
|
private BrowserWebDriverContainer<?> browser; |
|
|
@ -73,36 +74,24 @@ final class DolphinSchedulerExtension |
|
|
|
private HostAndPort address; |
|
|
|
private HostAndPort address; |
|
|
|
private String rootPath; |
|
|
|
private String rootPath; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Path record; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
@SuppressWarnings("UnstableApiUsage") |
|
|
|
@SuppressWarnings("UnstableApiUsage") |
|
|
|
public void beforeAll(ExtensionContext context) throws IOException { |
|
|
|
public void beforeAll(ExtensionContext context) throws IOException { |
|
|
|
Awaitility.setDefaultTimeout(Duration.ofSeconds(60)); |
|
|
|
Awaitility.setDefaultTimeout(Duration.ofSeconds(60)); |
|
|
|
Awaitility.setDefaultPollInterval(Duration.ofSeconds(10)); |
|
|
|
Awaitility.setDefaultPollInterval(Duration.ofSeconds(10)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setRecordPath(); |
|
|
|
|
|
|
|
|
|
|
|
if (LOCAL_MODE) { |
|
|
|
if (LOCAL_MODE) { |
|
|
|
runInLocal(); |
|
|
|
runInLocal(); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
runInDockerContainer(context); |
|
|
|
runInDockerContainer(context); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
final Path record; |
|
|
|
setBrowserContainerByOsName(); |
|
|
|
if (!Strings.isNullOrEmpty(System.getenv("RECORDING_PATH"))) { |
|
|
|
|
|
|
|
record = Paths.get(System.getenv("RECORDING_PATH")); |
|
|
|
|
|
|
|
if (!record.toFile().exists()) { |
|
|
|
|
|
|
|
if (!record.toFile().mkdir()) { |
|
|
|
|
|
|
|
throw new IOException("Failed to create recording directory: " + record.toAbsolutePath()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
record = Files.createTempDirectory("record-"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
browser = new BrowserWebDriverContainer<>() |
|
|
|
|
|
|
|
.withCapabilities(new ChromeOptions()) |
|
|
|
|
|
|
|
.withCreateContainerCmdModifier(cmd -> cmd.withUser("root")) |
|
|
|
|
|
|
|
.withFileSystemBind(Constants.HOST_CHROME_DOWNLOAD_PATH.toFile().getAbsolutePath(), |
|
|
|
|
|
|
|
Constants.SELENIUM_CONTAINER_CHROME_DOWNLOAD_PATH) |
|
|
|
|
|
|
|
.withRecordingMode(RECORD_ALL, record.toFile(), MP4); |
|
|
|
|
|
|
|
if (network != null) { |
|
|
|
if (network != null) { |
|
|
|
browser.withNetwork(network); |
|
|
|
browser.withNetwork(network); |
|
|
|
} |
|
|
|
} |
|
|
@ -128,8 +117,8 @@ final class DolphinSchedulerExtension |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void runInLocal() { |
|
|
|
private void runInLocal() { |
|
|
|
Testcontainers.exposeHostPorts(8888); |
|
|
|
Testcontainers.exposeHostPorts(3000); |
|
|
|
address = HostAndPort.fromParts("host.testcontainers.internal", 8888); |
|
|
|
address = HostAndPort.fromParts("host.testcontainers.internal", 3000); |
|
|
|
rootPath = "/"; |
|
|
|
rootPath = "/"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -159,6 +148,41 @@ final class DolphinSchedulerExtension |
|
|
|
rootPath = "/dolphinscheduler/ui/"; |
|
|
|
rootPath = "/dolphinscheduler/ui/"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void setBrowserContainerByOsName() { |
|
|
|
|
|
|
|
DockerImageName imageName; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (LOCAL_MODE && M1_CHIP_FLAG) { |
|
|
|
|
|
|
|
imageName = DockerImageName.parse("seleniarm/standalone-chromium:4.1.2-20220227") |
|
|
|
|
|
|
|
.asCompatibleSubstituteFor("selenium/standalone-chrome"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
browser = new BrowserWebDriverContainer<>(imageName) |
|
|
|
|
|
|
|
.withCapabilities(new ChromeOptions()) |
|
|
|
|
|
|
|
.withCreateContainerCmdModifier(cmd -> cmd.withUser("root")) |
|
|
|
|
|
|
|
.withFileSystemBind(Constants.HOST_CHROME_DOWNLOAD_PATH.toFile().getAbsolutePath(), |
|
|
|
|
|
|
|
Constants.SELENIUM_CONTAINER_CHROME_DOWNLOAD_PATH); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
browser = new BrowserWebDriverContainer<>() |
|
|
|
|
|
|
|
.withCapabilities(new ChromeOptions()) |
|
|
|
|
|
|
|
.withCreateContainerCmdModifier(cmd -> cmd.withUser("root")) |
|
|
|
|
|
|
|
.withFileSystemBind(Constants.HOST_CHROME_DOWNLOAD_PATH.toFile().getAbsolutePath(), |
|
|
|
|
|
|
|
Constants.SELENIUM_CONTAINER_CHROME_DOWNLOAD_PATH) |
|
|
|
|
|
|
|
.withRecordingMode(RECORD_ALL, record.toFile(), MP4); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void setRecordPath() throws IOException { |
|
|
|
|
|
|
|
if (!Strings.isNullOrEmpty(System.getenv("RECORDING_PATH"))) { |
|
|
|
|
|
|
|
record = Paths.get(System.getenv("RECORDING_PATH")); |
|
|
|
|
|
|
|
if (!record.toFile().exists()) { |
|
|
|
|
|
|
|
if (!record.toFile().mkdir()) { |
|
|
|
|
|
|
|
throw new IOException("Failed to create recording directory: " + record.toAbsolutePath()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
record = Files.createTempDirectory("record-"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void afterAll(ExtensionContext context) { |
|
|
|
public void afterAll(ExtensionContext context) { |
|
|
|
browser.afterTest(new TestDescription(context), Optional.empty()); |
|
|
|
browser.afterTest(new TestDescription(context), Optional.empty()); |
|
|
|