1
2
3
4
5
6
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
26
27
28
29
30
31
32
33
34 public final class XMLDBClientTest extends LocalGWESAbstractTestCase {
35
36
37
38
39 static Logger logger = Logger.getLogger(XMLDBClientTest.class);
40
41
42
43
44
45
46 public XMLDBClientTest(String testName) throws LoggingException {
47 super(testName);
48
49
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
58
59
60
61 }
62
63
64
65
66 public static Test suite() {
67 return new TestSuite(XMLDBClientTest.class);
68 }
69
70
71
72
73 public void testWorkflowStatisticsQuery() throws DatabaseException {
74 XMLDB.getInstance().getWorkflowStatistics();
75 }
76
77
78
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
153 count++;
154
155 if (line.contains("COMPLETED") && (!(line.contains("<failedTransitions>0")))) successfull++;
156
157 if (line.contains("COMPLETED") && (line.contains("<failedTransitions>0"))) noFailure++;
158
159 if (line.contains("TERMINATED") && (!(line.contains("<failedTransitions>0")))) errorWithDoF++;
160
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 }