2323import org .jetbrains .annotations .Nullable ;
2424import org .junit .Assert ;
2525import org .junit .Test ;
26+ import org .labkey .api .annotations .JavaRuntimeVersion ;
2627import org .labkey .api .cloud .CloudWatchService ;
2728import org .labkey .api .cloud .CloudWatcherConfig ;
2829import org .labkey .api .collections .ConcurrentHashSet ;
6162import static java .nio .file .StandardWatchEventKinds .OVERFLOW ;
6263
6364/**
64- * Wraps the low-level Java WatchService API with a simple listener-based interface. Unlike WatchService, which is limited to one
65- * registration per file system directory, a single instance of this class should be sufficient to handle all file system listener
66- * needs of the entire server.
67- *
68- * Callers register a FileSystemDirectoryListener on a directory Path, specifying the desired WatchEvent.Kinds (CREATE, DELETE,
69- * and/or MODIFY); whenever an event occurs on any file or child directory in that directory, the appropriate method is invoked
70- * on all listeners registered on that directory that have requested notification of that event.
71- *
72- * This class is thread-safe, for both listener registration and event invocation. Implementations of FileSystemDirectoryListener
73- * must be thread-safe. Listener methods must return quickly since they are all invoked by a single thread.
65+ * <p>Wraps the low-level Java WatchService API with a simple listener-based interface. Unlike WatchService, which is
66+ * limited to one registration per file system directory, a single instance of this class should be sufficient to handle
67+ * all file system listener needs of the entire server.
68+ * </p>
69+ * <p>
70+ * Callers register a FileSystemDirectoryListener on a directory Path, specifying the desired WatchEvent.Kinds (CREATE,
71+ * DELETE, and/or MODIFY); whenever an event occurs on any file or child directory in that directory, the appropriate
72+ * method is invoked on all listeners registered on that directory that have requested notification of that event.
73+ * </p>
74+ * <p>
75+ * This class is thread-safe, for both listener registration and event invocation. Implementations of
76+ * FileSystemDirectoryListener must be thread-safe. Listener methods must return quickly since they are all invoked by a
77+ * single thread.
78+ * </p>
7479 */
7580public class FileSystemWatcherImpl implements FileSystemWatcher
7681{
@@ -586,8 +591,10 @@ public void overflow()
586591
587592 assertEquals (3 , created .size ());
588593 assertTrue (created .containsAll (Set .of ("a" , "b" , "c" )));
589- // Note: Modified events occur on delete on Windows, but not Linux
590- Set <String > expectedModified = SystemUtils .IS_OS_WINDOWS ? Set .of ("a" , "b" , "c" ) : Set .of ("a" , "c" );
594+ // Note: In Java 17 on Windows, modified events occur on delete. This has never been the case on Linux and
595+ // is no longer the case in Java 25. TODO: Delete this check once we require Java 25
596+ @ JavaRuntimeVersion
597+ Set <String > expectedModified = SystemUtils .IS_OS_WINDOWS && SystemUtils .IS_JAVA_17 ? Set .of ("a" , "b" , "c" ) : Set .of ("a" , "c" );
591598 assertEquals (expectedModified .size (), modified .size ());
592599 assertTrue (created .containsAll (expectedModified ));
593600 int deletedCount = deleted .size ();
@@ -613,9 +620,9 @@ private void waitForEvents(AtomicInteger events, int targetCount) throws Interru
613620 i ++;
614621 }
615622
616- LOG .info ("Waiting for file watcher events took " + StringUtilsLabKey .pluralize (i , "second" ));
623+ LOG .info ("Waiting for file watcher events took {}" , StringUtilsLabKey .pluralize (i , "second" ));
617624
618- LOG .info ("Actual event count: " + events . get () + " vs. target: " + targetCount );
625+ LOG .info ("Actual event count: {} vs. target: {}" , events . get (), targetCount );
619626 //assertEquals(expectedEventCount, events.get());
620627 }
621628 }
0 commit comments