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 c34717414544e286b88cafc05a26a832c9bb2bda
Author: kezhenxu94 <[email protected]>
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 +++++++++++-----------
 .../docker/file-manage/docker-compose.yaml         | 11 ++---
 .../dolphinscheduler/e2e/core/Constants.java       | 22 +++-------
 .../e2e/core/DolphinSchedulerExtension.java        | 28 ++----------
 dolphinscheduler-e2e/pom.xml                       |  2 +-
 6 files changed, 39 insertions(+), 76 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-case/src/test/resources/docker/file-manage/docker-compose.yaml
 
b/dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/resources/docker/file-manage/docker-compose.yaml
index 4b5e254..b63bf51 100644
--- 
a/dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/resources/docker/file-manage/docker-compose.yaml
+++ 
b/dolphinscheduler-e2e/dolphinscheduler-e2e-case/src/test/resources/docker/file-manage/docker-compose.yaml
@@ -15,7 +15,7 @@
 # limitations under the License.
 #
 
-version: "2.1"
+version: "3.8"
 
 services:
   dolphinscheduler:
@@ -38,7 +38,7 @@ services:
       s3:
         condition: service_healthy
       mc:
-        condition: service_healthy
+        condition: service_completed_successfully
   s3:
     image: minio/minio:latest
     hostname: s3
@@ -67,12 +67,7 @@ services:
       - e2e
     command: bash -c '
       mc alias set s3 http://s3:9000 accessKey123 secretKey123
-      && mc mb s3/dolphinscheduler && tail -f /dev/null'
-    healthcheck:
-      test: [ "CMD", "echo", "1" ]
-      interval: 5s
-      timeout: 120s
-      retries: 120
+      && mc mb s3/dolphinscheduler'
     depends_on:
       s3:
         condition: service_healthy
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);
diff --git a/dolphinscheduler-e2e/pom.xml b/dolphinscheduler-e2e/pom.xml
index 7be8131..23d99c2 100644
--- a/dolphinscheduler-e2e/pom.xml
+++ b/dolphinscheduler-e2e/pom.xml
@@ -127,7 +127,7 @@
             <dependency>
                 <groupId>org.testcontainers</groupId>
                 <artifactId>testcontainers-bom</artifactId>
-                <version>1.16.1</version>
+                <version>1.16.3</version>
                 <scope>import</scope>
                 <type>pom</type>
             </dependency>

Reply via email to