提交 fdd391e7 编写于 作者: A andrew

Merge

......@@ -993,3 +993,4 @@ e880f2d161bf23a09f8c1a19861d7df7d2ed126f jdk8u222-b01
7ecf0b6b46aea31bcf2641fcd526d9b211db2420 jdk8u222-b03
8119ddcb3eecd4d3bd4aa6bde441f88d1fd6f999 jdk8u222-b04
887c8314411dd461ec4b1e14cd6368ed3d9a7a3b jdk8u222-b05
63b345c88831be5a690b857adfa84bd20ad376e1 jdk8u222-b06
/*
* Copyright (c) 2008, 2016, 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
......@@ -24,7 +24,10 @@
/* @test
* @bug 4313887 6873621 6979526 7006126 7020517
* @summary Unit test for java.nio.file.FileStore
* @library ..
* @key intermittent
* @library .. /lib/testlibrary
* @build jdk.testlibrary.FileUtils
* @run main Basic
*/
import java.nio.file.*;
......@@ -32,6 +35,7 @@ import java.nio.file.attribute.*;
import java.io.File;
import java.io.IOException;
import java.util.*;
import jdk.testlibrary.FileUtils;
public class Basic {
......@@ -109,31 +113,36 @@ public class Basic {
/**
* Test: Enumerate all FileStores
*/
FileStore prev = null;
for (FileStore store: FileSystems.getDefault().getFileStores()) {
System.out.format("%s (name=%s type=%s)\n", store, store.name(),
store.type());
// check space attributes are accessible
try {
store.getTotalSpace();
store.getUnallocatedSpace();
store.getUsableSpace();
} catch (NoSuchFileException nsfe) {
// ignore exception as the store could have been
// deleted since the iterator was instantiated
System.err.format("%s was not found\n", store);
} catch (AccessDeniedException ade) {
// ignore exception as the lack of ability to access the
// store due to lack of file permission or similar does not
// reflect whether the space attributes would be accessible
// were access to be permitted
System.err.format("%s is inaccessible\n", store);
if (FileUtils.areFileSystemsAccessible()) {
FileStore prev = null;
for (FileStore store: FileSystems.getDefault().getFileStores()) {
System.out.format("%s (name=%s type=%s)\n", store, store.name(),
store.type());
// check space attributes are accessible
try {
store.getTotalSpace();
store.getUnallocatedSpace();
store.getUsableSpace();
} catch (NoSuchFileException nsfe) {
// ignore exception as the store could have been
// deleted since the iterator was instantiated
System.err.format("%s was not found\n", store);
} catch (AccessDeniedException ade) {
// ignore exception as the lack of ability to access the
// store due to lack of file permission or similar does not
// reflect whether the space attributes would be accessible
// were access to be permitted
System.err.format("%s is inaccessible\n", store);
}
// two distinct FileStores should not be equal
assertTrue(!store.equals(prev));
prev = store;
}
// two distinct FileStores should not be equal
assertTrue(!store.equals(prev));
prev = store;
} else {
System.err.println
("Skipping FileStore check due to file system access failure");
}
}
}
/*
* 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
......@@ -24,12 +24,25 @@
/* @test
* @bug 4313887 6838333
* @summary Unit test for java.nio.file.FileSystem
* @library ..
* @library .. /lib/testlibrary
* @build jdk.testlibrary.FileUtils
* @run main Basic
*/
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;
import jdk.testlibrary.FileUtils;
/**
* Simple santity checks for java.nio.file.FileSystem
......@@ -41,6 +54,20 @@ public class Basic {
throw new RuntimeException(msg);
}
static void checkFileStores(FileSystem fs) throws IOException {
// sanity check method
if (FileUtils.areFileSystemsAccessible()) {
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 file system access failure");
}
}
static void checkSupported(FileSystem fs, String... views) {
for (String view: views) {
check(fs.supportedFileAttributeViews().contains(view),
......@@ -48,7 +75,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 +92,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(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"))
......
......@@ -33,6 +33,7 @@ import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
/**
......@@ -190,5 +191,41 @@ public final class FileUtils {
}
return excs;
}
/**
* Checks whether all file systems are accessible. This is performed
* by checking free disk space on all mounted file systems via a
* separate, spawned process. File systems are considered to be
* accessible if this process completes successfully before a given
* fixed duration has elapsed.
*
* @implNote On Unix this executes the {@code df} command in a separate
* process and on Windows always returns {@code true}.
*/
public static boolean areFileSystemsAccessible() throws IOException {
boolean areFileSystemsAccessible = true;
if (!isWindows) {
// try to check whether 'df' hangs
System.out.println("\n--- df output ---");
System.out.flush();
Process proc = new ProcessBuilder("df").inheritIO().start();
try {
proc.waitFor(90, TimeUnit.SECONDS);
} catch (InterruptedException ignored) {
}
try {
int exitValue = proc.exitValue();
if (exitValue != 0) {
System.err.printf("df process exited with %d != 0%n",
exitValue);
areFileSystemsAccessible = false;
}
} catch (IllegalThreadStateException ignored) {
System.err.println("df command apparently hung");
areFileSystemsAccessible = false;
}
}
return areFileSystemsAccessible;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册