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 4313887 6838333
26 * @summary Unit test for java.nio.file.WatchService
27 * @library ..
28 * @run main/timeout=120 Basic
29 */
30
31 import java.nio.file.*;
32 import static java.nio.file.StandardWatchEventKind.*;
33 import java.nio.file.attribute.*;
34 import java.io.*;
35 import java.util.*;
36 import java.util.concurrent.TimeUnit;
37
38 /**
39 * Unit test for WatchService that exercises all methods in various scenarios.
40 */
41
42 public class Basic {
43
44 static void checkKey(WatchKey key, Path dir) {
45 if (!key.isValid())
46 throw new RuntimeException("Key is not valid");
47 }
48
49 static void takeExpectedKey(WatchService watcher, WatchKey expected) {
50 System.out.println("take events...");
51 WatchKey key;
52 try {
53 key = watcher.take();
54 } catch (InterruptedException x) {
55 // not expected
56 throw new RuntimeException(x);
57 }
58 if (key != expected)
59 throw new RuntimeException("removed unexpected key");
60 }
61
62 static void checkExpectedEvent(Iterable<WatchEvent<?>> events,
63 WatchEvent.Kind<?> expectedKind,
64 Object expectedContext)
65 {
66 WatchEvent<?> event = events.iterator().next();
|
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 4313887 6838333 7017446
26 * @summary Unit test for java.nio.file.WatchService
27 * @library ..
28 * @run main/timeout=120 Basic
29 */
30
31 import java.nio.file.*;
32 import static java.nio.file.StandardWatchEventKind.*;
33 import java.nio.file.attribute.*;
34 import java.io.*;
35 import java.util.*;
36 import java.util.concurrent.TimeUnit;
37
38 /**
39 * Unit test for WatchService that exercises all methods in various scenarios.
40 */
41
42 public class Basic {
43
44 static void checkKey(WatchKey key, Path dir) {
45 if (!key.isValid())
46 throw new RuntimeException("Key is not valid");
47 if (key.watchable() != dir)
48 throw new RuntimeException("Unexpected watchable");
49 }
50
51 static void takeExpectedKey(WatchService watcher, WatchKey expected) {
52 System.out.println("take events...");
53 WatchKey key;
54 try {
55 key = watcher.take();
56 } catch (InterruptedException x) {
57 // not expected
58 throw new RuntimeException(x);
59 }
60 if (key != expected)
61 throw new RuntimeException("removed unexpected key");
62 }
63
64 static void checkExpectedEvent(Iterable<WatchEvent<?>> events,
65 WatchEvent.Kind<?> expectedKind,
66 Object expectedContext)
67 {
68 WatchEvent<?> event = events.iterator().next();
|