View Javadoc

1   /*$Id: MockSchedulerImpl.java,v 1.6 2004/12/03 14:47:41 jdt Exp $
2    * Created on 18-Feb-2004
3    *
4    * Copyright (C) AstroGrid. All rights reserved.
5    *
6    * This software is published under the terms of the AstroGrid 
7    * Software License version 1.2, a copy of which has been included 
8    * with this distribution in the LICENSE.txt file.  
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 $Log: MockSchedulerImpl.java,v $
119 Revision 1.6  2004/12/03 14:47:41  jdt
120 Merges from workflow-nww-776
121 
122 Revision 1.5.102.1  2004/12/01 21:48:20  nw
123 adjusted to work with new summary object,
124 and changed package of JobURN
125 
126 Revision 1.5  2004/07/01 21:15:00  nw
127 added results-listener interface to jes
128 
129 Revision 1.4  2004/04/08 14:43:26  nw
130 added delete and abort job functionality
131 
132 Revision 1.3  2004/03/15 23:45:07  nw
133 improved javadoc
134 
135 Revision 1.2  2004/03/15 01:30:45  nw
136 factored component descriptor out into separate package
137 
138 Revision 1.1  2004/03/15 00:30:54  nw
139 factored implemetation of scheduler out of parent package.
140 
141 Revision 1.6  2004/03/15 00:06:57  nw
142 removed SchedulerNotifier interface - replaced references to it by references to JobScheduler interface - identical
143 
144 Revision 1.5  2004/03/07 21:04:39  nw
145 merged in nww-itn05-pico - adds picocontainer
146 
147 Revision 1.4.4.1  2004/03/07 20:41:06  nw
148 added component descriptor interface impl,
149 refactored any primitive types passed into constructor
150 
151 Revision 1.4  2004/03/05 16:16:23  nw
152 worked now object model through jes.
153 implemented basic scheduling policy
154 removed internal facade
155 
156 Revision 1.3  2004/03/03 01:13:42  nw
157 updated jes to work with regenerated workflow object model
158 
159 Revision 1.2  2004/02/27 00:46:03  nw
160 merged branch nww-itn05-bz#91
161 
162 Revision 1.1.2.1  2004/02/27 00:27:42  nw
163 moved from test hierarchy.
164 
165 Revision 1.1.2.1  2004/02/19 13:41:25  nw
166 added tests for everything :)
167  
168 */