Skip to content

Commit

Permalink
[#733] test: fix LocalStorageManagerTest#testGetLocalStorageInfo on L…
Browse files Browse the repository at this point in the history
…inux 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
...
```
  • Loading branch information
kaijchen authored Mar 17, 2023
1 parent a2b9c17 commit d398148
Showing 1 changed file with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -236,10 +239,25 @@ public void testGetLocalStorageInfo() {
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);
Expand Down

0 comments on commit d398148

Please sign in to comment.