1 |
|
package jalview.gui; |
2 |
|
|
3 |
|
import static org.testng.Assert.assertEquals; |
4 |
|
import static org.testng.Assert.assertNotNull; |
5 |
|
import static org.testng.Assert.assertTrue; |
6 |
|
|
7 |
|
import jalview.analysis.AlignmentGenerator; |
8 |
|
import jalview.bin.Cache; |
9 |
|
import jalview.bin.Jalview; |
10 |
|
import jalview.datamodel.AlignmentI; |
11 |
|
import jalview.datamodel.SequenceGroup; |
12 |
|
import jalview.io.DataSourceType; |
13 |
|
import jalview.io.FileLoader; |
14 |
|
|
15 |
|
import java.awt.event.MouseEvent; |
16 |
|
import java.io.File; |
17 |
|
import java.io.IOException; |
18 |
|
import java.io.PrintStream; |
19 |
|
|
20 |
|
import org.testng.annotations.BeforeClass; |
21 |
|
import org.testng.annotations.Test; |
22 |
|
|
23 |
|
import junit.extensions.PA; |
24 |
|
|
|
|
| 0% |
Uncovered Elements: 74 (74) |
Complexity: 13 |
Complexity Density: 0.22 |
|
25 |
|
public class FreeUpMemoryTest |
26 |
|
{ |
27 |
|
private static final int ONE_MB = 1000 * 1000; |
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
32 |
0 |
@BeforeClass(alwaysRun = true)... |
33 |
|
public void setUp() |
34 |
|
{ |
35 |
0 |
Jalview.main(new String[] { "-nonews", "-props", |
36 |
|
"test/jalview/testProps.jvprops" }); |
37 |
0 |
String True = Boolean.TRUE.toString(); |
38 |
0 |
Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS", True); |
39 |
0 |
Cache.applicationProperties.setProperty("SHOW_QUALITY", True); |
40 |
0 |
Cache.applicationProperties.setProperty("SHOW_CONSERVATION", True); |
41 |
0 |
Cache.applicationProperties.setProperty("SHOW_OCCUPANCY", True); |
42 |
0 |
Cache.applicationProperties.setProperty("SHOW_IDENTITY", True); |
43 |
|
} |
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
@throws |
64 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 2 |
Complexity Density: 0.2 |
4-
|
|
65 |
0 |
@Test(groups = "Memory")... |
66 |
|
public void testFreeMemoryOnClose() throws IOException |
67 |
|
{ |
68 |
0 |
File f = generateAlignment(); |
69 |
0 |
f.deleteOnExit(); |
70 |
|
|
71 |
0 |
long expectedMin = 35L; |
72 |
0 |
long usedMemoryAtStart=getUsedMemory(); |
73 |
0 |
if (usedMemoryAtStart>expectedMin) |
74 |
|
{ |
75 |
0 |
System.err.println("used memory before test is "+usedMemoryAtStart+" > "+expectedMin+"MB .. adjusting minimum."); |
76 |
0 |
expectedMin = usedMemoryAtStart; |
77 |
|
} |
78 |
0 |
doStuffInJalview(f); |
79 |
|
|
80 |
0 |
Desktop.instance.closeAll_actionPerformed(null); |
81 |
|
|
82 |
0 |
checkUsedMemory(expectedMin); |
83 |
|
} |
84 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
85 |
0 |
private static long getUsedMemory()... |
86 |
|
{ |
87 |
0 |
long availableMemory = Runtime.getRuntime().totalMemory() / ONE_MB; |
88 |
0 |
long freeMemory = Runtime.getRuntime().freeMemory() / ONE_MB; |
89 |
0 |
long usedMemory = availableMemory - freeMemory; |
90 |
0 |
return usedMemory; |
91 |
|
} |
92 |
|
|
93 |
|
|
94 |
|
|
95 |
|
|
96 |
|
@param |
97 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
98 |
0 |
protected void checkUsedMemory(long expectedMax)... |
99 |
|
{ |
100 |
|
|
101 |
|
|
102 |
|
|
103 |
|
|
104 |
|
|
105 |
0 |
System.gc(); |
106 |
0 |
waitFor(1500); |
107 |
|
|
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
|
112 |
0 |
System.gc(); |
113 |
0 |
waitFor(1500); |
114 |
|
|
115 |
|
|
116 |
|
|
117 |
|
|
118 |
0 |
long usedMemory = getUsedMemory(); |
119 |
|
|
120 |
|
|
121 |
|
|
122 |
|
|
123 |
0 |
assertEquals(Desktop.instance.getAllFrames().length, 0); |
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
|
128 |
|
|
129 |
|
|
130 |
|
|
131 |
|
|
132 |
0 |
System.out.println("Used memory after gc = " + usedMemory + "MB"); |
133 |
0 |
assertTrue(usedMemory < expectedMax, String.format( |
134 |
|
"Used memory %d should be less than %d (Recommend running test manually to verify)", |
135 |
|
usedMemory, |
136 |
|
expectedMax)); |
137 |
|
} |
138 |
|
|
139 |
|
|
140 |
|
|
141 |
|
|
142 |
|
@param |
143 |
|
|
|
|
| 0% |
Uncovered Elements: 27 (27) |
Complexity: 5 |
Complexity Density: 0.24 |
|
144 |
0 |
protected void doStuffInJalview(File f)... |
145 |
|
{ |
146 |
|
|
147 |
|
|
148 |
|
|
149 |
0 |
AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(f.getPath(), |
150 |
|
DataSourceType.FILE); |
151 |
0 |
while (af.getViewport().isCalcInProgress()) |
152 |
|
{ |
153 |
0 |
waitFor(200); |
154 |
|
} |
155 |
|
|
156 |
|
|
157 |
|
|
158 |
|
|
159 |
0 |
af.overviewMenuItem_actionPerformed(null); |
160 |
0 |
assertNotNull(af.alignPanel.overviewPanel); |
161 |
|
|
162 |
|
|
163 |
|
|
164 |
|
|
165 |
0 |
Object[] args = new Object[] { |
166 |
|
new MouseEvent(af, 0, 0, 0, 0, 0, 1, true) }; |
167 |
0 |
PA.invokeMethod(af.alignPanel.overviewPanel, |
168 |
|
"showPopupMenu(java.awt.event.MouseEvent)", args); |
169 |
|
|
170 |
|
|
171 |
|
|
172 |
|
|
173 |
|
|
174 |
0 |
SequenceGroup sg = new SequenceGroup(); |
175 |
0 |
sg.setStartRes(0); |
176 |
0 |
sg.setEndRes(100); |
177 |
0 |
AlignmentI al = af.viewport.getAlignment(); |
178 |
0 |
for (int i = 0; i < al.getHeight(); i++) |
179 |
|
{ |
180 |
0 |
sg.addSequence(al.getSequenceAt(i), false); |
181 |
|
} |
182 |
0 |
af.viewport.setSelectionGroup(sg); |
183 |
|
|
184 |
|
|
185 |
|
|
186 |
|
|
187 |
0 |
af.openTreePcaDialog(); |
188 |
0 |
CalculationChooser dialog = af.alignPanel.getCalculationDialog(); |
189 |
0 |
dialog.openPcaPanel("BLOSUM62", dialog.getSimilarityParameters(true)); |
190 |
0 |
dialog.openTreePanel("BLOSUM62", dialog.getSimilarityParameters(false)); |
191 |
|
|
192 |
|
|
193 |
|
|
194 |
|
|
195 |
0 |
while (af.viewport.getCurrentTree() == null |
196 |
|
&& dialog.getPcaPanel().isWorking()) |
197 |
|
{ |
198 |
0 |
waitFor(10); |
199 |
|
} |
200 |
|
|
201 |
|
|
202 |
|
|
203 |
|
|
204 |
0 |
waitFor(100); |
205 |
|
} |
206 |
|
|
207 |
|
|
208 |
|
|
209 |
|
|
210 |
|
@param |
211 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 2 |
Complexity Density: 1 |
|
212 |
0 |
protected void waitFor(int waitMs)... |
213 |
|
{ |
214 |
0 |
try |
215 |
|
{ |
216 |
0 |
Thread.sleep(waitMs); |
217 |
|
} catch (InterruptedException e) |
218 |
|
{ |
219 |
|
} |
220 |
|
} |
221 |
|
|
222 |
|
|
223 |
|
|
224 |
|
|
225 |
|
|
226 |
|
|
227 |
|
|
228 |
|
|
229 |
|
@return |
230 |
|
@throws |
231 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
232 |
0 |
private File generateAlignment() throws IOException... |
233 |
|
{ |
234 |
0 |
File f = File.createTempFile("MemoryTest", "fa"); |
235 |
0 |
PrintStream ps = new PrintStream(f); |
236 |
0 |
AlignmentGenerator ag = new AlignmentGenerator(false, ps); |
237 |
0 |
int width = 100000; |
238 |
0 |
int height = 100; |
239 |
0 |
ag.generate(width, height, 0, 10, 15); |
240 |
0 |
return f; |
241 |
|
} |
242 |
|
} |