X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fgui%2FFreeUpMemoryTest.java;h=24697c0763fca3f47998b607eef21beabc9920a9;hb=05a051ebe9afb8e7e778bb9270572b47e84ce4c7;hp=e93bfac7162c27177ffb25d1c8e0a438d550c9d7;hpb=14193747f3831242bc7dfac12394eb20eb0ba480;p=jalview.git diff --git a/test/jalview/gui/FreeUpMemoryTest.java b/test/jalview/gui/FreeUpMemoryTest.java index e93bfac..24697c0 100644 --- a/test/jalview/gui/FreeUpMemoryTest.java +++ b/test/jalview/gui/FreeUpMemoryTest.java @@ -1,6 +1,7 @@ package jalview.gui; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertTrue; import jalview.analysis.AlignmentGenerator; @@ -11,6 +12,7 @@ import jalview.datamodel.SequenceGroup; import jalview.io.DataSourceType; import jalview.io.FileLoader; +import java.awt.event.MouseEvent; import java.io.File; import java.io.IOException; import java.io.PrintStream; @@ -18,6 +20,8 @@ import java.io.PrintStream; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; +import junit.extensions.PA; + public class FreeUpMemoryTest { private static final int ONE_MB = 1000 * 1000; @@ -30,16 +34,12 @@ public class FreeUpMemoryTest { Jalview.main(new String[] { "-nonews", "-props", "test/jalview/testProps.jvprops" }); - Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS", - Boolean.TRUE.toString()); - Cache.applicationProperties.setProperty("SHOW_QUALITY", - Boolean.TRUE.toString()); - Cache.applicationProperties.setProperty("SHOW_CONSERVATION", - Boolean.TRUE.toString()); - Cache.applicationProperties.setProperty("SHOW_OCCUPANCY", - Boolean.TRUE.toString()); - Cache.applicationProperties.setProperty("SHOW_IDENTITY", - Boolean.TRUE.toString()); + String True = Boolean.TRUE.toString(); + Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS", True); + Cache.applicationProperties.setProperty("SHOW_QUALITY", True); + Cache.applicationProperties.setProperty("SHOW_CONSERVATION", True); + Cache.applicationProperties.setProperty("SHOW_OCCUPANCY", True); + Cache.applicationProperties.setProperty("SHOW_IDENTITY", True); } /** @@ -68,13 +68,27 @@ public class FreeUpMemoryTest File f = generateAlignment(); f.deleteOnExit(); + long expectedMin = 35L; + long usedMemoryAtStart=getUsedMemory(); + if (usedMemoryAtStart>expectedMin) + { + System.err.println("used memory before test is "+usedMemoryAtStart+" > "+expectedMin+"MB .. adjusting minimum."); + expectedMin = usedMemoryAtStart; + } doStuffInJalview(f); Desktop.instance.closeAll_actionPerformed(null); - checkUsedMemory(35L); + checkUsedMemory(expectedMin); } + private static long getUsedMemory() + { + long availableMemory = Runtime.getRuntime().totalMemory() / ONE_MB; + long freeMemory = Runtime.getRuntime().freeMemory() / ONE_MB; + long usedMemory = availableMemory - freeMemory; + return usedMemory; + } /** * Requests garbage collection and then checks whether remaining memory in use * is less than the expected value (in Megabytes) @@ -84,26 +98,24 @@ public class FreeUpMemoryTest protected void checkUsedMemory(long expectedMax) { /* - * request garbage collection and wait briefly for it to run; + * request garbage collection and wait for it to run; * NB there is no guarantee when, or whether, it will do so + * wait time depends on JRE/processor, generous allowance here */ System.gc(); - waitFor(100); + waitFor(1500); /* * a second gc() call should not be necessary - but it is! * the test passes with it, and fails without it */ System.gc(); - waitFor(100); + waitFor(1500); /* * check used memory is 'reasonably low' */ - long availableMemory = Runtime.getRuntime().totalMemory() / ONE_MB; - long freeMemory = Runtime.getRuntime().freeMemory() / ONE_MB; - long usedMemory = availableMemory - freeMemory; - + long usedMemory = getUsedMemory(); /* * sanity check - fails if any frame was added after * closeAll_actionPerformed @@ -142,6 +154,20 @@ public class FreeUpMemoryTest } /* + * open an Overview window + */ + af.overviewMenuItem_actionPerformed(null); + assertNotNull(af.alignPanel.overviewPanel); + + /* + * exercise the pop-up menu in the Overview Panel (JAL-2864) + */ + Object[] args = new Object[] { + new MouseEvent(af, 0, 0, 0, 0, 0, 1, true) }; + PA.invokeMethod(af.alignPanel.overviewPanel, + "showPopupMenu(java.awt.event.MouseEvent)", args); + + /* * set a selection group - potential memory leak if it retains * a reference to the alignment */