1 | import java.nio.file.*; |
2 | import static java.nio.file.StandardWatchEventKinds.*; |
3 | |
4 | sbool testJDKWatchService() {
|
5 | ret recordSuccessOrFailure('testJDKWatchService, testJDKWatchService_noLog());
|
6 | }; |
7 | |
8 | sbool testJDKWatchService_noLog() false on exception {
|
9 | final File dir = mkdirs(createTempDir()); |
10 | final Path path = dir.toPath(); |
11 | |
12 | final WatchService watchService = FileSystems.getDefault().newWatchService(); |
13 | final WatchKey watchKey = path.register(watchService, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY, OVERFLOW); |
14 | |
15 | final Set<S> changes = synchroSet(); |
16 | thread {
|
17 | try {
|
18 | saveTextFile(newFile(dir, "bla"), "1"); |
19 | Countdown countdown = fiveSeconds(); |
20 | while (l(changes) < 2 && !countdown.done()) |
21 | sleep(1); |
22 | } finally {
|
23 | watchService.close(); |
24 | } |
25 | } |
26 | |
27 | final Countdown countdown = fiveSeconds(); |
28 | expectException(ClosedWatchServiceException.class, r {
|
29 | while (!countdown.done()) {
|
30 | final WatchKey wk = watchService.take(); |
31 | |
32 | for (WatchEvent<?> event : wk.pollEvents()) pcall {
|
33 | final Path changed = (Path) event.context(); |
34 | print("Changed: " + changed + ", " + event.kind());
|
35 | changes.add(changed.toFile().getName()); |
36 | } |
37 | |
38 | wk.reset(); |
39 | } |
40 | }); |
41 | |
42 | pcall { watchService.close(); }
|
43 | deleteDirectory(dir); |
44 | ret eq(changes, lithashset("bla", "bla_temp"));
|
45 | |
46 | } |
Began life as a copy of #1015923
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1015932 |
| Snippet name: | testJDKWatchService - returns true if OK |
| Eternal ID of this version: | #1015932/8 |
| Text MD5: | 6e237312dbdbe1af8b7b169cb5d8ef10 |
| Author: | stefan |
| Category: | javax / io |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2018-05-31 14:17:29 |
| Source code size: | 1406 bytes / 46 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 608 / 644 |
| Version history: | 7 change(s) |
| Referenced in: | [show references] |