1 /* Copyright (c) 2013 Alexander Sherstnev
\r
3 * Java Bioinformatics Analysis Web Services (JABAWS)
\r
6 * This library is free software; you can redistribute it and/or modify it under
\r
7 * the terms of the Apache License version 2 as published
\r
8 * by the Apache Software Foundation This library is distributed in the hope
\r
9 * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
\r
10 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
11 * Apache License for more details. A copy of the license is in
\r
12 * apache_license.txt. It is also available here:
\r
14 * @see: http://www.apache.org/licenses/LICENSE-2.0.txt
\r
16 * Any republication or derived work distributed in source code form must include
\r
17 * this copyright and license notice.
\r
19 //package compbio.runner.predictors;
\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.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
31 //import java.text.ParseException;
\r
32 //import java.util.Arrays;
\r
34 //import javax.xml.bind.ValidationException;
\r
36 //import org.ggf.drmaa.DrmaaException;
\r
37 //import org.ggf.drmaa.JobInfo;
\r
38 //import org.testng.annotations.BeforeMethod;
\r
39 //import org.testng.annotations.Test;
\r
41 //import compbio.data.sequence.JpredAlignment;
\r
42 //import compbio.engine.AsyncExecutor;
\r
43 //import compbio.engine.Configurator;
\r
44 //import compbio.engine.FilePuller;
\r
45 //import compbio.engine.SyncExecutor;
\r
46 //import compbio.engine.client.ConfExecutable;
\r
47 //import compbio.engine.client.ConfiguredExecutable;
\r
48 //import compbio.engine.client.Executable;
\r
49 //import compbio.engine.client.RunConfiguration;
\r
50 //import compbio.engine.cluster.drmaa.ClusterEngineUtil;
\r
51 //import compbio.engine.cluster.drmaa.ClusterRunner;
\r
52 //import compbio.engine.cluster.drmaa.StatisticManager;
\r
53 //import compbio.engine.local.LocalRunner;
\r
54 //import compbio.metadata.AllTestSuit;
\r
55 //import compbio.metadata.ChunkHolder;
\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.Preset;
\r
61 //import compbio.metadata.PresetManager;
\r
62 //import compbio.metadata.ResultNotAvailableException;
\r
63 //import compbio.metadata.RunnerConfig;
\r
64 //import compbio.runner.RunnerUtil;
\r
65 //import compbio.util.FileWatcher;
\r
66 //import compbio.util.SysPrefs;
\r
68 //public class JpredTester {
\r
70 // public static final String CURRENT_DIRECTORY = SysPrefs.getCurrentDirectory() + File.separator;
\r
72 // public static String test_output = "Jpred.test1.out";
\r
73 // public static String test_input = CURRENT_DIRECTORY + "testsrc" + File.separator + "testdata" + File.separator + "Jpred.test1.fasta";
\r
74 // private Jpred pred;
\r
76 // @BeforeMethod(alwaysRun = true)
\r
78 // pred = new Jpred();
\r
79 // pred.setInput(test_input);
\r
80 // pred.setOutput(test_output);
\r
84 // @Test(enabled=false,groups = {AllTestSuit.test_group_runner})
\r
85 // public void RunOnCluster() {
\r
86 // assertFalse(SysPrefs.isWindows, "Cluster execution can only be in unix environment");
\r
88 // PresetManager<Jpred> jpredPreset = RunnerUtil.getPresets(Jpred.class);
\r
89 // assert jpredPreset != null;
\r
90 // ConfiguredExecutable<Jpred> confpred = Configurator.configureExecutable(pred, Executable.ExecProvider.Cluster);
\r
91 // Preset<Jpred> conf = jpredPreset.getPresetByName("cluster configuration");
\r
92 // confpred.addParameters(conf.getOptions());
\r
93 // ClusterRunner runner = ClusterRunner.getInstance(confpred);
\r
94 // assertNotNull(runner, "Runner is NULL");
\r
96 // runner.executeJob();
\r
97 // JobStatus status = runner.getJobStatus();
\r
98 // assertTrue(status == JobStatus.PENDING || status == JobStatus.RUNNING, "Status of the process is wrong!");
\r
99 // JobInfo info = runner.getJobInfo();
\r
100 // assertNotNull(info, "JobInfo is null");
\r
101 // StatisticManager sm = new StatisticManager(info);
\r
102 // assertNotNull(sm, "Statistic manager is null");
\r
104 // String exits = sm.getExitStatus();
\r
105 // assertNotNull("Exit status is null", exits);
\r
106 // // cut 4 trailing zeros from the number
\r
107 // int exitsInt = ClusterEngineUtil.CLUSTER_STAT_IN_SEC.parse(exits).intValue();
\r
108 // assertEquals(0, exitsInt);
\r
109 // System.out.println(sm.getAllStats());
\r
110 // } catch (ParseException e) {
\r
111 // e.printStackTrace();
\r
112 // fail("Parse Exception: " + e.getMessage());
\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 // @Test(enabled=false,groups = {AllTestSuit.test_group_runner, AllTestSuit.test_group_cluster})
\r
133 // public void RunOnClusterAsync() {
\r
134 // assertFalse(SysPrefs.isWindows, "Cluster execution can only be in unix environment");
\r
136 // pred.addParameters(Arrays.asList("-dbname uniref90", "-dbpath /homes/www-jpred/databases/"));
\r
137 // ConfiguredExecutable<Jpred> confpred = Configurator.configureExecutable(pred, Executable.ExecProvider.Cluster);
\r
138 // AsyncExecutor aengine = Configurator.getAsyncEngine(confpred);
\r
139 // String jobId = aengine.submitJob(confpred);
\r
140 // assertNotNull(jobId, "Runner is NULL");
\r
141 // // let drmaa to start
\r
142 // Thread.sleep(500);
\r
143 // JobStatus status = aengine.getJobStatus(jobId);
\r
144 // while (status != JobStatus.FINISHED) {
\r
145 // Thread.sleep(1000);
\r
146 // status = aengine.getJobStatus(jobId);
\r
147 // ConfiguredExecutable<Jpred> result = (ConfiguredExecutable<Jpred>) aengine.getResults(jobId);
\r
148 // assertNotNull(result);
\r
149 // if (status == JobStatus.UNDEFINED || status == JobStatus.FAILED) {
\r
150 // fail("job " + jobId +" failed!");
\r
154 // } catch (JobSubmissionException e) {
\r
155 // e.printStackTrace();
\r
156 // fail("DrmaaException caught:" + e.getMessage());
\r
157 // } catch (InterruptedException 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_runner})
\r
167 // public void RunLocally() {
\r
169 // ConfiguredExecutable<Jpred> confpred = Configurator.configureExecutable(pred, Executable.ExecProvider.Local);
\r
170 // confpred.addParameters(Arrays.asList("-dbname ported_db", "-dbpath /data/UNIREFdb/"));
\r
172 // // For local execution use relative
\r
173 // LocalRunner lr = new LocalRunner(confpred);
\r
174 // lr.executeJob();
\r
175 // ConfiguredExecutable<?> al1 = lr.waitForResult();
\r
176 // assertNotNull(al1.getResults());
\r
177 // JpredAlignment totalign = (JpredAlignment) confpred.getResults();
\r
178 // assertNotNull(totalign);
\r
179 // assertEquals(totalign.getSize(), 14);
\r
180 // assertEquals(al1.getResults(), totalign);
\r
181 // } catch (JobSubmissionException e) {
\r
182 // e.printStackTrace();
\r
183 // fail(e.getLocalizedMessage());
\r
184 // } catch (ResultNotAvailableException e) {
\r
185 // e.printStackTrace();
\r
186 // fail(e.getLocalizedMessage());
\r
187 // } catch (JobExecutionException e) {
\r
188 // e.printStackTrace();
\r
189 // fail(e.getLocalizedMessage());
\r
193 // @Test(enabled=false,groups = {AllTestSuit.test_group_runner})
\r
194 // public void RunLocallyWithPreset() {
\r
196 // ConfiguredExecutable<Jpred> confpred = Configurator.configureExecutable(pred, Executable.ExecProvider.Local);
\r
197 // PresetManager<Jpred> preset = RunnerUtil.getPresets(Jpred.class);
\r
198 // assert preset != null;
\r
199 // Preset<Jpred> conf = preset.getPresetByName("laptop configuration");
\r
200 // confpred.addParameters(conf.getOptions());
\r
202 // // For local execution use relative
\r
203 // LocalRunner lr = new LocalRunner(confpred);
\r
204 // lr.executeJob();
\r
205 // ConfiguredExecutable<?> al1 = lr.waitForResult();
\r
206 // assertNotNull(al1.getResults());
\r
207 // JpredAlignment totalign = (JpredAlignment) confpred.getResults();
\r
208 // assertNotNull(totalign);
\r
209 // assertEquals(totalign.getSize(), 19);
\r
210 // assertEquals(al1.getResults(), totalign);
\r
211 // } catch (JobSubmissionException e) {
\r
212 // e.printStackTrace();
\r
213 // fail(e.getLocalizedMessage());
\r
214 // } catch (ResultNotAvailableException e) {
\r
215 // e.printStackTrace();
\r
216 // fail(e.getLocalizedMessage());
\r
217 // } catch (JobExecutionException e) {
\r
218 // e.printStackTrace();
\r
219 // fail(e.getLocalizedMessage());
\r
223 // @Test(enabled=false,groups = {AllTestSuit.test_group_runner})
\r
224 // public void readStatistics() {
\r
226 // Jpred jpred = new Jpred();
\r
227 // jpred.setInput(test_input);
\r
228 // jpred.setOutput(test_output);
\r
229 // ConfiguredExecutable<Jpred> confpred = Configurator.configureExecutable(jpred, Executable.ExecProvider.Local);
\r
230 // PresetManager<Jpred> preset = RunnerUtil.getPresets(Jpred.class);
\r
231 // assert preset != null;
\r
232 // Preset<Jpred> conf = preset.getPresetByName("laptop configuration");
\r
233 // confpred.addParameters(conf.getOptions());
\r
235 // // For local execution use relative
\r
236 // AsyncExecutor sexec = Configurator.getAsyncEngine(confpred);
\r
237 // String jobId = sexec.submitJob(confpred);
\r
238 // String file = confpred.getWorkDirectory() + File.separator + Jpred.getStatFile();
\r
239 // FilePuller fw = FilePuller.newFilePuller(file, FileWatcher.MIN_CHUNK_SIZE_BYTES);
\r
241 // long position = 0;
\r
242 // fw.waitForFile(2);
\r
243 // JobStatus status = sexec.getJobStatus(jobId);
\r
245 // if (fw.hasMoreData()) {
\r
246 // ChunkHolder ch = fw.pull(position);
\r
247 // String chunk = ch.getChunk();
\r
248 // position = ch.getNextPosition();
\r
251 // // Make sure the loop is terminated if the job fails
\r
252 // if ((status == JobStatus.UNDEFINED || status == JobStatus.FAILED)) {
\r
253 // fail("job " + jobId +" failed!");
\r
256 // Thread.sleep(200);
\r
257 // status = sexec.getJobStatus(jobId);
\r
258 // } while (status != JobStatus.FINISHED || fw.hasMoreData());
\r
260 // assertTrue(count >= 1);
\r
261 // ConfiguredExecutable<?> al = sexec.getResults(jobId);
\r
262 // assertNotNull(al.getResults());
\r
263 // } catch (JobSubmissionException e) {
\r
264 // e.printStackTrace();
\r
265 // fail(e.getMessage());
\r
266 // } catch (ResultNotAvailableException e) {
\r
267 // e.printStackTrace();
\r
268 // fail(e.getMessage());
\r
269 // } catch (IOException e) {
\r
270 // e.printStackTrace();
\r
271 // fail(e.getMessage());
\r
272 // } catch (InterruptedException e) {
\r
273 // e.printStackTrace();
\r
274 // fail(e.getMessage());
\r
278 // @Test(enabled=false,groups = {AllTestSuit.test_group_runner})
\r
279 // public void Persistance() {
\r
281 // Jpred jpred = new Jpred();
\r
282 // jpred.setError("errrr.txt");
\r
283 // jpred.setInput(test_input);
\r
284 // jpred.setOutput("outtt.txt");
\r
285 // assertEquals(jpred.getInput(), test_input);
\r
286 // assertEquals(jpred.getError(), "errrr.txt");
\r
287 // assertEquals(jpred.getOutput(), "outtt.txt");
\r
288 // ConfiguredExecutable<Jpred> confpred = Configurator.configureExecutable(jpred, Executable.ExecProvider.Local);
\r
289 // confpred.addParameters(Arrays.asList("-dbname ported_db", "-dbpath /data/UNIREFdb/"));
\r
291 // SyncExecutor sexec = Configurator.getSyncEngine(confpred);
\r
292 // sexec.executeJob();
\r
293 // ConfiguredExecutable<?> al = sexec.waitForResult();
\r
294 // assertNotNull(al.getResults());
\r
296 // // Save run configuration
\r
297 // assertTrue(confpred.saveRunConfiguration());
\r
299 // // See if loaded configuration is the same as saved
\r
300 // RunConfiguration loadedRun = RunConfiguration.load(new FileInputStream(new File(confpred.getWorkDirectory(), RunConfiguration.rconfigFile)));
\r
301 // assertEquals(((ConfExecutable<Jpred>) confpred).getRunConfiguration(),loadedRun);
\r
303 // // Load run configuration as ConfExecutable
\r
304 // ConfiguredExecutable<Jpred> jpred2 = (ConfiguredExecutable<Jpred>) confpred.loadRunConfiguration(new FileInputStream(new File(confpred.getWorkDirectory(), RunConfiguration.rconfigFile)));
\r
305 // assertNotNull(jpred2);
\r
306 // assertEquals(jpred2.getExecutable().getInput(), test_input);
\r
307 // assertEquals(jpred2.getExecutable().getError(), "errrr.txt");
\r
308 // assertEquals(jpred2.getExecutable().getOutput(), "outtt.txt");
\r
310 // // See in details whether executables are the same
\r
311 // assertEquals(jpred2.getExecutable(), jpred);
\r
312 // ConfiguredExecutable<Jpred> resjpred2 = Configurator.configureExecutable(jpred2.getExecutable(), Executable.ExecProvider.Local);
\r
314 // sexec = Configurator.getSyncEngine(resjpred2, Executable.ExecProvider.Local);
\r
315 // sexec.executeJob();
\r
316 // al = sexec.waitForResult();
\r
317 // assertNotNull(al);
\r
318 // } catch (JobSubmissionException e) {
\r
319 // e.printStackTrace();
\r
320 // fail(e.getMessage());
\r
321 // } catch (JobExecutionException e) {
\r
322 // e.printStackTrace();
\r
323 // fail(e.getMessage());
\r
324 // } catch (FileNotFoundException e) {
\r
325 // e.printStackTrace();
\r
326 // fail(e.getMessage());
\r
327 // } catch (IOException e) {
\r
328 // e.printStackTrace();
\r
329 // fail(e.getMessage());
\r
330 // } catch (ResultNotAvailableException e) {
\r
331 // e.printStackTrace();
\r
332 // fail(e.getMessage());
\r
336 // @Test(enabled=false,groups = {AllTestSuit.test_group_runner})
\r
337 // public void ConfigurationLoading() {
\r
339 // RunnerConfig<Jpred> jpredConfig = ConfExecutable.getRunnerOptions(Jpred.class);
\r
340 // assertNotNull(jpredConfig);
\r
341 // assertTrue(jpredConfig.getArguments().size() > 0);
\r
343 // PresetManager<Jpred> jpredPreset = ConfExecutable.getRunnerPresets(Jpred.class);
\r
344 // assertNotNull(jpredPreset);
\r
346 // LimitsManager<Jpred> jpredLimits = ConfExecutable.getRunnerLimits(Jpred.class);
\r
347 // assertNotNull(jpredLimits);
\r
348 // assertTrue(jpredLimits.getLimits().size() > 0);
\r
349 // jpredLimits.validate(jpredPreset);
\r
350 // } catch (FileNotFoundException e) {
\r
351 // e.printStackTrace();
\r
352 // fail(e.getLocalizedMessage());
\r
353 // } catch (IOException e) {
\r
354 // e.printStackTrace();
\r
355 // fail(e.getLocalizedMessage());
\r
356 // } catch (ValidationException e) {
\r
357 // e.printStackTrace();
\r
358 // fail(e.getLocalizedMessage());
\r