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.assertFalse;
\r
23 import static org.testng.Assert.assertNotNull;
\r
24 import static org.testng.Assert.assertNotSame;
\r
25 import static org.testng.Assert.assertTrue;
\r
26 import static org.testng.Assert.fail;
\r
28 import java.io.File;
\r
29 import java.io.FileInputStream;
\r
30 import java.io.FileNotFoundException;
\r
31 import java.io.IOException;
\r
33 import javax.xml.bind.ValidationException;
\r
35 import org.testng.annotations.BeforeMethod;
\r
36 import org.testng.annotations.Test;
\r
38 import compbio.engine.AsyncExecutor;
\r
39 import compbio.engine.Configurator;
\r
40 import compbio.engine.FilePuller;
\r
41 import compbio.engine.SyncExecutor;
\r
42 import compbio.engine.client.ConfExecutable;
\r
43 import compbio.engine.client.ConfiguredExecutable;
\r
44 import compbio.engine.client.Executable;
\r
45 import compbio.engine.client.RunConfiguration;
\r
46 import compbio.engine.client.Executable.ExecProvider;
\r
47 import compbio.engine.cluster.drmaa.JobRunner;
\r
48 import compbio.metadata.AllTestSuit;
\r
49 import compbio.metadata.ChunkHolder;
\r
50 import compbio.metadata.JobExecutionException;
\r
51 import compbio.metadata.JobStatus;
\r
52 import compbio.metadata.JobSubmissionException;
\r
53 import compbio.metadata.LimitsManager;
\r
54 import compbio.metadata.PresetManager;
\r
55 import compbio.metadata.ResultNotAvailableException;
\r
56 import compbio.metadata.RunnerConfig;
\r
57 import compbio.runner.msa.Mafft;
\r
58 import compbio.util.SysPrefs;
\r
60 public class MafftTester {
\r
62 private Mafft mafft;
\r
64 @BeforeMethod(groups = { AllTestSuit.test_group_cluster,
\r
65 AllTestSuit.test_group_runner, AllTestSuit.test_group_non_windows })
\r
66 public void init() {
\r
67 mafft = new Mafft();
\r
68 // mafft.setParameter("--aamatrix");
\r
69 // mafft.setParameter("PAM100");
\r
70 mafft.setInput(AllTestSuit.test_input); // .setOutput("Mafft.out").setError("mafft.progress");
\r
73 @Test(groups = { AllTestSuit.test_group_runner,
\r
74 AllTestSuit.test_group_non_windows })
\r
75 public void testSetInputTester() {
\r
76 Mafft mf = new Mafft();
\r
77 // System.out.println(mf.getParameters(null));
\r
78 mf.setInput("INNN");
\r
79 // System.out.println(mf.getParameters(null));
\r
80 mf.setError("ERRR");
\r
81 mf.setInput("INN222");
\r
82 mf.setOutput("OUT");
\r
83 // System.out.println(mf.getParameters(null));
\r
86 @Test(groups = { AllTestSuit.test_group_runner,
\r
87 AllTestSuit.test_group_non_windows })
\r
88 public void testExecute() {
\r
90 ConfiguredExecutable<Mafft> cmafft = Configurator
\r
91 .configureExecutable(mafft, Executable.ExecProvider.Local);
\r
92 cmafft.getParameters().setParam("--aamatrix", "PAM120");
\r
93 SyncExecutor sexecutor = Configurator.getSyncEngine(cmafft);
\r
94 sexecutor.executeJob();
\r
95 cmafft = (ConfiguredExecutable<Mafft>) sexecutor.waitForResult();
\r
96 assertNotNull(cmafft.getResults());
\r
97 } catch (JobSubmissionException e) {
\r
98 e.printStackTrace();
\r
99 fail(e.getMessage());
\r
100 } catch (JobExecutionException e) {
\r
101 e.printStackTrace();
\r
102 fail(e.getMessage());
\r
103 } catch (ResultNotAvailableException e) {
\r
104 e.printStackTrace();
\r
105 fail(e.getMessage());
\r
109 @Test(groups = { AllTestSuit.test_group_runner,
\r
110 AllTestSuit.test_group_non_windows })
\r
111 public void testPersistance() {
\r
113 Mafft mafft = new Mafft();
\r
114 mafft.setError("errrr.txt").setInput(AllTestSuit.test_input)
\r
115 .setOutput("outtt.txt");
\r
116 assertEquals(mafft.getInput(), AllTestSuit.test_input);
\r
117 assertEquals(mafft.getError(), "errrr.txt");
\r
118 assertEquals(mafft.getOutput(), "outtt.txt");
\r
119 ConfiguredExecutable<Mafft> cmafft = Configurator
\r
120 .configureExecutable(mafft, Executable.ExecProvider.Local);
\r
122 SyncExecutor sexec = Configurator.getSyncEngine(cmafft);
\r
123 sexec.executeJob();
\r
124 ConfiguredExecutable<?> al = sexec.waitForResult();
\r
125 assertNotNull(al.getResults());
\r
126 // Save run configuration
\r
127 assertTrue(cmafft.saveRunConfiguration());
\r
129 // See if loaded configuration is the same as saved
\r
130 RunConfiguration loadedRun = RunConfiguration
\r
131 .load(new FileInputStream(new File(cmafft
\r
132 .getWorkDirectory(), RunConfiguration.rconfigFile)));
\r
134 ((ConfExecutable<Mafft>) cmafft).getRunConfiguration(),
\r
136 // Load run configuration as ConfExecutable
\r
137 ConfiguredExecutable<Mafft> resurrectedCMafft = (ConfiguredExecutable<Mafft>) cmafft
\r
138 .loadRunConfiguration(new FileInputStream(new File(cmafft
\r
139 .getWorkDirectory(), RunConfiguration.rconfigFile)));
\r
140 assertNotNull(resurrectedCMafft);
\r
141 // See in details whether executables are the same
\r
142 assertEquals(resurrectedCMafft.getExecutable(), mafft);
\r
144 // Finally rerun the job in the new task directory
\r
145 ConfiguredExecutable<Mafft> resmafft = Configurator
\r
146 .configureExecutable(resurrectedCMafft.getExecutable(),
\r
147 Executable.ExecProvider.Local);
\r
149 sexec = Configurator.getSyncEngine(resmafft,
\r
150 Executable.ExecProvider.Local);
\r
151 sexec.executeJob();
\r
152 al = sexec.waitForResult();
\r
155 } catch (JobSubmissionException e) {
\r
156 e.printStackTrace();
\r
157 fail(e.getMessage());
\r
158 } catch (JobExecutionException e) {
\r
159 e.printStackTrace();
\r
160 fail(e.getMessage());
\r
161 } catch (FileNotFoundException e) {
\r
162 e.printStackTrace();
\r
163 fail(e.getMessage());
\r
164 } catch (IOException e) {
\r
165 e.printStackTrace();
\r
166 fail(e.getMessage());
\r
167 } catch (ResultNotAvailableException e) {
\r
168 e.printStackTrace();
\r
169 fail(e.getMessage());
\r
173 @Test(groups = { AllTestSuit.test_group_cluster,
\r
174 AllTestSuit.test_group_runner, AllTestSuit.test_group_non_windows })
\r
175 public void testClusterExecute() {
\r
178 ConfiguredExecutable<Mafft> cmafft = Configurator
\r
179 .configureExecutable(mafft, Executable.ExecProvider.Cluster);
\r
180 JobRunner sexecutor = (JobRunner) Configurator.getSyncEngine(
\r
181 cmafft, Executable.ExecProvider.Cluster);
\r
182 sexecutor.executeJob();
\r
183 ConfiguredExecutable<?> al = sexecutor.waitForResult();
\r
184 assertNotNull(al.getResults());
\r
185 } catch (JobSubmissionException e) {
\r
186 e.printStackTrace();
\r
187 fail(e.getMessage());
\r
188 } catch (JobExecutionException e) {
\r
189 e.printStackTrace();
\r
190 fail(e.getMessage());
\r
191 } catch (ResultNotAvailableException e) {
\r
192 e.printStackTrace();
\r
193 fail(e.getMessage());
\r
198 * This test demonstrates the problem with Drmaa which can return UNDEFINED status after Running!
\r
199 * enable it to see the problem
\r
201 @Test(enabled=false, groups = { AllTestSuit.test_group_cluster,
\r
202 AllTestSuit.test_group_runner, AllTestSuit.test_group_non_windows })
\r
203 public void testRunOnClusterAsyncCheckStatusShortPoolingTime() {
\r
204 assertFalse(SysPrefs.isWindows,
\r
205 "Cluster execution can only be in unix environment");
\r
207 ConfiguredExecutable<Mafft> confMafft = Configurator
\r
208 .configureExecutable(mafft, Executable.ExecProvider.Cluster);
\r
209 AsyncExecutor aengine = Configurator.getAsyncEngine(confMafft);
\r
210 String jobId = aengine.submitJob(confMafft);
\r
211 assertNotNull(jobId, "Runner is NULL");
\r
212 // let drmaa to start
\r
214 boolean run = false;
\r
215 JobStatus status = aengine.getJobStatus(jobId);
\r
216 while (status != JobStatus.FINISHED) {
\r
217 if (status == JobStatus.RUNNING) {
\r
221 status = aengine.getJobStatus(jobId);
\r
222 // Once the job was in the RUNNING state UNDEFINED should not
\r
224 // Unfortunately with a short pooling time like here
\r
225 // this problem occurs. There seems to be a bug in DRMAA SGE
\r
227 // Perhaps longer pooling time e.g. 5 second will fix the issue
\r
228 // see the next test case for this
\r
230 assertNotSame(status, JobStatus.UNDEFINED);
\r
234 } catch (JobSubmissionException e) {
\r
235 e.printStackTrace();
\r
236 fail("DrmaaException caught:" + e.getMessage());
\r
237 } catch (InterruptedException e) {
\r
238 e.printStackTrace();
\r
239 fail(e.getMessage());
\r
243 @Test(groups = { AllTestSuit.test_group_cluster,
\r
244 AllTestSuit.test_group_runner, AllTestSuit.test_group_non_windows })
\r
245 public void testRunOnClusterAsyncCheckStatusLongPoolingTime() {
\r
246 assertFalse(SysPrefs.isWindows,
\r
247 "Cluster execution can only be in unix environment");
\r
249 ConfiguredExecutable<Mafft> confMafft = Configurator
\r
250 .configureExecutable(mafft, Executable.ExecProvider.Cluster);
\r
251 AsyncExecutor aengine = Configurator.getAsyncEngine(confMafft);
\r
252 String jobId = aengine.submitJob(confMafft);
\r
253 assertNotNull(jobId, "Runner is NULL");
\r
254 // let drmaa to start
\r
256 boolean run = false;
\r
257 JobStatus status = aengine.getJobStatus(jobId);
\r
258 while (status != JobStatus.FINISHED) {
\r
259 if (status == JobStatus.RUNNING) {
\r
262 Thread.sleep(5000);
\r
263 status = aengine.getJobStatus(jobId);
\r
264 // Once the job was in the RUNNING state UNDEFINED should not
\r
266 // Hopefully with a long pooling time like here
\r
267 // this problem should not occur. There seems to be a bug in
\r
268 // DRMAA SGE implementation
\r
270 assertNotSame(status, JobStatus.UNDEFINED);
\r
274 } catch (JobSubmissionException e) {
\r
275 e.printStackTrace();
\r
276 fail("DrmaaException caught:" + e.getMessage());
\r
277 } catch (InterruptedException e) {
\r
278 e.printStackTrace();
\r
279 fail(e.getMessage());
\r
283 @Test(groups = { AllTestSuit.test_group_runner,
\r
284 AllTestSuit.test_group_non_windows })
\r
285 public void readStatistics() {
\r
286 Mafft mafft = new Mafft();
\r
287 mafft.setError("errrr.txt").setInput(AllTestSuit.test_input).setOutput(
\r
289 ConfiguredExecutable<Mafft> cmafft;
\r
292 cmafft = Configurator.configureExecutable(mafft,
\r
293 Executable.ExecProvider.Local);
\r
294 AsyncExecutor sexec = Configurator.getAsyncEngine(cmafft,
\r
295 ExecProvider.Local);
\r
296 String jobId = sexec.submitJob(cmafft);
\r
297 FilePuller fw = FilePuller.newFilePuller(compbio.engine.client.Util
\r
298 .getFullPath(cmafft.getWorkDirectory(), cmafft.getError()),
\r
303 while (fw.hasMoreData()) {
\r
304 ChunkHolder ch = fw.pull(position);
\r
305 String chunk = ch.getChunk();
\r
306 position = ch.getNextPosition();
\r
307 System.out.print("CHUNK:" + chunk);
\r
310 assertTrue(count > 1);
\r
311 ConfiguredExecutable<?> al = sexec.getResults(jobId);
\r
312 assertNotNull(al.getResults());
\r
313 } catch (JobSubmissionException e) {
\r
314 e.printStackTrace();
\r
315 fail(e.getMessage());
\r
316 } catch (ResultNotAvailableException e) {
\r
317 e.printStackTrace();
\r
318 fail(e.getMessage());
\r
319 } catch (IOException e) {
\r
320 e.printStackTrace();
\r
321 fail(e.getMessage());
\r
325 @Test(groups = { AllTestSuit.test_group_runner })
\r
326 public void testConfigurationLoading() {
\r
328 RunnerConfig<Mafft> mafftConfig = ConfExecutable
\r
329 .getRunnerOptions(Mafft.class);
\r
330 assertNotNull(mafftConfig);
\r
331 assertTrue(mafftConfig.getArguments().size() > 0);
\r
333 PresetManager<Mafft> mafftPresets = ConfExecutable
\r
334 .getRunnerPresets(Mafft.class);
\r
335 assertNotNull(mafftPresets);
\r
336 assertTrue(mafftPresets.getPresets().size() > 0);
\r
337 mafftPresets.validate(mafftConfig);
\r
339 LimitsManager<Mafft> mafftLimits = ConfExecutable
\r
340 .getRunnerLimits(Mafft.class);
\r
341 assertNotNull(mafftLimits);
\r
342 assertTrue(mafftLimits.getLimits().size() > 0);
\r
343 mafftLimits.validate(mafftPresets);
\r
345 } catch (FileNotFoundException e) {
\r
346 e.printStackTrace();
\r
347 fail(e.getLocalizedMessage());
\r
348 } catch (IOException e) {
\r
349 e.printStackTrace();
\r
350 fail(e.getLocalizedMessage());
\r
351 } catch (ValidationException e) {
\r
352 e.printStackTrace();
\r
353 fail(e.getLocalizedMessage());
\r