use of org.neo4j.io.fs.watcher.resource.WatchedResource in project neo4j by neo4j.
the class SelectiveFileSystemAbstractionTest method provideSelectiveWatcher.
@Test
public void provideSelectiveWatcher() throws IOException {
File specialFile = new File("special");
File otherFile = new File("other");
FileSystemAbstraction normal = mock(FileSystemAbstraction.class);
FileSystemAbstraction special = mock(FileSystemAbstraction.class);
FileWatcher specialWatcher = mock(FileWatcher.class);
FileWatcher normalWatcher = mock(FileWatcher.class);
WatchedResource specialResource = mock(WatchedResource.class);
WatchedResource normalResource = mock(WatchedResource.class);
when(special.fileWatcher()).thenReturn(specialWatcher);
when(normal.fileWatcher()).thenReturn(normalWatcher);
when(specialWatcher.watch(specialFile)).thenReturn(specialResource);
when(normalWatcher.watch(otherFile)).thenReturn(normalResource);
try (SelectiveFileSystemAbstraction fs = new SelectiveFileSystemAbstraction(specialFile, special, normal)) {
FileWatcher fileWatcher = fs.fileWatcher();
assertSame(specialResource, fileWatcher.watch(specialFile));
assertSame(normalResource, fileWatcher.watch(otherFile));
}
}
use of org.neo4j.io.fs.watcher.resource.WatchedResource in project neo4j by neo4j.
the class DefaultFileSystemWatcherTest method registerMultipleDirectoriesForMonitoring.
@Test
public void registerMultipleDirectoriesForMonitoring() throws Exception {
try (DefaultFileSystemWatcher watcher = new DefaultFileSystemWatcher(FileSystems.getDefault().newWatchService())) {
File directory1 = testDirectory.directory("test1");
File directory2 = testDirectory.directory("test2");
WatchedResource watchedResource1 = watcher.watch(directory1);
WatchedResource watchedResource2 = watcher.watch(directory2);
assertNotSame(watchedResource1, watchedResource2);
}
}
use of org.neo4j.io.fs.watcher.resource.WatchedResource in project neo4j by neo4j.
the class RestartableFileSystemWatcherTest method startStopFileWatchingCycle.
@Test
public void startStopFileWatchingCycle() throws IOException, InterruptedException {
File file1 = mock(File.class);
File file2 = mock(File.class);
WatchedResource resource1 = mock(WatchedResource.class);
WatchedResource resource2 = mock(WatchedResource.class);
watcher.watch(file1);
watcher.watch(file2);
when(delegate.watch(file1)).thenReturn(resource1);
when(delegate.watch(file2)).thenReturn(resource2);
int invocations = 100;
for (int i = 0; i < invocations; i++) {
startStopWatching();
}
verify(delegate, times(invocations)).watch(file1);
verify(delegate, times(invocations)).watch(file2);
verify(delegate, times(invocations)).startWatching();
verify(delegate, times(invocations)).stopWatching();
verify(resource1, times(invocations)).close();
verify(resource2, times(invocations)).close();
}
Aggregations