1 package compbio.engine;
\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
8 import java.io.FileInputStream;
\r
9 import java.io.IOException;
\r
10 import java.util.List;
\r
12 import org.testng.annotations.Test;
\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
24 public class LoadBalancerTester {
\r
27 public void testLoadBalance() {
\r
29 * This is 5 sequence x per 20000 length
\r
31 String test_input = AllTestSuit.TEST_DATA_PATH_ABSOLUTE
\r
32 + "testlimit.fasta";
\r
34 FileInputStream fio = new FileInputStream(test_input);
\r
35 List<FastaSequence> data = SequenceUtil.readFasta(fio);
\r
37 assertNotNull(data);
\r
38 assertTrue(data.size() > 0);
\r
40 ClustalW clustal = new ClustalW();
\r
42 * ClustalW local limit is 2 sequences per 500 letters
\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
56 // For testing of production configuration uncomment
\r
57 // assertEquals(aEngine, ExecProvider.Cluster);
\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