Add LoadBalancer and Limit testers from JWS2 branch
authorpvtroshin <pvtroshin@e3abac25-378b-4346-85de-24260fe3988d>
Wed, 24 Nov 2010 14:25:26 +0000 (14:25 +0000)
committerpvtroshin <pvtroshin@e3abac25-378b-4346-85de-24260fe3988d>
Wed, 24 Nov 2010 14:25:26 +0000 (14:25 +0000)
git-svn-id: link to svn.lifesci.dundee.ac.uk/svn/barton/ptroshin/JABA2@3388 e3abac25-378b-4346-85de-24260fe3988d

testsrc/compbio/engine/EngineConfiguratorTester.java
testsrc/compbio/engine/LoadBalancerTester.java [new file with mode: 0644]
testsrc/compbio/runner/msa/LimitTester.java

index 50763c0..6a0d27d 100644 (file)
@@ -22,9 +22,6 @@ import static org.testng.Assert.fail;
 \r
 import org.testng.annotations.Test;\r
 \r
-import compbio.engine.AsyncExecutor;\r
-import compbio.engine.Configurator;\r
-import compbio.engine.SyncExecutor;\r
 import compbio.engine.client.ConfiguredExecutable;\r
 import compbio.metadata.JobSubmissionException;\r
 import compbio.runner.msa.ClustalW;\r
@@ -56,6 +53,6 @@ public class EngineConfiguratorTester {
                        e.printStackTrace();\r
                        fail(e.getMessage());\r
                }\r
-\r
        }\r
+\r
 }\r
diff --git a/testsrc/compbio/engine/LoadBalancerTester.java b/testsrc/compbio/engine/LoadBalancerTester.java
new file mode 100644 (file)
index 0000000..7d0661a
--- /dev/null
@@ -0,0 +1,64 @@
+package compbio.engine;\r
+\r
+import static org.testng.Assert.assertEquals;\r
+import static org.testng.Assert.assertNotNull;\r
+import static org.testng.Assert.assertTrue;\r
+import static org.testng.Assert.fail;\r
+\r
+import java.io.FileInputStream;\r
+import java.io.IOException;\r
+import java.util.List;\r
+\r
+import org.testng.annotations.Test;\r
+\r
+import compbio.data.sequence.FastaSequence;\r
+import compbio.data.sequence.SequenceUtil;\r
+import compbio.engine.client.ConfiguredExecutable;\r
+import compbio.engine.client.Executable.ExecProvider;\r
+import compbio.metadata.AllTestSuit;\r
+import compbio.metadata.JobSubmissionException;\r
+import compbio.metadata.Limit;\r
+import compbio.metadata.PresetManager;\r
+import compbio.runner.msa.ClustalW;\r
+\r
+public class LoadBalancerTester {\r
+\r
+       @Test\r
+       public void testLoadBalance() {\r
+               /**\r
+                * This is 5 sequence x per 20000 length\r
+                */\r
+               String test_input = AllTestSuit.TEST_DATA_PATH_ABSOLUTE\r
+                               + "testlimit.fasta";\r
+               try {\r
+                       FileInputStream fio = new FileInputStream(test_input);\r
+                       List<FastaSequence> data = SequenceUtil.readFasta(fio);\r
+                       fio.close();\r
+                       assertNotNull(data);\r
+                       assertTrue(data.size() > 0);\r
+\r
+                       ClustalW clustal = new ClustalW();\r
+                       /**\r
+                        * ClustalW local limit is 40 sequences per 500 letters\r
+                        */\r
+                       ConfiguredExecutable<ClustalW> confClust = Configurator\r
+                                       .configureExecutable(clustal);\r
+                       ExecProvider aEngine = LoadBalancer.getEngine(confClust, data);\r
+                       Limit locExec = confClust\r
+                                       .getLimit(PresetManager.LOCAL_ENGINE_LIMIT_PRESET);\r
+                       assertTrue(locExec.getSeqNumber() <= data.size()\r
+                                       || locExec.getAvgSeqLength() * locExec.getSeqNumber() <= Limit\r
+                                                       .getAvgSequenceLength(data));\r
+\r
+                       assertEquals(aEngine, ExecProvider.Cluster);\r
+\r
+               } catch (JobSubmissionException e) {\r
+                       e.printStackTrace();\r
+                       fail(e.getMessage());\r
+               } catch (IOException e) {\r
+                       e.printStackTrace();\r
+                       fail(e.getMessage());\r
+               }\r
+\r
+       }\r
+}\r
index 75b319a..8a9e56a 100644 (file)
@@ -27,6 +27,7 @@ import static org.testng.Assert.fail;
 import java.io.File;\r
 import java.io.FileInputStream;\r
 import java.io.FileNotFoundException;\r
