Some lost files
[proteocache.git] / testsrc / compbio / engine / LoadBalancerTester.java
1 package compbio.engine;\r
2 \r
3 import static org.testng.Assert.assertEquals;\r
4 import static org.testng.Assert.assertNotNull;\r
5 import static org.testng.Assert.assertTrue;\r
6 import static org.testng.Assert.fail;\r
7 \r
8 import java.io.FileInputStream;\r
9 import java.io.IOException;\r
10 import java.util.List;\r
11 \r
12 import org.testng.annotations.Test;\r
13 \r
14 import compbio.data.sequence.FastaSequence;\r
15 import compbio.data.sequence.SequenceUtil;\r
16 import compbio.engine.client.ConfiguredExecutable;\r
17 import compbio.engine.client.Executable.ExecProvider;\r
18 import compbio.metadata.AllTestSuit;\r
19 import compbio.metadata.JobSubmissionException;\r
20 import compbio.metadata.Limit;\r
21 import compbio.metadata.PresetManager;\r
22 import compbio.runner.msa.ClustalW;\r
23 \r
24 public class LoadBalancerTester {\r
25 \r
26         @Test\r
27         public void testLoadBalance() {\r
28                 /**\r
29                  * This is 5 sequence x per 20000 length\r
30                  */\r
31                 String test_input = AllTestSuit.TEST_DATA_PATH_ABSOLUTE\r
32                                 + "testlimit.fasta";\r
33                 try {\r
34                         FileInputStream fio = new FileInputStream(test_input);\r
35                         List<FastaSequence> data = SequenceUtil.readFasta(fio);\r
36                         fio.close();\r
37                         assertNotNull(data);\r
38                         assertTrue(data.size() > 0);\r
39 \r
40                         ClustalW clustal = new ClustalW();\r
41                         /**\r
42                          * ClustalW local limit is 2 sequences per 500 letters\r
43                          */\r
44                         ConfiguredExecutable<ClustalW> confClust = Configurator\r
45                                         .configureExecutable(clustal);\r
46                         ExecProvider aEngine = LoadBalancer.getEngine(confClust, data);\r
47                         Limit<ClustalW> locExec = new Limit<ClustalW>(2, 500, PresetManager.LOCAL_ENGINE_LIMIT_PRESET); \r
48                         // For testing of production configuration uncomment\r
49                         //Limit locExec = confClust\r
50                         //              .getLimit(PresetManager.LOCAL_ENGINE_LIMIT_PRESET);\r
51                         assertTrue(locExec.getSeqNumber() <= data.size()\r
52                                         || locExec.getAvgSeqLength() * locExec.getSeqNumber() <= Limit\r
53                                                         .getAvgSequenceLength(data));\r
54                         // Engine will be local because LoadBalancer accessed the presets & limits \r
55                         // directly\r
56                         // For testing of production configuration uncomment\r
57                         // assertEquals(aEngine, ExecProvider.Cluster);\r
58 \r
59                 } catch (JobSubmissionException e) {\r
60                         e.printStackTrace();\r
61                         fail(e.getMessage());\r
62                 } catch (IOException e) {\r
63                         e.printStackTrace();\r
64                         fail(e.getMessage());\r
65                 }\r
66 \r
67         }\r
68 }\r