use of java.nio.file.FileStore in project vert.x by eclipse.
the class FileSystemImpl method fsPropsInternal.
private BlockingAction<FileSystemProps> fsPropsInternal(String path, Handler<AsyncResult<FileSystemProps>> handler) {
Objects.requireNonNull(path);
return new BlockingAction<FileSystemProps>(handler) {
public FileSystemProps perform() {
try {
Path target = vertx.resolveFile(path).toPath();
FileStore fs = Files.getFileStore(target);
return new FileSystemPropsImpl(fs.getTotalSpace(), fs.getUnallocatedSpace(), fs.getUsableSpace());
} catch (IOException e) {
throw new FileSystemException(e);
}
}
};
}
use of java.nio.file.FileStore in project elasticsearch by elastic.
the class ESFileStoreTests method testNegativeSpace.
public void testNegativeSpace() throws Exception {
FileStore mocked = mock(FileStore.class);
when(mocked.getUsableSpace()).thenReturn(-1L);
when(mocked.getTotalSpace()).thenReturn(-1L);
when(mocked.getUnallocatedSpace()).thenReturn(-1L);
assertEquals(-1, mocked.getUsableSpace());
FileStore store = new ESFileStore(mocked);
assertEquals(Long.MAX_VALUE, store.getUsableSpace());
assertEquals(Long.MAX_VALUE, store.getTotalSpace());
assertEquals(Long.MAX_VALUE, store.getUnallocatedSpace());
}
use of java.nio.file.FileStore in project lucene-solr by apache.
the class IOUtils method spinsLinux.
// following methods are package-private for testing ONLY
// note: requires a real or fake linux filesystem!
static boolean spinsLinux(Path path) throws IOException {
FileStore store = getFileStore(path);
// this won't have a corresponding block device
if ("tmpfs".equals(store.type())) {
return false;
}
// get block device name
String devName = store.name();
// not a device (e.g. NFS server)
if (!devName.startsWith("/")) {
return true;
}
// resolve any symlinks to real block device (e.g. LVM)
// /dev/sda0 -> sda0
// /devices/XXX -> sda0
devName = path.getRoot().resolve(devName).toRealPath().getFileName().toString();
// now try to find the longest matching device folder in /sys/block
// (that starts with our dev name):
Path sysinfo = path.getRoot().resolve("sys").resolve("block");
Path devsysinfo = null;
int matchlen = 0;
try (DirectoryStream<Path> stream = Files.newDirectoryStream(sysinfo)) {
for (Path device : stream) {
String name = device.getFileName().toString();
if (name.length() > matchlen && devName.startsWith(name)) {
devsysinfo = device;
matchlen = name.length();
}
}
}
if (devsysinfo == null) {
// give up
return true;
}
// read first byte from rotational, it's a 1 if it spins.
Path rotational = devsysinfo.resolve("queue").resolve("rotational");
try (InputStream stream = Files.newInputStream(rotational)) {
return stream.read() == '1';
}
}
use of java.nio.file.FileStore in project lucene-solr by apache.
the class TestIOUtils method testSSD.
public void testSSD() throws Exception {
assumeFalse("windows is not supported", Constants.WINDOWS);
Path dir = createTempDir();
dir = FilterPath.unwrap(dir).toRealPath();
// fake ssd
FileStore root = new MockFileStore(dir.toString() + " (/dev/zzz1)", "btrfs", "/dev/zzz1");
// make a fake /dev/zzz1 for it
Path devdir = dir.resolve("dev");
Files.createDirectories(devdir);
Files.createFile(devdir.resolve("zzz1"));
// make a fake /sys/block/zzz/queue/rotational file for it
Path sysdir = dir.resolve("sys").resolve("block").resolve("zzz").resolve("queue");
Files.createDirectories(sysdir);
try (OutputStream o = Files.newOutputStream(sysdir.resolve("rotational"))) {
o.write("0\n".getBytes(StandardCharsets.US_ASCII));
}
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));
}
use of java.nio.file.FileStore in project lucene-solr by apache.
the class TestIOUtils method testNVME.
public void testNVME() throws Exception {
assumeFalse("windows is not supported", Constants.WINDOWS);
Path dir = createTempDir();
dir = FilterPath.unwrap(dir).toRealPath();
// fake ssd
FileStore root = new MockFileStore(dir.toString() + " (/dev/nvme0n1p1)", "btrfs", "/dev/nvme0n1p1");
// make a fake /dev/nvme0n1p1 for it
Path devdir = dir.resolve("dev");
Files.createDirectories(devdir);
Files.createFile(devdir.resolve("nvme0n1p1"));
// make a fake /sys/block/nvme0n1/queue/rotational file for it
Path sysdir = dir.resolve("sys").resolve("block").resolve("nvme0n1").resolve("queue");
Files.createDirectories(sysdir);
try (OutputStream o = Files.newOutputStream(sysdir.resolve("rotational"))) {
o.write("0\n".getBytes(StandardCharsets.US_ASCII));
}
// As test for the longest path match, add some other devices (that have no queue/rotational), too:
Files.createFile(dir.resolve("sys").resolve("block").resolve("nvme0"));
Files.createFile(dir.resolve("sys").resolve("block").resolve("dummy"));
Files.createFile(dir.resolve("sys").resolve("block").resolve("nvm"));
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));
}
Aggregations