Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
rickchengx committed Oct 17, 2022
1 parent 5f4179f commit 4986bf1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 30 deletions.
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 @@ -49,6 +49,7 @@
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 @@ -66,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 @@ -85,7 +86,7 @@ public void beforeAll(ExtensionContext context) throws IOException {
if (LOCAL_MODE) {
runInLocal();
} else {
runInDockerContainer(context);
runInDockerContainer();
}

setBrowserContainerByOsName();
Expand Down Expand Up @@ -120,15 +121,16 @@ private void runInLocal() {
rootPath = "/";
}

private void runInDockerContainer(ExtensionContext context) {
compose = createDockerCompose(context);
compose.start();
private void runInDockerContainer() {
network = Network.newNetwork();

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 = Network.builder().id(networkId).build();
address = HostAndPort.fromParts("dolphinscheduler", 12345);
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();

address = HostAndPort.fromParts(Constants.DOLPHINSCHEDULER_STANDALONE_NETWORK_ALIAS, 12345);
rootPath = "/dolphinscheduler/ui/";
}

Expand Down Expand Up @@ -171,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 @@ -192,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;
}
}

0 comments on commit 4986bf1

Please sign in to comment.