use of java.nio.file.WatchService in project jimfs by google.
the class WatchServiceConfigurationTest method testDefaultConfig.
@Test
public void testDefaultConfig() {
WatchService watchService = WatchServiceConfiguration.DEFAULT.newWatchService(fs.getDefaultView(), fs.getPathService());
assertThat(watchService).isInstanceOf(PollingWatchService.class);
PollingWatchService pollingWatchService = (PollingWatchService) watchService;
assertThat(pollingWatchService.interval).isEqualTo(5);
assertThat(pollingWatchService.timeUnit).isEqualTo(SECONDS);
}
use of java.nio.file.WatchService in project jimfs by google.
the class ConfigurationTest method testFileSystemWithCustomWatchServicePollingInterval.
@Test
public void testFileSystemWithCustomWatchServicePollingInterval() throws IOException {
FileSystem fs = Jimfs.newFileSystem(Configuration.unix().toBuilder().setWatchServiceConfiguration(polling(10, MILLISECONDS)).build());
WatchService watchService = fs.newWatchService();
assertThat(watchService).isInstanceOf(PollingWatchService.class);
PollingWatchService pollingWatchService = (PollingWatchService) watchService;
assertThat(pollingWatchService.interval).isEqualTo(10);
assertThat(pollingWatchService.timeUnit).isEqualTo(MILLISECONDS);
}
use of java.nio.file.WatchService in project jimfs by google.
the class ConfigurationTest method testFileSystemWithDefaultWatchService.
@Test
public void testFileSystemWithDefaultWatchService() throws IOException {
FileSystem fs = Jimfs.newFileSystem(Configuration.unix());
WatchService watchService = fs.newWatchService();
assertThat(watchService).isInstanceOf(PollingWatchService.class);
PollingWatchService pollingWatchService = (PollingWatchService) watchService;
assertThat(pollingWatchService.interval).isEqualTo(5);
assertThat(pollingWatchService.timeUnit).isEqualTo(SECONDS);
}
use of java.nio.file.WatchService in project jimfs by google.
the class JimfsFileSystemCloseTest method testPathMethodsThrow.
@Test
public void testPathMethodsThrow() throws IOException {
Path p = fs.getPath("/foo");
Files.createDirectory(p);
WatchService ws = fs.newWatchService();
fs.close();
try {
p.register(ws, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY);
fail();
} catch (ClosedWatchServiceException expected) {
}
try {
p = p.toRealPath();
fail();
} catch (ClosedFileSystemException expected) {
}
// While technically (according to the FileSystem.close() spec) all methods on Path should
// probably throw, we only throw for methods that access the file system itself in some way...
// path manipulation methods seem totally harmless to keep working, and I don't see any need to
// add the overhead of checking that the file system is open for each of those method calls.
}
use of java.nio.file.WatchService in project jimfs by google.
the class JimfsFileSystemCloseTest method testOpenWatchServicesClosed.
@Test
public void testOpenWatchServicesClosed() throws IOException {
WatchService ws1 = fs.newWatchService();
WatchService ws2 = fs.newWatchService();
assertNull(ws1.poll());
assertNull(ws2.poll());
fs.close();
try {
ws1.poll();
fail();
} catch (ClosedWatchServiceException expected) {
}
try {
ws2.poll();
fail();
} catch (ClosedWatchServiceException expected) {
}
}
Aggregations