Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/nio/file/WatchService/UpdateInterference.java
38828 views
1
/*
2
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
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
/* @test
25
* @bug 8145981
26
* @summary LinuxWatchService sometimes reports inotify events against wrong directory
27
* @run main UpdateInterference
28
*/
29
import java.io.IOException;
30
import java.nio.file.*;
31
import java.util.List;
32
import java.util.concurrent.TimeUnit;
33
import static java.nio.file.StandardWatchEventKinds.*;
34
35
public class UpdateInterference {
36
public static void main(String[] args) throws IOException, InterruptedException {
37
final Path root = Files.createTempDirectory("test");
38
final Path foo = root.resolve("foo");
39
final Path bar = root.resolve("bar");
40
final Path baz = root.resolve("baz");
41
42
Files.createDirectory(foo);
43
Files.createDirectory(bar);
44
Files.createDirectory(baz);
45
46
final WatchService watcher = root.getFileSystem().newWatchService();
47
final WatchKey fooKey = foo.register(watcher, ENTRY_CREATE);
48
final WatchKey barKey = bar.register(watcher, ENTRY_CREATE);
49
50
new Thread() {
51
{ setDaemon(true); }
52
53
@Override
54
public void run() {
55
while (true) {
56
try {
57
final Path temp = Files.createTempFile(foo, "temp", ".tmp");
58
Files.delete(temp);
59
Thread.sleep(10);
60
} catch (IOException | InterruptedException e) {
61
throw new RuntimeException(e);
62
}
63
}
64
}
65
}.start();
66
67
new Thread() {
68
{ setDaemon(true); }
69
70
@Override
71
public void run() {
72
WatchKey bazKeys[] = new WatchKey[32];
73
while (true) {
74
try {
75
for( int i = 0; i < bazKeys.length; i++) {
76
bazKeys[i] = baz.register(watcher, ENTRY_CREATE);
77
}
78
for( int i = 0; i < bazKeys.length; i++) {
79
bazKeys[i].cancel();
80
}
81
Thread.sleep(1);
82
} catch (IOException | InterruptedException e) {
83
throw new RuntimeException(e);
84
}
85
}
86
}
87
}.start();
88
89
long time = System.currentTimeMillis();
90
while ((System.currentTimeMillis() - time) < 15000) {
91
final WatchKey key = watcher.poll(60, TimeUnit.SECONDS);
92
if (key == null) continue;
93
94
if (key != fooKey) {
95
List<WatchEvent<?>> pollEvents = key.pollEvents();
96
for (WatchEvent<?> watchEvent : pollEvents) {
97
System.out.println(watchEvent.count() + " " +
98
watchEvent.kind() + " " +
99
watchEvent.context());
100
}
101
throw new RuntimeException("Event received for unexpected key");
102
}
103
key.reset();
104
}
105
}
106
}
107
108
109