From c3b3895160a0bb6eb793b4af3136976f5d2f7e2d Mon Sep 17 00:00:00 2001 From: Brian Burkhalter Date: Fri, 24 Feb 2017 11:28:00 -0800 Subject: [PATCH] 8175115: Improve instrumentation of java/nio/file/WatchService/LotsOfEvents.java Attempt an additional long poll to check for missed events and print more information Reviewed-by: rriggs --- .../nio/file/WatchService/LotsOfEvents.java | 49 +++++++++++++------ 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/jdk/test/java/nio/file/WatchService/LotsOfEvents.java b/jdk/test/java/nio/file/WatchService/LotsOfEvents.java index 042dfd94146..6990c1e8d89 100644 --- a/jdk/test/java/nio/file/WatchService/LotsOfEvents.java +++ b/jdk/test/java/nio/file/WatchService/LotsOfEvents.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2017, 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 @@ -23,22 +23,25 @@ /* @test * @bug 6907760 6929532 - * @summary Tests WatchService behavior when lots of events are pending + * @summary Tests WatchService behavior when lots of events are pending (use -Dseed=X to set PRNG seed) * @library .. + * @library /lib/testlibrary/ + * @build jdk.testlibrary.* * @run main/timeout=180 LotsOfEvents * @key randomness */ -import java.nio.file.*; -import static java.nio.file.StandardWatchEventKinds.*; import java.io.IOException; import java.io.OutputStream; +import java.nio.file.*; +import static java.nio.file.StandardWatchEventKinds.*; import java.util.*; import java.util.concurrent.TimeUnit; +import jdk.testlibrary.RandomFactory; public class LotsOfEvents { - static final Random rand = new Random(); + private static final Random RAND = RandomFactory.getRandom(); public static void main(String[] args) throws Exception { Path dir = TestUtil.createTemporaryDirectory(); @@ -70,7 +73,7 @@ public class LotsOfEvents { Thread.sleep(1000); // check that we see the create events (or overflow) - drainAndCheckOverflowEvents(watcher, ENTRY_CREATE, n); + drainAndCheckOverflowEvents(dir, watcher, ENTRY_CREATE, n); // delete the files for (int i=0; i expectedKind, int count) throws IOException, InterruptedException @@ -123,8 +127,25 @@ public class LotsOfEvents { } // check that all expected events were received or there was an overflow - if (nread < count && !gotOverflow) - throw new RuntimeException("Insufficient events"); + if (nread < count && !gotOverflow) { + System.err.printf("Test directory %s contains %d files%n", + dir, Files.list(dir).count()); + + long timeBeforePoll = System.nanoTime(); + key = watcher.poll(15, TimeUnit.SECONDS); + long timeAfterPoll = System.nanoTime(); + if (key == null) { + System.err.println("key still null after extra polling"); + } else { + List> events = key.pollEvents(); + System.err.printf("Retrieved key with %d events after %d ns%n", + events.size(), timeAfterPoll - timeBeforePoll); + } + + throw new RuntimeException("Insufficient " + + expectedKind.name() + " events: expected " + + count + ", received " + nread); + } } /** @@ -134,14 +155,14 @@ public class LotsOfEvents { throws IOException, InterruptedException { // this test uses a random number of files - final int nfiles = 5 + rand.nextInt(10); + final int nfiles = 5 + RAND.nextInt(10); DirectoryEntry[] entries = new DirectoryEntry[nfiles]; for (int i=0; i