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