1 /* Copyright (c) 2009 Peter Troshin
\r
3 * JAva Bioinformatics Analysis Web Services (JABAWS) @version: 1.0
\r
5 * This library is free software; you can redistribute it and/or modify it under the terms of the
\r
6 * Apache License version 2 as published by the Apache Software Foundation
\r
8 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
\r
9 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache
\r
10 * License for more details.
\r
12 * A copy of the license is in apache_license.txt. It is also available here:
\r
13 * @see: http://www.apache.org/licenses/LICENSE-2.0.txt
\r
15 * Any republication or derived work distributed in source code form
\r
16 * must include this copyright and license notice.
\r
19 package compbio.runner.msa;
\r
21 import static org.testng.Assert.assertEquals;
\r
22 import static org.testng.Assert.assertNotNull;
\r
23 import static org.testng.Assert.assertNull;
\r
24 import static org.testng.Assert.assertTrue;
\r
25 import static org.testng.Assert.fail;
\r
27 import java.io.File;
\r
28 import java.io.FileInputStream;
\r
29 import java.io.FileNotFoundException;
\r
30 import java.io.IOException;
\r
32 import javax.xml.bind.ValidationException;
\r
34 import org.testng.annotations.BeforeMethod;
\r
35 import org.testng.annotations.Test;
\r
37 import compbio.engine.AsyncExecutor;
\r
38 import compbio.engine.Configurator;
\r
39 import compbio.engine.FilePuller;
\r
40 import compbio.engine.SyncExecutor;
\r
41 import compbio.engine.client.ConfExecutable;
\r
42 import compbio.engine.client.ConfiguredExecutable;
\r
43 import compbio.engine.client.Executable;
\r
44 import compbio.engine.client.RunConfiguration;
\r
45 import compbio.engine.cluster.drmaa.JobRunner;
\r
46 import compbio.metadata.AllTestSuit;
\r
47 import compbio.metadata.ChunkHolder;
\r
48 import compbio.metadata.JobExecutionException;
\r
49 import compbio.metadata.JobSubmissionException;
\r
50 import compbio.metadata.LimitsManager;
\r
51 import compbio.metadata.PresetManager;
\r
52 import compbio.metadata.ResultNotAvailableException;
\r
53 import compbio.metadata.RunnerConfig;
\r
55 public class ProbconsTester {
\r
57 private Probcons probc;
\r
59 @BeforeMethod(groups = { AllTestSuit.test_group_cluster,
\r
60 AllTestSuit.test_group_runner, AllTestSuit.test_group_non_windows })
\r
61 public void init() {
\r
62 probc = new Probcons();
\r
63 probc.setInput(AllTestSuit.test_input); // .setOutput("Mafft.out").setError("mafft.progress");
\r
66 @Test(groups = { AllTestSuit.test_group_runner,
\r
67 AllTestSuit.test_group_non_windows })
\r
68 public void testSetInputTester() {
\r
69 Probcons mf = new Probcons();
\r
70 // System.out.println(mf.getParameters(null));
\r
71 mf.setInput("INNN");
\r
72 // System.out.println(mf.getParameters(null));
\r
73 mf.setError("ERRR");
\r
74 mf.setInput("INN222");
\r
75 mf.setOutput("OUT");
\r
76 // System.out.println(mf.getParameters(null));
\r
79 @Test(groups = { AllTestSuit.test_group_runner,
\r
80 AllTestSuit.test_group_non_windows })
\r
81 public void testExecute() {
\r
83 ConfiguredExecutable<Probcons> cmafft = Configurator
\r
84 .configureExecutable(probc, Executable.ExecProvider.Local);
\r
85 // option for sub matrix is not supported
\r
86 // cmafft.getParameters().setParam("--matrixfile", "PAM200");
\r
87 SyncExecutor sexecutor = Configurator.getSyncEngine(cmafft);
\r
88 sexecutor.executeJob();
\r
89 cmafft = (ConfiguredExecutable<Probcons>) sexecutor.waitForResult();
\r
90 assertNotNull(cmafft.getResults());
\r
91 } catch (JobSubmissionException e) {
\r
92 e.printStackTrace();
\r
93 fail(e.getMessage());
\r
94 } catch (JobExecutionException e) {
\r
95 e.printStackTrace();
\r
96 fail(e.getMessage());
\r
97 } catch (ResultNotAvailableException e) {
\r
98 e.printStackTrace();
\r
99 fail(e.getMessage());
\r
103 @Test(groups = { AllTestSuit.test_group_runner,
\r
104 AllTestSuit.test_group_non_windows })
\r
105 public void testPersistance() {
\r
107 Probcons mafft = new Probcons();
\r
108 mafft.setError("errrr.txt").setInput(AllTestSuit.test_input)
\r
109 .setOutput("outtt.txt");
\r
110 assertEquals(mafft.getInput(), AllTestSuit.test_input);
\r
111 assertEquals(mafft.getError(), "errrr.txt");
\r
112 assertEquals(mafft.getOutput(), "outtt.txt");
\r
113 ConfiguredExecutable<Probcons> cmafft = Configurator
\r
114 .configureExecutable(mafft, Executable.ExecProvider.Local);
\r
116 SyncExecutor sexec = Configurator.getSyncEngine(cmafft);
\r
117 sexec.executeJob();
\r
118 ConfiguredExecutable<?> al = sexec.waitForResult();
\r
119 assertNotNull(al.getResults());
\r
120 // Save run configuration
\r
121 assertTrue(cmafft.saveRunConfiguration());
\r
123 // See if loaded configuration is the same as saved
\r
124 RunConfiguration loadedRun = RunConfiguration
\r
125 .load(new FileInputStream(new File(cmafft
\r
126 .getWorkDirectory(), RunConfiguration.rconfigFile)));
\r
127 assertEquals(((ConfExecutable<Probcons>) cmafft)
\r
128 .getRunConfiguration(), loadedRun);
\r
129 // Load run configuration as ConfExecutable
\r
130 ConfiguredExecutable<Probcons> resurrectedCMafft = (ConfiguredExecutable<Probcons>) cmafft
\r
131 .loadRunConfiguration(new FileInputStream(new File(cmafft
\r
132 .getWorkDirectory(), RunConfiguration.rconfigFile)));
\r
133 assertNotNull(resurrectedCMafft);
\r
134 // See in details whether executables are the same
\r
135 assertEquals(resurrectedCMafft.getExecutable(), mafft);
\r
137 // Finally rerun the job in the new task directory
\r
138 ConfiguredExecutable<Probcons> resmafft = Configurator
\r
139 .configureExecutable(resurrectedCMafft.getExecutable(),
\r
140 Executable.ExecProvider.Local);
\r
142 sexec = Configurator.getSyncEngine(resmafft,
\r
143 Executable.ExecProvider.Local);
\r
144 sexec.executeJob();
\r
145 al = sexec.waitForResult();
\r
148 } catch (JobSubmissionException e) {
\r
149 e.printStackTrace();
\r
150 fail(e.getMessage());
\r
151 } catch (JobExecutionException e) {
\r
152 e.printStackTrace();
\r
153 fail(e.getMessage());
\r
154 } catch (FileNotFoundException e) {
\r
155 e.printStackTrace();
\r
156 fail(e.getMessage());
\r
157 } catch (IOException e) {
\r
158 e.printStackTrace();
\r
159 fail(e.getMessage());
\r
160 } catch (ResultNotAvailableException e) {
\r
161 e.printStackTrace();
\r
162 fail(e.getMessage());
\r
166 @Test(groups = { AllTestSuit.test_group_cluster,
\r
167 AllTestSuit.test_group_runner, AllTestSuit.test_group_non_windows })
\r
168 public void testClusterExecute() {
\r
170 ConfiguredExecutable<Probcons> cmafft = Configurator
\r
171 .configureExecutable(probc, Executable.ExecProvider.Cluster);
\r
172 JobRunner sexecutor = (JobRunner) Configurator.getSyncEngine(
\r
173 cmafft, Executable.ExecProvider.Cluster);
\r
174 sexecutor.executeJob();
\r
175 ConfiguredExecutable<?> al = sexecutor.waitForResult();
\r
176 assertNotNull(al.getResults());
\r
177 } catch (JobSubmissionException e) {
\r
178 e.printStackTrace();
\r
179 fail(e.getMessage());
\r
180 } catch (JobExecutionException e) {
\r
181 e.printStackTrace();
\r
182 fail(e.getMessage());
\r
183 } catch (ResultNotAvailableException e) {
\r
184 e.printStackTrace();
\r
185 fail(e.getMessage());
\r
189 @Test(groups = { AllTestSuit.test_group_runner,
\r
190 AllTestSuit.test_group_non_windows })
\r
191 public void readStatistics() {
\r
192 Probcons probs = new Probcons();
\r
193 probs.setError("errrr.txt").setInput(AllTestSuit.test_input).setOutput(
\r
195 ConfiguredExecutable<Probcons> cprobs;
\r
198 cprobs = Configurator.configureExecutable(probs,
\r
199 Executable.ExecProvider.Local);
\r
200 AsyncExecutor sexec = Configurator.getAsyncEngine(cprobs);
\r
201 String jobId = sexec.submitJob(cprobs);
\r
202 FilePuller fw = FilePuller.newFilePuller(compbio.engine.client.Util
\r
203 .getFullPath(cprobs.getWorkDirectory(), cprobs.getError()),
\r
205 ConfiguredExecutable<?> al = sexec.getResults(jobId);
\r
206 assertNotNull(al.getResults());
\r
207 // Code below is performance dependent
\r
208 // thus cannot be moved up before the results is obtained
\r
212 while (fw.hasMoreData()) {
\r
213 ChunkHolder ch = fw.pull(position);
\r
214 String chunk = ch.getChunk();
\r
215 position = ch.getNextPosition();
\r
216 System.out.print("CHUNK:" + chunk);
\r
219 assertTrue(count > 1, "TaskId:" + jobId);
\r
221 } catch (JobSubmissionException e) {
\r
222 e.printStackTrace();
\r
223 fail(e.getMessage());
\r
224 } catch (ResultNotAvailableException e) {
\r
225 e.printStackTrace();
\r
226 fail(e.getMessage());
\r
227 } catch (IOException e) {
\r
228 e.printStackTrace();
\r
229 fail(e.getMessage());
\r
233 @Test(groups = { AllTestSuit.test_group_runner })
\r
234 public void testConfigurationLoading() {
\r
236 RunnerConfig<Probcons> probsConfig = ConfExecutable
\r
237 .getRunnerOptions(Probcons.class);
\r
238 assertNotNull(probsConfig);
\r
239 assertTrue(probsConfig.getArguments().size() > 0);
\r
241 PresetManager<Probcons> probsPresets = ConfExecutable
\r
242 .getRunnerPresets(Probcons.class);
\r
243 assertNull(probsPresets);
\r
245 LimitsManager<Probcons> probsLimits = ConfExecutable
\r
246 .getRunnerLimits(Probcons.class);
\r
247 assertNotNull(probsLimits);
\r
248 assertTrue(probsLimits.getLimits().size() > 0);
\r
249 probsLimits.validate(probsPresets);
\r
251 } catch (FileNotFoundException e) {
\r
252 e.printStackTrace();
\r
253 fail(e.getLocalizedMessage());
\r
254 } catch (IOException e) {
\r
255 e.printStackTrace();
\r
256 fail(e.getLocalizedMessage());
\r
257 } catch (ValidationException e) {
\r
258 e.printStackTrace();
\r
259 fail(e.getLocalizedMessage());
\r