// Test
final AtomicLong watcherEventOccurredTime = new AtomicLong(0L);
final AtomicInteger watcherEventOccurredCount = new AtomicInteger(0);
final AtomicLong fileWrittenTime = new AtomicLong(0L);
DefaultRecursiveWatcher watcher = new DefaultRecursiveWatcher(Paths.get(tempDir.getAbsolutePath()), new ArrayList<Path>(), 300, new WatchListener() {
@Override
public void watchEventsOccurred() {
watcherEventOccurredCount.addAndGet(1);
watcherEventOccurredTime.set(System.currentTimeMillis());
}
});
// Start watcher
watcher.start();
Thread.sleep(200); // Wait for watch service to set watch on all folders
File largeFile = new File(tempDir+"/largefile");
TestFileUtil.createRandomFile(largeFile, 50*1024*1024);
fileWrittenTime.set(System.currentTimeMillis());
// Stop watcher (close watches)
Thread.sleep(400); // Wait for the watcher to fire an event
watcher.stop();
// Test
assertNotSame(0L, watcherEventOccurredTime.get());
assertEquals(1, watcherEventOccurredCount.get());
assertNotSame(0L, fileWrittenTime.get());