Add testing dirs
[proteocache.git] / testsrc / compbio / engine / LoadBalancerTester.java
diff --git a/testsrc/compbio/engine/LoadBalancerTester.java b/testsrc/compbio/engine/LoadBalancerTester.java
new file mode 100644 (file)
index 0000000..f345720
--- /dev/null
@@ -0,0 +1,68 @@
+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 2 sequences per 500 letters\r
+                        */\r
+                       ConfiguredExecutable<ClustalW> confClust = Configurator\r
+                                       .configureExecutable(clustal);\r
+                       ExecProvider aEngine = LoadBalancer.getEngine(confClust, data);\r
+                       Limit<ClustalW> locExec = new Limit<ClustalW>(2, 500, PresetManager.LOCAL_ENGINE_LIMIT_PRESET); \r
+                       // For testing of production configuration uncomment\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
+                       // Engine will be local because LoadBalancer accessed the presets & limits \r
+                       // directly\r
+                       // For testing of production configuration uncomment\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