--- /dev/null
+/* Copyright (c) 2009 Peter Troshin\r
+ * \r
+ * JAva Bioinformatics Analysis Web Services (JABAWS) @version: 1.0 \r
+ * \r
+ * This library is free software; you can redistribute it and/or modify it under the terms of the\r
+ * Apache License version 2 as published by the Apache Software Foundation\r
+ * \r
+ * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without\r
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache \r
+ * License for more details.\r
+ * \r
+ * A copy of the license is in apache_license.txt. It is also available here:\r
+ * @see: http://www.apache.org/licenses/LICENSE-2.0.txt\r
+ * \r
+ * Any republication or derived work distributed in source code form\r
+ * must include this copyright and license notice.\r
+ */\r
+\r
+package compbio.engine.local;\r
+\r
+import static org.testng.Assert.assertFalse;\r
+import static org.testng.Assert.assertTrue;\r
+import static org.testng.AssertJUnit.assertNotSame;\r
+import static org.testng.AssertJUnit.assertNull;\r
+import static org.testng.AssertJUnit.fail;\r
+\r
+import java.util.concurrent.CancellationException;\r
+\r
+import org.testng.annotations.Test;\r
+\r
+import compbio.engine.Configurator;\r
+import compbio.engine.client.ConfiguredExecutable;\r
+import compbio.engine.client.Executable;\r
+import compbio.engine.client.EngineUtil;\r
+import compbio.metadata.AllTestSuit;\r
+import compbio.metadata.JobExecutionException;\r
+import compbio.metadata.JobStatus;\r
+import compbio.metadata.JobSubmissionException;\r
+import compbio.metadata.ResultNotAvailableException;\r
+import compbio.runner.msa.ClustalW;\r
+\r
+public class LocalRunnerTester {\r
+\r
+ public static String cluster_test_outfile = "TO1381.clustal.cluster.out"; // "/homes/pvtroshin/TO1381.clustal.cluster.out\r
+ // go up 2 directories from workspace: workspace/clustengine\r
+ public static String test_input = AllTestSuit.TEST_DATA_PATH_ABSOLUTE\r
+ + "TO1381.fasta";\r
+ public static String test_outfile = "TO1381.clustal.out";\r
+\r
+ @Test(expectedExceptions = CancellationException.class, groups = { AllTestSuit.test_group_engine })\r
+ public void testCancelLocally() {\r
+ ClustalW clustal = new ClustalW();\r
+ clustal.setInput(test_input).setOutput(test_outfile);\r
+\r
+ try {\r
+ ConfiguredExecutable<ClustalW> confClust = Configurator\r
+ .configureExecutable(clustal);\r
+ LocalRunner lr = new LocalRunner(confClust);\r
+\r
+ lr.executeJob();\r
+ // Thread.sleep(10); //wait for 100ms\r
+ assertNotSame("Job has finished already. Too late to test cancel!",\r
+ JobStatus.FINISHED, lr.getJobStatus());\r
+ lr.cancelJob();\r
+ // This call causes CancellationException to be thrown\r
+ Executable<?> clustalr = lr.waitForResult();\r
+ assertTrue(EngineUtil.isMarked(confClust.getWorkDirectory(),\r
+ JobStatus.CANCELLED));\r
+ assertTrue(EngineUtil.isMarked(confClust.getWorkDirectory(),\r
+ JobStatus.STARTED));\r
+ assertTrue(EngineUtil.isMarked(confClust.getWorkDirectory(),\r
+ JobStatus.COLLECTED));\r
+ assertTrue(EngineUtil.isMarked(confClust.getWorkDirectory(),\r
+ JobStatus.FINISHED));\r
+ assertFalse(EngineUtil.isMarked(confClust.getWorkDirectory(),\r
+ JobStatus.SUBMITTED));\r
+ } catch (JobSubmissionException e) {\r
+ e.printStackTrace();\r
+ fail(e.getLocalizedMessage());\r
+ } catch (JobExecutionException e) {\r
+ e.printStackTrace();\r
+ fail(e.getLocalizedMessage());\r
+ }\r
+ }\r
+\r
+ @Test(expectedExceptions = { CancellationException.class,\r
+ JobExecutionException.class }, groups = { AllTestSuit.test_group_engine })\r
+ public void testMultipleCancelLocally() throws JobExecutionException {\r
+ ClustalW clustal = new ClustalW();\r
+ ClustalW clustal2 = new ClustalW();\r
+ clustal.setInput(test_input).setOutput(test_outfile);\r
+ clustal2.setInput(test_input).setOutput(test_outfile);\r
+ try {\r
+ ConfiguredExecutable<ClustalW> confClust = Configurator\r
+ .configureExecutable(clustal);\r
+ ConfiguredExecutable<ClustalW> confClust2 = Configurator\r
+ .configureExecutable(clustal2);\r
+\r
+ LocalRunner lr = new LocalRunner(confClust);\r
+ LocalRunner lr2 = new LocalRunner(confClust2);\r
+\r
+ lr.executeJob();\r
+ lr2.executeJob();\r
+\r
+ // Thread.sleep(10); //wait for 100ms\r
+ assertNotSame("Job has finished already. Too late to test cancel!",\r
+ JobStatus.FINISHED, lr.getJobStatus());\r
+ lr.cancelJob();\r
+ // Thread.sleep(10);\r
+ assertNotSame("Job has finished already. Too late to test cancel!",\r
+ JobStatus.FINISHED, lr2.getJobStatus());\r
+ lr2.cancelJob();\r
+ // This call causes CancellationException to be thrown\r
+ Executable<?> clustalr = lr.waitForResult();\r
+ Executable<?> clustalr2 = lr2.waitForResult();\r
+\r
+ } catch (JobSubmissionException e) {\r
+ e.printStackTrace();\r
+ fail(e.getLocalizedMessage());\r
+ }\r
+ }\r
+\r
+ @Test(expectedExceptions = { CancellationException.class }, groups = { AllTestSuit.test_group_engine })\r
+ public void testCancelCompletedTaskLocally() throws JobExecutionException {\r
+ ClustalW clustal = new ClustalW();\r
+ clustal.setInput(test_input).setOutput(test_outfile);\r
+\r
+ try {\r
+ ConfiguredExecutable<ClustalW> confClust = Configurator\r
+ .configureExecutable(clustal, Executable.ExecProvider.Local);\r
+ LocalRunner lr = new LocalRunner(confClust);\r
+ lr.executeJob();\r
+ Thread.currentThread();\r
+ Thread.sleep(30); // wait for 100ms\r
+ assertNotSame("Job has not finished!", JobStatus.FINISHED, lr\r
+ .getJobStatus());\r
+ lr.cancelJob();\r
+ // This call causes ResultNotAvailableException to be thrown\r
+ ConfiguredExecutable<?> clustalr = lr.waitForResult();\r
+ assertNull(clustalr.getResults());\r
+ } catch (JobSubmissionException e) {\r
+ e.printStackTrace();\r
+ fail(e.getLocalizedMessage());\r
+ } catch (InterruptedException e) {\r
+ e.printStackTrace();\r
+ fail(e.getLocalizedMessage());\r
+ } catch (ResultNotAvailableException e) {\r
+ e.printStackTrace();\r
+ fail(e.getLocalizedMessage());\r
+ }\r
+ }\r
+\r
+}\r