Remove test jobs from statistics
authorpvtroshin <pvtroshin@e3abac25-378b-4346-85de-24260fe3988d>
Wed, 5 Oct 2011 10:51:38 +0000 (10:51 +0000)
committerpvtroshin <pvtroshin@e3abac25-378b-4346-85de-24260fe3988d>
Wed, 5 Oct 2011 10:51:38 +0000 (10:51 +0000)
git-svn-id: link to svn.lifesci.dundee.ac.uk/svn/barton/ptroshin/JABA2@4642 e3abac25-378b-4346-85de-24260fe3988d

.project
testsrc/compbio/stat/collector/TestInputFilter.java [new file with mode: 0644]
testsrc/testdata/test_input.aln [new file with mode: 0644]
testsrc/testdata/test_input.fasta [new file with mode: 0644]
webservices/compbio/stat/collector/ExecutionStatCollector.java
webservices/compbio/stat/collector/InputFilter.java [new file with mode: 0644]
webservices/compbio/ws/client/WSTester.java

index b47d53e..c564e9d 100644 (file)
--- a/.project
+++ b/.project
                        <arguments>\r
                        </arguments>\r
                </buildCommand>\r
+               <buildCommand>\r
+                       <name>net.sourceforge.metrics.builder</name>\r
+                       <arguments>\r
+                       </arguments>\r
+               </buildCommand>\r
        </buildSpec>\r
        <natures>\r
                <nature>org.eclipse.jdt.core.javanature</nature>\r
                <nature>org.eclipse.wst.common.project.facet.core.nature</nature>\r
+               <nature>net.sourceforge.metrics.nature</nature>\r
        </natures>\r
 </projectDescription>\r
diff --git a/testsrc/compbio/stat/collector/TestInputFilter.java b/testsrc/compbio/stat/collector/TestInputFilter.java
new file mode 100644 (file)
index 0000000..23203e1
--- /dev/null
@@ -0,0 +1,40 @@
+package compbio.stat.collector;\r
+\r
+import java.io.File;\r
+import java.io.IOException;\r
+\r
+import org.testng.Assert;\r
+import org.testng.annotations.Test;\r
+\r
+import compbio.metadata.AllTestSuit;\r
+\r
+public class TestInputFilter {\r
+\r
+       final static String FASTA_INPUT = AllTestSuit.TEST_DATA_PATH_ABSOLUTE\r
+                       + "TO1381.fasta";\r
+       final static String ALN_INPUT = AllTestSuit.TEST_DATA_PATH_ABSOLUTE\r
+                       + "TO1381L.aln";\r
+       final static String TEST_FASTA_INPUT = AllTestSuit.TEST_DATA_PATH_ABSOLUTE\r
+                       + "test_input.fasta";\r
+       final static String TEST_ALIGNMENT_INPUT = AllTestSuit.TEST_DATA_PATH_ABSOLUTE\r
+                       + "test_input.aln";\r
+       @Test\r
+       public void TestInputFilter() {\r
+               InputFilter ifilter = new InputFilter();\r
+               try {\r
+                       // Makes sure real files are accepted\r
+                       Assert.assertTrue(ifilter.accept(new File(FASTA_INPUT)));\r
+                       Assert.assertTrue(ifilter.accept(new File(ALN_INPUT)));\r
+\r
+                       // .. and test files are not\r
+                       Assert.assertFalse(ifilter.accept(new File(TEST_ALIGNMENT_INPUT)));\r
+                       Assert.assertFalse(ifilter.accept(new File(TEST_FASTA_INPUT)));\r
+                       // does not matter if the file is empty, it is still not a test\r
+                       // file!\r
+                       Assert.assertTrue(ifilter.accept(File.createTempFile("aaa", "bbb")));\r
+               } catch (IOException e) {\r
+                       e.printStackTrace();\r
+                       Assert.fail(e.getMessage());\r
+               }\r
+       }\r
+}\r
diff --git a/testsrc/testdata/test_input.aln b/testsrc/testdata/test_input.aln
new file mode 100644 (file)
index 0000000..d989481
--- /dev/null
@@ -0,0 +1,4 @@
+>Foo\r
+MTADGPRELLQLRAAVRHRPQDFVAWLMLADAELGMGDTTAGEMAVQRGLALHPGHPEAV--------\r
+>Bar\r
+ASDAAPEH------------PGIALWLHALE-DAGQAEAAA---AYTRAHQLLPEEPYITAQLLNAVA\r
diff --git a/testsrc/testdata/test_input.fasta b/testsrc/testdata/test_input.fasta
new file mode 100644 (file)
index 0000000..ac2e701
--- /dev/null
@@ -0,0 +1,4 @@
+>Foo\r
+MTADGPRELLQLRAAVRHRPQDFVAWLMLADAELGMGDTTAGEMAVQRGLALHPGHPEAV\r
+>Bar\r
+ASDAAPEHPGIALWLHALEDAGQAEAAAAYTRAHQLLPEEPYITAQLLNAVA\r
index ad89058..c64a5b8 100644 (file)
@@ -346,9 +346,15 @@ public class ExecutionStatCollector implements Runnable {
                }\r
        }\r
 \r
