Search in sources :

Example 16 with WatchService

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);
}
Also used : WatchService(java.nio.file.WatchService) Test(org.junit.Test)

Example 17 with WatchService

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);
}
Also used : FileSystem(java.nio.file.FileSystem) WatchService(java.nio.file.WatchService) Test(org.junit.Test)

Example 18 with WatchService

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);
}
Also used : FileSystem(java.nio.file.FileSystem) WatchService(java.nio.file.WatchService) Test(org.junit.Test)

Example 19 with WatchService

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.
}
Also used : Path(java.nio.file.Path) ClosedFileSystemException(java.nio.file.ClosedFileSystemException) ClosedWatchServiceException(java.nio.file.ClosedWatchServiceException) WatchService(java.nio.file.WatchService) Test(org.junit.Test)

Example 20 with WatchService

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) {
    }
}
Also used : ClosedWatchServiceException(java.nio.file.ClosedWatchServiceException) WatchService(java.nio.file.WatchService) Test(org.junit.Test)

Aggregations

WatchService (java.nio.file.WatchService)56 Path (java.nio.file.Path)40 WatchKey (java.nio.file.WatchKey)32 WatchEvent (java.nio.file.WatchEvent)23 IOException (java.io.IOException)21 Test (org.junit.Test)18 File (java.io.File)16 FileSystem (java.nio.file.FileSystem)6 ClosedWatchServiceException (java.nio.file.ClosedWatchServiceException)5 Kind (java.nio.file.WatchEvent.Kind)5 FileSystems (java.nio.file.FileSystems)4 StandardWatchEventKinds (java.nio.file.StandardWatchEventKinds)4 SensitivityWatchEventModifier (com.sun.nio.file.SensitivityWatchEventModifier)3 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)3 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 TimeUnit (java.util.concurrent.TimeUnit)3 BufferedReader (java.io.BufferedReader)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2