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/26 02:15:43 UTC

[dolphinscheduler] branch cleanup/e2e created (now 2adec09)

This is an automated email from the ASF dual-hosted git repository.

kezhenxu94 pushed a change to branch cleanup/e2e
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git.


      at 2adec09  Clean up the E2E with Java API to avoid platform sensitive

This branch includes the following new commits:

     new 2adec09  Clean up the E2E with Java API to avoid platform sensitive

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


[dolphinscheduler] 01/01: Clean up the E2E with Java API to avoid platform sensitive

Posted by ke...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

kezhenxu94 pushed a commit to branch cleanup/e2e
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git

commit 2adec094b35e5f69ee138b1221365368cbb1a4c4
Author: kezhenxu94 <ke...@apache.org>
AuthorDate: Wed Jan 26 10:14:39 2022 +0800

    Clean up the E2E with Java API to avoid platform sensitive
---
 .github/workflows/e2e.yml                          |  1 +
 .../e2e/cases/FileManageE2ETest.java               | 51 +++++++++++-----------
 .../dolphinscheduler/e2e/core/Constants.java       | 22 +++-------
 .../e2e/core/DolphinSchedulerExtension.java        | 28 ++----------
 4 files changed, 35 insertions(+), 67 deletions(-)

diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml
index e7255ac..14b90a0 100644
--- a/.github/workflows/e2e.yml
+++ b/.github/workflows/e2e.yml
@@ -20,6 +20,7 @@ on:
   push:
     branches:
       - dev
+      - cleanup/e2e
 
 name: E2E
 
diff --git a/dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/cases/FileManageE2ETest.java b/dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/cases/FileManageE2ETest.java
index 1a32b5e..8531099 100644
--- a/dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/cases/FileManageE2ETest.java
+++ b/dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/java/org/apache/dolphinscheduler/e2e/cases/FileManageE2ETest.java
@@ -20,6 +20,9 @@
 package org.apache.dolphinscheduler.e2e.cases;
 
 
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.awaitility.Awaitility.await;
+
 import org.apache.dolphinscheduler.e2e.core.Constants;
 import org.apache.dolphinscheduler.e2e.core.DolphinScheduler;
 import org.apache.dolphinscheduler.e2e.pages.LoginPage;
@@ -29,6 +32,13 @@ import org.apache.dolphinscheduler.e2e.pages.security.SecurityPage;
 import org.apache.dolphinscheduler.e2e.pages.security.TenantPage;
 import org.apache.dolphinscheduler.e2e.pages.security.UserPage;
 
+import java.io.File;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Comparator;
+
 import org.junit.jupiter.api.AfterAll;
 import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Order;