+       // TODO test!\r
        void collectStatistics() {\r
                File[] files = workDirectory.listFiles(directories);\r
                for (File file : files) {\r
+                       if (!InputFilter.accept(new File(file.getPath() + File.separator\r
+                                       + SkeletalExecutable.INPUT))) {\r
+                               // skip work directory with test input\r
+                               continue;\r
+                       }\r
                        JobDirectory jd = new JobDirectory(file);\r
                        JobStat jstat = jd.getJobStat();\r
                        // Do not record stats on the job that has not completed yet\r
@@ -361,7 +367,6 @@ public class ExecutionStatCollector implements Runnable {
                        // System.out.println(jd.getJobStat().getJobReportTabulated());\r
                }\r
        }\r
-\r
        @Override\r
        public void run() {\r
                log.info("Started updating statistics at " + new Date());\r
diff --git a/webservices/compbio/stat/collector/InputFilter.java b/webservices/compbio/stat/collector/InputFilter.java
new file mode 100644 (file)
index 0000000..f55e843
--- /dev/null
@@ -0,0 +1,65 @@
+package compbio.stat.collector;\r
+\r
+import java.io.BufferedReader;\r
+import java.io.File;\r
+import java.io.FileReader;\r
+import java.io.IOException;\r
+\r
+import org.apache.log4j.Logger;\r
+\r
+import compbio.util.FileUtil;\r
+import compbio.util.Util;\r
+import compbio.ws.client.WSTester;\r
+\r
+public class InputFilter {\r
+\r
+       private static final Logger log = Logger.getLogger(InputFilter.class);\r
+       /**\r
+        * Accepts input as valid unless it is a test input\r
+        * \r
+        * @param input\r
+        * @return\r
+        */\r
+       static boolean accept(File input) {\r
+               if (input == null)\r
+                       return true;\r
+               assert input.isFile() : "Input file is not a file! " + input;\r
+               String[] fastainput = WSTester.fastaInput.split("\n");\r
+               assert fastainput.length == 4;\r
+               String[] aligninput = WSTester.fastaAlignment.split("\n");\r
+               assert aligninput.length == 4;\r
+               // We do now know the type of the input here so must compare with both\r
+               // references\r
+               boolean isReference = compareLines(input, fastainput);\r
+               if (!isReference) {\r
+                       isReference = compareLines(input, aligninput);\r
+               }\r
+               // only accept genuine input\r
+               return !isReference;\r
+       }\r
+\r
+       private static boolean compareLines(File input, String[] reference) {\r
+               BufferedReader reader = null;\r
+               try {\r
+                       reader = new BufferedReader(new FileReader(input));\r
+                       // only compare first four lines of the file with reference\r
+                       // because the reference length is only 4 lines\r
+                       for (int i = 0; i < 4; i++) {\r
+                               String line = reader.readLine();\r
+                               if (Util.isEmpty(line)) {\r
+                                       return false;\r
+                               }\r
+                               line = line.trim();\r
+                               if (!line.equals(reference[i].trim())) {\r
+                                       return false;\r
+                               }\r
+                       }\r
+                       reader.close();\r
+               } catch (IOException ioe) {\r
+                       log.warn(ioe, ioe.getCause());\r
+               } finally {\r
+                       FileUtil.closeSilently(reader);\r
+               }\r
+               return true;\r
+       }\r
+}\r
index 8838903..f4a4708 100644 (file)
@@ -66,15 +66,15 @@ public class WSTester {
        /**\r
         * Sequences to be used as input for all WS\r
         */\r
-       static final String fastaInput = ">Foo\n"\r
+       public static final String fastaInput = ">Foo\n"\r
                        + "MTADGPRELLQLRAAVRHRPQDFVAWLMLADAELGMGDTTAGEMAVQRGLALHPGHPEAV"\r
                        + "\n>Bar\n"\r
-                       + "ASDAAPEHPGIALWLHALEDAGQAEAAAAYTRAHQLLPEEPYITAQLLNAVA";\r
+                       + "ASDAAPEHPGIALWLHALEDAGQAEAAAAYTRAHQLLPEEPYITAQLLNAVA\n";\r
 \r
-       static final String fastaAlignment = ">Foo\r\n"\r
-                       + "MTADGPRELLQLRAAVRHRPQDFVAWLMLADAELGMGDTTAGEMAVQRGLALHPGHPEAV--------\r\n"\r
-                       + ">Bar\r\n"\r
-                       + "ASDAAPEH------------PGIALWLHALE-DAGQAEAAA---AYTRAHQLLPEEPYITAQLLNAVA\r\n"\r
+       public static final String fastaAlignment = ">Foo\n"\r
+                       + "MTADGPRELLQLRAAVRHRPQDFVAWLMLADAELGMGDTTAGEMAVQRGLALHPGHPEAV--------\n"\r
+                       + ">Bar\n"\r
+                       + "ASDAAPEH------------PGIALWLHALE-DAGQAEAAA---AYTRAHQLLPEEPYITAQLLNAVA\n"\r
                        + "";\r
 \r
        static final List<FastaSequence> seqs = loadSeqs();\r