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.local;
\r
21 import static org.testng.Assert.assertFalse;
\r
22 import static org.testng.Assert.assertTrue;
\r
23 import static org.testng.AssertJUnit.assertNotSame;
\r
24 import static org.testng.AssertJUnit.assertNull;
\r
25 import static org.testng.AssertJUnit.fail;
\r
27 import java.util.concurrent.CancellationException;
\r
29 import org.testng.annotations.Test;
\r
31 import compbio.engine.Configurator;
\r
32 import compbio.engine.client.ConfiguredExecutable;
\r
33 import compbio.engine.client.Executable;
\r
34 import compbio.engine.client.Util;
\r
35 import compbio.metadata.AllTestSuit;
\r
36 import compbio.metadata.JobExecutionException;
\r
37 import compbio.metadata.JobStatus;
\r
38 import compbio.metadata.JobSubmissionException;
\r
39 import compbio.metadata.ResultNotAvailableException;
\r
40 import compbio.runner.msa.ClustalW;
\r
42 public class LocalRunnerTester {
\r
44 public static String cluster_test_outfile = "TO1381.clustal.cluster.out"; // "/homes/pvtroshin/TO1381.clustal.cluster.out
\r
45 // go up 2 directories from workspace: workspace/clustengine
\r
46 public static String test_input = AllTestSuit.TEST_DATA_PATH_ABSOLUTE
\r
48 public static String test_outfile = "TO1381.clustal.out";
\r
50 @Test(expectedExceptions = CancellationException.class, groups = { AllTestSuit.test_group_engine })
\r
51 public void testCancelLocally() {
\r
52 ClustalW clustal = new ClustalW();
\r
53 clustal.setInput(test_input).setOutput(test_outfile);
\r
56 ConfiguredExecutable<ClustalW> confClust = Configurator
\r
57 .configureExecutable(clustal);
\r
58 LocalRunner lr = new LocalRunner(confClust);
\r
61 // Thread.sleep(10); //wait for 100ms
\r
62 assertNotSame("Job has finished already. Too late to test cancel!",
\r
63 JobStatus.FINISHED, lr.getJobStatus());
\r
65 // This call causes CancellationException to be thrown
\r
66 Executable<?> clustalr = lr.waitForResult();
\r
67 assertTrue(Util.isMarked(confClust.getWorkDirectory(),
\r
68 JobStatus.CANCELLED));
\r
69 assertTrue(Util.isMarked(confClust.getWorkDirectory(),
\r
70 JobStatus.STARTED));
\r
71 assertTrue(Util.isMarked(confClust.getWorkDirectory(),
\r
72 JobStatus.COLLECTED));
\r
73 assertTrue(Util.isMarked(confClust.getWorkDirectory(),
\r
74 JobStatus.FINISHED));
\r
75 assertFalse(Util.isMarked(confClust.getWorkDirectory(),
\r
76 JobStatus.SUBMITTED));
\r
77 } catch (JobSubmissionException e) {
\r
78 e.printStackTrace();
\r
79 fail(e.getLocalizedMessage());
\r
80 } catch (JobExecutionException e) {
\r
81 e.printStackTrace();
\r
82 fail(e.getLocalizedMessage());
\r
86 @Test(expectedExceptions = { CancellationException.class,
\r
87 JobExecutionException.class }, groups = { AllTestSuit.test_group_engine })
\r
88 public void testMultipleCancelLocally() throws JobExecutionException {
\r
89 ClustalW clustal = new ClustalW();
\r
90 ClustalW clustal2 = new ClustalW();
\r
91 clustal.setInput(test_input).setOutput(test_outfile);
\r
92 clustal2.setInput(test_input).setOutput(test_outfile);
\r
94 ConfiguredExecutable<ClustalW> confClust = Configurator
\r
95 .configureExecutable(clustal);
\r
96 ConfiguredExecutable<ClustalW> confClust2 = Configurator
\r
97 .configureExecutable(clustal2);
\r
99 LocalRunner lr = new LocalRunner(confClust);
\r
100 LocalRunner lr2 = new LocalRunner(confClust2);
\r
105 // Thread.sleep(10); //wait for 100ms
\r
106 assertNotSame("Job has finished already. Too late to test cancel!",
\r
107 JobStatus.FINISHED, lr.getJobStatus());
\r
109 // Thread.sleep(10);
\r
110 assertNotSame("Job has finished already. Too late to test cancel!",
\r
111 JobStatus.FINISHED, lr2.getJobStatus());
\r
113 // This call causes CancellationException to be thrown
\r
114 Executable<?> clustalr = lr.waitForResult();
\r
115 Executable<?> clustalr2 = lr2.waitForResult();
\r
117 } catch (JobSubmissionException e) {
\r
118 e.printStackTrace();
\r
119 fail(e.getLocalizedMessage());
\r
123 @Test(expectedExceptions = { CancellationException.class }, groups = { AllTestSuit.test_group_engine })
\r
124 public void testCancelCompletedTaskLocally() throws JobExecutionException {
\r
125 ClustalW clustal = new ClustalW();
\r
126 clustal.setInput(test_input).setOutput(test_outfile);
\r
129 ConfiguredExecutable<ClustalW> confClust = Configurator
\r
130 .configureExecutable(clustal, Executable.ExecProvider.Local);
\r
131 LocalRunner lr = new LocalRunner(confClust);
\r
133 Thread.currentThread();
\r
134 Thread.sleep(30); // wait for 100ms
\r
135 assertNotSame("Job has not finished!", JobStatus.FINISHED, lr
\r
138 // This call causes ResultNotAvailableException to be thrown
\r
139 ConfiguredExecutable<?> clustalr = lr.waitForResult();
\r
140 assertNull(clustalr.getResults());
\r
141 } catch (JobSubmissionException e) {
\r
142 e.printStackTrace();
\r
143 fail(e.getLocalizedMessage());
\r
144 } catch (InterruptedException e) {
\r
145 e.printStackTrace();
\r
146 fail(e.getLocalizedMessage());
\r
147 } catch (ResultNotAvailableException e) {
\r
148 e.printStackTrace();
\r
149 fail(e.getLocalizedMessage());
\r