+import java.io.IOException;\r
 import java.util.List;\r
 \r
 import javax.xml.bind.JAXBException;\r
@@ -34,13 +35,13 @@ import javax.xml.bind.JAXBException;
 import org.testng.annotations.BeforeMethod;\r
 import org.testng.annotations.Test;\r
 \r
-import compbio.engine.client.ConfExecutable;\r
+import compbio.data.sequence.FastaSequence;\r
+import compbio.data.sequence.SequenceUtil;\r
 import compbio.engine.conf.RunnerConfigMarshaller;\r
 import compbio.metadata.AllTestSuit;\r
 import compbio.metadata.Limit;\r
 import compbio.metadata.LimitsManager;\r
 import compbio.metadata.PresetManager;\r
-import compbio.runner.msa.ClustalW;\r
 \r
 public class LimitTester {\r
 \r
@@ -48,7 +49,7 @@ public class LimitTester {
                        + "ClustalLimits.xml";\r
        static String test_input = AllTestSuit.TEST_DATA_PATH_ABSOLUTE\r
                        + "TO1381.fasta"; //\r
-       static final String input =  AllTestSuit.TEST_DATA_PATH\r
+       static final String input = AllTestSuit.TEST_DATA_PATH\r
                        + "ClustalPresets.xml";\r
 \r
        LimitsManager<ClustalW> clustalLimitConfig = null;\r
@@ -103,4 +104,43 @@ public class LimitTester {
                assertEquals(limit.getAvgSeqLength(), 400);\r
                assertTrue(limit.isDefault());\r
        }\r
+\r
+       @Test\r
+       public void testLimitExceeded() {\r
+\r
+               String test_input = AllTestSuit.TEST_DATA_PATH_ABSOLUTE\r
+                               + "testlimit.fasta";\r
+\r
+               FileInputStream fio;\r
+               try {\r
+                       fio = new FileInputStream(test_input);\r
+                       List<FastaSequence> data = SequenceUtil.readFasta(fio);\r
+                       fio.close();\r
+                       assertNotNull(data);\r
+                       assertEquals(data.size(), 6);\r
+                       assertEquals(Limit.getAvgSequenceLength(data), 20486);\r
+                       Limit small = new Limit(40, 500, "default");\r
+\r
+                       assertTrue(small.isExceeded(data));\r
+\r
+                       Limit large = new Limit(500, 500, "default");\r
+                       assertFalse(large.isExceeded(data));\r
+\r
+                       Limit numSeqOnly = new Limit(6, 0, "default");\r
+                       assertFalse(numSeqOnly.isExceeded(data));\r
+\r
+                       Limit exnumSeqOnly = new Limit(5, 0, "default");\r
+                       assertTrue(exnumSeqOnly.isExceeded(data));\r
+\r
+                       Limit numSeq3 = new Limit(5, 1000000, "default");\r
+                       assertTrue(numSeq3.isExceeded(data));\r
+\r
+               } catch (FileNotFoundException e) {\r
+                       e.printStackTrace();\r
+                       fail(e.getMessage());\r
+               } catch (IOException e) {\r
+                       e.printStackTrace();\r
+                       fail(e.getMessage());\r
+               }\r
+       }\r
 }\r