From cc4af2b1f8675eb721268666ef8e7417566fb72b Mon Sep 17 00:00:00 2001 From: pvtroshin Date: Wed, 24 Nov 2010 14:25:26 +0000 Subject: [PATCH] Add LoadBalancer and Limit testers from JWS2 branch git-svn-id: link to svn.lifesci.dundee.ac.uk/svn/barton/ptroshin/JABA2@3388 e3abac25-378b-4346-85de-24260fe3988d --- .../compbio/engine/EngineConfiguratorTester.java | 5 +- testsrc/compbio/engine/LoadBalancerTester.java | 64 ++++++++++++++++++++ testsrc/compbio/runner/msa/LimitTester.java | 46 +++++++++++++- 3 files changed, 108 insertions(+), 7 deletions(-) create mode 100644 testsrc/compbio/engine/LoadBalancerTester.java diff --git a/testsrc/compbio/engine/EngineConfiguratorTester.java b/testsrc/compbio/engine/EngineConfiguratorTester.java index 50763c0..6a0d27d 100644 --- a/testsrc/compbio/engine/EngineConfiguratorTester.java +++ b/testsrc/compbio/engine/EngineConfiguratorTester.java @@ -22,9 +22,6 @@ import static org.testng.Assert.fail; import org.testng.annotations.Test; -import compbio.engine.AsyncExecutor; -import compbio.engine.Configurator; -import compbio.engine.SyncExecutor; import compbio.engine.client.ConfiguredExecutable; import compbio.metadata.JobSubmissionException; import compbio.runner.msa.ClustalW; @@ -56,6 +53,6 @@ public class EngineConfiguratorTester { e.printStackTrace(); fail(e.getMessage()); } - } + } diff --git a/testsrc/compbio/engine/LoadBalancerTester.java b/testsrc/compbio/engine/LoadBalancerTester.java new file mode 100644 index 0000000..7d0661a --- /dev/null +++ b/testsrc/compbio/engine/LoadBalancerTester.java @@ -0,0 +1,64 @@ +package compbio.engine; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; +import static org.testng.Assert.fail; + +import java.io.FileInputStream; +import java.io.IOException; +import java.util.List; + +import org.testng.annotations.Test; + +import compbio.data.sequence.FastaSequence; +import compbio.data.sequence.SequenceUtil; +import compbio.engine.client.ConfiguredExecutable; +import compbio.engine.client.Executable.ExecProvider; +import compbio.metadata.AllTestSuit; +import compbio.metadata.JobSubmissionException; +import compbio.metadata.Limit; +import compbio.metadata.PresetManager; +import compbio.runner.msa.ClustalW; + +public class LoadBalancerTester { + + @Test + public void testLoadBalance() { + /** + * This is 5 sequence x per 20000 length + */ + String test_input = AllTestSuit.TEST_DATA_PATH_ABSOLUTE + + "testlimit.fasta"; + try { + FileInputStream fio = new FileInputStream(test_input); + List data = SequenceUtil.readFasta(fio); + fio.close(); + assertNotNull(data); + assertTrue(data.size() > 0); + + ClustalW clustal = new ClustalW(); + /** + * ClustalW local limit is 40 sequences per 500 letters + */ + ConfiguredExecutable confClust = Configurator + .configureExecutable(clustal); + ExecProvider aEngine = LoadBalancer.getEngine(confClust, data); + Limit locExec = confClust + .getLimit(PresetManager.LOCAL_ENGINE_LIMIT_PRESET); + assertTrue(locExec.getSeqNumber() <= data.size() + || locExec.getAvgSeqLength() * locExec.getSeqNumber() <= Limit + .getAvgSequenceLength(data)); + + assertEquals(aEngine, ExecProvider.Cluster); + + } catch (JobSubmissionException e) { + e.printStackTrace(); + fail(e.getMessage()); + } catch (IOException e) { + e.printStackTrace(); + fail(e.getMessage()); + } + + } +} diff --git a/testsrc/compbio/runner/msa/LimitTester.java b/testsrc/compbio/runner/msa/LimitTester.java index 75b319a..8a9e56a 100644 --- a/testsrc/compbio/runner/msa/LimitTester.java +++ b/testsrc/compbio/runner/msa/LimitTester.java @@ -27,6 +27,7 @@ import static org.testng.Assert.fail; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; +import java.io.IOException; import java.util.List; import javax.xml.bind.JAXBException; @@ -34,13 +35,13 @@ import javax.xml.bind.JAXBException; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; -import compbio.engine.client.ConfExecutable; +import compbio.data.sequence.FastaSequence; +import compbio.data.sequence.SequenceUtil; import compbio.engine.conf.RunnerConfigMarshaller; import compbio.metadata.AllTestSuit; import compbio.metadata.Limit; import compbio.metadata.LimitsManager; import compbio.metadata.PresetManager; -import compbio.runner.msa.ClustalW; public class LimitTester { @@ -48,7 +49,7 @@ public class LimitTester { + "ClustalLimits.xml"; static String test_input = AllTestSuit.TEST_DATA_PATH_ABSOLUTE + "TO1381.fasta"; // - static final String input = AllTestSuit.TEST_DATA_PATH + static final String input = AllTestSuit.TEST_DATA_PATH + "ClustalPresets.xml"; LimitsManager clustalLimitConfig = null; @@ -103,4 +104,43 @@ public class LimitTester { assertEquals(limit.getAvgSeqLength(), 400); assertTrue(limit.isDefault()); } + + @Test + public void testLimitExceeded() { + + String test_input = AllTestSuit.TEST_DATA_PATH_ABSOLUTE + + "testlimit.fasta"; + + FileInputStream fio; + try { + fio = new FileInputStream(test_input); + List data = SequenceUtil.readFasta(fio); + fio.close(); + assertNotNull(data); + assertEquals(data.size(), 6); + assertEquals(Limit.getAvgSequenceLength(data), 20486); + Limit small = new Limit(40, 500, "default"); + + assertTrue(small.isExceeded(data)); + + Limit large = new Limit(500, 500, "default"); + assertFalse(large.isExceeded(data)); + + Limit numSeqOnly = new Limit(6, 0, "default"); + assertFalse(numSeqOnly.isExceeded(data)); + + Limit exnumSeqOnly = new Limit(5, 0, "default"); + assertTrue(exnumSeqOnly.isExceeded(data)); + + Limit numSeq3 = new Limit(5, 1000000, "default"); + assertTrue(numSeq3.isExceeded(data)); + + } catch (FileNotFoundException e) { + e.printStackTrace(); + fail(e.getMessage()); + } catch (IOException e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } } -- 1.7.10.2