Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8264539: Improve failure message of java/nio/file/WatchService/SensitivityModifier.java #3290

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -30,10 +30,17 @@
* @key randomness
*/

import java.nio.file.*;
import java.nio.file.Files;
import java.nio.file.FileSystem;
import java.nio.file.Path;
import java.nio.file.WatchEvent;
import java.nio.file.WatchKey;
import java.nio.file.WatchService;
import static java.nio.file.StandardWatchEventKinds.*;
import java.io.OutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.TimeUnit;
import com.sun.nio.file.SensitivityWatchEventModifier;
@@ -42,14 +49,19 @@ public class SensitivityModifier {

static final Random rand = new Random();

static final Map<Path,Integer> pathToTime = new HashMap<>();

static void register(Path[] dirs, WatchService watcher) throws IOException {
SensitivityWatchEventModifier[] sensitivtives =
pathToTime.clear();
SensitivityWatchEventModifier[] sensitivities =
SensitivityWatchEventModifier.values();
for (int i=0; i<dirs.length; i++) {
SensitivityWatchEventModifier sensivity =
sensitivtives[ rand.nextInt(sensitivtives.length) ];
SensitivityWatchEventModifier sensitivity =
sensitivities[rand.nextInt(sensitivities.length)];
Path dir = dirs[i];
dir.register(watcher, new WatchEvent.Kind<?>[]{ ENTRY_MODIFY }, sensivity);
dir.register(watcher, new WatchEvent.Kind<?>[]{ ENTRY_MODIFY },
sensitivity);
pathToTime.put(dir, sensitivity.sensitivityValueInSeconds());
}
}

@@ -108,7 +120,10 @@ static void doTest(Path top) throws Exception {
if (eventReceived) {
System.out.println("Event OK");
} else {
throw new RuntimeException("No ENTRY_MODIFY event received for " + file);
Path parent = file.getParent();
String msg = String.format("No ENTRY_MODIFY event received for %s (dir: %s, sensitivity: %d)",
file, parent, pathToTime.get(parent));
throw new RuntimeException(msg);
Copy link
Contributor

@AlanBateman AlanBateman Apr 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not clear to me that this helps. Have you looked at changing the 1s at L104. I assume the issue is that the test needs the idle (no events) time increased to deal with cases where the watcher is slow to queue events.

Copy link
Member Author

@bplb bplb Apr 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a better idea but I think this change should go in also. I have not in any case been able to reproduce it. There is no record of on which specific machines it was sighted.

Copy link
Contributor

@AlanBateman AlanBateman Apr 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay.

}

// re-register the directories to force changing their sensitivity