1 /* |
1 /* |
2 * Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
28 * @build jdk.testlibrary.FileUtils |
28 * @build jdk.testlibrary.FileUtils |
29 * @run main/othervm Basic |
29 * @run main/othervm Basic |
30 */ |
30 */ |
31 |
31 |
32 import java.io.File; |
32 import java.io.File; |
33 import java.nio.file.*; |
|
34 import java.io.IOException; |
33 import java.io.IOException; |
35 import java.net.URI; |
34 import java.net.URI; |
36 import java.net.URISyntaxException; |
35 import java.net.URISyntaxException; |
|
36 import java.nio.file.Files; |
|
37 import java.nio.file.FileStore; |
|
38 import java.nio.file.FileSystem; |
|
39 import java.nio.file.FileSystems; |
|
40 import java.nio.file.Path; |
|
41 import java.nio.file.Paths; |
|
42 import java.nio.file.ProviderNotFoundException; |
37 import java.util.HashMap; |
43 import java.util.HashMap; |
|
44 import java.util.concurrent.TimeUnit; |
38 import jdk.testlibrary.FileUtils; |
45 import jdk.testlibrary.FileUtils; |
39 |
46 |
40 /** |
47 /** |
41 * Simple sanity checks for java.nio.file.FileSystem |
48 * Simple sanity checks for java.nio.file.FileSystem |
42 */ |
49 */ |
43 public class Basic { |
50 public class Basic { |
44 |
51 |
45 static void check(boolean okay, String msg) { |
52 static void check(boolean okay, String msg) { |
46 if (!okay) |
53 if (!okay) |
47 throw new RuntimeException(msg); |
54 throw new RuntimeException(msg); |
|
55 } |
|
56 |
|
57 static void checkFileStores(String os, FileSystem fs) throws IOException { |
|
58 boolean checkFileStores = true; |
|
59 if (!os.equals("Windows")) { |
|
60 // try to check whether 'df' hangs |
|
61 System.out.println("\n--- Begin df output ---"); |
|
62 System.out.flush(); |
|
63 Process proc = new ProcessBuilder("df").inheritIO().start(); |
|
64 try { |
|
65 proc.waitFor(90, TimeUnit.SECONDS); |
|
66 } catch (InterruptedException ignored) { |
|
67 } |
|
68 System.out.println("--- End df output ---\n"); |
|
69 System.out.flush(); |
|
70 try { |
|
71 int exitValue = proc.exitValue(); |
|
72 if (exitValue != 0) { |
|
73 System.err.printf("df process exited with %d != 0%n", |
|
74 exitValue); |
|
75 checkFileStores = false; |
|
76 } |
|
77 } catch (IllegalThreadStateException ignored) { |
|
78 System.err.println("df command apparently hung"); |
|
79 checkFileStores = false; |
|
80 } |
|
81 } |
|
82 |
|
83 // sanity check method |
|
84 if (checkFileStores) { |
|
85 System.out.println("\n--- Begin FileStores ---"); |
|
86 for (FileStore store: fs.getFileStores()) { |
|
87 System.out.println(store); |
|
88 } |
|
89 System.out.println("--- EndFileStores ---\n"); |
|
90 } else { |
|
91 System.err.println("Skipping FileStore check due to df failure"); |
|
92 } |
48 } |
93 } |
49 |
94 |
50 static void checkSupported(FileSystem fs, String... views) { |
95 static void checkSupported(FileSystem fs, String... views) { |
51 for (String view: views) { |
96 for (String view: views) { |
52 check(fs.supportedFileAttributeViews().contains(view), |
97 check(fs.supportedFileAttributeViews().contains(view), |
68 System.out.println("Expected ProviderNotFoundException caught: " |
113 System.out.println("Expected ProviderNotFoundException caught: " |
69 + "\"" + pnfe.getMessage() + "\""); |
114 + "\"" + pnfe.getMessage() + "\""); |
70 } |
115 } |
71 } |
116 } |
72 |
117 |
73 public static void main(String[] args) throws IOException, URISyntaxException { |
118 public static void main(String[] args) |
|
119 throws IOException, URISyntaxException { |
|
120 String os = System.getProperty("os.name"); |
74 FileSystem fs = FileSystems.getDefault(); |
121 FileSystem fs = FileSystems.getDefault(); |
75 |
122 |
76 // close should throw UOE |
123 // close should throw UOE |
77 try { |
124 try { |
78 fs.close(); |
125 fs.close(); |
83 check(!fs.isReadOnly(), "should provide read-write access"); |
130 check(!fs.isReadOnly(), "should provide read-write access"); |
84 |
131 |
85 check(fs.provider().getScheme().equals("file"), |
132 check(fs.provider().getScheme().equals("file"), |
86 "should use 'file' scheme"); |
133 "should use 'file' scheme"); |
87 |
134 |
88 // santity check method - need to re-visit this in future as I/O errors |
135 // sanity check FileStores |
89 // are possible |
136 checkFileStores(os, fs); |
90 for (FileStore store: fs.getFileStores()) { |
|
91 System.out.println(store); |
|
92 } |
|
93 |
137 |
94 // sanity check supportedFileAttributeViews |
138 // sanity check supportedFileAttributeViews |
95 checkSupported(fs, "basic"); |
139 checkSupported(fs, "basic"); |
96 String os = System.getProperty("os.name"); |
|
97 if (os.equals("SunOS")) |
140 if (os.equals("SunOS")) |
98 checkSupported(fs, "posix", "unix", "owner", "acl", "user"); |
141 checkSupported(fs, "posix", "unix", "owner", "acl", "user"); |
99 if (os.equals("Linux")) |
142 if (os.equals("Linux")) |
100 checkSupported(fs, "posix", "unix", "owner", "dos", "user"); |
143 checkSupported(fs, "posix", "unix", "owner", "dos", "user"); |
101 if (os.contains("OS X")) |
144 if (os.contains("OS X")) |