View Javadoc

1   /*
2    * $Id: GWES_StoreRestoreRestartTest.java 1537 2011-07-27 15:34:04Z hoheisel $
3    *
4    * Copyright (c) 2005-2006, The K-Wf Grid Consortium
5    * Fraunhofer Institute for Computer Architecture and Software Technology
6    * See http://www.kwfgrid.eu and http://www.first.fraunhofer.de for more details.
7    */
8   
9   package net.kwfgrid.gwes;
10  
11  import junit.framework.Assert;
12  import junit.framework.Test;
13  import junit.framework.TestSuite;
14  import net.kwfgrid.gwes.exception.*;
15  import net.kwfgrid.gworkflowdl.structure.WorkflowFormatException;
16  import org.apache.log4j.Logger;
17  import org.jaxen.JaxenException;
18  import org.jdom.JDOMException;
19  
20  import java.io.IOException;
21  
22  /**
23   * This test requires connection to the XML workflow database!
24   *
25   * <code>
26   * maven -Dtestcase=net.kwfgrid.gwes.GWES_StoreRestoreRestartTest test:single
27   * </code>
28   *
29   * @author Andreas Hoheisel
30   *         (<a href="http://www.andreas-hoheisel.de">www.andreas-hoheisel.de</a>)
31   * @version $Id: GWES_StoreRestoreRestartTest.java 1537 2011-07-27 15:34:04Z hoheisel $
32   */
33  public final class GWES_StoreRestoreRestartTest extends LocalGWESAbstractTestCase {
34  
35      /**
36       * log4j logger
37       */
38      static Logger logger = Logger.getLogger(GWES_StoreRestoreRestartTest.class);
39  
40      public final String userID;
41  
42      GWES gwes;
43  
44      String workflowID;
45  
46      /**
47       * Create the test case.
48       *
49       * @param testName name of the test case
50       */
51      public GWES_StoreRestoreRestartTest(String testName) throws LoggingException {
52          super(testName);
53          userID = System.getProperty("user.name");
54      }
55  
56      /**
57       * @return the suite of tests being tested
58       */
59      public static Test suite() {
60          return new TestSuite(GWES_StoreRestoreRestartTest.class);
61      }
62  
63      public void testStoreRestore() throws IOException, StateTransitionException, WorkflowFormatException, WorkflowSecurityException, NoSuchWorkflowException, InterruptedException, DatabaseException, JaxenException, JDOMException, LoggingException, GWESException {
64          gwes = new GWESEngine();
65          String fn = "examples/controlflow/gworkflowdl_breakpoint.xml";
66          workflowID = gwes.initiate(readfile(fn), userID);
67          logger.info("workflowID: " + workflowID);
68          gwes.start(workflowID, userID);
69          waitWorkflowStatus(gwes, workflowID);
70  
71          // now the workflow should suspend at the breakpoint
72          logger.info("Status: " + WorkflowStatus.getStatusAsString(gwes.getStatus(workflowID, userID)));
73  
74          // store and abort the workflow
75          String path = gwes.store(workflowID, userID);
76          logger.info("Workflow stored at "+path);
77          gwes.abort(workflowID, userID);
78  
79          // restore the workflow
80          String restoredWorkfow = gwes.restore(path, userID);
81          logger.info("Status of restored workflow: " + WorkflowStatus.getStatusAsString(gwes.getStatus(restoredWorkfow, userID)));
82          gwes.start(restoredWorkfow, userID);
83          waitWorkflowStatus(gwes, restoredWorkfow);
84  
85          // now the restored workflow should complete
86          logger.info("Status of restored workflow: " + WorkflowStatus.getStatusAsString(gwes.getStatus(restoredWorkfow, userID)));
87  
88          /* evaluate results */
89          Assert.assertEquals("Status of aborted workflow", WorkflowStatus.STATUS_TERMINATED, gwes.getStatus(workflowID, userID));
90          Assert.assertEquals("Status of restored workflow", WorkflowStatus.STATUS_COMPLETED, gwes.getStatus(restoredWorkfow, userID));
91  
92          String[] end = gwes.getData(restoredWorkfow, "end", userID);
93          logger.info("Token on end place\n" + end[0].trim());
94          Assert.assertEquals("Token on end place", "<control xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" xsi:type=\"xsd:boolean\">true</control>", end[0].trim());
95      }
96  
97      public void testAbortRestart() throws IOException, StateTransitionException, WorkflowFormatException, WorkflowSecurityException, NoSuchWorkflowException, InterruptedException, DatabaseException, JaxenException, JDOMException, LoggingException, GWESException {
98          gwes = new GWESEngine();
99          String fn = "examples/controlflow/gworkflowdl_breakpoint.xml";
100         workflowID = gwes.initiate(readfile(fn), userID);
101         logger.info("workflowID: " + workflowID);
102         gwes.start(workflowID, userID);
103         waitWorkflowStatus(gwes, workflowID);
104 
105         // now the workflow should suspend at the breakpoint
106         logger.info("Status: " + WorkflowStatus.getStatusAsString(gwes.getStatus(workflowID, userID)));
107 
108         // abort the workflow
109         gwes.abort(workflowID, userID);
110         logger.info("Status: " + WorkflowStatus.getStatusAsString(gwes.getStatus(workflowID, userID)));
111         Assert.assertEquals("Status of aborted workflow", WorkflowStatus.STATUS_TERMINATED, gwes.getStatus(workflowID, userID));
112 
113         // restart the workflow
114         String restartedWorkfow = gwes.restart(workflowID, userID);
115         gwes.start(restartedWorkfow, userID);
116         logger.info("Status of restarted workflow: " + WorkflowStatus.getStatusAsString(gwes.getStatus(restartedWorkfow, userID)));
117         waitWorkflowStatus(gwes, restartedWorkfow);
118 
119         // now the restarted workflow should reach the breakpoint and supend
120         logger.info("Status of restarted workflow: " + WorkflowStatus.getStatusAsString(gwes.getStatus(restartedWorkfow, userID)));
121         Assert.assertEquals("Status of restarted workflow", WorkflowStatus.STATUS_SUSPENDED, gwes.getStatus(restartedWorkfow, userID));
122         gwes.resume(restartedWorkfow, userID);
123         waitWorkflowStatus(gwes, restartedWorkfow);
124 
125         /* evaluate results */
126         Assert.assertEquals("Status of restarted workflow", WorkflowStatus.STATUS_COMPLETED, gwes.getStatus(restartedWorkfow, userID));
127 
128         String[] end = gwes.getData(restartedWorkfow, "end", userID);
129         logger.info("Token on end place\n" + end[0].trim());
130         Assert.assertEquals("Token on end place", "<control xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" xsi:type=\"xsd:boolean\">true</control>", end[0].trim());
131     }
132 
133 }