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
14
15
16
17
18
19
20
21
22
23
24 public abstract class RequirementsTest extends JobBaseTest {
25
26 protected RequirementsTest(String jobprotocol) throws Exception {
27 super(jobprotocol);
28 }
29
30
31
32
33 @Test
34 public void test_run_inWorkingDirectory() throws Exception {
35
36
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
44 job = runJob(desc);
45
46
47 job.waitFor();
48
49 assertEquals(
50 State.FAILED,
51 job.getState());
52 }
53 catch (NoSuccessException noSuccess) {
54
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
69
70 @Test
71 public void test_run_queueRequirement() throws Exception {
72
73
74 JobDescription desc = createSimpleJob();
75
76 desc.setAttribute(JobDescription.QUEUE, "impossible_azerty");
77
78 Job job = null;
79 try {
80
81 job = runJob(desc);
82
83
84 job.waitFor();
85
86 assertEquals(
87 State.FAILED,
88 job.getState());
89 }
90 catch (NoSuccessException noSuccess) {
91
92 }
93 finally {
94 if(job != null) {
95 job.waitFor(Float.valueOf(FINALY_TIMEOUT));
96 }
97 }
98 }
99
100
101
102
103 @Test
104 public void test_run_cpuTimeRequirement() throws Exception {
105
106
107 JobDescription desc = createSimpleJob();
108
109 desc.setAttribute(JobDescription.TOTALCPUTIME, String.valueOf(60*60*24*14));
110
111 Job job = null;
112 try {
113
114 job = runJob(desc);
115
116
117 job.waitFor();
118
119
120 assertEquals(
121 State.FAILED,
122 job.getState());
123 }
124 catch (NoSuccessException noSuccess) {
125
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
140
141 @Test
142 public void test_run_memoryRequirement() throws Exception {
143
144
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
150 Job job = runJob(desc);
151
152
153 job.waitFor();
154
155
156 assertEquals(
157 State.DONE,
158 job.getState());
159 }
160
161
162
163
164 @Test
165 @Ignore
166 public void test_run_processRequirement() throws Exception {
167
168
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
177 job = runJob(desc);
178
179
180 job.waitFor();
181
182
183 assertEquals(
184 State.FAILED,
185 job.getState());
186 }
187 catch (NoSuccessException noSuccess) {
188
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 }