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

ckj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-uniffle.git


The following commit(s) were added to refs/heads/master by this push:
     new d3981485 [#733] test: fix 
LocalStorageManagerTest#testGetLocalStorageInfo on Linux SSD platform (#734)
d3981485 is described below

commit d3981485daf97869337c95783fa842cac8af1a76
Author: Kaijie Chen <[email protected]>
AuthorDate: Fri Mar 17 14:05:38 2023 +0800

    [#733] test: fix LocalStorageManagerTest#testGetLocalStorageInfo on Linux 
SSD platform (#734)
    
    ### What changes were proposed in this pull request?
    
    Detect SSD on Linux platform, and Assert local storage info accordingly.
    
    ### Why are the changes needed?
    
    Fix: #733
    
    ### Does this PR introduce _any_ user-facing change?
    
    No.
    
    ### How was this patch tested?
    
    Tested on Linux+SSD, Linux+HDD, and macOS+SSD.
    
    ```console
    $ mvn test -Dtest=LocalStorageManagerTest
    ...
    [INFO] -------------------------------------------------------
    [INFO]  T E S T S
    [INFO] -------------------------------------------------------
    [INFO] Running org.apache.uniffle.server.storage.LocalStorageManagerTest
    [INFO] Tests run: 6, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 
1.843 s - in org.apache.uniffle.server.storage.LocalStorageManagerTest
    [INFO]
    [INFO] Results:
    [INFO]
    [INFO] Tests run: 6, Failures: 0, Errors: 0, Skipped: 0
    ...
    ```
---
 .../server/storage/LocalStorageManagerTest.java    | 24 +++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git 
a/server/src/test/java/org/apache/uniffle/server/storage/LocalStorageManagerTest.java
 
b/server/src/test/java/org/apache/uniffle/server/storage/LocalStorageManagerTest.java
index 6fdcf20e..43c8f064 100644
--- 
a/server/src/test/java/org/apache/uniffle/server/storage/LocalStorageManagerTest.java
+++ 
b/server/src/test/java/org/apache/uniffle/server/storage/LocalStorageManagerTest.java
@@ -17,14 +17,17 @@
 
 package org.apache.uniffle.server.storage;
 
+import java.io.BufferedReader;
 import java.io.File;
 import java.io.IOException;
+import java.io.InputStreamReader;
 import java.nio.file.Files;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.commons.lang.SystemUtils;
 import org.junit.jupiter.api.AfterAll;
 import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Test;
@@ -236,10 +239,25 @@ public class LocalStorageManagerTest {
     Map<String, StorageInfo> storageInfo = 
localStorageManager.getStorageInfo();
     assertEquals(1, storageInfo.size());
     try {
-      String mountPoint = Files.getFileStore(new File("/tmp").toPath()).name();
+      final String path = "/tmp";
+      final String mountPoint = Files.getFileStore(new 
File(path).toPath()).name();
       assertNotNull(storageInfo.get(mountPoint));
-      // by default, it should report HDD as local storage type
-      assertEquals(StorageMedia.HDD, storageInfo.get(mountPoint).getType());
+      // on Linux environment, it can detect SSD as local storage type
+      if (SystemUtils.IS_OS_LINUX) {
+        final String cmd = String.format("%s | %s | %s",
+            "lsblk -a -o name,rota",
+            "grep $(df --output=source " + path + " | tail -n 1 | sed -E 
's_^.+/__')",
+            "awk '{print $2}'"
+        );
+        Process process = Runtime.getRuntime().exec(new String[]{"bash", "-c", 
cmd});
+        BufferedReader br = new BufferedReader(new 
InputStreamReader(process.getInputStream()));
+        final String line = br.readLine();
+        br.close();
+        final StorageMedia expected = "0".equals(line) ? StorageMedia.SSD : 
StorageMedia.HDD;
+        assertEquals(expected, storageInfo.get(mountPoint).getType());
+      } else {
+        assertEquals(StorageMedia.HDD, storageInfo.get(mountPoint).getType());
+      }
       assertEquals(StorageStatus.NORMAL, 
storageInfo.get(mountPoint).getStatus());
     } catch (IOException e) {
       throw new RuntimeException(e);

Reply via email to