Add testing dirs
[proteocache.git] / testsrc / compbio / engine / cluster / drmaa / ClusterSessionTester.java
diff --git a/testsrc/compbio/engine/cluster/drmaa/ClusterSessionTester.java b/testsrc/compbio/engine/cluster/drmaa/ClusterSessionTester.java
new file mode 100644 (file)
index 0000000..d72337b
--- /dev/null
@@ -0,0 +1,96 @@
+/* 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.cluster.drmaa;\r
+\r
+import static org.testng.Assert.assertEquals;\r
+import static org.testng.Assert.assertFalse;\r
+import static org.testng.Assert.assertTrue;\r
+import static org.testng.Assert.fail;\r
+\r
+import org.testng.annotations.Test;\r
+\r
+import compbio.engine.AsyncExecutor;\r
+import compbio.engine.Configurator;\r
+import compbio.engine.Job;\r
+import compbio.engine.client.ConfiguredExecutable;\r
+import compbio.engine.client.Executable;\r
+import compbio.metadata.AllTestSuit;\r
+import compbio.metadata.JobSubmissionException;\r
+import compbio.metadata.ResultNotAvailableException;\r
+import compbio.runner.msa.ClustalW;\r
+import compbio.util.Util;\r
+\r
+public class ClusterSessionTester {\r
+\r
+       @Test(sequential = true, groups = { AllTestSuit.test_group_cluster,\r
+                       AllTestSuit.test_group_engine })\r
+       public void testTaskList() {\r
+               ClustalW cl = new ClustalW();\r
+\r
+               try {\r
+                       ConfiguredExecutable<ClustalW> clw = Configurator\r
+                                       .configureExecutable(cl, Executable.ExecProvider.Cluster);\r
+                       ClusterRunner jr = ClusterRunner.getInstance(clw);\r
+                       String jobId = jr.submitJob();\r
+                       ClusterSession cs = ClusterSession.getInstance();\r
+                       // this only holds for sequential execution\r
+                       //assertEquals(cs.jobs.size(), 1);\r
+                       assertTrue(Job.getByTaskId(jobId, cs.jobs) != null);\r
+                       assertEquals(Job.getByTaskId(jobId, cs.jobs).getConfExecutable(),\r
+                                       clw);\r
+                       jr.cancelJob(jobId);\r
+                       // this only holds for sequential execution\r
+                       assertEquals(cs.jobs.size(), 0);\r
+\r
+                       clw = Configurator.configureExecutable(cl,\r
+                                       Executable.ExecProvider.Cluster);\r
+                       assertFalse(Util.isEmpty(clw.getWorkDirectory()));\r
+                       AsyncExecutor aengine = Configurator.getAsyncEngine(clw);\r
+                       jobId = aengine.submitJob(clw);\r
+                       assertEquals(cs.jobs.size(), 1);\r
+                       assertTrue(Job.getByTaskId(jobId, cs.jobs) != null);\r
+                       assertEquals(Job.getByTaskId(jobId, cs.jobs).getConfExecutable(),\r
+                                       clw);\r
+                       assertFalse(Util.isEmpty(compbio.engine.Configurator\r
+                                       .getWorkDirectory(jobId)));\r
+                       String workDir = clw.getWorkDirectory();\r
+                       assertEquals(workDir, compbio.engine.Configurator\r
+                                       .getWorkDirectory(jobId));\r
+\r
+                       aengine.getResults(jobId);\r
+                       assertEquals(cs.jobs.size(), 0);\r
+                       assertFalse(Util.isEmpty(clw.getWorkDirectory()));\r
+                       // after job has been removed from the list (e.g when completed)\r
+                       // reference to a work directory can still be obtained by other\r
+                       // means\r
+                       assertFalse(Util.isEmpty(compbio.engine.Configurator\r
+                                       .getWorkDirectory(jobId)));\r
+                       assertEquals(compbio.engine.Configurator.getWorkDirectory(jobId),\r
+                                       workDir);\r
+\r
+               } catch (JobSubmissionException e) {\r
+                       e.printStackTrace();\r
+                       fail(e.getMessage());\r
+               } catch (ResultNotAvailableException e) {\r
+                       e.printStackTrace();\r
+                       fail(e.getMessage());\r
+               }\r
+       }\r
+\r
+}\r