author | bpb |
Thu, 06 Jun 2019 14:13:59 -0700 | |
changeset 55271 | 5c7c3662c386 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1 |
/* |
55271
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved. |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
4 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
8 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
13 |
* accompanied this code). |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
14 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
18 |
* |
5506 | 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. |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
22 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
23 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
24 |
/* @test |
8537
045f48a970d8
7020517: (fs) FileStore.equals returns true if both volumes have the same serial number
alanb
parents:
8158
diff
changeset
|
25 |
* @bug 4313887 6873621 6979526 7006126 7020517 |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
26 |
* @summary Unit test for java.nio.file.FileStore |
44121
3ed4e4e86d3f
8176237: (fs) java/nio/file/FileStore/Basic.java should conditionally check FileStores
bpb
parents:
39561
diff
changeset
|
27 |
* @key intermittent |
45286
cd809e28c082
8180887: move FileUtils to top level testlibrary
iignatyev
parents:
44121
diff
changeset
|
28 |
* @library .. /test/lib |
45467
99c87a16a8e4
8181761: add explicit @build actions for jdk.test.lib classes in all :tier2 tests
iignatyev
parents:
45286
diff
changeset
|
29 |
* @build jdk.test.lib.Platform |
99c87a16a8e4
8181761: add explicit @build actions for jdk.test.lib classes in all :tier2 tests
iignatyev
parents:
45286
diff
changeset
|
30 |
* jdk.test.lib.util.FileUtils |
44121
3ed4e4e86d3f
8176237: (fs) java/nio/file/FileStore/Basic.java should conditionally check FileStores
bpb
parents:
39561
diff
changeset
|
31 |
* @run main Basic |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
32 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
33 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
34 |
import java.nio.file.*; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
35 |
import java.nio.file.attribute.*; |
8158 | 36 |
import java.io.File; |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
37 |
import java.io.IOException; |
45286
cd809e28c082
8180887: move FileUtils to top level testlibrary
iignatyev
parents:
44121
diff
changeset
|
38 |
|
cd809e28c082
8180887: move FileUtils to top level testlibrary
iignatyev
parents:
44121
diff
changeset
|
39 |
import jdk.test.lib.util.FileUtils; |
44121
3ed4e4e86d3f
8176237: (fs) java/nio/file/FileStore/Basic.java should conditionally check FileStores
bpb
parents:
39561
diff
changeset
|
40 |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
41 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
42 |
public class Basic { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
43 |
|
8158 | 44 |
static final long G = 1024L * 1024L * 1024L; |
45 |
||
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
46 |
public static void main(String[] args) throws IOException { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
47 |
Path dir = TestUtil.createTemporaryDirectory(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
48 |
try { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
49 |
doTests(dir); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
50 |
} finally { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
51 |
TestUtil.removeAll(dir); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
52 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
53 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
54 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
55 |
static void assertTrue(boolean okay) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
56 |
if (!okay) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
57 |
throw new RuntimeException("Assertion failed"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
58 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
59 |
|
8158 | 60 |
static void checkWithin1GB(long value1, long value2) { |
61 |
long diff = Math.abs(value1 - value2); |
|
62 |
if (diff > G) |
|
63 |
throw new RuntimeException("values differ by more than 1GB"); |
|
64 |
} |
|
65 |
||
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
66 |
static void doTests(Path dir) throws IOException { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
67 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
68 |
* Test: Directory should be on FileStore that is writable |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
69 |
*/ |
8158 | 70 |
assertTrue(!Files.getFileStore(dir).isReadOnly()); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
71 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
72 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
73 |
* Test: Two files should have the same FileStore |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
74 |
*/ |
8158 | 75 |
Path file1 = Files.createFile(dir.resolve("foo")); |
76 |
Path file2 = Files.createFile(dir.resolve("bar")); |
|
77 |
FileStore store1 = Files.getFileStore(file1); |
|
78 |
FileStore store2 = Files.getFileStore(file2); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
79 |
assertTrue(store1.equals(store2)); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
80 |
assertTrue(store2.equals(store1)); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
81 |
assertTrue(store1.hashCode() == store2.hashCode()); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
82 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
83 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
84 |
* Test: File and FileStore attributes |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
85 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
86 |
assertTrue(store1.supportsFileAttributeView("basic")); |
3721
1adb60cc9f39
6873621: (file) FileStore.supportsFileAttributeView(Class<FileAttributeView> type) returns wrong result
alanb
parents:
2057
diff
changeset
|
87 |
assertTrue(store1.supportsFileAttributeView(BasicFileAttributeView.class)); |
1adb60cc9f39
6873621: (file) FileStore.supportsFileAttributeView(Class<FileAttributeView> type) returns wrong result
alanb
parents:
2057
diff
changeset
|
88 |
assertTrue(store1.supportsFileAttributeView("posix") == |
1adb60cc9f39
6873621: (file) FileStore.supportsFileAttributeView(Class<FileAttributeView> type) returns wrong result
alanb
parents:
2057
diff
changeset
|
89 |
store1.supportsFileAttributeView(PosixFileAttributeView.class)); |
1adb60cc9f39
6873621: (file) FileStore.supportsFileAttributeView(Class<FileAttributeView> type) returns wrong result
alanb
parents:
2057
diff
changeset
|
90 |
assertTrue(store1.supportsFileAttributeView("dos") == |
1adb60cc9f39
6873621: (file) FileStore.supportsFileAttributeView(Class<FileAttributeView> type) returns wrong result
alanb
parents:
2057
diff
changeset
|
91 |
store1.supportsFileAttributeView(DosFileAttributeView.class)); |
1adb60cc9f39
6873621: (file) FileStore.supportsFileAttributeView(Class<FileAttributeView> type) returns wrong result
alanb
parents:
2057
diff
changeset
|
92 |
assertTrue(store1.supportsFileAttributeView("acl") == |
1adb60cc9f39
6873621: (file) FileStore.supportsFileAttributeView(Class<FileAttributeView> type) returns wrong result
alanb
parents:
2057
diff
changeset
|
93 |
store1.supportsFileAttributeView(AclFileAttributeView.class)); |
1adb60cc9f39
6873621: (file) FileStore.supportsFileAttributeView(Class<FileAttributeView> type) returns wrong result
alanb
parents:
2057
diff
changeset
|
94 |
assertTrue(store1.supportsFileAttributeView("user") == |
1adb60cc9f39
6873621: (file) FileStore.supportsFileAttributeView(Class<FileAttributeView> type) returns wrong result
alanb
parents:
2057
diff
changeset
|
95 |
store1.supportsFileAttributeView(UserDefinedFileAttributeView.class)); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
96 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
97 |
/** |
8158 | 98 |
* Test: Space atributes |
99 |
*/ |
|
100 |
File f = file1.toFile(); |
|
101 |
long total = f.getTotalSpace(); |
|
102 |
long free = f.getFreeSpace(); |
|
103 |
long usable = f.getUsableSpace(); |
|
104 |
||
105 |
// check values are "close" |
|
106 |
checkWithin1GB(total, store1.getTotalSpace()); |
|
107 |
checkWithin1GB(free, store1.getUnallocatedSpace()); |
|
108 |
checkWithin1GB(usable, store1.getUsableSpace()); |
|
109 |
||
110 |
// get values by name |
|
111 |
checkWithin1GB(total, (Long)store1.getAttribute("totalSpace")); |
|
112 |
checkWithin1GB(free, (Long)store1.getAttribute("unallocatedSpace")); |
|
113 |
checkWithin1GB(usable, (Long)store1.getAttribute("usableSpace")); |
|
114 |
||
115 |
/** |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
116 |
* Test: Enumerate all FileStores |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
117 |
*/ |
55271
5c7c3662c386
8224617: (fs) java/nio/file/FileStore/Basic.java found filesystem twice
bpb
parents:
47216
diff
changeset
|
118 |
if (FileUtils.areAllMountPointsAccessible()) { |
44121
3ed4e4e86d3f
8176237: (fs) java/nio/file/FileStore/Basic.java should conditionally check FileStores
bpb
parents:
39561
diff
changeset
|
119 |
FileStore prev = null; |
3ed4e4e86d3f
8176237: (fs) java/nio/file/FileStore/Basic.java should conditionally check FileStores
bpb
parents:
39561
diff
changeset
|
120 |
for (FileStore store: FileSystems.getDefault().getFileStores()) { |
3ed4e4e86d3f
8176237: (fs) java/nio/file/FileStore/Basic.java should conditionally check FileStores
bpb
parents:
39561
diff
changeset
|
121 |
System.out.format("%s (name=%s type=%s)\n", store, store.name(), |
3ed4e4e86d3f
8176237: (fs) java/nio/file/FileStore/Basic.java should conditionally check FileStores
bpb
parents:
39561
diff
changeset
|
122 |
store.type()); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
123 |
|
44121
3ed4e4e86d3f
8176237: (fs) java/nio/file/FileStore/Basic.java should conditionally check FileStores
bpb
parents:
39561
diff
changeset
|
124 |
// check space attributes are accessible |
3ed4e4e86d3f
8176237: (fs) java/nio/file/FileStore/Basic.java should conditionally check FileStores
bpb
parents:
39561
diff
changeset
|
125 |
try { |
3ed4e4e86d3f
8176237: (fs) java/nio/file/FileStore/Basic.java should conditionally check FileStores
bpb
parents:
39561
diff
changeset
|
126 |
store.getTotalSpace(); |
3ed4e4e86d3f
8176237: (fs) java/nio/file/FileStore/Basic.java should conditionally check FileStores
bpb
parents:
39561
diff
changeset
|
127 |
store.getUnallocatedSpace(); |
3ed4e4e86d3f
8176237: (fs) java/nio/file/FileStore/Basic.java should conditionally check FileStores
bpb
parents:
39561
diff
changeset
|
128 |
store.getUsableSpace(); |
3ed4e4e86d3f
8176237: (fs) java/nio/file/FileStore/Basic.java should conditionally check FileStores
bpb
parents:
39561
diff
changeset
|
129 |
} catch (NoSuchFileException nsfe) { |
3ed4e4e86d3f
8176237: (fs) java/nio/file/FileStore/Basic.java should conditionally check FileStores
bpb
parents:
39561
diff
changeset
|
130 |
// ignore exception as the store could have been |
3ed4e4e86d3f
8176237: (fs) java/nio/file/FileStore/Basic.java should conditionally check FileStores
bpb
parents:
39561
diff
changeset
|
131 |
// deleted since the iterator was instantiated |
3ed4e4e86d3f
8176237: (fs) java/nio/file/FileStore/Basic.java should conditionally check FileStores
bpb
parents:
39561
diff
changeset
|
132 |
System.err.format("%s was not found\n", store); |
3ed4e4e86d3f
8176237: (fs) java/nio/file/FileStore/Basic.java should conditionally check FileStores
bpb
parents:
39561
diff
changeset
|
133 |
} catch (AccessDeniedException ade) { |
3ed4e4e86d3f
8176237: (fs) java/nio/file/FileStore/Basic.java should conditionally check FileStores
bpb
parents:
39561
diff
changeset
|
134 |
// ignore exception as the lack of ability to access the |
3ed4e4e86d3f
8176237: (fs) java/nio/file/FileStore/Basic.java should conditionally check FileStores
bpb
parents:
39561
diff
changeset
|
135 |
// store due to lack of file permission or similar does not |
3ed4e4e86d3f
8176237: (fs) java/nio/file/FileStore/Basic.java should conditionally check FileStores
bpb
parents:
39561
diff
changeset
|
136 |
// reflect whether the space attributes would be accessible |
3ed4e4e86d3f
8176237: (fs) java/nio/file/FileStore/Basic.java should conditionally check FileStores
bpb
parents:
39561
diff
changeset
|
137 |
// were access to be permitted |
3ed4e4e86d3f
8176237: (fs) java/nio/file/FileStore/Basic.java should conditionally check FileStores
bpb
parents:
39561
diff
changeset
|
138 |
System.err.format("%s is inaccessible\n", store); |
3ed4e4e86d3f
8176237: (fs) java/nio/file/FileStore/Basic.java should conditionally check FileStores
bpb
parents:
39561
diff
changeset
|
139 |
} |
3ed4e4e86d3f
8176237: (fs) java/nio/file/FileStore/Basic.java should conditionally check FileStores
bpb
parents:
39561
diff
changeset
|
140 |
|
3ed4e4e86d3f
8176237: (fs) java/nio/file/FileStore/Basic.java should conditionally check FileStores
bpb
parents:
39561
diff
changeset
|
141 |
// two distinct FileStores should not be equal |
3ed4e4e86d3f
8176237: (fs) java/nio/file/FileStore/Basic.java should conditionally check FileStores
bpb
parents:
39561
diff
changeset
|
142 |
assertTrue(!store.equals(prev)); |
3ed4e4e86d3f
8176237: (fs) java/nio/file/FileStore/Basic.java should conditionally check FileStores
bpb
parents:
39561
diff
changeset
|
143 |
prev = store; |
32008
55efc6c88c68
8073078: java/nio/file/FileStore/Basic.java sensitive to NFS configuration
bpb
parents:
29528
diff
changeset
|
144 |
} |
44121
3ed4e4e86d3f
8176237: (fs) java/nio/file/FileStore/Basic.java should conditionally check FileStores
bpb
parents:
39561
diff
changeset
|
145 |
} else { |
3ed4e4e86d3f
8176237: (fs) java/nio/file/FileStore/Basic.java should conditionally check FileStores
bpb
parents:
39561
diff
changeset
|
146 |
System.err.println |
3ed4e4e86d3f
8176237: (fs) java/nio/file/FileStore/Basic.java should conditionally check FileStores
bpb
parents:
39561
diff
changeset
|
147 |
("Skipping FileStore check due to file system access failure"); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
148 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
149 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
150 |
} |