1   /*$Id: ParforSingletonFeatureTest.java,v 1.2 2004/08/13 09:10:05 nw Exp $
2    * Created on 09-Aug-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.groovy;
12  
13  import org.astrogrid.applications.beans.v1.cea.castor.types.ExecutionPhase;
14  import org.astrogrid.workflow.beans.v1.Parfor;
15  import org.astrogrid.workflow.beans.v1.Script;
16  import org.astrogrid.workflow.beans.v1.Set;
17  import org.astrogrid.workflow.beans.v1.Workflow;
18  import org.astrogrid.workflow.beans.v1.execution.StepExecutionRecord;
19  
20  /***
21   * @author Noel Winstanley nw@jb.man.ac.uk 09-Aug-2004
22   *
23   */
24  public class ParforSingletonFeatureTest extends AbstractTestForFeature {
25  
26      /*** Construct a new ParforSingletonFeatureTest
27       * @param name
28       */
29      public ParforSingletonFeatureTest(String name) {
30          super(name);
31      }
32  
33      /***
34       * @see org.astrogrid.jes.jobscheduler.impl.groovy.AbstractTestForFeature#buildWorkflow()
35       */
36      protected Workflow buildWorkflow() {
37          Workflow wf = super.createMinimalWorkflow();
38          Set acc = new Set();
39          acc.setVar("acc");
40          acc.setValue("${0}");
41          wf.getSequence().addActivity(acc);
42          
43          Parfor f = new Parfor();
44          f.setVar("i");
45          f.setItems("${[1]}");
46          
47          Script sc = new Script();
48          sc.setBody("acc = acc + i");
49          f.setActivity(sc);
50          
51          wf.getSequence().addActivity(f);
52          
53          Script end = new Script();
54          end.setBody("print (acc == 1)"); 
55          wf.getSequence().addActivity(end);
56          
57          return wf;
58      }
59  
60      /***
61       * @see org.astrogrid.jes.jobscheduler.impl.groovy.AbstractTestForFeature#verifyWorkflow(org.astrogrid.workflow.beans.v1.Workflow)
62       */
63      protected void verifyWorkflow(Workflow result) {
64          assertWorkflowCompleted(result);
65          Script body = (Script)((Parfor)result.getSequence().getActivity(1)).getActivity();
66          assertEquals(1,body.getStepExecutionRecordCount());
67          for (int i = 0; i < body.getStepExecutionRecordCount(); i++) {
68              StepExecutionRecord rec = body.getStepExecutionRecord(i);
69              assertEquals(ExecutionPhase.COMPLETED,rec.getStatus());
70              assertTrue(rec.getMessageCount() > 0);        
71          }
72          
73          Script end = (Script)result.getSequence().getActivity(2);
74          assertScriptCompletedWithMessage(end,"true");        
75      }        
76  
77  }
78  
79  
80  /* 
81  $Log: ParforSingletonFeatureTest.java,v $
82  Revision 1.2  2004/08/13 09:10:05  nw
83  tidied imports
84  
85  Revision 1.1  2004/08/09 17:34:10  nw
86  implemented parfor.
87  removed references to rulestore
88   
89  */