1 19 20 package org.netbeans.modules.tasklist.docscan; 21 22 import org.netbeans.junit.NbTestCase; 23 import org.netbeans.junit.MemoryFilter; 24 import org.openide.util.actions.SystemAction; 25 import org.openide.filesystems.LocalFileSystem; 26 import org.openide.filesystems.Repository; 27 import org.openide.filesystems.FileSystem; 28 29 import javax.swing.*; 30 import java.net.URL ; 31 import java.io.File ; 32 import java.lang.reflect.InvocationTargetException ; 33 import java.util.Collections ; 34 35 42 public final class HeapTest extends NbTestCase { 43 44 public HeapTest(String s) { 45 super(s); 46 } 47 48 49 50 private FileSystem dataFS; 51 private Filter filter = new Filter(); 52 53 protected void setUp () throws Exception { 54 URL url = this.getClass().getResource("data"); 55 String resString = NbTestCase.convertNBFSURL(url); 56 LocalFileSystem fs = new LocalFileSystem(); 57 fs.setRootDirectory(new File (resString)); 58 Repository.getDefault().addFileSystem(fs); 59 dataFS = fs; 60 } 61 62 public void testBug40565() { 63 64 if (SourceTasksAction.class.getClassLoader() != getClass().getClassLoader()) { 65 throw new IllegalStateException ("Test must be laoded by tested module classloader"); 66 } 67 68 try { 69 SwingUtilities.invokeAndWait( new Runnable () { 70 public void run() { 71 SourceTasksAction action = (SourceTasksAction) SystemAction.get(SourceTasksAction.class); 73 action.performAction(); 74 75 } 76 }); 77 } catch (InterruptedException e) { 78 79 } catch (InvocationTargetException e) { 80 81 } 82 83 SourceTasksView view = (SourceTasksView) SourceTasksView.getCurrent(); 84 85 86 87 view.selectedFolder = dataFS.findResource("leaks"); 88 view.getAllFiles().doClick(1); 89 90 try { 92 Thread.sleep(20000); 93 } catch (InterruptedException e) { 94 } 95 97 view.getRefresh().doClick(1); 98 try { 99 Thread.sleep(2000); 100 } catch (InterruptedException e) { 101 } 102 103 int TL_SIZE = 6650336; 105 int TABLE_SIZE = 7308880 + 40000; 108 int TABLE_LEAK = 400; 110 int initial_table_size = assertSize("Table actual size too big", Collections.singleton(view.discloseTable()), TABLE_SIZE, filter); 112 int initial_node_size = assertSize("Node actual size too big", Collections.singleton(view.discloseNode()), Integer.MAX_VALUE, filter); 113 int initial_view_size = assertSize("View actual size too big", Collections.singleton(view), Integer.MAX_VALUE, filter); 114 115 for (int i = 0 ; i <5; i++) { 116 view.getRefresh().doClick(1); 117 try { 118 Thread.sleep(2000); 119 } catch (InterruptedException e) { 120 } 121 122 int current_table_size = assertSize("Table after refresh #" + i, Collections.singleton(view.discloseTable()), initial_table_size + TABLE_LEAK, filter); } 129 assertSize("View after refresh test", Collections.singleton(view), initial_view_size, filter); 131 } 132 133 private class Filter implements MemoryFilter { 134 public boolean reject (Object obj) { 135 return obj instanceof java.lang.ref.Reference ; 136 } 137 } 138 } 139 | Popular Tags |