1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.vfs2.provider.zip;
18
19 import static org.junit.jupiter.api.Assertions.assertTrue;
20
21 import java.io.File;
22
23 import org.apache.commons.vfs2.FileObject;
24 import org.apache.commons.vfs2.FileSystemException;
25 import org.apache.commons.vfs2.cache.WeakRefFilesCache;
26 import org.apache.commons.vfs2.impl.StandardFileSystemManager;
27 import org.junit.jupiter.api.Test;
28
29 public class ZipFileSystemTest {
30
31
32
33
34 @Test
35 public void testZipFileUseWeakRefFilesCache() throws FileSystemException {
36
37 final File file = new File("src/test/resources/test-data/test.zip");
38 final String fileUri = "zip:file:" + file.getAbsolutePath();
39 FileObject fileObject = null;
40
41 try (StandardFileSystemManager manager = new StandardFileSystemManager()) {
42
43 @SuppressWarnings("resource")
44 final WeakRefFilesCache filesCache = new WeakRefFilesCache();
45 manager.setFilesCache(filesCache);
46 manager.init();
47
48 int cnt = 0;
49 while (cnt < 100_000) {
50 cnt++;
51
52
53 try {
54 fileObject = manager.resolveFile(fileUri);
55 assertTrue(fileObject.exists());
56 } finally {
57 FileObject.close(fileObject);
58 fileObject = null;
59 }
60
61 if (cnt % 200 == 0) {
62 System.gc();
63 }
64 }
65 }
66 }
67
68 }