diff --git a/test/java/nio/file/FileSystem/Basic.java b/test/java/nio/file/FileSystem/Basic.java index 89903611b4f8068f88424ee39b86c301d02ed117..be123db34c7dcdfa57f89e1fd35dff919b8cab13 100644 --- a/test/java/nio/file/FileSystem/Basic.java +++ b/test/java/nio/file/FileSystem/Basic.java @@ -1,5 +1,5 @@ /* - * 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"))