JAL-931 - groovy test harness code.
authorjprocter <jprocter@compbio.dundee.ac.uk>
Wed, 14 Sep 2011 11:01:50 +0000 (12:01 +0100)
committerjprocter <jprocter@compbio.dundee.ac.uk>
Wed, 14 Sep 2011 11:01:50 +0000 (12:01 +0100)
examples/groovy/JvLoadTestHarness.groovy [new file with mode: 0644]
examples/groovy/JvLoadTester.groovy [new file with mode: 0644]

diff --git a/examples/groovy/JvLoadTestHarness.groovy b/examples/groovy/JvLoadTestHarness.groovy
new file mode 100644 (file)
index 0000000..c0b3384
--- /dev/null
@@ -0,0 +1,12 @@
+// You need to add the groovy directory to the class path from the script window\r
+// or add the groovy directory to the java classpath when running Jalview\r
+\r
+jvtst = new JvLoadTester().newJvLoadTest('D:\\fooTest.jar');\r
+try { jvtst.TestForAll('D:\\e6-workspace\\Jalview RNA\\examples\\rna\\rfamSml') } \r
+catch (OutOfMemoryError e) { \r
+// inspect jvtst to find out what file + file index it was on\r
+}\r
+// Terminate Jalview - useful if running from command line\r
+if (Jalview.isInBatchMode()) {\r
+ Jalview.quit() \r
+}
\ No newline at end of file
diff --git a/examples/groovy/JvLoadTester.groovy b/examples/groovy/JvLoadTester.groovy
new file mode 100644 (file)
index 0000000..d944ece
--- /dev/null
@@ -0,0 +1,138 @@
+import jalview.gui.*;\r
+import jalview.io.*;\r
+\r
+def class JvLoadTest {\r
+    FileLoader fl = null;\r
+    def String safename = null;\r
+    JvLoadTest(String sname) { \r
+       if (!new File(sname).exists() || new File(sname).canWrite())\r
+           {\r
+               safename = sname;\r
+           } else {\r
+               System.err.println("Warning : "+sname+" isn't being used to store temporary files.");\r
+           }   \r
+    }\r
+    def public boolean doTest (file) {\r
+       fl = new FileLoader(false);\r
+       System.gc();\r
+       AlignFrame af = fl.LoadFileWaitTillLoaded(file\r
+                                                 ,FormatAdapter.FILE);\r
+       return doTest(af);\r
+    }\r
+    def public boolean doSequentialReadTest (file) {\r
+       return doSequentialReadTest(file, 0);\r
+    }\r
+    // Return true if there is more data to read.\r
+    def public boolean peekFp(FileParse fp) {\r
+       try { fp.mark(); }  catch (Exception ex) { System.err.println("FAILED mark."+ex); return false; };\r
+       try {\r
+         def String nl;\r
+         for (i in 1..3) { \r
+          nl = fp.nextLine();\r
+          if (nl==null) { return false; }\r
+          System.out.println(nl +"\\n");\r
+          }\r
+       } catch (Exception e) { // end of file.\r
+               return false; };\r
+       try { fp.reset(); } catch (Exception ex) { System.err.println("FAILED rewind."+ex); return false; };\r
+       return true;\r
+    }\r
+    /*\r
+      Halt after loading the mx'th entry in the filestream\r
+    */\r
+    def public boolean doSequentialReadTest (file, int mx) {\r
+       // first properly open the file\r
+       //      if (!doTest(file)) { return };\r
+       def FileParse fp = null;\r
+       try {\r
+               fp = new FileParse(file, AppletFormatAdapter.FILE);\r
+       } catch (Exception e) { System.err.println("Couldn't open "+file+"\\n"); e.printStackTrace(); return false;};\r
+       Desktop.instance.closeAll_actionPerformed(null)\r
+           System.gc();\r
+       while (fp!=null && fp.isValid() && (mx==0 || mx!=fp.index)) {\r
+           if (!peekFp(fp)) return false;\r
+           fl = new FileLoader(false);\r
+           AlignFrame af = fl.LoadFileWaitTillLoaded(fp, null);\r
+           System.out.println("FileParse index: "+fp.index);   \r
+           if (af!=null && (mx==0 || mx!=fp.index))\r
+               {       def boolean res = doTest(af);\r
+               if (!res)\r
+                   {\r
+                       // return false;\r
+                   }\r
+               } else {\r
+                   // return false;\r
+               }\r
+       }\r
+       return true;\r
+    }\r
+    def public void waitTillSettled(AlignFrame af)\r
+    {\r
+       if (af==null) { return; }\r
+       Thread.sleep(10);\r
+       while (af.getViewport().updatingConsensus || af.getViewport().updatingConservation) {\r
+           Thread.sleep(150); // wait until things settle down\r
+       }\r
+    }\r
+    def public boolean doTest(AlignFrame af) {\r
+       Object pr = af.getViewport().getAlignment().getProperty("AC");\r
+       if (pr!=null) { System.out.println("Accession = "+(String) pr); }\r
+       af.selectAllSequenceMenuItem_actionPerformed(null)\r
+           def boolean done = false;\r
+       // Just try to save - don\'t mess around with clipboard\r
+       /*while (!done) {\r
+         try {\r
+         af.copy_actionPerformed(null)\r
+         done = true;\r
+         } catch (Exception e) {\r
+         Thread.sleep(100); // wait until clipboard might be available again\r
+         }\r
+         }*/\r
+       if (af==null) { return false; }\r
+       waitTillSettled(af);\r
+       // Try and save as a jalview project and reload\r
+       try {\r
+           //      af.saveAlignment(safename, "Jalview")\r
+           new Jalview2XML().SaveState(new java.io.File(safename));\r
+           Thread.sleep(100);\r
+               } catch (Exception ex) { \r
+                   System.out.println("Couldn\'t save.");\r
+                   ex.printStackTrace(System.err);\r
+                   return false;\r
+               }\r
+       waitTillSettled(af);\r
+       try {\r
+           Desktop.instance.closeAll_actionPerformed(null);\r
+       } catch (Exception ex) {}\r
+       System.gc();\r
+       try {\r
+           af = new FileLoader(false).LoadFileWaitTillLoaded(safename, FormatAdapter.FILE);    \r
+       } \r
+       catch (Exception ex) {\r
+           System.out.println("Couldn't reload saved file.");\r
+            System.gc();\r
+           return false;\r
+       }\r
+       waitTillSettled(af);\r
+\r
+       Desktop.instance.closeAll_actionPerformed(null);\r
+\r
+       // af.paste(true)\r
+       // af.newView_actionPerformed(null)\r
+       // af.newView_actionPerformed(null)\r
+\r
+       return true;\r
+    }\r
+    def public boolean TestForAll(String dir) {\r
+       println "For directory or file : "+dir;\r
+       File fd = new File(dir);\r
+       if (!fd.isDirectory()) { return doSequentialReadTest(dir); }\r
+       fd.eachFile() { file -> TestForAll(file.getAbsolutePath()) };\r
+    }\r
+}\r
+def JvLoadTest newJvLoadTest(String tempFile) {\r
+       jalview.gui.Desktop.instance.closeAll_actionPerformed(null);\r
+       System.gc();\r
+       jalview.gui.Desktop.instance.desktop.showMemoryUsage(true);\r
+       return new JvLoadTest(tempFile)\r
+}
\ No newline at end of file