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