View Javadoc

1   package org.ogf.saga.job.description;
2   
3   import org.junit.After;
4   import org.junit.Assert;
5   import org.junit.Before;
6   import org.junit.BeforeClass;
7   import org.junit.Ignore;
8   import org.junit.Test;
9   import org.ogf.saga.job.JobDescription;
10  import org.ogf.saga.job.JobFactory;
11  import org.ogf.saga.job.JobService;
12  import org.ogf.saga.job.base.JobBaseTest;
13  
14  /* ***************************************************
15  * *** Centre de Calcul de l'IN2P3 - Lyon (France) ***
16  * ***             http://cc.in2p3.fr/             ***
17  * ***************************************************
18  * File:   JobDescriptionTest
19  * Author: Sylvain Reynaud (sreynaud@in2p3.fr)
20  * Date:   1 fev. 2008
21  * ***************************************************
22  * Description:                                      */
23  /**
24   *
25   */
26  public abstract class DescriptionTest extends JobBaseTest {
27      private JobService m_jobTranslator;
28      private JobDescription m_jobDescription;
29  
30      protected DescriptionTest(String jobprotocol) throws Exception {
31          super(jobprotocol);
32          m_jobTranslator = JobFactory.createJobService(m_session, m_jobservice);
33      }
34  
35      ////////////////////////////////////// test supported attributes //////////////////////////////////////
36  
37      @Test
38      public void test_executable() throws Exception {
39          this.change(JobDescription.EXECUTABLE, "/bin/executable2");
40      }
41      @Test
42      public void test_arguments() throws Exception {
43          this.change(JobDescription.ARGUMENTS, new String[]{"arg", "arg2"});
44      }
45      @Test
46      public void test_spmdVariation() throws Exception {
47          this.change(JobDescription.SPMDVARIATION, "MPI");
48      }
49      @Test
50      public void test_totalCPUCount() throws Exception {
51          this.change(JobDescription.TOTALCPUCOUNT, "2");
52      }
53      @Test
54      public void test_numberOfProcesses() throws Exception {
55          this.change(JobDescription.NUMBEROFPROCESSES, "4");
56      }
57      @Test
58      public void test_processesPerHost() throws Exception {
59          this.change(JobDescription.PROCESSESPERHOST, "2");
60      }
61      @Test
62      public void test_threadsPerProcess() throws Exception {
63          this.change(JobDescription.THREADSPERPROCESS, "2");
64      }
65      @Test
66      public void test_environment() throws Exception {
67          this.change(JobDescription.ENVIRONMENT, new String[]{"var=value", "var2=value2"});
68      }
69      @Test
70      public void test_workingDirectory() throws Exception {
71          this.change(JobDescription.WORKINGDIRECTORY, "/tmp/workdir2");
72      }
73      @Test
74      public void test_input() throws Exception {
75          this.change(JobDescription.INPUT, "stdin2.txt");
76      }
77      @Test
78      public void test_output() throws Exception {
79          this.change(JobDescription.OUTPUT, "stdout2.txt");
80      }
81      @Test
82      public void test_error() throws Exception {
83          this.change(JobDescription.ERROR, "stderr2.txt");
84      }
85      /** WARNING: attribute FileTransfer is removed from job description when staging is done by engine instead of plugin */
86      @Test
87      public void test_fileTransfer() throws Exception {
88          m_jobDescription.setVectorAttribute(JobDescription.FILETRANSFER, new String[]{"myfile>myf", "file1<f1"});
89          this.change(JobDescription.FILETRANSFER, new String[]{"myfile>myf", "file2<f2"});
90      }
91      @Test
92      public void test_cleanup() throws Exception {
93          m_jobDescription.setVectorAttribute(JobDescription.FILETRANSFER, new String[]{"myfile>myf", "file1<f1"});
94      	this.change(JobDescription.CLEANUP, JobDescription.TRUE);
95      }
96      @Test
97      public void test_wallTimeLimit() throws Exception {
98          this.change(JobDescription.WALLTIMELIMIT, "120");
99      }
100     @Test
101     public void test_totalCPUTime() throws Exception {
102         this.change(JobDescription.TOTALCPUTIME, "120");
103     }
104     @Test
105     public void test_totalPhysicalMemory() throws Exception {
106         this.change(JobDescription.TOTALPHYSICALMEMORY, "2048");
107     }
108     @Test
109     public void test_cpuArchitecture() throws Exception {
110         this.change(JobDescription.CPUARCHITECTURE, "ia64");
111     }
112     @Test
113     public void test_operatingSystemType() throws Exception {
114         this.change(JobDescription.OPERATINGSYSTEMTYPE, "WINNT");
115     }
116     @Test
117     public void test_candidateHosts() throws Exception {
118         this.change(JobDescription.CANDIDATEHOSTS, new String[]{"myhost", "host2"});
119     }
120     @Test
121     public void test_queue() throws Exception {
122         this.change(JobDescription.QUEUE, "queue2");
123     }
124 /* TODO: uncomment this test when it will be supported by adaptors
125     @Test
126     public void test_jobProject() throws Exception {
127         this.change(JobDescription.JOBPROJECT, "project2");
128     }
129 */
130 
131     ////////////////////////////////////// common methods //////////////////////////////////////
132     @Before
133     public void setUp() throws Exception {
134 //        super.setUp();
135         m_jobDescription = JobFactory.createJobDescription();
136         // attributes to be supported by the adaptor
137         m_jobDescription.setAttribute(JobDescription.EXECUTABLE, "/bin/executable1");
138         m_jobDescription.setVectorAttribute(JobDescription.ARGUMENTS, new String[]{"arg", "arg1"});
139         m_jobDescription.setAttribute(JobDescription.SPMDVARIATION, "None");
140         m_jobDescription.setAttribute(JobDescription.TOTALCPUCOUNT, "1");
141         m_jobDescription.setAttribute(JobDescription.NUMBEROFPROCESSES, "2");
142         m_jobDescription.setAttribute(JobDescription.PROCESSESPERHOST, "1");
143         m_jobDescription.setAttribute(JobDescription.THREADSPERPROCESS, "1");
144         m_jobDescription.setVectorAttribute(JobDescription.ENVIRONMENT, new String[]{"var=value", "var1=value1"});
145         m_jobDescription.setAttribute(JobDescription.WORKINGDIRECTORY, "/tmp/workdir1");
146         m_jobDescription.setAttribute(JobDescription.INTERACTIVE, JobDescription.FALSE); // not yet supported by JSAGA
147         m_jobDescription.setAttribute(JobDescription.INPUT, "stdin1.txt");
148         m_jobDescription.setAttribute(JobDescription.OUTPUT, "stdout1.txt");
149         m_jobDescription.setAttribute(JobDescription.ERROR, "stderr1.txt");
150         // JobDescription.FILETRANSFER ignored because it modifies job description
151         m_jobDescription.setAttribute(JobDescription.CLEANUP, JobDescription.FALSE);
152         // JobDescription.JOBSTARTTIME is not supported by JSAGA
153         m_jobDescription.setAttribute(JobDescription.WALLTIMELIMIT, "60");
154         m_jobDescription.setAttribute(JobDescription.TOTALCPUTIME, "60");
155         m_jobDescription.setAttribute(JobDescription.TOTALPHYSICALMEMORY, "1024");
156         m_jobDescription.setAttribute(JobDescription.CPUARCHITECTURE, "x86");
157         m_jobDescription.setAttribute(JobDescription.OPERATINGSYSTEMTYPE, "LINUX");
158         m_jobDescription.setVectorAttribute(JobDescription.CANDIDATEHOSTS, new String[]{"myhost", "host1"});
159         m_jobDescription.setAttribute(JobDescription.QUEUE, "queue1");
160         m_jobDescription.setAttribute(JobDescription.JOBPROJECT, "project1");
161         // JobDescription.JOBCONTACT is not supported by JSAGA
162     }
163 
164     @After
165     public void tearDown() throws Exception {
166         m_jobDescription = null;
167 //        super.tearDown();
168     }
169 
170     private void change(String attributeName, String attributeValue) throws Exception {
171         String unexpected = m_jobTranslator.createJob(m_jobDescription).getAttribute("NativeJobDescription");
172         m_jobDescription.setAttribute(attributeName, attributeValue);
173         String translated = m_jobTranslator.createJob(m_jobDescription).getAttribute("NativeJobDescription");
174         Assert.assertFalse(unexpected.equals(translated));
175     }
176 
177     private void change(String attributeName, String[] attributeValues) throws Exception {
178         String unexpected = m_jobTranslator.createJob(m_jobDescription).getAttribute("NativeJobDescription");
179         m_jobDescription.setVectorAttribute(attributeName, attributeValues);
180         String translated = m_jobTranslator.createJob(m_jobDescription).getAttribute("NativeJobDescription");
181         Assert.assertFalse(unexpected.equals(translated));
182     }
183 }