d72337b6cc935c1adce4da7a7e0cb84f881b5151
[proteocache.git] / testsrc / compbio / engine / cluster / drmaa / ClusterSessionTester.java
1 /* Copyright (c) 2009 Peter Troshin\r
2  *  \r
3  *  JAva Bioinformatics Analysis Web Services (JABAWS) @version: 1.0     \r
4  * \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
7  * \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
11  * \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
14  * \r
15  * Any republication or derived work distributed in source code form\r
16  * must include this copyright and license notice.\r
17  */\r
18 \r
19 package compbio.engine.cluster.drmaa;\r
20 \r
21 import static org.testng.Assert.assertEquals;\r
22 import static org.testng.Assert.assertFalse;\r
23 import static org.testng.Assert.assertTrue;\r
24 import static org.testng.Assert.fail;\r
25 \r
26 import org.testng.annotations.Test;\r
27 \r
28 import compbio.engine.AsyncExecutor;\r
29 import compbio.engine.Configurator;\r
30 import compbio.engine.Job;\r
31 import compbio.engine.client.ConfiguredExecutable;\r
32 import compbio.engine.client.Executable;\r
33 import compbio.metadata.AllTestSuit;\r
34 import compbio.metadata.JobSubmissionException;\r
35 import compbio.metadata.ResultNotAvailableException;\r
36 import compbio.runner.msa.ClustalW;\r
37 import compbio.util.Util;\r
38 \r
39 public class ClusterSessionTester {\r
40 \r
41         @Test(sequential = true, groups = { AllTestSuit.test_group_cluster,\r
42                         AllTestSuit.test_group_engine })\r
43         public void testTaskList() {\r
44                 ClustalW cl = new ClustalW();\r
45 \r
46                 try {\r
47                         ConfiguredExecutable<ClustalW> clw = Configurator\r
48                                         .configureExecutable(cl, Executable.ExecProvider.Cluster);\r
49                         ClusterRunner jr = ClusterRunner.getInstance(clw);\r
50                         String jobId = jr.submitJob();\r
51                         ClusterSession cs = ClusterSession.getInstance();\r
52                         // this only holds for sequential execution\r
53                         //assertEquals(cs.jobs.size(), 1);\r
54                         assertTrue(Job.getByTaskId(jobId, cs.jobs) != null);\r
55                         assertEquals(Job.getByTaskId(jobId, cs.jobs).getConfExecutable(),\r
56                                         clw);\r
57                         jr.cancelJob(jobId);\r
58                         // this only holds for sequential execution\r
59                         assertEquals(cs.jobs.size(), 0);\r
60 \r
61                         clw = Configurator.configureExecutable(cl,\r
62                                         Executable.ExecProvider.Cluster);\r
63                         assertFalse(Util.isEmpty(clw.getWorkDirectory()));\r
64                         AsyncExecutor aengine = Configurator.getAsyncEngine(clw);\r
65                         jobId = aengine.submitJob(clw);\r
66                         assertEquals(cs.jobs.size(), 1);\r
67                         assertTrue(Job.getByTaskId(jobId, cs.jobs) != null);\r
68                         assertEquals(Job.getByTaskId(jobId, cs.jobs).getConfExecutable(),\r
69                                         clw);\r
70                         assertFalse(Util.isEmpty(compbio.engine.Configurator\r
71                                         .getWorkDirectory(jobId)));\r
72                         String workDir = clw.getWorkDirectory();\r
73                         assertEquals(workDir, compbio.engine.Configurator\r
74                                         .getWorkDirectory(jobId));\r
75 \r
76                         aengine.getResults(jobId);\r
77                         assertEquals(cs.jobs.size(), 0);\r
78                         assertFalse(Util.isEmpty(clw.getWorkDirectory()));\r
79                         // after job has been removed from the list (e.g when completed)\r
80                         // reference to a work directory can still be obtained by other\r
81                         // means\r
82                         assertFalse(Util.isEmpty(compbio.engine.Configurator\r
83                                         .getWorkDirectory(jobId)));\r
84                         assertEquals(compbio.engine.Configurator.getWorkDirectory(jobId),\r
85                                         workDir);\r
86 \r
87                 } catch (JobSubmissionException e) {\r
88                         e.printStackTrace();\r
89                         fail(e.getMessage());\r
90                 } catch (ResultNotAvailableException e) {\r
91                         e.printStackTrace();\r
92                         fail(e.getMessage());\r
93                 }\r
94         }\r
95 \r
96 }\r