1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 __authors__ = ["Jérôme Kieffer", "Olof Svensson"]
30 __contact__ = "Jerome.Kieffer@esrf.eu"
31 __license__ = "LGPLv3+"
32 __copyright__ = "European Synchrotron Radiation Facility, Grenoble, France"
33
34 """This is the EDJob interface for launching jobs"""
35
36 import time
37 from EDVerbose import EDVerbose
38 from EDTestCase import EDTestCase
39 from EDAssert import EDAssert
40 from EDJob import EDJob
41
42
43
45 """
46 Unit & execution test for the EDParallelExecute class
47 """
48 strPluginName = "EDPluginTestPluginFactory"
49 strXmlInput = """<?xml version="1.0" ?>
50 <XSDataString>
51 <value>Test string value.</value>
52 </XSDataString>"""
55
56
57
59 """
60 check the status after a job creation
61 """
62 EDVerbose.DEBUG("EDTestCaseEDJob.unitTestInitialState")
63 edJob = EDJob(self.strPluginName)
64 strJobId = edJob.getJobId()
65 EDVerbose.DEBUG("EDJobId is: %s" % strJobId)
66 EDAssert.equal(2, len(strJobId.split("-")), "JobID is composed of 2 parts")
67 EDAssert.equal(True, strJobId.split("-")[1].isdigit(), "JobID's second part is an integer")
68 EDAssert.equal("uninitialized", edJob.getStatus(), "Initial stat is ''uninitialized''")
69
70
80
82 """
83 check the execution of a job (without callback)
84 """
85 EDVerbose.DEBUG("EDTestCaseEDJob.unitTestExecute")
86 edJob = EDJob(self.strPluginName)
87 strJobId = edJob.getJobId()
88 edJob.setDataInput(self.strXmlInput)
89 ref = edJob.execute()
90 EDAssert.equal(strJobId, ref, "JobId has not changed")
91 strStatus = edJob.getStatus()
92 EDVerbose.WARNING("Job %s in State %s" % (strJobId, strStatus))
93
94 while strStatus in ["running", "uninitialized"]:
95 EDVerbose.WARNING("Job %s in state %s" % (strJobId, strStatus))
96 time.sleep(0.01)
97 strStatus = edJob.getStatus()
98
99 xsdOut = edJob.getDataOutput()
100 while xsdOut is None:
101 EDVerbose.WARNING("No Output data, still waiting for output data to arrive, %s" % edJob.getStatus())
102 time.sleep(0.01)
103 xsdOut = edJob.getDataOutput()
104 strOutput = xsdOut.strip()
105 strStatus = edJob.getStatus()
106 while strStatus == "running":
107 EDVerbose.WARNING("Job %s is still in state %s" % (strJobId, strStatus))
108 time.sleep(0.01)
109 strStatus = edJob.getStatus()
110
111 EDAssert.equal(strOutput, self.strXmlInput, "Output is OK")
112 EDAssert.equal("success", edJob.getStatus(), "Job %s is finished with ''success''" % edJob.getJobId())
113
114
116 """
117 Example of Call Back function ...
118 """
119 myJob = EDJob.getJobFromID(_strJobId)
120 strOutput = myJob.getDataOutput().strip()
121 EDAssert.equal(strOutput, self.strXmlInput, "From Callback: Output is OK")
122 EDAssert.equal("success", myJob.getStatus(), "From Callback: Job %s is finished with ''success''" % _strJobId)
123
124
136
148
149
156
157
158 if __name__ == '__main__':
159
160 edTestCaseEDJob = EDTestCaseEDJob("EDTestCaseEDJob")
161 edTestCaseEDJob.execute()
162