1
2
3
4
5
6
7
8
9
10
11 package org.astrogrid.jes.jobscheduler.impl;
12
13 import org.astrogrid.component.descriptor.ComponentDescriptor;
14 import org.astrogrid.jes.beans.v1.axis.executionrecord.JobURN;
15 import org.astrogrid.jes.jobscheduler.JobScheduler;
16 import org.astrogrid.jes.types.v1.cea.axis.JobIdentifierType;
17 import org.astrogrid.jes.types.v1.cea.axis.MessageType;
18 import org.astrogrid.jes.types.v1.cea.axis.ResultListType;
19
20 import junit.framework.Test;
21
22 /*** Mock implementation of a JobScheduler - just counts the number of times its methods are called.
23 * @author Noel Winstanley nw@jb.man.ac.uk 18-Feb-2004
24 *
25 */
26 public class MockSchedulerImpl implements JobScheduler , ComponentDescriptor{
27 /*** Construct a new MockJobScheduler
28 *
29 */
30 public MockSchedulerImpl() {
31 this(true);
32 }
33 public MockSchedulerImpl(boolean willSucceed) {
34 this.willSucceed = willSucceed;
35 }
36 protected final boolean willSucceed;
37 protected int callCount = 0;
38 public int getCallCount() {
39 return callCount;
40 }
41 /***
42 * @see org.astrogrid.jes.delegate.v1.jobscheduler.JobScheduler#scheduleNewJob(org.astrogrid.jes.types.v1.JobURN)
43 */
44 public void scheduleNewJob(JobURN request) throws Exception {
45 callCount++;
46 if (! willSucceed) {
47 throw new Exception("You wanted me to fail");
48 }
49 }
50
51 /***
52 * @see org.astrogrid.jes.delegate.v1.jobscheduler.JobScheduler#resumeJob(org.astrogrid.jes.types.v1.cea.axis.JobIdentifierType, org.astrogrid.jes.types.v1.cea.axis.MessageType)
53 */
54 public void resumeJob(JobIdentifierType arg0, MessageType arg1) throws Exception {
55 callCount++;
56 if (! willSucceed) {
57 throw new Exception("you wanted me to fail");
58 }
59 }
60
61 /***
62 * @see org.astrogrid.jes.jobscheduler.JobScheduler#reportResults(org.astrogrid.jes.types.v1.cea.axis.JobIdentifierType, org.astrogrid.jes.types.v1.cea.axis.ResultListType)
63 */
64 public void reportResults(JobIdentifierType id, ResultListType results) throws Exception {
65 callCount++;
66 if (! willSucceed) {
67 throw new Exception("you wanted me to fail");
68 }
69 }
70 /***
71 * @see org.astrogrid.jes.component.ComponentDescriptor#getName()
72 */
73 public String getName() {
74 return "Mock Job Scheduler";
75 }
76 /***
77 * @see org.astrogrid.jes.component.ComponentDescriptor#getDescription()
78 */
79 public String getDescription() {
80 return "Mock implementation - does nothing apart from count methods called\n" +
81 (willSucceed ? "Set to succeed at each method call" : "Set to fail at each method call: will thrown exceptions");
82 }
83 /***
84 * @see org.astrogrid.jes.component.ComponentDescriptor#getInstallationTest()
85 */
86 public Test getInstallationTest() {
87 return null;
88 }
89 /***
90 * @see org.astrogrid.jes.jobscheduler.JobScheduler#abortJob(org.astrogrid.jes.types.v1.JobURN)
91 */
92 public void abortJob(JobURN jobURN) throws Exception {
93 callCount++;
94 if (! willSucceed) {
95 throw new Exception("you wanted me to fail");
96 }
97 }
98 /***
99 * @see org.astrogrid.jes.jobscheduler.JobScheduler#deleteJob(org.astrogrid.jes.types.v1.JobURN)
100 */
101 public void deleteJob(JobURN jobURN) throws Exception {
102 callCount++;
103 if (! willSucceed) {
104 throw new Exception("you wanted me to fail");
105 }
106 }
107 /***
108 *
109 */
110 public void resetCallCount() {
111 callCount = 0;
112 }
113
114 }
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168