Search in sources :

Example 16 with FileStore

use of java.nio.file.FileStore in project lucene-solr by apache.

the class TestIOUtils method testTmpfsDoesntSpin.

public void testTmpfsDoesntSpin() throws Exception {
    Path dir = createTempDir();
    dir = FilterPath.unwrap(dir).toRealPath();
    // fake tmpfs
    FileStore root = new MockFileStore(dir.toString() + " (/dev/sda1)", "tmpfs", "/dev/sda1");
    Map<String, FileStore> mappings = Collections.singletonMap(dir.toString(), root);
    FileSystem mockLinux = new MockLinuxFileSystemProvider(dir.getFileSystem(), mappings, dir).getFileSystem(null);
    Path mockPath = mockLinux.getPath(dir.toString());
    assertFalse(IOUtils.spinsLinux(mockPath));
}
Also used : FilterPath(org.apache.lucene.mockfile.FilterPath) Path(java.nio.file.Path) FileStore(java.nio.file.FileStore) FileSystem(java.nio.file.FileSystem) FilterFileSystem(org.apache.lucene.mockfile.FilterFileSystem)

Example 17 with FileStore

use of java.nio.file.FileStore in project lucene-solr by apache.

the class TestIOUtils method testGetFileStore.

public void testGetFileStore() throws Exception {
    Path dir = createTempDir();
    dir = FilterPath.unwrap(dir).toRealPath();
    // now we can create some fake mount points:
    FileStore root = new MockFileStore(dir.toString() + " (/dev/sda1)", "ntfs", "/dev/sda1");
    FileStore usr = new MockFileStore(dir.resolve("usr").toString() + " (/dev/sda2)", "xfs", "/dev/sda2");
    // associate some preset files to these
    Map<String, FileStore> mappings = new HashMap<>();
    mappings.put(dir.toString(), root);
    mappings.put(dir.resolve("foo.txt").toString(), root);
    mappings.put(dir.resolve("usr").toString(), usr);
    mappings.put(dir.resolve("usr/bar.txt").toString(), usr);
    FileSystem mockLinux = new MockLinuxFileSystemProvider(dir.getFileSystem(), mappings, dir).getFileSystem(null);
    Path mockPath = mockLinux.getPath(dir.toString());
    // sanity check our mock:
    assertSame(usr, Files.getFileStore(mockPath.resolve("usr")));
    assertSame(usr, Files.getFileStore(mockPath.resolve("usr/bar.txt")));
    // for root filesystem we get a crappy one
    assertNotSame(root, Files.getFileStore(mockPath));
    assertNotSame(usr, Files.getFileStore(mockPath));
    assertNotSame(root, Files.getFileStore(mockPath.resolve("foo.txt")));
    assertNotSame(usr, Files.getFileStore(mockPath.resolve("foo.txt")));
    // now test our method:
    assertSame(usr, IOUtils.getFileStore(mockPath.resolve("usr")));
    assertSame(usr, IOUtils.getFileStore(mockPath.resolve("usr/bar.txt")));
    assertSame(root, IOUtils.getFileStore(mockPath));
    assertSame(root, IOUtils.getFileStore(mockPath.resolve("foo.txt")));
}
Also used : FilterPath(org.apache.lucene.mockfile.FilterPath) Path(java.nio.file.Path) FileStore(java.nio.file.FileStore) HashMap(java.util.HashMap) FileSystem(java.nio.file.FileSystem) FilterFileSystem(org.apache.lucene.mockfile.FilterFileSystem)

Aggregations

FileStore (java.nio.file.FileStore)17 Path (java.nio.file.Path)11 FileSystem (java.nio.file.FileSystem)8 FilterFileSystem (org.apache.lucene.mockfile.FilterFileSystem)8 FilterPath (org.apache.lucene.mockfile.FilterPath)8 OutputStream (java.io.OutputStream)5 IOException (java.io.IOException)4 FileSystemException (java.nio.file.FileSystemException)2 SuppressForbidden (org.elasticsearch.common.SuppressForbidden)2 NSDictionary (com.dd.plist.NSDictionary)1 NSNumber (com.dd.plist.NSNumber)1 NSObject (com.dd.plist.NSObject)1 FileSystemException (io.vertx.core.file.FileSystemException)1 File (java.io.File)1 InputStream (java.io.InputStream)1 BigInteger (java.math.BigInteger)1 HashMap (java.util.HashMap)1 Random (java.util.Random)1 UUID (java.util.UUID)1 NodeEnvironment (org.elasticsearch.env.NodeEnvironment)1