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.engine.cluster.drmaa;
\r
21 import static org.testng.AssertJUnit.assertEquals;
\r
22 import static org.testng.AssertJUnit.assertFalse;
\r
23 import static org.testng.AssertJUnit.assertNotNull;
\r
24 import static org.testng.AssertJUnit.assertNull;
\r
25 import static org.testng.AssertJUnit.assertTrue;
\r
26 import static org.testng.AssertJUnit.fail;
\r
28 import org.testng.annotations.Test;
\r
30 import compbio.engine.AsyncExecutor;
\r
31 import compbio.engine.Configurator;
\r
32 import compbio.engine.client.ConfiguredExecutable;
\r
33 import compbio.engine.client.Executable;
\r
34 import compbio.metadata.AllTestSuit;
\r
35 import compbio.metadata.JobStatus;
\r
36 import compbio.metadata.JobSubmissionException;
\r
37 import compbio.metadata.ResultNotAvailableException;
\r
38 import compbio.runner.msa.ClustalW;
\r
39 import compbio.util.SysPrefs;
\r
41 public class DrmaaAsyncClusterEngineTester {
\r
43 public static String test_input = AllTestSuit.TEST_DATA_PATH_ABSOLUTE
\r
45 public static String large_test_input = AllTestSuit.TEST_DATA_PATH_ABSOLUTE
\r
46 + "1000x3000Dna.fasta";
\r
47 public static String cluster_test_outfile = "TO1381.clustal.cluster.out";
\r
50 * This test uses ClustalW executable as runnable to testing, thus depends
\r
51 * on its correct functioning
\r
53 @Test(groups = { AllTestSuit.test_group_cluster,
\r
54 AllTestSuit.test_group_engine })
\r
55 public void testSubmit() {
\r
56 ClustalW clustal = new ClustalW();
\r
57 assertFalse("Cluster execution can only be in unix environment",
\r
58 SysPrefs.isWindows);
\r
59 clustal.setInput(test_input).setOutput(cluster_test_outfile);
\r
61 ConfiguredExecutable<ClustalW> confClustal = Configurator
\r
62 .configureExecutable(clustal);
\r
63 AsyncExecutor runner = new AsyncJobRunner();
\r
64 assertNotNull("Runner is NULL", runner);
\r
65 String jobId = runner.submitJob(confClustal);
\r
66 assertEquals("Input was not set!", test_input, clustal.getInput());
\r
67 assertNotNull("JobId is null", jobId);
\r
68 JobStatus status = runner.getJobStatus(jobId);
\r
69 assertTrue("Status of the process is wrong!",
\r
70 status == JobStatus.PENDING || status == JobStatus.RUNNING);
\r
71 JobStatus info = runner.getJobStatus(jobId);
\r
72 assertNotNull("JobInfo is null", info);
\r
73 Executable<?> result = runner.getResults(jobId);
\r
75 } catch (JobSubmissionException e) {
\r
76 e.printStackTrace();
\r
77 fail(e.getMessage());
\r
78 } catch (ResultNotAvailableException e) {
\r
79 e.printStackTrace();
\r
80 fail(e.getMessage());
\r
84 @Test(expectedExceptions = ResultNotAvailableException.class, groups = {
\r
85 AllTestSuit.test_group_cluster, AllTestSuit.test_group_engine })
\r
86 // expectedExceptions = ResultNotAvailableException.class,
\r
87 public void testCancel() throws ResultNotAvailableException {
\r
88 ClustalW clustal = new ClustalW();
\r
89 assertFalse("Cluster execution can only be in unix environment",
\r
90 SysPrefs.isWindows);
\r
91 clustal.setInput(large_test_input).setOutput(cluster_test_outfile);
\r
94 ConfiguredExecutable<ClustalW> confClustal = Configurator
\r
95 .configureExecutable(clustal);
\r
96 AsyncJobRunner runner = new AsyncJobRunner();
\r
97 String jobId = runner.submitJob(confClustal);
\r
98 assertNotNull("Runner is NULL", runner);
\r
99 // assertNotNull("JobId is null", jobId1);
\r
101 JobStatus status = runner.getJobStatus(jobId);
\r
102 assertTrue("Status of the process is wrong!",
\r
103 status == JobStatus.PENDING || status == JobStatus.RUNNING);
\r
104 assertFalse("Status of the process is wrong!",
\r
105 status == JobStatus.FINISHED);
\r
106 runner.cancelJob(jobId);
\r
107 // This is never NULL as long as the job has started!
\r
108 ConfiguredExecutable<?> exec = runner.getResults(jobId);
\r
109 assertNull(exec.getResults());
\r
110 } catch (JobSubmissionException e) {
\r
111 e.printStackTrace();
\r
112 fail("DrmaaException caught:" + e.getMessage());
\r
113 } catch (InterruptedException e) {
\r
114 e.printStackTrace();
\r
115 fail("Interupted exception caught:" + e.getMessage());
\r
119 @Test(groups = { AllTestSuit.test_group_cluster,
\r
120 AllTestSuit.test_group_engine })
\r
121 public void testGetJobStatus() {
\r
122 ClustalW clustal = new ClustalW();
\r
123 assertFalse("Cluster execution can only be in unix environment",
\r
124 SysPrefs.isWindows);
\r
125 clustal.setInput(test_input).setOutput(cluster_test_outfile);
\r
128 AsyncJobRunner runner = new AsyncJobRunner();
\r
129 ConfiguredExecutable<ClustalW> confClustal = Configurator
\r
130 .configureExecutable(clustal);
\r
131 String jobId = runner.submitJob(confClustal);
\r
132 assertNotNull("Runner is NULL", runner);
\r
133 AsyncJobRunner runner2 = new AsyncJobRunner();
\r
135 boolean hasRun = false;
\r
136 boolean hasPended = false;
\r
137 Thread.sleep(500);
\r
138 JobStatus status = runner2.getJobStatus(jobId);
\r
139 while (status != JobStatus.FINISHED) {
\r
140 if (status == JobStatus.CANCELLED) {
\r
141 fail("Job is not cancelled!");
\r
143 if (status == JobStatus.FAILED) {
\r
144 fail("Job should not fail!");
\r
146 if (status == JobStatus.RUNNING) {
\r
149 if (status == JobStatus.PENDING) {
\r
152 if (status == JobStatus.UNDEFINED) {
\r
153 System.out.println("Wrong status (UNDEFINED) reported by cluster engine!");
\r
156 status = runner2.getJobStatus(jobId);
\r
158 assertTrue(hasRun);
\r
159 assertTrue(hasPended);
\r
160 assertTrue(hasRun);
\r
161 // Bear in mind that if the task were not put in the queue
\r
163 // the status could be UNDEFINED!
\r
164 // assertFalse(hasUndefined);
\r
165 AsyncJobRunner runner3 = new AsyncJobRunner();
\r
166 Executable<?> exec = runner3.getResults(jobId);
\r
167 assertNotNull(exec);
\r
168 // Now try collecting result for the second time
\r
170 Thread.sleep(1000);
\r
171 exec = runner3.getResults(jobId);
\r
172 assertNotNull(exec);
\r
173 } catch (JobSubmissionException e) {
\r
174 e.printStackTrace();
\r
175 fail("DrmaaException caught:" + e.getMessage());
\r
176 } catch (ResultNotAvailableException e) {
\r
177 e.printStackTrace();
\r
178 fail(e.getMessage());
\r
179 } catch (InterruptedException e) {
\r
180 e.printStackTrace();
\r
181 fail(e.getMessage());
\r