JAL-4160 update args used in test suite for new CLI framework
[jalview.git] / test / jalview / gui / FreeUpMemoryTest.java
index 09ee560..475af2f 100644 (file)
@@ -1,3 +1,23 @@
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ * 
+ * This file is part of Jalview.
+ * 
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License 
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *  
+ * Jalview is distributed in the hope that it will be useful, but 
+ * WITHOUT ANY WARRANTY; without even the implied warranty 
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
+ * PURPOSE.  See the GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
 package jalview.gui;
 
 import static org.testng.Assert.assertNotNull;
@@ -90,7 +110,7 @@ public class FreeUpMemoryTest
   /*
    * maximum retained heap usage (in MB) for a passing test
    */
-  private static int MAX_RESIDUAL_HEAP = 38;
+  private static int MAX_RESIDUAL_HEAP = 45;
 
   /**
    * Configure (read-only) Jalview property settings for test
@@ -100,7 +120,7 @@ public class FreeUpMemoryTest
   {
     Jalview.main(
             new String[]
-            { "-nonews", "-props", "test/jalview/testProps.jvprops" });
+            { "--nonews", "--props", "test/jalview/testProps.jvprops" });
     String True = Boolean.TRUE.toString();
     Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS", True);
     Cache.applicationProperties.setProperty("SHOW_QUALITY", True);
@@ -117,7 +137,8 @@ public class FreeUpMemoryTest
 
     doStuffInJalview(f);
 
-    Desktop.instance.closeAll_actionPerformed(null);
+    if (Desktop.instance != null)
+      Desktop.instance.closeAll_actionPerformed(null);
 
     checkUsedMemory(MAX_RESIDUAL_HEAP);
   }
@@ -134,7 +155,7 @@ public class FreeUpMemoryTest
     long freeMemory = Runtime.getRuntime().freeMemory();
     long usedMemory = availableMemory - freeMemory;
 
-    return (int) (usedMemory/ ONE_MB);
+    return (int) (usedMemory / ONE_MB);
   }
 
   /**
@@ -150,6 +171,7 @@ public class FreeUpMemoryTest
      * NB there is no guarantee when, or whether, it will do so
      */
     long usedMemory = 0L;
+    Long minUsedMemory = null;
     int gcCount = 0;
     while (gcCount < 3)
     {
@@ -157,6 +179,10 @@ public class FreeUpMemoryTest
       System.gc();
       waitFor(1500);
       usedMemory = getUsedMemory();
+      if (minUsedMemory == null || usedMemory < minUsedMemory)
+      {
+        minUsedMemory = usedMemory;
+      }
       if (usedMemory < expectedMax)
       {
         break;
@@ -171,9 +197,9 @@ public class FreeUpMemoryTest
      * - take a heap dump and identify large objects in the heap and their referers
      * - fix code as necessary to null the references on close
      */
-    System.out
-            .println("Used memory after " + gcCount + " call(s) to gc() = "
-                    + usedMemory + "MB (should be <=" + expectedMax + ")");
+    System.out.println("(Minimum) Used memory after " + gcCount
+            + " call(s) to gc() = " + minUsedMemory + "MB (should be <="
+            + expectedMax + ")");
     assertTrue(usedMemory <= expectedMax, String.format(
             "Used memory %d should be less than %d (Recommend running test manually to verify)",
             usedMemory, expectedMax));