View Javadoc

1   /*
2    * $Id: XMLDBClientTest.java 1529 2011-06-22 16:37:19Z hoheisel $
3    *
4    * Copyright (c) 2005, 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.DatabaseException;
15  import net.kwfgrid.gwes.exception.LoggingException;
16  import net.kwfgrid.gwes.exception.NoSuchWorkflowException;
17  import net.kwfgrid.gworkflowdl.structure.*;
18  import org.apache.log4j.Logger;
19  import java.io.IOException;
20  import java.util.Properties;
21  import java.util.Map;
22  import java.util.Iterator;
23  
24  /**
25   * Invoke this test with maven using:
26   * <p>
27   * <code>
28   * maven -Dtestcase=net.kwfgrid.gwes.XMLDBClientTest test:single
29   * </code>
30   * @author Andreas Hoheisel
31   *         (<a href="http://www.andreas-hoheisel.de">www.andreas-hoheisel.de</a>)
32   * @version $Id: XMLDBClientTest.java 1529 2011-06-22 16:37:19Z hoheisel $
33   */
34  public final class XMLDBClientTest extends LocalGWESAbstractTestCase {
35  
36      /**
37       * log4j logger
38       */
39      static Logger logger = Logger.getLogger(XMLDBClientTest.class);
40  
41      /**
42       * Create the test case.
43       *
44       * @param testName name of the test case
45       */
46      public XMLDBClientTest(String testName) throws LoggingException {
47          super(testName);
48  
49          //read gwes.properties and set as system properties
50          Properties props = System.getProperties();
51          try {
52              props.load(getClass().getResourceAsStream("/gwes.properties"));
53              System.setProperties(props);
54          } catch (Exception e) {
55              logger.warn("Could not load gwes.properties:", e);
56          }
57  //        System.setProperty("workflow.repository.url", "http://localhost:8080/exist");
58  //        System.setProperty("workflow.repository.user", "admin");
59  //        System.setProperty("workflow.repository.password", "");
60  //        System.setProperty("resource.repository.dgrdl.collection", "/db/dgrdl");
61      }
62  
63      /**
64       * @return the suite of tests being tested
65       */
66      public static Test suite() {
67          return new TestSuite(XMLDBClientTest.class);
68      }
69  
70      /**
71       * Test
72       */
73      public void testWorkflowStatisticsQuery() throws DatabaseException {
74          XMLDB.getInstance().getWorkflowStatistics();
75      }
76  
77      /**
78       * Test
79       */
80      public void testStoreTemporaryWorkflowDirectory() throws DatabaseException, NoSuchWorkflowException {
81          XMLDB.getInstance().removeWorkflow("123");
82          XMLDB.getInstance().storeTemporaryWorkflowDirectory("hardware:test", "test", "tmpdir", "123", "123_005");
83          XMLDB.getInstance().storeTemporaryWorkflowDirectory("hardware:test2", "test2", "tmpdir2", "123", "123_006");
84          String[] res = XMLDB.getInstance().getTemporaryWorkflowDirectories("123");
85          XMLDB.getInstance().removeWorkflow("123");
86  
87          for (String re : res) {
88              logger.info(re);
89          }
90  
91          Assert.assertEquals("temporary workflow directory", res[res.length-1], "<resource uri=\"hardware:test2\"><directory>gsiftp://test2/tmpdir2</directory></resource>");
92      }
93  
94      public void testGetProperties() throws DatabaseException, NoSuchWorkflowException {
95          String[] workflowIDs = XMLDB.getInstance().getWorkflowIDs();
96          String[][] p = XMLDB.getInstance().getProperties(workflowIDs[0]);
97          for (int i=0; i<p.length; i++) {
98              logger.info(p[i][0]+"=\""+p[i][1]+"\"");
99          }
100     }
101 
102     public void testSetGetProperies() throws DatabaseException, NoSuchWorkflowException {
103         String[] workflowIDs = XMLDB.getInstance().getWorkflowIDs();
104         XMLDB.getInstance().setProperty(workflowIDs[0],"testname","testvalue");
105         String value = XMLDB.getInstance().getProperty(workflowIDs[0],"testname");
106         logger.info("value="+value);
107         Assert.assertEquals("Value", "testvalue", value);
108     }
109 
110     public void testGetStatus() throws DatabaseException, NoSuchWorkflowException {
111         String[] workflowIDs = XMLDB.getInstance().getWorkflowIDs();
112         int status = XMLDB.getInstance().getStatus(workflowIDs[0]);
113         logger.info("status "+status+" ("+ WorkflowStatus.getStatusAsString(status)+")");
114     }
115 
116     public void testGetData() throws DatabaseException, NoSuchWorkflowException, CapacityException, WorkflowFormatException, IOException {
117         String gworkflowdlPath = "examples/controlflow/gworkflowdl_duplicate.xml";
118         String placeID = "begin";
119         String workflowID = "test";
120 
121         configureFactory();
122 
123         Workflow workflow = Factory.newWorkflow(workflowID);
124         workflow.fromXML(readfile(gworkflowdlPath));
125         String document = XMLDB.getInstance().storeWorkflow(workflow);
126         logger.info(document);
127 
128         String[] data = XMLDB.getInstance().getData(workflowID,placeID);
129         for (String dat : data) {
130             logger.info(dat);
131         }
132     }
133 
134     public void testGetWorkflowStatusArray() throws DatabaseException {
135         Map statusmap = XMLDB.getInstance().getWorkflowStatusMap();
136         Iterator iter = statusmap.keySet().iterator();
137         while (iter.hasNext()) {
138             String workflowID = (String) iter.next();
139             logger.info(workflowID);
140         }
141     }
142 
143     public void testFailedTransitions() throws DatabaseException, NoSuchWorkflowException {
144         String[] statistics = XMLDB.getInstance().getFaultToleranceStatistics();
145         int count = 0;
146         int noFailure = 0;
147         int successfull = 0;
148         int errorWithoutDoF = 0;
149         int errorWithDoF = 0;
150         int rest;
151         for (String line:statistics) {
152         	//number of all workflows
153         	count++;
154         	//number of workflows, which failed and completed because of DoF
155         	if (line.contains("COMPLETED") && (!(line.contains("<failedTransitions>0")))) successfull++;
156         	//perfect Workflows with no faults
157         	if (line.contains("COMPLETED") && (line.contains("<failedTransitions>0"))) noFailure++;
158         	//failed workflows, although there has been DoF
159         	if (line.contains("TERMINATED") && (!(line.contains("<failedTransitions>0")))) errorWithDoF++;
160         	//failed workflows, but there has been no DoF (property set to false)
161         	if (line.contains("TERMINATED") && (line.contains("<failedTransitions>0"))) errorWithoutDoF++;
162         	logger.info(line);
163         }
164         logger.info("Total number of Workflows " + count + ".");
165         logger.info("Total number of completed Workflows because of DoF " + successfull + ".");
166         logger.info("Total number of failed Workflows with DoF " + errorWithDoF + ".");
167         logger.info("Total number of failed Workflows without DoF " + errorWithoutDoF + ".");
168         logger.info("Total number of failure-free workflows " + noFailure + ".");
169         rest=count-(noFailure+successfull+errorWithDoF+errorWithoutDoF);
170         logger.info("The rest are " + rest + " workflows.");
171     }
172 
173 }