1 package org.ogf.saga.job.run;
2
3 import org.junit.Assert;
4 import org.junit.Test;
5 import org.ogf.saga.error.IncorrectStateException;
6 import org.ogf.saga.error.NotImplementedException;
7 import org.ogf.saga.job.Job;
8 import org.ogf.saga.job.JobDescription;
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
25
26 public abstract class RequiredTest extends JobBaseTest {
27
28 protected RequiredTest(String jobprotocol) throws Exception {
29 super(jobprotocol);
30 }
31
32
33
34
35 @Test
36 public void test_run_long() throws Exception {
37
38
39 JobDescription desc = createLongJob();
40
41
42 Job job = runJob(desc);
43
44
45 job.waitFor();
46
47
48 Assert.assertEquals(
49 State.DONE,
50 job.getState());
51 }
52
53
54
55
56 @Test
57 public void test_run_error() throws Exception {
58
59
60 JobDescription desc = createErrorJob();
61
62
63 Job job = runJob(desc);
64
65
66 job.waitFor();
67
68
69 Assert.assertEquals(
70 State.FAILED,
71 job.getState());
72 }
73
74
75
76
77 @Test
78 public void test_cancel_running() throws Exception {
79
80
81 JobDescription desc = createLongJob();
82
83
84 Job job = runJob(desc);
85
86
87 if (! super.waitForSubState(job, MODEL+":RUNNING_ACTIVE")) {
88 job.waitFor(Float.valueOf(MAX_QUEUING_TIME));
89 Assert.fail("Job did not enter RUNNING_ACTIVE state within "+MAX_QUEUING_TIME+" seconds");
90 }
91
92 try {
93
94 job.cancel();
95
96
97 job.waitFor(Float.valueOf(FINALY_TIMEOUT));
98
99
100 Assert.assertEquals(
101 State.CANCELED,
102 job.getState());
103 }
104 catch (NotImplementedException notImplemented) {
105 Assert.fail("WARNING : CANCEL not implemented in plugin");
106 }
107 finally {
108 job.waitFor(Float.valueOf(FINALY_TIMEOUT));
109 }
110 }
111
112
113
114
115 @Test(expected=IncorrectStateException.class)
116 public void test_cancel_new() throws Exception {
117
118
119 JobDescription desc = createSimpleJob();
120
121
122 Job job = createJob(desc);
123
124
125 checkStatus(job.getState(), State.NEW);
126
127
128 job.cancel();
129
130
131 Thread.sleep(2000);
132
133 }
134
135
136
137
138
139 @Test
140 public void test_cancel_done() throws Exception {
141
142
143 JobDescription desc = createSimpleJob();
144
145
146 Job job = runJob(desc);
147
148
149 job.waitFor();
150
151
152 checkStatus(job.getState(), State.DONE);
153
154
155 job.cancel();
156
157
158 Thread.sleep(2000);
159
160
161 checkStatus(job.getState(), State.DONE);
162 }
163 }