提交 fa5fbb55 编写于 作者: A adinn

8173910: (fs) java/nio/file/FileSystem/Basic.java should conditionally check FileStores

Summary: On Unix platforms, spawn a 'df' process and skip FileStore check if it hangs
Reviewed-by: alanb
上级 a2a4deb6
/*
* Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -27,9 +27,19 @@
* @library ..
*/
import java.nio.file.*;
import java.nio.file.attribute.*;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.FileStore;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.ProviderNotFoundException;
import java.util.HashMap;
import java.util.concurrent.TimeUnit;
/**
* Simple santity checks for java.nio.file.FileSystem
......@@ -41,6 +51,44 @@ public class Basic {
throw new RuntimeException(msg);
}
static void checkFileStores(String os, FileSystem fs) throws IOException {
boolean checkFileStores = true;
if (!os.equals("Windows")) {
// try to check whether 'df' hangs
System.out.println("\n--- Begin df output ---");
System.out.flush();
Process proc = new ProcessBuilder("df").inheritIO().start();
try {
proc.waitFor(90, TimeUnit.SECONDS);
} catch (InterruptedException ignored) {
}
System.out.println("--- End df output ---\n");
System.out.flush();
try {
int exitValue = proc.exitValue();
if (exitValue != 0) {
System.err.printf("df process exited with %d != 0%n",
exitValue);
checkFileStores = false;
}
} catch (IllegalThreadStateException ignored) {
System.err.println("df command apparently hung");
checkFileStores = false;
}
}
// sanity check method
if (checkFileStores) {
System.out.println("\n--- Begin FileStores ---");
for (FileStore store: fs.getFileStores()) {
System.out.println(store);
}
System.out.println("--- EndFileStores ---\n");
} else {
System.err.println("Skipping FileStore check due to df failure");
}
}
static void checkSupported(FileSystem fs, String... views) {
for (String view: views) {
check(fs.supportedFileAttributeViews().contains(view),
......@@ -48,7 +96,9 @@ public class Basic {
}
}
public static void main(String[] args) throws IOException {
public static void main(String[] args)
throws IOException, URISyntaxException {
String os = System.getProperty("os.name");
FileSystem fs = FileSystems.getDefault();
// close should throw UOE
......@@ -63,15 +113,11 @@ public class Basic {
check(fs.provider().getScheme().equals("file"),
"should use 'file' scheme");
// santity check method - need to re-visit this in future as I/O errors
// are possible
for (FileStore store: fs.getFileStores()) {
System.out.println(store);
}
// sanity check FileStores
checkFileStores(os, fs);
// sanity check supportedFileAttributeViews
checkSupported(fs, "basic");
String os = System.getProperty("os.name");
if (os.equals("SunOS"))
checkSupported(fs, "posix", "unix", "owner", "acl", "user");
if (os.equals("Linux"))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册