--- /dev/null
+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
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
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
+ "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
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