package org.jboss.test.virtual.test; import org.jboss.virtual.VFS; import org.jboss.virtual.VirtualFile; import org.jboss.virtual.VirtualFileVisitor; import org.jboss.virtual.VisitorAttributes; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.net.URL; /** * @author Marko Strukelj */ public class VFSZipMemoryTestCase extends AbstractVFSTest { public VFSZipMemoryTestCase(String name) { super(name, true); } public void testMemoryUsage() throws Exception { String DIR = "c:/development/test/GateIn-3.1.0-CR01/server/default/deploy/"; for (int i=0; i<2; i++) { // visit a big archive URL url = new File(DIR).toURL(); VFS vfs = VFS.getVFS(new URL("file:" + url.getPath())); //VFSUtils.enableNoReaper(vfs); // fully read everything inside vfs.visit(new VirtualFileVisitor() { public VisitorAttributes getAttributes() { return VisitorAttributes.RECURSE_LEAVES_ONLY; } public void visit(VirtualFile virtualFile) { try { System.out.println(virtualFile); InputStream in = virtualFile.openStream(); byte [] buf = new byte[100000]; while (in.read(buf) != -1) { // we're just reading and dumping } } catch (IOException e) { throw new RuntimeException("Failed to read virtual file: " + virtualFile, e); } } }); // gc + measure memory usage System.gc(); System.out.println("Used memory: " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory())); // wait a little Thread.sleep(10000); // gc + measure memory usage again System.gc(); System.out.println("Used memory: " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory())); Thread.sleep(10000); // gc + measure memory usage again System.gc(); System.out.println("Used memory: " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory())); } } }