Merge branch 'feature/JAL-3690_callback-based-web-services' into alpha/JAL-3066_Jalvi...
[jalview.git] / test / jalview / gui / FreeUpMemoryTest.java
index 9b21274..66e0d22 100644 (file)
@@ -35,11 +35,11 @@ public class FreeUpMemoryTest
     Jalview.main(new String[] { "-nonews", "-props",
         "test/jalview/testProps.jvprops" });
     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);
+    Cache.setPropertyNoSave("SHOW_ANNOTATIONS", True);
+    Cache.setPropertyNoSave("SHOW_QUALITY", True);
+    Cache.setPropertyNoSave("SHOW_CONSERVATION", True);
+    Cache.setPropertyNoSave("SHOW_OCCUPANCY", True);
+    Cache.setPropertyNoSave("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);
+    Desktop.getInstance().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)
@@ -101,15 +115,12 @@ public class FreeUpMemoryTest
     /*
      * 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
      */
-    assertEquals(Desktop.instance.getAllFrames().length, 0);
+    assertEquals(Desktop.getInstance().getAllFrames().length, 0);
 
     /*
      * if this assertion fails