@@ -37,14 +47,7 @@ import org.openqa.selenium.By;
 import org.openqa.selenium.WebElement;
 import org.openqa.selenium.remote.RemoteWebDriver;
 
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.awaitility.Awaitility.await;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.RandomAccessFile;
-import java.nio.file.Paths;
-import java.util.Arrays;
+import lombok.SneakyThrows;
 
 @DolphinScheduler(composeFiles = "docker/file-manage/docker-compose.yaml")
 public class FileManageE2ETest {
@@ -72,9 +75,9 @@ public class FileManageE2ETest {
 
     private static final String testUnder1GBFileName = "test_file_0.01G";
 
-    private static final String testOver1GBFilePath = Constants.HOST_TMP_PATH + "/test_file_1.5G";
+    private static final Path testOver1GBFilePath = Constants.HOST_TMP_PATH.resolve("test_file_1.5G");
 
-    private static final String testUnder1GBFilePath = Constants.HOST_TMP_PATH + "/" + testUnder1GBFileName;
+    private static final Path testUnder1GBFilePath = Constants.HOST_TMP_PATH.resolve(testUnder1GBFileName);
 
     @BeforeAll
     public static void setup() {
@@ -95,18 +98,14 @@ public class FileManageE2ETest {
     }
 
     @AfterAll
+    @SneakyThrows
     public static void cleanup() {
-        String[] command = {"/bin/bash", "-c", String.format("sudo rm -f %s && sudo rm -f %s && sudo rm -rf %s", testUnder1GBFilePath, testOver1GBFilePath, Constants.HOST_CHROME_DOWNLOAD_PATH)};
-
-        try {
-            Process pro = Runtime.getRuntime().exec(command);
-            int status = pro.waitFor();
-            if (status != 0) {
-                throw new RuntimeException(String.format("Failed to call shell's command: %s", Arrays.toString(command)));
-            }
-        } catch (Exception e) {
-            throw new RuntimeException(e);
-        }
+        Files.deleteIfExists(testUnder1GBFilePath);
+        Files.deleteIfExists(testOver1GBFilePath);
+        Files.walk(Constants.HOST_CHROME_DOWNLOAD_PATH)
+             .sorted(Comparator.reverseOrder())
+             .map(Path::toFile)
+             .forEach(File::delete);
     }
 
     @Test
@@ -267,10 +266,10 @@ public class FileManageE2ETest {
     void testUploadOver1GBFile() throws IOException {
         final FileManagePage page = new FileManagePage(browser);
 
-        RandomAccessFile file = new RandomAccessFile(testOver1GBFilePath, "rw");
+        RandomAccessFile file = new RandomAccessFile(testOver1GBFilePath.toFile(), "rw");
         file.setLength((long) (1.5 * 1024 * 1024 * 1024));
 
-        page.uploadFile(testOver1GBFilePath);
+        page.uploadFile(testOver1GBFilePath.toFile().getAbsolutePath());
 
         await().untilAsserted(() ->
             assertThat(browser.findElement(By.tagName("body")).getText())
@@ -285,10 +284,10 @@ public class FileManageE2ETest {
 
         browser.navigate().refresh();
 
-        RandomAccessFile file = new RandomAccessFile(testUnder1GBFilePath, "rw");
+        RandomAccessFile file = new RandomAccessFile(testUnder1GBFilePath.toFile(), "rw");
         file.setLength((long) (0.01 * 1024 * 1024 * 1024));
 
-        page.uploadFile(testUnder1GBFilePath);
+        page.uploadFile(testUnder1GBFilePath.toFile().getAbsolutePath());
 
         await().untilAsserted(() -> {
             assertThat(page.fileList())
@@ -305,7 +304,7 @@ public class FileManageE2ETest {
 
         page.downloadFile(testUnder1GBFileName);
 
-        File file = new File(Paths.get(Constants.HOST_CHROME_DOWNLOAD_PATH, testUnder1GBFileName).toFile().getAbsolutePath());
+        File file = Constants.HOST_CHROME_DOWNLOAD_PATH.resolve(testUnder1GBFileName).toFile();
 
         await().untilAsserted(() -> {
             assert file.exists();
diff --git a/dolphinscheduler-e2e/dolphinscheduler-e2e-core/src/main/java/org/apache/dolphinscheduler/e2e/core/Constants.java b/dolphinscheduler-e2e/dolphinscheduler-e2e-core/src/main/java/org/apache/dolphinscheduler/e2e/core/Constants.java
index 1852fa8..caa3a2b 100644
--- a/dolphinscheduler-e2e/dolphinscheduler-e2e-core/src/main/java/org/apache/dolphinscheduler/e2e/core/Constants.java
+++ b/dolphinscheduler-e2e/dolphinscheduler-e2e-core/src/main/java/org/apache/dolphinscheduler/e2e/core/Constants.java
@@ -17,35 +17,25 @@
 
 package org.apache.dolphinscheduler.e2e.core;
 
+import lombok.experimental.UtilityClass;
+
+import java.nio.file.Path;
 import java.nio.file.Paths;
 
-/**
- * Constants
- */
+@UtilityClass
 public final class Constants {
-
-    private Constants() {
-        throw new UnsupportedOperationException("Construct Constants");
-    }
-
     /**
      * tmp directory path
      */
-    public static final String HOST_TMP_PATH = System.getProperty("java.io.tmpdir");
+    public static final Path HOST_TMP_PATH = Paths.get(System.getProperty("java.io.tmpdir"));
 
     /**
      * chrome download path in host
      */
-    public static final String HOST_CHROME_DOWNLOAD_PATH = Paths.get(System.getProperty("java.io.tmpdir"), "download").toFile().getAbsolutePath();
+    public static final Path HOST_CHROME_DOWNLOAD_PATH = HOST_TMP_PATH.resolve("download");
 
     /**
      * chrome download path in selenium/standalone-chrome-debug container
      */
     public static final String SELENIUM_CONTAINER_CHROME_DOWNLOAD_PATH = "/home/seluser/Downloads";
-
-    /**
-     * host os name
-     */
-    public static final String OS_NAME = System.getProperties().getProperty("os.name");
-
 }
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 0273df2..76c5be3 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
@@ -31,7 +31,6 @@ import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.time.Duration;
-import java.util.Arrays;
 import java.util.List;
 import java.util.Objects;
 import java.util.Optional;
@@ -118,32 +117,11 @@ final class DolphinSchedulerExtension
             record = Files.createTempDirectory("record-");
         }
 
-        // According to https://github.com/SeleniumHQ/docker-selenium#mounting-volumes-to-retrieve-downloaded-files
-        if ("linux".equalsIgnoreCase(Constants.OS_NAME)) {
-            File file = new File(Constants.HOST_CHROME_DOWNLOAD_PATH);
-            boolean result = file.mkdir();
-
-            if (!result) {
-                throw new IOException(String.format("mkdir %s error", Constants.HOST_CHROME_DOWNLOAD_PATH));
-            }
-
-            String[] command = {"/bin/bash", "-c", String.format("sudo chown 1200:1201 %s", Constants.HOST_CHROME_DOWNLOAD_PATH)};
-
-            try {
-                Process pro = Runtime.getRuntime().exec(command);
-                int status = pro.waitFor();
-                if (status != 0) {
-                    throw new IOException(String.format("Failed to call shell's command: %s", Arrays.toString(command)));
-                }
-            } catch (Exception e) {
-                throw new IOException(e);
-            }
-            
-        }
-
         browser = new BrowserWebDriverContainer<>()
             .withCapabilities(new ChromeOptions())
-            .withFileSystemBind(Constants.HOST_CHROME_DOWNLOAD_PATH, Constants.SELENIUM_CONTAINER_CHROME_DOWNLOAD_PATH)
+            .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) {
             browser.withNetwork(network);