author | chegar |
Thu, 17 Oct 2019 20:54:25 +0100 | |
branch | datagramsocketimpl-branch |
changeset 58679 | 9c3209ff7550 |
parent 58678 | 9cf78a70fa4f |
parent 55677 | 4b1de39beda3 |
permissions | -rw-r--r-- |
45267 | 1 |
/* |
55271
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
2 |
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved. |
45267 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
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 |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
||
24 |
package jdk.test.lib.util; |
|
25 |
||
26 |
import jdk.test.lib.Platform; |
|
27 |
||
55271
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
28 |
import java.io.BufferedReader; |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
29 |
import java.io.InputStreamReader; |
45267 | 30 |
import java.io.IOException; |
50727
081b132c4dc0
8202292: java/io/FileOutputStream/UnreferencedFOSClosesFd.java fails with "raw fd count wrong"
rriggs
parents:
47249
diff
changeset
|
31 |
import java.io.PrintStream; |
081b132c4dc0
8202292: java/io/FileOutputStream/UnreferencedFOSClosesFd.java fails with "raw fd count wrong"
rriggs
parents:
47249
diff
changeset
|
32 |
import java.io.UncheckedIOException; |
081b132c4dc0
8202292: java/io/FileOutputStream/UnreferencedFOSClosesFd.java fails with "raw fd count wrong"
rriggs
parents:
47249
diff
changeset
|
33 |
import java.lang.ProcessBuilder.Redirect; |
45267 | 34 |
import java.nio.file.DirectoryNotEmptyException; |
35 |
import java.nio.file.FileVisitResult; |
|
36 |
import java.nio.file.Files; |
|
37 |
import java.nio.file.NoSuchFileException; |
|
38 |
import java.nio.file.Path; |
|
50727
081b132c4dc0
8202292: java/io/FileOutputStream/UnreferencedFOSClosesFd.java fails with "raw fd count wrong"
rriggs
parents:
47249
diff
changeset
|
39 |
import java.nio.file.Paths; |
45267 | 40 |
import java.nio.file.SimpleFileVisitor; |
41 |
import java.nio.file.attribute.BasicFileAttributes; |
|
50727
081b132c4dc0
8202292: java/io/FileOutputStream/UnreferencedFOSClosesFd.java fails with "raw fd count wrong"
rriggs
parents:
47249
diff
changeset
|
42 |
import java.time.Instant; |
081b132c4dc0
8202292: java/io/FileOutputStream/UnreferencedFOSClosesFd.java fails with "raw fd count wrong"
rriggs
parents:
47249
diff
changeset
|
43 |
import java.time.Duration; |
51107
35e64b62b284
8205610: [TESTLIB] Improve listing of open file descriptors
rriggs
parents:
50727
diff
changeset
|
44 |
import java.util.Arrays; |
45267 | 45 |
import java.util.ArrayList; |
50727
081b132c4dc0
8202292: java/io/FileOutputStream/UnreferencedFOSClosesFd.java fails with "raw fd count wrong"
rriggs
parents:
47249
diff
changeset
|
46 |
import java.util.ArrayDeque; |
081b132c4dc0
8202292: java/io/FileOutputStream/UnreferencedFOSClosesFd.java fails with "raw fd count wrong"
rriggs
parents:
47249
diff
changeset
|
47 |
import java.util.HashSet; |
45267 | 48 |
import java.util.List; |
50727
081b132c4dc0
8202292: java/io/FileOutputStream/UnreferencedFOSClosesFd.java fails with "raw fd count wrong"
rriggs
parents:
47249
diff
changeset
|
49 |
import java.util.Optional; |
55271
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
50 |
import java.util.concurrent.atomic.AtomicBoolean; |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
51 |
import java.util.concurrent.atomic.AtomicReference; |
45267 | 52 |
import java.util.concurrent.TimeUnit; |
53 |
||
54 |
/** |
|
55 |
* Common library for various test file utility functions. |
|
56 |
*/ |
|
57 |
public final class FileUtils { |
|
58 |
private static final boolean IS_WINDOWS = Platform.isWindows(); |
|
59 |
private static final int RETRY_DELETE_MILLIS = IS_WINDOWS ? 500 : 0; |
|
60 |
private static final int MAX_RETRY_DELETE_TIMES = IS_WINDOWS ? 15 : 0; |
|
61 |
||
62 |
/** |
|
63 |
* Deletes a file, retrying if necessary. |
|
64 |
* |
|
65 |
* @param path the file to delete |
|
66 |
* |
|
67 |
* @throws NoSuchFileException |
|
68 |
* if the file does not exist (optional specific exception) |
|
69 |
* @throws DirectoryNotEmptyException |
|
70 |
* if the file is a directory and could not otherwise be deleted |
|
71 |
* because the directory is not empty (optional specific exception) |
|
72 |
* @throws IOException |
|
73 |
* if an I/O error occurs |
|
74 |
*/ |
|
75 |
public static void deleteFileWithRetry(Path path) throws IOException { |
|
76 |
try { |
|
77 |
deleteFileWithRetry0(path); |
|
78 |
} catch (InterruptedException x) { |
|
79 |
throw new IOException("Interrupted while deleting.", x); |
|
80 |
} |
|
81 |
} |
|
82 |
||
83 |
/** |
|
84 |
* Deletes a file, retrying if necessary. |
|
85 |
* No exception thrown if file doesn't exist. |
|
86 |
* |
|
87 |
* @param path the file to delete |
|
88 |
* |
|
89 |
* @throws NoSuchFileException |
|
90 |
* if the file does not exist (optional specific exception) |
|
91 |
* @throws DirectoryNotEmptyException |
|
92 |
* if the file is a directory and could not otherwise be deleted |
|
93 |
* because the directory is not empty (optional specific exception) |
|
94 |
* @throws IOException |
|
95 |
* if an I/O error occurs |
|
96 |
*/ |
|
97 |
public static void deleteFileIfExistsWithRetry(Path path) throws IOException { |
|
98 |
try { |
|
55677
4b1de39beda3
8227438: [TESTLIB] Determine if file exists by Files.exists in function FileUtils.deleteFileIfExistsWithRetry
fyuan
parents:
55271
diff
changeset
|
99 |
if (!Files.notExists(path)) { |
45267 | 100 |
deleteFileWithRetry0(path); |
101 |
} |
|
102 |
} catch (InterruptedException x) { |
|
103 |
throw new IOException("Interrupted while deleting.", x); |
|
104 |
} |
|
105 |
} |
|
106 |
||
107 |
private static void deleteFileWithRetry0(Path path) |
|
108 |
throws IOException, InterruptedException { |
|
109 |
int times = 0; |
|
110 |
IOException ioe = null; |
|
111 |
while (true) { |
|
112 |
try { |
|
113 |
Files.delete(path); |
|
47249
82c43b3c0ea0
8185458: Added comment for Files.notExists in FileUtils test library
anazarov
parents:
45920
diff
changeset
|
114 |
// Checks for absence of the file. Semantics of Files.exists() is not the same. |
45920
ddc079e73172
8184961: jdk.test.lib.util.FileUtils.deleteFileWithRetry0 should wait for absence of a file
anazarov
parents:
45267
diff
changeset
|
115 |
while (!Files.notExists(path)) { |
45267 | 116 |
times++; |
117 |
if (times > MAX_RETRY_DELETE_TIMES) { |
|
118 |
throw new IOException("File still exists after " + times + " waits."); |
|
119 |
} |
|
120 |
Thread.sleep(RETRY_DELETE_MILLIS); |
|
121 |
} |
|
122 |
break; |
|
123 |
} catch (NoSuchFileException | DirectoryNotEmptyException x) { |
|
124 |
throw x; |
|
125 |
} catch (IOException x) { |
|
126 |
// Backoff/retry in case another process is accessing the file |
|
127 |
times++; |
|
128 |
if (ioe == null) { |
|
129 |
ioe = x; |
|
130 |
} else { |
|
131 |
ioe.addSuppressed(x); |
|
132 |
} |
|
133 |
||
134 |
if (times > MAX_RETRY_DELETE_TIMES) { |
|
135 |
throw ioe; |
|
136 |
} |
|
137 |
Thread.sleep(RETRY_DELETE_MILLIS); |
|
138 |
} |
|
139 |
} |
|
140 |
} |
|
141 |
||
142 |
/** |
|
143 |
* Deletes a directory and its subdirectories, retrying if necessary. |
|
144 |
* |
|
145 |
* @param dir the directory to delete |
|
146 |
* |
|
147 |
* @throws IOException |
|
148 |
* If an I/O error occurs. Any such exceptions are caught |
|
149 |
* internally. If only one is caught, then it is re-thrown. |
|
150 |
* If more than one exception is caught, then the second and |
|
151 |
* following exceptions are added as suppressed exceptions of the |
|
152 |
* first one caught, which is then re-thrown. |
|
153 |
*/ |
|
154 |
public static void deleteFileTreeWithRetry(Path dir) throws IOException { |
|
155 |
IOException ioe = null; |
|
156 |
final List<IOException> excs = deleteFileTreeUnchecked(dir); |
|
157 |
if (!excs.isEmpty()) { |
|
158 |
ioe = excs.remove(0); |
|
159 |
for (IOException x : excs) { |
|
160 |
ioe.addSuppressed(x); |
|
161 |
} |
|
162 |
} |
|
163 |
if (ioe != null) { |
|
164 |
throw ioe; |
|
165 |
} |
|
166 |
} |
|
167 |
||
168 |
public static List<IOException> deleteFileTreeUnchecked(Path dir) { |
|
169 |
final List<IOException> excs = new ArrayList<>(); |
|
170 |
try { |
|
171 |
java.nio.file.Files.walkFileTree(dir, new SimpleFileVisitor<>() { |
|
172 |
@Override |
|
173 |
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { |
|
174 |
try { |
|
175 |
deleteFileWithRetry0(file); |
|
176 |
} catch (IOException x) { |
|
177 |
excs.add(x); |
|
178 |
} catch (InterruptedException x) { |
|
179 |
excs.add(new IOException("Interrupted while deleting.", x)); |
|
180 |
return FileVisitResult.TERMINATE; |
|
181 |
} |
|
182 |
return FileVisitResult.CONTINUE; |
|
183 |
} |
|
184 |
@Override |
|
185 |
public FileVisitResult postVisitDirectory(Path dir, IOException exc) { |
|
186 |
try { |
|
187 |
deleteFileWithRetry0(dir); |
|
188 |
} catch (IOException x) { |
|
189 |
excs.add(x); |
|
190 |
} catch (InterruptedException x) { |
|
191 |
excs.add(new IOException("Interrupted while deleting.", x)); |
|
192 |
return FileVisitResult.TERMINATE; |
|
193 |
} |
|
194 |
return FileVisitResult.CONTINUE; |
|
195 |
} |
|
196 |
@Override |
|
197 |
public FileVisitResult visitFileFailed(Path file, IOException exc) { |
|
198 |
excs.add(exc); |
|
199 |
return FileVisitResult.CONTINUE; |
|
200 |
} |
|
201 |
}); |
|
202 |
} catch (IOException x) { |
|
203 |
excs.add(x); |
|
204 |
} |
|
205 |
return excs; |
|
206 |
} |
|
207 |
||
208 |
/** |
|
209 |
* Checks whether all file systems are accessible. This is performed |
|
210 |
* by checking free disk space on all mounted file systems via a |
|
211 |
* separate, spawned process. File systems are considered to be |
|
212 |
* accessible if this process completes successfully before a given |
|
213 |
* fixed duration has elapsed. |
|
214 |
* |
|
215 |
* @implNote On Unix this executes the {@code df} command in a separate |
|
216 |
* process and on Windows always returns {@code true}. |
|
217 |
*/ |
|
218 |
public static boolean areFileSystemsAccessible() throws IOException { |
|
219 |
boolean areFileSystemsAccessible = true; |
|
220 |
if (!IS_WINDOWS) { |
|
221 |
// try to check whether 'df' hangs |
|
222 |
System.out.println("\n--- df output ---"); |
|
223 |
System.out.flush(); |
|
224 |
Process proc = new ProcessBuilder("df").inheritIO().start(); |
|
225 |
try { |
|
226 |
proc.waitFor(90, TimeUnit.SECONDS); |
|
227 |
} catch (InterruptedException ignored) { |
|
228 |
} |
|
229 |
try { |
|
230 |
int exitValue = proc.exitValue(); |
|
231 |
if (exitValue != 0) { |
|
232 |
System.err.printf("df process exited with %d != 0%n", |
|
233 |
exitValue); |
|
234 |
areFileSystemsAccessible = false; |
|
235 |
} |
|
236 |
} catch (IllegalThreadStateException ignored) { |
|
237 |
System.err.println("df command apparently hung"); |
|
238 |
areFileSystemsAccessible = false; |
|
239 |
} |
|
240 |
} |
|
241 |
return areFileSystemsAccessible; |
|
242 |
} |
|
50727
081b132c4dc0
8202292: java/io/FileOutputStream/UnreferencedFOSClosesFd.java fails with "raw fd count wrong"
rriggs
parents:
47249
diff
changeset
|
243 |
|
081b132c4dc0
8202292: java/io/FileOutputStream/UnreferencedFOSClosesFd.java fails with "raw fd count wrong"
rriggs
parents:
47249
diff
changeset
|
244 |
/** |
55271
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
245 |
* Checks whether all file systems are accessible. This is performed |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
246 |
* by checking free disk space on all mounted file systems via a |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
247 |
* separate, spawned process. File systems are considered to be |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
248 |
* accessible if this process completes successfully before a given |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
249 |
* fixed duration has elapsed. |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
250 |
* |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
251 |
* @implNote On Unix this executes the {@code df} command in a separate |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
252 |
* process and on Windows always returns {@code true}. |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
253 |
* |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
254 |
* @return whether file systems appear to be accessible |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
255 |
* |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
256 |
* @throws RuntimeException if there are duplicate mount points or some |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
257 |
* other execution problem occurs |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
258 |
*/ |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
259 |
public static boolean areAllMountPointsAccessible() { |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
260 |
final AtomicBoolean areMountPointsOK = new AtomicBoolean(true); |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
261 |
if (!IS_WINDOWS) { |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
262 |
Thread thr = new Thread(() -> { |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
263 |
try { |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
264 |
Process proc = new ProcessBuilder("df").start(); |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
265 |
BufferedReader reader = new BufferedReader |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
266 |
(new InputStreamReader(proc.getInputStream())); |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
267 |
// Skip the first line as it is the "df" output header. |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
268 |
if (reader.readLine() != null ) { |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
269 |
String prevMountPoint = null, mountPoint = null; |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
270 |
while ((mountPoint = reader.readLine()) != null) { |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
271 |
if (prevMountPoint != null && |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
272 |
mountPoint.equals(prevMountPoint)) { |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
273 |
throw new RuntimeException |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
274 |
("System configuration error: " + |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
275 |
"duplicate mount point " + mountPoint + |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
276 |
" detected"); |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
277 |
} |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
278 |
prevMountPoint = mountPoint; |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
279 |
} |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
280 |
} |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
281 |
|
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
282 |
try { |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
283 |
proc.waitFor(90, TimeUnit.SECONDS); |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
284 |
} catch (InterruptedException ignored) { |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
285 |
} |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
286 |
try { |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
287 |
int exitValue = proc.exitValue(); |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
288 |
if (exitValue != 0) { |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
289 |
System.err.printf("df process exited with %d != 0%n", |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
290 |
exitValue); |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
291 |
areMountPointsOK.set(false); |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
292 |
} |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
293 |
} catch (IllegalThreadStateException ignored) { |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
294 |
System.err.println("df command apparently hung"); |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
295 |
areMountPointsOK.set(false); |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
296 |
} |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
297 |
} catch (IOException ioe) { |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
298 |
throw new RuntimeException(ioe); |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
299 |
}; |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
300 |
}); |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
301 |
|
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
302 |
final AtomicReference throwableReference = |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
303 |
new AtomicReference<Throwable>(); |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
304 |
thr.setUncaughtExceptionHandler( |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
305 |
new Thread.UncaughtExceptionHandler() { |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
306 |
public void uncaughtException(Thread t, Throwable e) { |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
307 |
throwableReference.set(e); |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
308 |
} |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
309 |
}); |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
310 |
|
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
311 |
thr.start(); |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
312 |
try { |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
313 |
thr.join(120*1000L); |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
314 |
} catch (InterruptedException ie) { |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
315 |
throw new RuntimeException(ie); |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
316 |
} |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
317 |
|
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
318 |
Throwable uncaughtException = (Throwable)throwableReference.get(); |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
319 |
if (uncaughtException != null) { |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
320 |
throw new RuntimeException(uncaughtException); |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
321 |
} |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
322 |
|
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
323 |
if (thr.isAlive()) { |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
324 |
throw new RuntimeException("df thread did not join in time"); |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
325 |
} |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
326 |
} |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
327 |
|
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
328 |
return areMountPointsOK.get(); |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
329 |
} |
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
330 |
|
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
51107
diff
changeset
|
331 |
/** |
50727
081b132c4dc0
8202292: java/io/FileOutputStream/UnreferencedFOSClosesFd.java fails with "raw fd count wrong"
rriggs
parents:
47249
diff
changeset
|
332 |
* List the open file descriptors (if supported by the 'lsof' command). |
081b132c4dc0
8202292: java/io/FileOutputStream/UnreferencedFOSClosesFd.java fails with "raw fd count wrong"
rriggs
parents:
47249
diff
changeset
|
333 |
* @param ps a printStream to send the output to |
081b132c4dc0
8202292: java/io/FileOutputStream/UnreferencedFOSClosesFd.java fails with "raw fd count wrong"
rriggs
parents:
47249
diff
changeset
|
334 |
* @throws UncheckedIOException if an error occurs |
081b132c4dc0
8202292: java/io/FileOutputStream/UnreferencedFOSClosesFd.java fails with "raw fd count wrong"
rriggs
parents:
47249
diff
changeset
|
335 |
*/ |
081b132c4dc0
8202292: java/io/FileOutputStream/UnreferencedFOSClosesFd.java fails with "raw fd count wrong"
rriggs
parents:
47249
diff
changeset
|
336 |
public static void listFileDescriptors(PrintStream ps) { |
51107
35e64b62b284
8205610: [TESTLIB] Improve listing of open file descriptors
rriggs
parents:
50727
diff
changeset
|
337 |
|
35e64b62b284
8205610: [TESTLIB] Improve listing of open file descriptors
rriggs
parents:
50727
diff
changeset
|
338 |
Optional<String[]> lsof = Arrays.stream(lsCommands) |
35e64b62b284
8205610: [TESTLIB] Improve listing of open file descriptors
rriggs
parents:
50727
diff
changeset
|
339 |
.filter(args -> Files.isExecutable(Path.of(args[0]))) |
50727
081b132c4dc0
8202292: java/io/FileOutputStream/UnreferencedFOSClosesFd.java fails with "raw fd count wrong"
rriggs
parents:
47249
diff
changeset
|
340 |
.findFirst(); |
51107
35e64b62b284
8205610: [TESTLIB] Improve listing of open file descriptors
rriggs
parents:
50727
diff
changeset
|
341 |
lsof.ifPresent(args -> { |
50727
081b132c4dc0
8202292: java/io/FileOutputStream/UnreferencedFOSClosesFd.java fails with "raw fd count wrong"
rriggs
parents:
47249
diff
changeset
|
342 |
try { |
081b132c4dc0
8202292: java/io/FileOutputStream/UnreferencedFOSClosesFd.java fails with "raw fd count wrong"
rriggs
parents:
47249
diff
changeset
|
343 |
ps.printf("Open File Descriptors:%n"); |
081b132c4dc0
8202292: java/io/FileOutputStream/UnreferencedFOSClosesFd.java fails with "raw fd count wrong"
rriggs
parents:
47249
diff
changeset
|
344 |
long pid = ProcessHandle.current().pid(); |
51107
35e64b62b284
8205610: [TESTLIB] Improve listing of open file descriptors
rriggs
parents:
50727
diff
changeset
|
345 |
ProcessBuilder pb = new ProcessBuilder(args[0], args[1], Integer.toString((int) pid)); |
50727
081b132c4dc0
8202292: java/io/FileOutputStream/UnreferencedFOSClosesFd.java fails with "raw fd count wrong"
rriggs
parents:
47249
diff
changeset
|
346 |
pb.redirectErrorStream(true); // combine stderr and stdout |
081b132c4dc0
8202292: java/io/FileOutputStream/UnreferencedFOSClosesFd.java fails with "raw fd count wrong"
rriggs
parents:
47249
diff
changeset
|
347 |
pb.redirectOutput(Redirect.PIPE); |
081b132c4dc0
8202292: java/io/FileOutputStream/UnreferencedFOSClosesFd.java fails with "raw fd count wrong"
rriggs
parents:
47249
diff
changeset
|
348 |
|
081b132c4dc0
8202292: java/io/FileOutputStream/UnreferencedFOSClosesFd.java fails with "raw fd count wrong"
rriggs
parents:
47249
diff
changeset
|
349 |
Process p = pb.start(); |
081b132c4dc0
8202292: java/io/FileOutputStream/UnreferencedFOSClosesFd.java fails with "raw fd count wrong"
rriggs
parents:
47249
diff
changeset
|
350 |
Instant start = Instant.now(); |
081b132c4dc0
8202292: java/io/FileOutputStream/UnreferencedFOSClosesFd.java fails with "raw fd count wrong"
rriggs
parents:
47249
diff
changeset
|
351 |
p.getInputStream().transferTo(ps); |
081b132c4dc0
8202292: java/io/FileOutputStream/UnreferencedFOSClosesFd.java fails with "raw fd count wrong"
rriggs
parents:
47249
diff
changeset
|
352 |
|
081b132c4dc0
8202292: java/io/FileOutputStream/UnreferencedFOSClosesFd.java fails with "raw fd count wrong"
rriggs
parents:
47249
diff
changeset
|
353 |
try { |
081b132c4dc0
8202292: java/io/FileOutputStream/UnreferencedFOSClosesFd.java fails with "raw fd count wrong"
rriggs
parents:
47249
diff
changeset
|
354 |
int timeout = 10; |
081b132c4dc0
8202292: java/io/FileOutputStream/UnreferencedFOSClosesFd.java fails with "raw fd count wrong"
rriggs
parents:
47249
diff
changeset
|
355 |
if (!p.waitFor(timeout, TimeUnit.SECONDS)) { |
081b132c4dc0
8202292: java/io/FileOutputStream/UnreferencedFOSClosesFd.java fails with "raw fd count wrong"
rriggs
parents:
47249
diff
changeset
|
356 |
System.out.printf("waitFor timed out: %d%n", timeout); |
081b132c4dc0
8202292: java/io/FileOutputStream/UnreferencedFOSClosesFd.java fails with "raw fd count wrong"
rriggs
parents:
47249
diff
changeset
|
357 |
} |
081b132c4dc0
8202292: java/io/FileOutputStream/UnreferencedFOSClosesFd.java fails with "raw fd count wrong"
rriggs
parents:
47249
diff
changeset
|
358 |
} catch (InterruptedException ie) { |
081b132c4dc0
8202292: java/io/FileOutputStream/UnreferencedFOSClosesFd.java fails with "raw fd count wrong"
rriggs
parents:
47249
diff
changeset
|
359 |
throw new IOException("interrupted", ie); |
081b132c4dc0
8202292: java/io/FileOutputStream/UnreferencedFOSClosesFd.java fails with "raw fd count wrong"
rriggs
parents:
47249
diff
changeset
|
360 |
} |
081b132c4dc0
8202292: java/io/FileOutputStream/UnreferencedFOSClosesFd.java fails with "raw fd count wrong"
rriggs
parents:
47249
diff
changeset
|
361 |
ps.println(); |
081b132c4dc0
8202292: java/io/FileOutputStream/UnreferencedFOSClosesFd.java fails with "raw fd count wrong"
rriggs
parents:
47249
diff
changeset
|
362 |
} catch (IOException ioe) { |
081b132c4dc0
8202292: java/io/FileOutputStream/UnreferencedFOSClosesFd.java fails with "raw fd count wrong"
rriggs
parents:
47249
diff
changeset
|
363 |
throw new UncheckedIOException("error listing file descriptors", ioe); |
081b132c4dc0
8202292: java/io/FileOutputStream/UnreferencedFOSClosesFd.java fails with "raw fd count wrong"
rriggs
parents:
47249
diff
changeset
|
364 |
} |
081b132c4dc0
8202292: java/io/FileOutputStream/UnreferencedFOSClosesFd.java fails with "raw fd count wrong"
rriggs
parents:
47249
diff
changeset
|
365 |
}); |
081b132c4dc0
8202292: java/io/FileOutputStream/UnreferencedFOSClosesFd.java fails with "raw fd count wrong"
rriggs
parents:
47249
diff
changeset
|
366 |
} |
51107
35e64b62b284
8205610: [TESTLIB] Improve listing of open file descriptors
rriggs
parents:
50727
diff
changeset
|
367 |
|
35e64b62b284
8205610: [TESTLIB] Improve listing of open file descriptors
rriggs
parents:
50727
diff
changeset
|
368 |
// Possible command locations and arguments |
35e64b62b284
8205610: [TESTLIB] Improve listing of open file descriptors
rriggs
parents:
50727
diff
changeset
|
369 |
static String[][] lsCommands = new String[][] { |
35e64b62b284
8205610: [TESTLIB] Improve listing of open file descriptors
rriggs
parents:
50727
diff
changeset
|
370 |
{"/usr/bin/lsof", "-p"}, |
35e64b62b284
8205610: [TESTLIB] Improve listing of open file descriptors
rriggs
parents:
50727
diff
changeset
|
371 |
{"/usr/sbin/lsof", "-p"}, |
35e64b62b284
8205610: [TESTLIB] Improve listing of open file descriptors
rriggs
parents:
50727
diff
changeset
|
372 |
{"/bin/lsof", "-p"}, |
35e64b62b284
8205610: [TESTLIB] Improve listing of open file descriptors
rriggs
parents:
50727
diff
changeset
|
373 |
{"/sbin/lsof", "-p"}, |
35e64b62b284
8205610: [TESTLIB] Improve listing of open file descriptors
rriggs
parents:
50727
diff
changeset
|
374 |
{"/usr/local/bin/lsof", "-p"}, |
35e64b62b284
8205610: [TESTLIB] Improve listing of open file descriptors
rriggs
parents:
50727
diff
changeset
|
375 |
{"/usr/bin/pfiles", "-F"}, // Solaris |
35e64b62b284
8205610: [TESTLIB] Improve listing of open file descriptors
rriggs
parents:
50727
diff
changeset
|
376 |
}; |
45267 | 377 |
} |