@Test public void testFileStoreReport() throws Exception { Path targetPath = detectTargetFolder().toPath(); Path lclSftp = Utils.resolve( targetPath, SftpConstants.SFTP_SUBSYSTEM_NAME, getClass().getSimpleName(), getCurrentTestName()); Path parentPath = targetPath.getParent(); FileStore store = Files.getFileStore(lclSftp.getRoot()); final String queryPath = Utils.resolveRelativeRemotePath(parentPath, lclSftp); final SpaceAvailableExtensionInfo expected = new SpaceAvailableExtensionInfo(store); sshd.setSubsystemFactories( Arrays.<NamedFactory<Command>>asList( new SftpSubsystemFactory() { @Override public Command create() { return new SftpSubsystem( getExecutorService(), isShutdownOnExit(), getUnsupportedAttributePolicy()) { @Override protected SpaceAvailableExtensionInfo doSpaceAvailable(int id, String path) throws IOException { if (!queryPath.equals(path)) { throw new StreamCorruptedException( "Mismatched query paths: expected=" + queryPath + ", actual=" + path); } return expected; } }; } })); try (SshClient client = SshClient.setUpDefaultClient()) { client.start(); try (ClientSession session = client .connect(getCurrentTestName(), "localhost", port) .verify(7L, TimeUnit.SECONDS) .getSession()) { session.addPasswordIdentity(getCurrentTestName()); session.auth().verify(5L, TimeUnit.SECONDS); try (SftpClient sftp = session.createSftpClient()) { SpaceAvailableExtension ext = assertExtensionCreated(sftp, SpaceAvailableExtension.class); SpaceAvailableExtensionInfo actual = ext.available(queryPath); assertEquals("Mismatched information", expected, actual); } } finally { client.stop(); } } }
public static void main(String[] args) throws IOException { System.out.format("%-20s %12s %12s %12s\n", "Filesystem", "kbytes", "used", "avail"); if (args.length == 0) { FileSystem fs = FileSystems.getDefault(); for (FileStore store : fs.getFileStores()) { printFileStore(store); } } else { for (String file : args) { FileStore store = Files.getFileStore(Paths.get(file)); printFileStore(store); } } }
@Test public void preallocateTooLarge() throws Exception { assumeTrue(Platform.isLinux()); FileIO fio = FileIO.open(file, EnumSet.of(OpenOption.CREATE, OpenOption.MAPPED, OpenOption.PREALLOCATE)); FileStore fs = Files.getFileStore(file.toPath()); assumeTrue("ext4".equals(fs.type()) && !fs.name().contains("docker")); long len = file.getTotalSpace() * 100L; // setLength traps the IOException and prevents resizing / remapping. Not remapping avoids // the SIGBUS issue. fio.setLength(len); assertEquals(0, fio.length()); fio.close(); }
private void setupFooter() { try { usedFileStore = Files.getFileStore(ToolSettings.NBITES_DIR_PATH); } catch (Exception e) { e.printStackTrace(); ; throw new Error(e); } Debug.warn("Tool footer using fileStore: %s", usedFileStore.name()); display.diskAvailLabel.setText(Utility.progressString(progressSize, 0.5)); display.jvmAvailLabel.setText(Utility.progressString(progressSize, 0.5)); footerJvmTimer = new Timer( 1000, // ms new ActionListener() { @Override public void actionPerformed(ActionEvent e) { footerJvmAction(); } }); footerJvmTimer.start(); footerDiskTimer = new Timer( 1000, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { footerDiskAction(); } }); footerDiskTimer.start(); }