This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-vfs.git

commit 9e408066374fb0ea4f0b4f5133cc6997ac3a162d
Author: Gary Gregory <[email protected]>
AuthorDate: Thu Mar 11 10:06:53 2021 -0500

    Add test to check that a file cache is empty after VFS.close().
---
 .../vfs2/impl/DefaultFileSystemManagerTest.java    | 38 ++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git 
a/commons-vfs2/src/test/java/org/apache/commons/vfs2/impl/DefaultFileSystemManagerTest.java
 
b/commons-vfs2/src/test/java/org/apache/commons/vfs2/impl/DefaultFileSystemManagerTest.java
index 4c22157..51b829c 100644
--- 
a/commons-vfs2/src/test/java/org/apache/commons/vfs2/impl/DefaultFileSystemManagerTest.java
+++ 
b/commons-vfs2/src/test/java/org/apache/commons/vfs2/impl/DefaultFileSystemManagerTest.java
@@ -25,6 +25,7 @@ import org.apache.commons.vfs2.FileName;
 import org.apache.commons.vfs2.FileObject;
 import org.apache.commons.vfs2.FileSystemException;
 import org.apache.commons.vfs2.FileSystemManager;
+import org.apache.commons.vfs2.FilesCache;
 import org.apache.commons.vfs2.VFS;
 import org.apache.commons.vfs2.cache.NullFilesCache;
 import org.apache.commons.vfs2.provider.ram.RamFileProvider;
@@ -77,6 +78,43 @@ public class DefaultFileSystemManagerTest {
         }
     }
 
+    @Test
+    public void testFileCacheEmptyAfterVFSClose() throws FileSystemException {
+        final FileSystemManager manager = VFS.getManager();
+        Assert.assertNotNull(manager);
+        try (final FileObject fileObject = manager
+            
.resolveFile(Paths.get("src/test/resources/test-data/read-tests/file1.txt").toUri()))
 {
+            Assert.assertTrue(fileObject.exists());
+            final FilesCache filesCache = manager.getFilesCache();
+            final FileName name = fileObject.getName();
+            // Make sure we have file object in the cache.
+            
Assert.assertNotNull(filesCache.getFile(fileObject.getFileSystem(), name));
+            VFS.close();
+            // Cache MUST now be empty.
+            Assert.assertNull(filesCache.getFile(fileObject.getFileSystem(), 
name));
+        }
+    }
+
+    @Test
+    public void testFileCacheEmptyAfterManagerClose() throws 
FileSystemException {
+        final FileSystemManager manager = VFS.getManager();
+        Assert.assertNotNull(manager);
+        try (final FileObject fileObject = manager
+            
.resolveFile(Paths.get("src/test/resources/test-data/read-tests/file1.txt").toUri()))
 {
+            Assert.assertTrue(fileObject.exists());
+            final FilesCache filesCache = manager.getFilesCache();
+            final FileName name = fileObject.getName();
+            // Make sure we have file object in the cache.
+            
Assert.assertNotNull(filesCache.getFile(fileObject.getFileSystem(), name));
+            manager.close();
+            // Cache MUST now be empty.
+            Assert.assertNull(filesCache.getFile(fileObject.getFileSystem(), 
name));
+        } finally {
+            // Makes sure we reset the singleton or other tests will fail.
+            VFS.close();
+        }
+    }
+
     /**
      * Even if the file name is absolute, the base file must be given. This is 
an inconsistency in the API, but it is
      * documented as such.

Reply via email to