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.disorder;
\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.assertNull;
\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
32 import java.text.ParseException;
\r
33 import java.util.Map;
\r
34 import java.util.Set;
\r
36 import javax.xml.bind.ValidationException;
\r
38 import org.ggf.drmaa.DrmaaException;
\r
39 import org.ggf.drmaa.JobInfo;
\r
40 import org.testng.annotations.BeforeMethod;
\r
41 import org.testng.annotations.Test;
\r
43 import compbio.data.sequence.Score;
\r
44 import compbio.data.sequence.ScoreManager;
\r
45 import compbio.engine.AsyncExecutor;
\r
46 import compbio.engine.Configurator;
\r
47 import compbio.engine.SyncExecutor;
\r
48 import compbio.engine.client.ConfExecutable;
\r
49 import compbio.engine.client.ConfiguredExecutable;
\r
50 import compbio.engine.client.Executable;
\r
51 import compbio.engine.client.RunConfiguration;
\r
52 import compbio.engine.cluster.drmaa.ClusterUtil;
\r
53 import compbio.engine.cluster.drmaa.JobRunner;
\r
54 import compbio.engine.cluster.drmaa.StatisticManager;
\r
55 import compbio.engine.local.LocalRunner;
\r
56 import compbio.metadata.AllTestSuit;
\r
57 import compbio.metadata.JobExecutionException;
\r
58 import compbio.metadata.JobStatus;
\r
59 import compbio.metadata.JobSubmissionException;
\r
60 import compbio.metadata.LimitsManager;
\r
61 import compbio.metadata.PresetManager;
\r
62 import compbio.metadata.ResultNotAvailableException;
\r
63 import compbio.metadata.RunnerConfig;
\r
64 import compbio.util.SysPrefs;
\r
66 public class GlobPlotTester {
\r
68 public static String test_outfile = "TO1381.globprot.out";
\r
70 private GlobPlot globprot;
\r
72 @BeforeMethod(alwaysRun = true)
\r
74 globprot = new GlobPlot();
\r
75 globprot.setInput(AllTestSuit.test_input).setOutput(test_outfile);
\r
78 @Test(groups = {AllTestSuit.test_group_cluster,
\r
79 AllTestSuit.test_group_runner})
\r
80 public void testRunOnCluster() {
\r
81 assertFalse(SysPrefs.isWindows,
\r
82 "Cluster execution can only be in unix environment");
\r
84 ConfiguredExecutable<GlobPlot> confGlobPlot = Configurator
\r
85 .configureExecutable(globprot,
\r
86 Executable.ExecProvider.Cluster);
\r
87 JobRunner runner = JobRunner.getInstance(confGlobPlot);
\r
89 assertNotNull(runner, "Runner is NULL");
\r
90 runner.executeJob();
\r
91 // assertNotNull("JobId is null", jobId1);
\r
92 JobStatus status = runner.getJobStatus();
\r
93 assertTrue(status == JobStatus.PENDING
\r
94 || status == JobStatus.RUNNING,
\r
95 "Status of the process is wrong!");
\r
96 JobInfo info = runner.getJobInfo();
\r
97 assertNotNull(info, "JobInfo is null");
\r
98 StatisticManager sm = new StatisticManager(info);
\r
99 assertNotNull(sm, "Statictic manager is null");
\r
102 String exits = sm.getExitStatus();
\r
103 assertNotNull("Exit status is null", exits);
\r
104 // cut 4 trailing zeros from the number
\r
105 int exitsInt = ClusterUtil.CLUSTER_STAT_IN_SEC.parse(exits)
\r
107 assertEquals(0, exitsInt);
\r
108 System.out.println(sm.getAllStats());
\r
110 } catch (ParseException e) {
\r
111 e.printStackTrace();
\r
112 fail("Parse Exception: " + e.getMessage());
\r
114 // assertFalse(runner.cleanup());
\r
115 assertTrue(sm.hasExited());
\r
116 assertFalse(sm.wasAborted());
\r
117 assertFalse(sm.hasDump());
\r
118 assertFalse(sm.hasSignaled());
\r
120 } catch (JobSubmissionException e) {
\r
121 e.printStackTrace();
\r
122 fail("DrmaaException caught:" + e.getMessage());
\r
123 } catch (JobExecutionException e) {
\r
124 e.printStackTrace();
\r
125 fail("DrmaaException caught:" + e.getMessage());
\r
126 } catch (DrmaaException e) {
\r
127 e.printStackTrace();
\r
128 fail("DrmaaException caught:" + e.getMessage());
\r
133 * This tests fails from time to time depending on the cluster load or some
\r
134 * other factors. Any client code has to adjust for this issue
\r
136 @Test(groups = {AllTestSuit.test_group_cluster,
\r
137 AllTestSuit.test_group_runner})
\r
138 public void testRunOnClusterAsync() {
\r
139 assertFalse(SysPrefs.isWindows,
\r
140 "Cluster execution can only be in unix environment");
\r
142 ConfiguredExecutable<GlobPlot> confGlobPlot = Configurator
\r
143 .configureExecutable(globprot,
\r
144 Executable.ExecProvider.Cluster);
\r
145 AsyncExecutor aengine = Configurator.getAsyncEngine(confGlobPlot);
\r
146 String jobId = aengine.submitJob(confGlobPlot);
\r
147 assertNotNull(jobId, "Runner is NULL");
\r
148 // let drmaa to start
\r
150 JobStatus status = aengine.getJobStatus(jobId);
\r
151 while (status != JobStatus.FINISHED) {
\r
152 System.out.println("Job Status: " + status);
\r
153 Thread.sleep(1000);
\r
154 status = aengine.getJobStatus(jobId);
\r
155 ConfiguredExecutable<GlobPlot> result = (ConfiguredExecutable<GlobPlot>) aengine
\r
156 .getResults(jobId);
\r
157 assertNotNull(result);
\r
158 System.out.println("RES:" + result);
\r
159 // Some times the job could be removed from the cluster
\r
161 // before it has been reported to finish. Make sure
\r
162 // to stop waiting in such case
\r
163 if (status == JobStatus.UNDEFINED) {
\r
167 } catch (JobSubmissionException e) {
\r
168 e.printStackTrace();
\r
169 fail("DrmaaException caught:" + e.getMessage());
\r
170 } catch (InterruptedException e) {
\r
171 e.printStackTrace();
\r
172 fail(e.getMessage());
\r
173 } catch (ResultNotAvailableException e) {
\r
174 e.printStackTrace();
\r
175 fail(e.getMessage());
\r
179 @Test(groups = {AllTestSuit.test_group_runner})
\r
180 public void testRunLocally() {
\r
182 ConfiguredExecutable<GlobPlot> confGlobPlot = Configurator
\r
183 .configureExecutable(globprot,
\r
184 Executable.ExecProvider.Local);
\r
186 // For local execution use relative
\r
187 LocalRunner lr = new LocalRunner(confGlobPlot);
\r
189 ConfiguredExecutable<?> al1 = lr.waitForResult();
\r
190 assertNotNull(al1.getResults());
\r
191 ScoreManager al2 = confGlobPlot.getResults();
\r
192 assertNotNull(al2);
\r
193 assertEquals(al2.asMap().size(), 3);
\r
194 assertEquals(al1.getResults(), al2);
\r
195 } catch (JobSubmissionException e) {
\r
196 e.printStackTrace();
\r
197 fail(e.getLocalizedMessage());
\r
198 } catch (ResultNotAvailableException e) {
\r
199 e.printStackTrace();
\r
200 fail(e.getLocalizedMessage());
\r
201 } catch (JobExecutionException e) {
\r
202 e.printStackTrace();
\r
203 fail(e.getLocalizedMessage());
\r
207 @Test(groups = {AllTestSuit.test_group_runner})
\r
208 public void readStatistics() {
\r
209 // No execution statistics is available!
\r
212 @Test(groups = {AllTestSuit.test_group_runner})
\r
213 public void testPersistance() {
\r
215 GlobPlot disembl = new GlobPlot();
\r
216 disembl.setError("errrr.txt").setInput(AllTestSuit.test_input)
\r
217 .setOutput("outtt.txt");
\r
218 assertEquals(disembl.getInput(), AllTestSuit.test_input);
\r
219 assertEquals(disembl.getError(), "errrr.txt");
\r
220 assertEquals(disembl.getOutput(), "outtt.txt");
\r
221 ConfiguredExecutable<GlobPlot> cGlobPlot = Configurator
\r
222 .configureExecutable(disembl, Executable.ExecProvider.Local);
\r
224 SyncExecutor sexec = Configurator.getSyncEngine(cGlobPlot);
\r
225 sexec.executeJob();
\r
226 ConfiguredExecutable<?> al = sexec.waitForResult();
\r
227 assertNotNull(al.getResults());
\r
228 // Save run configuration
\r
229 assertTrue(cGlobPlot.saveRunConfiguration());
\r
231 // See if loaded configuration is the same as saved
\r
232 RunConfiguration loadedRun = RunConfiguration
\r
233 .load(new FileInputStream(new File(cGlobPlot
\r
234 .getWorkDirectory(), RunConfiguration.rconfigFile)));
\r
236 ((ConfExecutable<GlobPlot>) cGlobPlot)
\r
237 .getRunConfiguration(),
\r
239 // Load run configuration as ConfExecutable
\r
240 ConfiguredExecutable<GlobPlot> resurrectedCGlobPlot = (ConfiguredExecutable<GlobPlot>) cGlobPlot
\r
241 .loadRunConfiguration(new FileInputStream(new File(
\r
242 cGlobPlot.getWorkDirectory(),
\r
243 RunConfiguration.rconfigFile)));
\r
244 assertNotNull(resurrectedCGlobPlot);
\r
245 assertEquals(resurrectedCGlobPlot.getExecutable().getInput(),
\r
246 AllTestSuit.test_input);
\r
247 assertEquals(resurrectedCGlobPlot.getExecutable().getError(),
\r
249 assertEquals(resurrectedCGlobPlot.getExecutable().getOutput(),
\r
251 // See in details whether executables are the same
\r
252 assertEquals(resurrectedCGlobPlot.getExecutable(), disembl);
\r
254 ConfiguredExecutable<GlobPlot> resGlobPlot = Configurator
\r
255 .configureExecutable(resurrectedCGlobPlot.getExecutable(),
\r
256 Executable.ExecProvider.Local);
\r
258 sexec = Configurator.getSyncEngine(resGlobPlot,
\r
259 Executable.ExecProvider.Local);
\r
260 sexec.executeJob();
\r
261 al = sexec.waitForResult();
\r
264 } catch (JobSubmissionException e) {
\r
265 e.printStackTrace();
\r
266 fail(e.getMessage());
\r
267 } catch (JobExecutionException e) {
\r
268 e.printStackTrace();
\r
269 fail(e.getMessage());
\r
270 } catch (FileNotFoundException e) {
\r
271 e.printStackTrace();
\r
272 fail(e.getMessage());
\r
273 } catch (IOException e) {
\r
274 e.printStackTrace();
\r
275 fail(e.getMessage());
\r
276 } catch (ResultNotAvailableException e) {
\r
277 e.printStackTrace();
\r
278 fail(e.getMessage());
\r
282 @Test(groups = {AllTestSuit.test_group_runner})
\r
283 public void testConfigurationLoading() {
\r
285 RunnerConfig<GlobPlot> globplotConfig = ConfExecutable
\r
286 .getRunnerOptions(GlobPlot.class);
\r
287 // There is no GlobPlot parameters
\r
288 assertNull(globplotConfig);
\r
290 PresetManager<GlobPlot> disemblPresets = ConfExecutable
\r
291 .getRunnerPresets(GlobPlot.class);
\r
292 assertNull(disemblPresets); // there is no presets
\r
294 LimitsManager<GlobPlot> disemblLimits = ConfExecutable
\r
295 .getRunnerLimits(GlobPlot.class);
\r
296 assertNotNull(disemblLimits);
\r
297 assertTrue(disemblLimits.getLimits().size() > 0);
\r
298 disemblLimits.validate(disemblPresets);
\r
300 } catch (FileNotFoundException e) {
\r
301 e.printStackTrace();
\r
302 fail(e.getLocalizedMessage());
\r
303 } catch (IOException e) {
\r
304 e.printStackTrace();
\r
305 fail(e.getLocalizedMessage());
\r
306 } catch (ValidationException e) {
\r
307 e.printStackTrace();
\r
308 fail(e.getLocalizedMessage());
\r