View Javadoc

1   package org.ogf.saga.job.run;
2   
3   import org.junit.Ignore;
4   import org.junit.Test;
5   import org.ogf.saga.error.NoSuccessException;
6   import org.ogf.saga.job.Job;
7   import org.ogf.saga.job.JobDescription;
8   import org.ogf.saga.job.abstracts.Attribute;
9   import org.ogf.saga.job.base.JobBaseTest;
10  import org.ogf.saga.task.State;
11  
12  /* **************************************************
13  * *** Centre de Calcul de l'IN2P3 - Lyon (France) ***
14  * ***             http://cc.in2p3.fr/             ***
15  * ***************************************************
16  * File:   JobRunDescriptionTest
17  * Author: Nicolas Demesy (nicolas.demesy@bt.com)
18  * Date:   30 janv. 2008
19  * ***************************************************
20  * Description: 
21  * This test suite is made to be sure that the plug-in 
22  * transmits well the requested attributes
23  */
24  public abstract class RequirementsTest extends JobBaseTest {
25  	
26  	protected RequirementsTest(String jobprotocol) throws Exception {
27          super(jobprotocol);
28      }
29  
30      /**
31       * Runs job on a requested working directory
32       */
33      @Test
34      public void test_run_inWorkingDirectory() throws Exception {
35          
36      	// prepare
37      	Attribute[] attributes = new Attribute[1];
38      	attributes[0] = new Attribute(JobDescription.WORKINGDIRECTORY, "/dummy");
39      	JobDescription desc = createJob("/bin/pwd", attributes, null);
40      	
41      	Job job = null;
42      	try {
43  	    	// submit
44  	        job = runJob(desc);
45  	        
46  	        // wait for end
47  	        job.waitFor();
48  	        
49  	        assertEquals(
50  	                State.FAILED,
51  	                job.getState());
52          }
53          catch (NoSuccessException noSuccess) {
54          	// test is successful is exception instance of BadResource
55              if (!noSuccess.getClass().getName().endsWith("BadResource")) {
56                  throw noSuccess;
57              }
58          }
59          finally {
60          	if(job != null) {
61          		job.waitFor(Float.valueOf(FINALY_TIMEOUT));
62          	}
63          }        
64      }
65      
66     
67      /**
68       * Runs job, requests an impossible queue and expects FAILED status
69       */
70      @Test
71      public void test_run_queueRequirement() throws Exception {
72          
73      	// prepare a simple job
74      	JobDescription desc = createSimpleJob();
75      	// ask for a impossible queue 
76      	desc.setAttribute(JobDescription.QUEUE, "impossible_azerty");
77      	
78      	Job job = null;
79      	try {
80  	    	// submit
81  	        job = runJob(desc);
82  	        
83  	        // wait for end
84  	        job.waitFor();
85  	        
86  	        assertEquals(
87  	                State.FAILED,
88  	                job.getState()); 	        
89          }
90          catch (NoSuccessException noSuccess) {
91          	// test may be successful
92          }
93          finally {
94          	if(job != null) {
95          		job.waitFor(Float.valueOf(FINALY_TIMEOUT));
96          	}
97          }
98      }
99      
100     /**
101      * Runs job, estimated an impossible job duration and expects FAILED status
102      */
103     @Test
104     public void test_run_cpuTimeRequirement() throws Exception {
105         
106     	// prepare a simple job
107     	JobDescription desc = createSimpleJob();
108     	// and inform the scheduler to the estimate time is 14 days
109     	desc.setAttribute(JobDescription.TOTALCPUTIME, String.valueOf(60*60*24*14));
110     	
111     	Job job = null;
112     	try {
113     		// submit
114 	        job = runJob(desc);
115 	        
116 	        // wait the end
117 	        job.waitFor();  
118 	        
119 	        // check job status
120 	        assertEquals(
121 	                State.FAILED,
122 	                job.getState());
123     	}
124     	catch (NoSuccessException noSuccess) {
125         	// test is successful is exception instance of BadResource
126             if (!noSuccess.getClass().getName().endsWith("BadResource")) {
127                 throw noSuccess;
128             }
129         }
130     	finally {
131         	if(job != null) {
132         		job.waitFor(Float.valueOf(FINALY_TIMEOUT));
133         	}
134         }
135 	        
136     }
137     
138     /**
139      * Runs simple job, requests 256 Mo of memory and expects DONE status (it is just an information)
140      */
141     @Test
142     public void test_run_memoryRequirement() throws Exception {
143         
144     	// prepare a job witch requires 256 Mo of RAM
145     	Attribute[] attributes = new Attribute[1];
146     	attributes[0] = new Attribute(JobDescription.TOTALPHYSICALMEMORY, "256");
147     	JobDescription desc =  createJob(SIMPLE_JOB_BINARY, attributes, null);
148     	
149     	// submit
150         Job job = runJob(desc);
151         
152         // wait for the end
153         job.waitFor();  
154         
155         // check job status
156         assertEquals(
157                 State.DONE,
158                 job.getState());       
159     }
160         
161     /**
162      * Runs simple job and expects FAILED status
163      */
164     @Test
165     @Ignore
166     public void test_run_processRequirement() throws Exception {
167         
168     	// prepare a job witch requires 1 million of nodes
169     	Attribute[] attributes = new Attribute[2];
170     	attributes[0] = new Attribute(JobDescription.NUMBEROFPROCESSES, "1000000");
171     	attributes[1] = new Attribute(JobDescription.PROCESSESPERHOST, "1");
172     	JobDescription desc =  createJob(SIMPLE_JOB_BINARY, attributes, null);
173     	
174     	Job job = null;
175     	try {
176     		// submit
177 	        job = runJob(desc);
178 	        
179 	        // wait the end
180 	        job.waitFor();  
181 	        
182 	        // check job status
183 	        assertEquals(
184 	                State.FAILED,
185 	                job.getState());
186     	}
187     	catch (NoSuccessException noSuccess) {
188         	// test is successful is exception instance of BadResource
189             if (!noSuccess.getClass().getName().endsWith("BadResource")) {
190                 throw noSuccess;
191             }
192         }
193     	finally {
194         	if(job != null) {
195         		job.waitFor(Float.valueOf(FINALY_TIMEOUT));
196         	}
197         }
198     }
199 
200 }