Hello,

I am currently implementing a database Blob provider, and while writing some unit tests I noticed that VFS is not catching the case that a file is (still) open. It will happily call doRename(). Afterwards both source and target file objects are isContentOpen==false.

Is this the intended behaviour? For some providers a opened file might not exist and they will fail (ram provider). Currently the DB Blob behaves the same.

This is my unit test for the ram provider and the failure to rename (the not existing object):

    @Test
    public void testRenameOpen() throws IOException
    {
        final long now = System.currentTimeMillis();

final FileObject testFile = manager.resolveFile("ram:/fo5-old", smallSizedFso); final FileObject targetFile = manager.resolveFile("ram:/fo5-new", smallSizedFso);
        assertEquals(false, testFile.exists());
        assertEquals(FileType.IMAGINARY, testFile.getType());

        OutputStream os = testFile.getContent().getOutputStream();
        assertEquals(false, testFile.exists());
        os.write(255);
        //not closed -> not exist
        assertEquals(false, testFile.exists());
        assertEquals(true,  testFile.isContentOpen());

        try{
        testFile.moveTo(targetFile); // Throws:
        } catch (FileSystemException ignored) { }

        assertEquals(false,  testFile.isContentOpen()); // if fails -> true
        assertEquals(false,  targetFile.isContentOpen());
    }

If I dont catch it, this stacktrace is visible:

org.apache.commons.vfs2.FileSystemException: Could not rename "ram:///fo5-old" to "ram:///fo5-new". at org.apache.commons.vfs2.provider.AbstractFileObject.moveTo(AbstractFileObject.java:1353) at org.apache.commons.vfs2.provider.ram.test.CustomRamProviderTest.testRenameOpen(CustomRamProviderTest.java:289)
...
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) Caused by: org.apache.commons.vfs2.FileSystemException: Unknown message with code "File does not exist: ram:///fo5-old". at org.apache.commons.vfs2.provider.ram.RamFileSystem.rename(RamFileSystem.java:195) at org.apache.commons.vfs2.provider.ram.RamFileObject.doRename(RamFileObject.java:188) at org.apache.commons.vfs2.provider.AbstractFileObject.moveTo(AbstractFileObject.java:1339)
        ... 26 more

--
http://bernd.eckenfels.net

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org

Reply via email to