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.engine.AsyncExecutor;
\r
45 import compbio.engine.Configurator;
\r
46 import compbio.engine.SyncExecutor;
\r
47 import compbio.engine.client.ConfExecutable;
\r
48 import compbio.engine.client.ConfiguredExecutable;
\r
49 import compbio.engine.client.Executable;
\r
50 import compbio.engine.client.RunConfiguration;
\r
51 import compbio.engine.cluster.drmaa.ClusterUtil;
\r
52 import compbio.engine.cluster.drmaa.JobRunner;
\r
53 import compbio.engine.cluster.drmaa.StatisticManager;
\r
54 import compbio.engine.local.LocalRunner;
\r
55 import compbio.metadata.AllTestSuit;
\r
56 import compbio.metadata.JobExecutionException;
\r
57 import compbio.metadata.JobStatus;
\r
58 import compbio.metadata.JobSubmissionException;
\r
59 import compbio.metadata.LimitsManager;
\r
60 import compbio.metadata.PresetManager;
\r
61 import compbio.metadata.ResultNotAvailableException;
\r
62 import compbio.metadata.RunnerConfig;
\r
63 import compbio.util.SysPrefs;
\r
65 public class GlobPlotTester {
\r
67 public static String test_outfile = "TO1381.globprot.out";
\r
69 private GlobPlot globprot;
\r
71 @BeforeMethod(alwaysRun = true)
\r
73 globprot = new GlobPlot();
\r
74 globprot.setInput(AllTestSuit.test_input).setOutput(test_outfile);
\r
77 @Test(groups = {AllTestSuit.test_group_cluster,
\r
78 AllTestSuit.test_group_runner})
\r
79 public void testRunOnCluster() {
\r
80 assertFalse(SysPrefs.isWindows,
\r
81 "Cluster execution can only be in unix environment");
\r
83 ConfiguredExecutable<GlobPlot> confGlobPlot = Configurator
\r
84 .configureExecutable(globprot,
\r
85 Executable.ExecProvider.Cluster);
\r
86 JobRunner runner = JobRunner.getInstance(confGlobPlot);
\r
88 assertNotNull(runner, "Runner is NULL");
\r
89 runner.executeJob();
\r
90 // assertNotNull("JobId is null", jobId1);
\r
91 JobStatus status = runner.getJobStatus();
\r
92 assertTrue(status == JobStatus.PENDING
\r
93 || status == JobStatus.RUNNING,
\r
94 "Status of the process is wrong!");
\r
95 JobInfo info = runner.getJobInfo();
\r
96 assertNotNull(info, "JobInfo is null");
\r
97 StatisticManager sm = new StatisticManager(info);
\r
98 assertNotNull(sm, "Statictic manager is null");
\r
101 String exits = sm.getExitStatus();
\r
102 assertNotNull("Exit status is null", exits);
\r
103 // cut 4 trailing zeros from the number
\r
104 int exitsInt = ClusterUtil.CLUSTER_STAT_IN_SEC.parse(exits)
\r
106 assertEquals(0, exitsInt);
\r
107 System.out.println(sm.getAllStats());
\r
109 } catch (ParseException e) {
\r
110 e.printStackTrace();
\r
111 fail("Parse Exception: " + e.getMessage());
\r
113 // assertFalse(runner.cleanup());
\r
114 assertTrue(sm.hasExited());
\r
115 assertFalse(sm.wasAborted());
\r
116 assertFalse(sm.hasDump());
\r
117 assertFalse(sm.hasSignaled());
\r
119 } catch (JobSubmissionException e) {
\r
120 e.printStackTrace();
\r
121 fail("DrmaaException caught:" + e.getMessage());
\r
122 } catch (JobExecutionException e) {
\r
123 e.printStackTrace();
\r
124 fail("DrmaaException caught:" + e.getMessage());
\r
125 } catch (DrmaaException e) {
\r
126 e.printStackTrace();
\r
127 fail("DrmaaException caught:" + e.getMessage());
\r
132 * This tests fails from time to time depending on the cluster load or some
\r
133 * other factors. Any client code has to adjust for this issue
\r
135 @Test(groups = {AllTestSuit.test_group_cluster,
\r
136 AllTestSuit.test_group_runner})
\r
137 public void testRunOnClusterAsync() {
\r
138 assertFalse(SysPrefs.isWindows,
\r
139 "Cluster execution can only be in unix environment");
\r
141 ConfiguredExecutable<GlobPlot> confGlobPlot = Configurator
\r
142 .configureExecutable(globprot,
\r
143 Executable.ExecProvider.Cluster);
\r
144 AsyncExecutor aengine = Configurator.getAsyncEngine(confGlobPlot);
\r
145 String jobId = aengine.submitJob(confGlobPlot);
\r
146 assertNotNull(jobId, "Runner is NULL");
\r
147 // let drmaa to start
\r
149 JobStatus status = aengine.getJobStatus(jobId);
\r
150 while (status != JobStatus.FINISHED) {
\r
151 System.out.println("Job Status: " + status);
\r
152 Thread.sleep(1000);
\r
153 status = aengine.getJobStatus(jobId);
\r
154 ConfiguredExecutable<GlobPlot> result = (ConfiguredExecutable<GlobPlot>) aengine
\r
155 .getResults(jobId);
\r
156 assertNotNull(result);
\r
157 System.out.println("RES:" + result);
\r
158 // Some times the job could be removed from the cluster
\r
160 // before it has been reported to finish. Make sure
\r
161 // to stop waiting in such case
\r
162 if (status == JobStatus.UNDEFINED) {
\r
166 } catch (JobSubmissionException e) {
\r
167 e.printStackTrace();
\r
168 fail("DrmaaException caught:" + e.getMessage());
\r
169 } catch (InterruptedException e) {
\r
170 e.printStackTrace();
\r
171 fail(e.getMessage());
\r
172 } catch (ResultNotAvailableException e) {
\r
173 e.printStackTrace();
\r
174 fail(e.getMessage());
\r
178 @Test(groups = {AllTestSuit.test_group_runner})
\r
179 public void testRunLocally() {
\r
181 ConfiguredExecutable<GlobPlot> confGlobPlot = Configurator
\r
182 .configureExecutable(globprot,
\r
183 Executable.ExecProvider.Local);
\r
185 // For local execution use relative
\r
186 LocalRunner lr = new LocalRunner(confGlobPlot);
\r
188 ConfiguredExecutable<?> al1 = lr.waitForResult();
\r
189 assertNotNull(al1.getResults());
\r
190 Map<String, Set<Score>> al2 = confGlobPlot.getResults();
\r
191 assertNotNull(al2);
\r
192 assertEquals(al2.size(), 3);
\r
193 assertEquals(al1.getResults(), al2);
\r
194 } catch (JobSubmissionException e) {
\r
195 e.printStackTrace();
\r
196 fail(e.getLocalizedMessage());
\r
197 } catch (ResultNotAvailableException e) {
\r
198 e.printStackTrace();
\r
199 fail(e.getLocalizedMessage());
\r
200 } catch (JobExecutionException e) {
\r
201 e.printStackTrace();
\r
202 fail(e.getLocalizedMessage());
\r
206 @Test(groups = {AllTestSuit.test_group_runner})
\r
207 public void readStatistics() {
\r
208 // No execution statistics is available!
\r
211 @Test(groups = {AllTestSuit.test_group_runner})
\r
212 public void testPersistance() {
\r
214 GlobPlot disembl = new GlobPlot();
\r
215 disembl.setError("errrr.txt").setInput(AllTestSuit.test_input)
\r
216 .setOutput("outtt.txt");
\r
217 assertEquals(disembl.getInput(), AllTestSuit.test_input);
\r
218 assertEquals(disembl.getError(), "errrr.txt");
\r
219 assertEquals(disembl.getOutput(), "outtt.txt");
\r
220 ConfiguredExecutable<GlobPlot> cGlobPlot = Configurator
\r
221 .configureExecutable(disembl, Executable.ExecProvider.Local);
\r
223 SyncExecutor sexec = Configurator.getSyncEngine(cGlobPlot);
\r
224 sexec.executeJob();
\r
225 ConfiguredExecutable<?> al = sexec.waitForResult();
\r
226 assertNotNull(al.getResults());
\r
227 // Save run configuration
\r
228 assertTrue(cGlobPlot.saveRunConfiguration());
\r
230 // See if loaded configuration is the same as saved
\r
231 RunConfiguration loadedRun = RunConfiguration
\r
232 .load(new FileInputStream(new File(cGlobPlot
\r
233 .getWorkDirectory(), RunConfiguration.rconfigFile)));
\r
235 ((ConfExecutable<GlobPlot>) cGlobPlot)
\r
236 .getRunConfiguration(),
\r
238 // Load run configuration as ConfExecutable
\r
239 ConfiguredExecutable<GlobPlot> resurrectedCGlobPlot = (ConfiguredExecutable<GlobPlot>) cGlobPlot
\r
240 .loadRunConfiguration(new FileInputStream(new File(
\r
241 cGlobPlot.getWorkDirectory(),
\r
242 RunConfiguration.rconfigFile)));
\r
243 assertNotNull(resurrectedCGlobPlot);
\r
244 assertEquals(resurrectedCGlobPlot.getExecutable().getInput(),
\r
245 AllTestSuit.test_input);
\r
246 assertEquals(resurrectedCGlobPlot.getExecutable().getError(),
\r
248 assertEquals(resurrectedCGlobPlot.getExecutable().getOutput(),
\r
250 // See in details whether executables are the same
\r
251 assertEquals(resurrectedCGlobPlot.getExecutable(), disembl);
\r
253 ConfiguredExecutable<GlobPlot> resGlobPlot = Configurator
\r
254 .configureExecutable(resurrectedCGlobPlot.getExecutable(),
\r
255 Executable.ExecProvider.Local);
\r
257 sexec = Configurator.getSyncEngine(resGlobPlot,
\r
258 Executable.ExecProvider.Local);
\r
259 sexec.executeJob();
\r
260 al = sexec.waitForResult();
\r
263 } catch (JobSubmissionException e) {
\r
264 e.printStackTrace();
\r
265 fail(e.getMessage());
\r
266 } catch (JobExecutionException e) {
\r
267 e.printStackTrace();
\r
268 fail(e.getMessage());
\r
269 } catch (FileNotFoundException e) {
\r
270 e.printStackTrace();
\r
271 fail(e.getMessage());
\r
272 } catch (IOException e) {
\r
273 e.printStackTrace();
\r
274 fail(e.getMessage());
\r
275 } catch (ResultNotAvailableException e) {
\r
276 e.printStackTrace();
\r
277 fail(e.getMessage());
\r
281 @Test(groups = {AllTestSuit.test_group_runner})
\r
282 public void testConfigurationLoading() {
\r
284 RunnerConfig<GlobPlot> disemblConfig = ConfExecutable
\r
285 .getRunnerOptions(GlobPlot.class);
\r
286 assertNotNull(disemblConfig);
\r
287 // There is no disembl parameters
\r
288 assertTrue(disemblConfig.getArguments().size() == 0);
\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