@Test public void recoversFromFileDeletions() throws Exception { monitor.start(listener); verify(listener, timeout(3000).times(1)).fileChanged(); delete(monitoredFile); Thread.sleep(2000); write(monitoredFile, "some new content"); verify(listener, timeout(3000).times(2)).fileChanged(); }
@Override public void start(Listener listener) { LOGGER.debug("start, initialDelay={}, pollPeriod={}", new Object[] {initialDelay, pollPeriod}); synchronized (this) { if (monitoredTask != null) { String message = format("File monitor for '%s' is already started", monitoredFile); throw new IllegalStateException(message); } monitoredTask = executor.scheduleAtFixedRate( detectFileChangesTask(listener), initialDelay.toMillis(), pollPeriod.toMillis(), MILLISECONDS); } }
FileChangeMonitor implements FileMonitor { @Override public void start(Listener listener) { LOGGER.debug("start, initialDelay={}, pollPeriod={}", new Object[] {initialDelay, pollPeriod}); synchronized (this) { if (monitoredTask != null) { String message = format("File monitor for '%s' is already started", monitoredFile); throw new IllegalStateException(message); } monitoredTask = executor.scheduleAtFixedRate( detectFileChangesTask(listener), initialDelay.toMillis(), pollPeriod.toMillis(), MILLISECONDS); } } }
FileChangeMonitor implements FileMonitor { @Override public void start(Listener listener) { LOGGER.debug("start, initialDelay={}, pollPeriod={}", new Object[] {initialDelay, pollPeriod}); synchronized (this) { if (monitoredTask != null) { String message = format("File monitor for '%s' is already started", monitoredFile); throw new IllegalStateException(message); } monitoredTask = executor.scheduleAtFixedRate( detectFileChangesTask(listener), initialDelay.toMillis(), pollPeriod.toMillis(), MILLISECONDS); } } FileChangeMonitor(String monitoredFile, Duration initialDelay, Duration pollPeriod);  FileChangeMonitor(String monitoredFile); }
FileChangeMonitor implements FileMonitor { @Override public void start(Listener listener) { LOGGER.debug("start, initialDelay={}, pollPeriod={}", new Object[] {initialDelay, pollPeriod}); synchronized (this) { if (monitoredTask != null) { String message = format("File monitor for '%s' is already started", monitoredFile); throw new IllegalStateException(message); } monitoredTask = executor.scheduleAtFixedRate( detectFileChangesTask(listener), initialDelay.toMillis(), pollPeriod.toMillis(), MILLISECONDS); } } FileChangeMonitor(String monitoredFile, Duration initialDelay, Duration pollPeriod);  FileChangeMonitor(String monitoredFile); @Override void start(Listener listener); void stop(); }
FileChangeMonitor implements FileMonitor { @Override public void start(Listener listener) { LOGGER.debug("start, initialDelay={}, pollPeriod={}", new Object[] {initialDelay, pollPeriod}); synchronized (this) { if (monitoredTask != null) { String message = format("File monitor for '%s' is already started", monitoredFile); throw new IllegalStateException(message); } monitoredTask = executor.scheduleAtFixedRate( detectFileChangesTask(listener), initialDelay.toMillis(), pollPeriod.toMillis(), MILLISECONDS); } } FileChangeMonitor(String monitoredFile, Duration initialDelay, Duration pollPeriod);  FileChangeMonitor(String monitoredFile); @Override void start(Listener listener); void stop();  }