Mercurial > hg > orthanc
annotate UnitTestsSources/MultiThreadingTests.cpp @ 2604:76ef12fa136c jobs
fix race conditions if creating Lua jobs
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 18 May 2018 17:37:14 +0200 |
parents | 988936118354 |
children | f2b9d3256060 |
rev | line source |
---|---|
827
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
776
diff
changeset
|
1 /** |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
776
diff
changeset
|
2 * Orthanc - A Lightweight, RESTful DICOM Store |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1009
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
2447
878b59270859
upgrade to year 2018
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2382
diff
changeset
|
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium |
827
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
776
diff
changeset
|
6 * |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
776
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
776
diff
changeset
|
8 * modify it under the terms of the GNU General Public License as |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
776
diff
changeset
|
9 * published by the Free Software Foundation, either version 3 of the |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
776
diff
changeset
|
10 * License, or (at your option) any later version. |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
776
diff
changeset
|
11 * |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
776
diff
changeset
|
12 * In addition, as a special exception, the copyright holders of this |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
776
diff
changeset
|
13 * program give permission to link the code of its release with the |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
776
diff
changeset
|
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
776
diff
changeset
|
15 * that use the same license as the "OpenSSL" library), and distribute |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
776
diff
changeset
|
16 * the linked executables. You must obey the GNU General Public License |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
776
diff
changeset
|
17 * in all respects for all of the code used other than "OpenSSL". If you |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
776
diff
changeset
|
18 * modify file(s) with this exception, you may extend this exception to |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
776
diff
changeset
|
19 * your version of the file(s), but you are not obligated to do so. If |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
776
diff
changeset
|
20 * you do not wish to do so, delete this exception statement from your |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
776
diff
changeset
|
21 * version. If you delete this exception statement from all source files |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
776
diff
changeset
|
22 * in the program, then also delete it here. |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
776
diff
changeset
|
23 * |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
776
diff
changeset
|
24 * This program is distributed in the hope that it will be useful, but |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
776
diff
changeset
|
25 * WITHOUT ANY WARRANTY; without even the implied warranty of |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
776
diff
changeset
|
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
776
diff
changeset
|
27 * General Public License for more details. |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
776
diff
changeset
|
28 * |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
776
diff
changeset
|
29 * You should have received a copy of the GNU General Public License |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
776
diff
changeset
|
30 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
776
diff
changeset
|
31 **/ |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
776
diff
changeset
|
32 |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
776
diff
changeset
|
33 |
831
84513f2ee1f3
pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
827
diff
changeset
|
34 #include "PrecompiledHeadersUnitTests.h" |
723 | 35 #include "gtest/gtest.h" |
36 | |
2569 | 37 #include "../Core/JobsEngine/JobsEngine.h" |
38 #include "../Core/MultiThreading/Locker.h" | |
723 | 39 #include "../Core/OrthancException.h" |
2143
fd5875662670
creation of namespace SystemToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2140
diff
changeset
|
40 #include "../Core/SystemToolbox.h" |
723 | 41 #include "../Core/Toolbox.h" |
2569 | 42 #include "../OrthancServer/Scheduler/ServerScheduler.h" |
723 | 43 |
44 using namespace Orthanc; | |
45 | |
46 namespace | |
47 { | |
1396
ac4efabeb80c
Migration of the orthanc-client as a separate project
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1304
diff
changeset
|
48 class DynamicInteger : public IDynamicObject |
723 | 49 { |
50 private: | |
51 int value_; | |
52 std::set<int>& target_; | |
53 | |
54 public: | |
55 DynamicInteger(int value, std::set<int>& target) : | |
56 value_(value), target_(target) | |
57 { | |
58 } | |
59 | |
60 int GetValue() const | |
61 { | |
62 return value_; | |
63 } | |
64 }; | |
65 } | |
66 | |
67 | |
68 TEST(MultiThreading, SharedMessageQueueBasic) | |
69 { | |
70 std::set<int> s; | |
71 | |
72 SharedMessageQueue q; | |
73 ASSERT_TRUE(q.WaitEmpty(0)); | |
74 q.Enqueue(new DynamicInteger(10, s)); | |
75 ASSERT_FALSE(q.WaitEmpty(1)); | |
76 q.Enqueue(new DynamicInteger(20, s)); | |
77 q.Enqueue(new DynamicInteger(30, s)); | |
78 q.Enqueue(new DynamicInteger(40, s)); | |
79 | |
80 std::auto_ptr<DynamicInteger> i; | |
81 i.reset(dynamic_cast<DynamicInteger*>(q.Dequeue(1))); ASSERT_EQ(10, i->GetValue()); | |
82 i.reset(dynamic_cast<DynamicInteger*>(q.Dequeue(1))); ASSERT_EQ(20, i->GetValue()); | |
83 i.reset(dynamic_cast<DynamicInteger*>(q.Dequeue(1))); ASSERT_EQ(30, i->GetValue()); | |
84 ASSERT_FALSE(q.WaitEmpty(1)); | |
85 i.reset(dynamic_cast<DynamicInteger*>(q.Dequeue(1))); ASSERT_EQ(40, i->GetValue()); | |
86 ASSERT_TRUE(q.WaitEmpty(0)); | |
87 ASSERT_EQ(NULL, q.Dequeue(1)); | |
88 } | |
89 | |
90 | |
91 TEST(MultiThreading, SharedMessageQueueClean) | |
92 { | |
93 std::set<int> s; | |
94 | |
95 try | |
96 { | |
97 SharedMessageQueue q; | |
98 q.Enqueue(new DynamicInteger(10, s)); | |
99 q.Enqueue(new DynamicInteger(20, s)); | |
1583
9ea3d082b064
got rid of custom exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1582
diff
changeset
|
100 throw OrthancException(ErrorCode_InternalError); |
723 | 101 } |
102 catch (OrthancException&) | |
103 { | |
104 } | |
105 } | |
106 | |
107 | |
769
3f946e5c3802
ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
760
diff
changeset
|
108 |
3f946e5c3802
ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
760
diff
changeset
|
109 |
2382
7284093111b0
big reorganization to cleanly separate framework vs. server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
110 #include "../Core/DicomNetworking/ReusableDicomUserConnection.h" |
769
3f946e5c3802
ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
760
diff
changeset
|
111 |
3f946e5c3802
ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
760
diff
changeset
|
112 TEST(ReusableDicomUserConnection, DISABLED_Basic) |
3f946e5c3802
ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
760
diff
changeset
|
113 { |
3f946e5c3802
ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
760
diff
changeset
|
114 ReusableDicomUserConnection c; |
3f946e5c3802
ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
760
diff
changeset
|
115 c.SetMillisecondsBeforeClose(200); |
3f946e5c3802
ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
760
diff
changeset
|
116 printf("START\n"); fflush(stdout); |
775
d3ba35466225
integration mainline -> lua-scripting
Sebastien Jodogne <s.jodogne@gmail.com>
diff
changeset
|
117 |
769
3f946e5c3802
ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
760
diff
changeset
|
118 { |
1427
d710ea64f0fd
Custom setting of the local AET during C-Store SCU (both in Lua and in the REST API)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1396
diff
changeset
|
119 RemoteModalityParameters remote("STORESCP", "localhost", 2000, ModalityManufacturer_Generic); |
d710ea64f0fd
Custom setting of the local AET during C-Store SCU (both in Lua and in the REST API)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1396
diff
changeset
|
120 ReusableDicomUserConnection::Locker lock(c, "ORTHANC", remote); |
2222
21713ce8717b
Fix handling of Move Originator AET and ID in C-MOVE SCP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2143
diff
changeset
|
121 lock.GetConnection().StoreFile("/home/jodogne/DICOM/Cardiac/MR.X.1.2.276.0.7230010.3.1.4.2831157719.2256.1336386844.676281"); |
769
3f946e5c3802
ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
760
diff
changeset
|
122 } |
3f946e5c3802
ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
760
diff
changeset
|
123 |
3f946e5c3802
ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
760
diff
changeset
|
124 printf("**\n"); fflush(stdout); |
2242
4e8e0ad2001c
move USleep() in SystemToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2222
diff
changeset
|
125 SystemToolbox::USleep(1000000); |
769
3f946e5c3802
ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
760
diff
changeset
|
126 printf("**\n"); fflush(stdout); |
3f946e5c3802
ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
760
diff
changeset
|
127 |
3f946e5c3802
ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
760
diff
changeset
|
128 { |
1427
d710ea64f0fd
Custom setting of the local AET during C-Store SCU (both in Lua and in the REST API)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1396
diff
changeset
|
129 RemoteModalityParameters remote("STORESCP", "localhost", 2000, ModalityManufacturer_Generic); |
d710ea64f0fd
Custom setting of the local AET during C-Store SCU (both in Lua and in the REST API)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1396
diff
changeset
|
130 ReusableDicomUserConnection::Locker lock(c, "ORTHANC", remote); |
2222
21713ce8717b
Fix handling of Move Originator AET and ID in C-MOVE SCP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2143
diff
changeset
|
131 lock.GetConnection().StoreFile("/home/jodogne/DICOM/Cardiac/MR.X.1.2.276.0.7230010.3.1.4.2831157719.2256.1336386844.676277"); |
769
3f946e5c3802
ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
760
diff
changeset
|
132 } |
3f946e5c3802
ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
760
diff
changeset
|
133 |
2140 | 134 SystemToolbox::ServerBarrier(); |
769
3f946e5c3802
ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
760
diff
changeset
|
135 printf("DONE\n"); fflush(stdout); |
3f946e5c3802
ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
760
diff
changeset
|
136 } |
765 | 137 |
138 | |
139 | |
1000
13e230bbd882
rename filter to command
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
995
diff
changeset
|
140 class Tutu : public IServerCommand |
765 | 141 { |
142 private: | |
143 int factor_; | |
144 | |
145 public: | |
146 Tutu(int f) : factor_(f) | |
147 { | |
148 } | |
149 | |
150 virtual bool Apply(ListOfStrings& outputs, | |
151 const ListOfStrings& inputs) | |
152 { | |
153 for (ListOfStrings::const_iterator | |
1304 | 154 it = inputs.begin(); it != inputs.end(); ++it) |
765 | 155 { |
156 int a = boost::lexical_cast<int>(*it); | |
157 int b = factor_ * a; | |
158 | |
159 printf("%d * %d = %d\n", a, factor_, b); | |
160 | |
161 //if (a == 84) { printf("BREAK\n"); return false; } | |
162 | |
163 outputs.push_back(boost::lexical_cast<std::string>(b)); | |
164 } | |
165 | |
2242
4e8e0ad2001c
move USleep() in SystemToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2222
diff
changeset
|
166 SystemToolbox::USleep(30000); |
765 | 167 |
168 return true; | |
169 } | |
170 }; | |
171 | |
768 | 172 |
770 | 173 static void Tata(ServerScheduler* s, ServerJob* j, bool* done) |
768 | 174 { |
1000
13e230bbd882
rename filter to command
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
995
diff
changeset
|
175 typedef IServerCommand::ListOfStrings ListOfStrings; |
779 | 176 |
770 | 177 while (!(*done)) |
768 | 178 { |
179 ListOfStrings l; | |
180 s->GetListOfJobs(l); | |
1304 | 181 for (ListOfStrings::iterator it = l.begin(); it != l.end(); ++it) |
182 { | |
183 printf(">> %s: %0.1f\n", it->c_str(), 100.0f * s->GetProgress(*it)); | |
184 } | |
2242
4e8e0ad2001c
move USleep() in SystemToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2222
diff
changeset
|
185 SystemToolbox::USleep(3000); |
768 | 186 } |
187 } | |
188 | |
189 | |
1009
26642cecd36d
clearer job interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1005
diff
changeset
|
190 TEST(MultiThreading, ServerScheduler) |
765 | 191 { |
995
8c67382f44a7
limit number of jobs in the scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
994
diff
changeset
|
192 ServerScheduler scheduler(10); |
765 | 193 |
194 ServerJob job; | |
1000
13e230bbd882
rename filter to command
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
995
diff
changeset
|
195 ServerCommandInstance& f2 = job.AddCommand(new Tutu(2)); |
13e230bbd882
rename filter to command
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
995
diff
changeset
|
196 ServerCommandInstance& f3 = job.AddCommand(new Tutu(3)); |
13e230bbd882
rename filter to command
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
995
diff
changeset
|
197 ServerCommandInstance& f4 = job.AddCommand(new Tutu(4)); |
13e230bbd882
rename filter to command
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
995
diff
changeset
|
198 ServerCommandInstance& f5 = job.AddCommand(new Tutu(5)); |
765 | 199 f2.AddInput(boost::lexical_cast<std::string>(42)); |
200 //f3.AddInput(boost::lexical_cast<std::string>(42)); | |
201 //f4.AddInput(boost::lexical_cast<std::string>(42)); | |
1009
26642cecd36d
clearer job interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1005
diff
changeset
|
202 f2.ConnectOutput(f3); |
26642cecd36d
clearer job interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1005
diff
changeset
|
203 f3.ConnectOutput(f4); |
26642cecd36d
clearer job interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1005
diff
changeset
|
204 f4.ConnectOutput(f5); |
26642cecd36d
clearer job interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1005
diff
changeset
|
205 |
26642cecd36d
clearer job interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1005
diff
changeset
|
206 f3.SetConnectedToSink(true); |
26642cecd36d
clearer job interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1005
diff
changeset
|
207 f5.SetConnectedToSink(true); |
765 | 208 |
209 job.SetDescription("tutu"); | |
210 | |
770 | 211 bool done = false; |
212 boost::thread t(Tata, &scheduler, &job, &done); | |
768 | 213 |
214 | |
765 | 215 //scheduler.Submit(job); |
216 | |
1000
13e230bbd882
rename filter to command
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
995
diff
changeset
|
217 IServerCommand::ListOfStrings l; |
765 | 218 scheduler.SubmitAndWait(l, job); |
219 | |
1492 | 220 ASSERT_EQ(2u, l.size()); |
1009
26642cecd36d
clearer job interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1005
diff
changeset
|
221 ASSERT_EQ(42 * 2 * 3, boost::lexical_cast<int>(l.front())); |
26642cecd36d
clearer job interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1005
diff
changeset
|
222 ASSERT_EQ(42 * 2 * 3 * 4 * 5, boost::lexical_cast<int>(l.back())); |
26642cecd36d
clearer job interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1005
diff
changeset
|
223 |
1000
13e230bbd882
rename filter to command
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
995
diff
changeset
|
224 for (IServerCommand::ListOfStrings::iterator i = l.begin(); i != l.end(); i++) |
765 | 225 { |
226 printf("** %s\n", i->c_str()); | |
227 } | |
228 | |
2140 | 229 //SystemToolbox::ServerBarrier(); |
2242
4e8e0ad2001c
move USleep() in SystemToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2222
diff
changeset
|
230 //SystemToolbox::USleep(3000000); |
768 | 231 |
1453
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1427
diff
changeset
|
232 scheduler.Stop(); |
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1427
diff
changeset
|
233 |
770 | 234 done = true; |
1453
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1427
diff
changeset
|
235 if (t.joinable()) |
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1427
diff
changeset
|
236 { |
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1427
diff
changeset
|
237 t.join(); |
c0bdc47165ef
code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1427
diff
changeset
|
238 } |
765 | 239 } |
2556 | 240 |
241 | |
242 | |
2557 | 243 class DummyJob : public Orthanc::IJob |
244 { | |
245 private: | |
2598
34dc57f4a7d2
simplification of JobStepResult
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2589
diff
changeset
|
246 bool fails_; |
2565 | 247 unsigned int count_; |
248 unsigned int steps_; | |
2557 | 249 |
250 public: | |
251 DummyJob() : | |
2598
34dc57f4a7d2
simplification of JobStepResult
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2589
diff
changeset
|
252 fails_(false), |
2565 | 253 count_(0), |
254 steps_(4) | |
2557 | 255 { |
256 } | |
257 | |
2598
34dc57f4a7d2
simplification of JobStepResult
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2589
diff
changeset
|
258 explicit DummyJob(bool fails) : |
34dc57f4a7d2
simplification of JobStepResult
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2589
diff
changeset
|
259 fails_(fails), |
2565 | 260 count_(0), |
261 steps_(4) | |
2557 | 262 { |
263 } | |
264 | |
2570
2e879c796ec7
JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
265 virtual void Start() |
2e879c796ec7
JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
266 { |
2e879c796ec7
JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
267 } |
2583
1b6a6d80b6f2
OrthancPeerStoreJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2581
diff
changeset
|
268 |
1b6a6d80b6f2
OrthancPeerStoreJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2581
diff
changeset
|
269 virtual void SignalResubmit() |
1b6a6d80b6f2
OrthancPeerStoreJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2581
diff
changeset
|
270 { |
1b6a6d80b6f2
OrthancPeerStoreJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2581
diff
changeset
|
271 } |
2570
2e879c796ec7
JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
272 |
2598
34dc57f4a7d2
simplification of JobStepResult
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2589
diff
changeset
|
273 virtual JobStepResult ExecuteStep() |
2557 | 274 { |
2598
34dc57f4a7d2
simplification of JobStepResult
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2589
diff
changeset
|
275 if (fails_) |
2565 | 276 { |
2598
34dc57f4a7d2
simplification of JobStepResult
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2589
diff
changeset
|
277 return JobStepResult::Failure(ErrorCode_ParameterOutOfRange); |
34dc57f4a7d2
simplification of JobStepResult
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2589
diff
changeset
|
278 } |
34dc57f4a7d2
simplification of JobStepResult
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2589
diff
changeset
|
279 else if (count_ == steps_ - 1) |
34dc57f4a7d2
simplification of JobStepResult
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2589
diff
changeset
|
280 { |
34dc57f4a7d2
simplification of JobStepResult
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2589
diff
changeset
|
281 return JobStepResult::Success(); |
2565 | 282 } |
283 else | |
284 { | |
285 count_++; | |
2598
34dc57f4a7d2
simplification of JobStepResult
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2589
diff
changeset
|
286 return JobStepResult::Continue(); |
2565 | 287 } |
2557 | 288 } |
289 | |
290 virtual void ReleaseResources() | |
291 { | |
292 } | |
293 | |
294 virtual float GetProgress() | |
295 { | |
2565 | 296 return static_cast<float>(count_) / static_cast<float>(steps_ - 1); |
2557 | 297 } |
298 | |
2580
055d7d4a823f
avoid unecessary openings of DICOM connection for C-Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
299 virtual void GetJobType(std::string& type) |
055d7d4a823f
avoid unecessary openings of DICOM connection for C-Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
300 { |
055d7d4a823f
avoid unecessary openings of DICOM connection for C-Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
301 type = "DummyJob"; |
055d7d4a823f
avoid unecessary openings of DICOM connection for C-Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
302 } |
055d7d4a823f
avoid unecessary openings of DICOM connection for C-Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
303 |
055d7d4a823f
avoid unecessary openings of DICOM connection for C-Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
304 virtual void GetInternalContent(Json::Value& value) |
055d7d4a823f
avoid unecessary openings of DICOM connection for C-Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
305 { |
055d7d4a823f
avoid unecessary openings of DICOM connection for C-Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
306 } |
055d7d4a823f
avoid unecessary openings of DICOM connection for C-Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
307 |
055d7d4a823f
avoid unecessary openings of DICOM connection for C-Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
308 virtual void GetPublicContent(Json::Value& value) |
2557 | 309 { |
2565 | 310 value["hello"] = "world"; |
2557 | 311 } |
312 }; | |
313 | |
314 | |
2558 | 315 static bool CheckState(Orthanc::JobsRegistry& registry, |
2557 | 316 const std::string& id, |
317 Orthanc::JobState state) | |
318 { | |
319 Orthanc::JobState s; | |
2558 | 320 if (registry.GetState(s, id)) |
2557 | 321 { |
322 return state == s; | |
323 } | |
324 else | |
325 { | |
326 return false; | |
327 } | |
328 } | |
329 | |
330 | |
2581
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
331 static bool CheckErrorCode(Orthanc::JobsRegistry& registry, |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
332 const std::string& id, |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
333 Orthanc::ErrorCode code) |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
334 { |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
335 Orthanc::JobInfo s; |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
336 if (registry.GetJobInfo(s, id)) |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
337 { |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
338 return code == s.GetStatus().GetErrorCode(); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
339 } |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
340 else |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
341 { |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
342 return false; |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
343 } |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
344 } |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
345 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
346 |
2558 | 347 TEST(JobsRegistry, Priority) |
2557 | 348 { |
2558 | 349 JobsRegistry registry; |
2557 | 350 |
351 std::string i1, i2, i3, i4; | |
2558 | 352 registry.Submit(i1, new DummyJob(), 10); |
353 registry.Submit(i2, new DummyJob(), 30); | |
354 registry.Submit(i3, new DummyJob(), 20); | |
355 registry.Submit(i4, new DummyJob(), 5); | |
2557 | 356 |
2558 | 357 registry.SetMaxCompletedJobs(2); |
2557 | 358 |
359 std::set<std::string> id; | |
2558 | 360 registry.ListJobs(id); |
2557 | 361 |
362 ASSERT_EQ(4u, id.size()); | |
363 ASSERT_TRUE(id.find(i1) != id.end()); | |
364 ASSERT_TRUE(id.find(i2) != id.end()); | |
365 ASSERT_TRUE(id.find(i3) != id.end()); | |
366 ASSERT_TRUE(id.find(i4) != id.end()); | |
367 | |
2558 | 368 ASSERT_TRUE(CheckState(registry, i2, Orthanc::JobState_Pending)); |
2557 | 369 |
370 { | |
2558 | 371 JobsRegistry::RunningJob job(registry, 0); |
2557 | 372 ASSERT_TRUE(job.IsValid()); |
373 ASSERT_EQ(30, job.GetPriority()); | |
374 ASSERT_EQ(i2, job.GetId()); | |
375 | |
2558 | 376 ASSERT_TRUE(CheckState(registry, i2, Orthanc::JobState_Running)); |
2557 | 377 } |
378 | |
2558 | 379 ASSERT_TRUE(CheckState(registry, i2, Orthanc::JobState_Failure)); |
380 ASSERT_TRUE(CheckState(registry, i3, Orthanc::JobState_Pending)); | |
2557 | 381 |
382 { | |
2558 | 383 JobsRegistry::RunningJob job(registry, 0); |
2557 | 384 ASSERT_TRUE(job.IsValid()); |
385 ASSERT_EQ(20, job.GetPriority()); | |
386 ASSERT_EQ(i3, job.GetId()); | |
387 | |
388 job.MarkSuccess(); | |
389 | |
2558 | 390 ASSERT_TRUE(CheckState(registry, i3, Orthanc::JobState_Running)); |
2557 | 391 } |
392 | |
2558 | 393 ASSERT_TRUE(CheckState(registry, i3, Orthanc::JobState_Success)); |
2557 | 394 |
395 { | |
2558 | 396 JobsRegistry::RunningJob job(registry, 0); |
2557 | 397 ASSERT_TRUE(job.IsValid()); |
398 ASSERT_EQ(10, job.GetPriority()); | |
399 ASSERT_EQ(i1, job.GetId()); | |
400 } | |
401 | |
402 { | |
2558 | 403 JobsRegistry::RunningJob job(registry, 0); |
2557 | 404 ASSERT_TRUE(job.IsValid()); |
405 ASSERT_EQ(5, job.GetPriority()); | |
406 ASSERT_EQ(i4, job.GetId()); | |
407 } | |
408 | |
409 { | |
2558 | 410 JobsRegistry::RunningJob job(registry, 1); |
2557 | 411 ASSERT_FALSE(job.IsValid()); |
412 } | |
413 | |
414 Orthanc::JobState s; | |
2558 | 415 ASSERT_TRUE(registry.GetState(s, i1)); |
416 ASSERT_FALSE(registry.GetState(s, i2)); // Removed because oldest | |
417 ASSERT_FALSE(registry.GetState(s, i3)); // Removed because second oldest | |
418 ASSERT_TRUE(registry.GetState(s, i4)); | |
2557 | 419 |
2558 | 420 registry.SetMaxCompletedJobs(1); // (*) |
421 ASSERT_FALSE(registry.GetState(s, i1)); // Just discarded by (*) | |
422 ASSERT_TRUE(registry.GetState(s, i4)); | |
2557 | 423 } |
424 | |
425 | |
2558 | 426 TEST(JobsRegistry, Simultaneous) |
2557 | 427 { |
2558 | 428 JobsRegistry registry; |
429 | |
430 std::string i1, i2; | |
431 registry.Submit(i1, new DummyJob(), 20); | |
432 registry.Submit(i2, new DummyJob(), 10); | |
433 | |
434 ASSERT_TRUE(CheckState(registry, i1, Orthanc::JobState_Pending)); | |
435 ASSERT_TRUE(CheckState(registry, i2, Orthanc::JobState_Pending)); | |
436 | |
437 { | |
438 JobsRegistry::RunningJob job1(registry, 0); | |
439 JobsRegistry::RunningJob job2(registry, 0); | |
440 | |
441 ASSERT_TRUE(job1.IsValid()); | |
442 ASSERT_TRUE(job2.IsValid()); | |
443 | |
444 job1.MarkFailure(); | |
445 job2.MarkSuccess(); | |
446 | |
447 ASSERT_TRUE(CheckState(registry, i1, Orthanc::JobState_Running)); | |
448 ASSERT_TRUE(CheckState(registry, i2, Orthanc::JobState_Running)); | |
449 } | |
450 | |
451 ASSERT_TRUE(CheckState(registry, i1, Orthanc::JobState_Failure)); | |
452 ASSERT_TRUE(CheckState(registry, i2, Orthanc::JobState_Success)); | |
453 } | |
454 | |
455 | |
456 TEST(JobsRegistry, Resubmit) | |
457 { | |
458 JobsRegistry registry; | |
2557 | 459 |
460 std::string id; | |
2558 | 461 registry.Submit(id, new DummyJob(), 10); |
2557 | 462 |
2558 | 463 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending)); |
2557 | 464 |
2558 | 465 registry.Resubmit(id); |
466 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending)); | |
2557 | 467 |
468 { | |
2558 | 469 JobsRegistry::RunningJob job(registry, 0); |
2557 | 470 ASSERT_TRUE(job.IsValid()); |
471 job.MarkFailure(); | |
472 | |
2558 | 473 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Running)); |
2557 | 474 |
2558 | 475 registry.Resubmit(id); |
476 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Running)); | |
2557 | 477 } |
478 | |
2558 | 479 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Failure)); |
2557 | 480 |
2558 | 481 registry.Resubmit(id); |
482 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending)); | |
2557 | 483 |
484 { | |
2558 | 485 JobsRegistry::RunningJob job(registry, 0); |
2557 | 486 ASSERT_TRUE(job.IsValid()); |
487 ASSERT_EQ(id, job.GetId()); | |
488 | |
489 job.MarkSuccess(); | |
2558 | 490 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Running)); |
491 } | |
492 | |
493 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Success)); | |
494 | |
495 registry.Resubmit(id); | |
496 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Success)); | |
497 } | |
498 | |
499 | |
500 TEST(JobsRegistry, Retry) | |
501 { | |
502 JobsRegistry registry; | |
503 | |
504 std::string id; | |
505 registry.Submit(id, new DummyJob(), 10); | |
506 | |
507 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending)); | |
508 | |
509 { | |
510 JobsRegistry::RunningJob job(registry, 0); | |
511 ASSERT_TRUE(job.IsValid()); | |
512 job.MarkRetry(0); | |
513 | |
514 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Running)); | |
515 } | |
516 | |
517 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Retry)); | |
518 | |
519 registry.Resubmit(id); | |
520 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Retry)); | |
521 | |
522 registry.ScheduleRetries(); | |
523 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending)); | |
524 | |
525 { | |
526 JobsRegistry::RunningJob job(registry, 0); | |
527 ASSERT_TRUE(job.IsValid()); | |
528 job.MarkSuccess(); | |
529 | |
530 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Running)); | |
2557 | 531 } |
532 | |
2558 | 533 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Success)); |
534 } | |
535 | |
536 | |
537 TEST(JobsRegistry, PausePending) | |
538 { | |
539 JobsRegistry registry; | |
540 | |
541 std::string id; | |
542 registry.Submit(id, new DummyJob(), 10); | |
543 | |
544 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending)); | |
545 | |
546 registry.Pause(id); | |
547 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Paused)); | |
548 | |
549 registry.Pause(id); | |
550 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Paused)); | |
551 | |
552 registry.Resubmit(id); | |
553 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Paused)); | |
554 | |
555 registry.Resume(id); | |
556 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending)); | |
2557 | 557 } |
2558 | 558 |
559 | |
560 TEST(JobsRegistry, PauseRunning) | |
561 { | |
562 JobsRegistry registry; | |
563 | |
564 std::string id; | |
565 registry.Submit(id, new DummyJob(), 10); | |
566 | |
567 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending)); | |
568 | |
569 { | |
570 JobsRegistry::RunningJob job(registry, 0); | |
571 ASSERT_TRUE(job.IsValid()); | |
572 | |
573 registry.Resubmit(id); | |
2562 | 574 job.MarkPause(); |
2558 | 575 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Running)); |
576 } | |
577 | |
578 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Paused)); | |
579 | |
580 registry.Resubmit(id); | |
581 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Paused)); | |
582 | |
583 registry.Resume(id); | |
584 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending)); | |
585 | |
586 { | |
587 JobsRegistry::RunningJob job(registry, 0); | |
588 ASSERT_TRUE(job.IsValid()); | |
589 | |
590 job.MarkSuccess(); | |
591 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Running)); | |
592 } | |
593 | |
594 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Success)); | |
595 } | |
596 | |
597 | |
598 TEST(JobsRegistry, PauseRetry) | |
599 { | |
600 JobsRegistry registry; | |
601 | |
602 std::string id; | |
603 registry.Submit(id, new DummyJob(), 10); | |
604 | |
605 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending)); | |
606 | |
607 { | |
608 JobsRegistry::RunningJob job(registry, 0); | |
609 ASSERT_TRUE(job.IsValid()); | |
610 | |
611 job.MarkRetry(0); | |
612 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Running)); | |
613 } | |
614 | |
615 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Retry)); | |
616 | |
617 registry.Pause(id); | |
618 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Paused)); | |
619 | |
620 registry.Resume(id); | |
621 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending)); | |
622 | |
623 { | |
624 JobsRegistry::RunningJob job(registry, 0); | |
625 ASSERT_TRUE(job.IsValid()); | |
626 | |
627 job.MarkSuccess(); | |
628 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Running)); | |
629 } | |
630 | |
631 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Success)); | |
632 } | |
2565 | 633 |
634 | |
2581
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
635 TEST(JobsRegistry, Cancel) |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
636 { |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
637 JobsRegistry registry; |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
638 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
639 std::string id; |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
640 registry.Submit(id, new DummyJob(), 10); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
641 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
642 ASSERT_FALSE(registry.Cancel("nope")); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
643 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
644 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
645 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_Success)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
646 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
647 ASSERT_TRUE(registry.Cancel(id)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
648 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Failure)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
649 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_CanceledJob)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
650 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
651 ASSERT_TRUE(registry.Cancel(id)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
652 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Failure)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
653 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_CanceledJob)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
654 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
655 ASSERT_TRUE(registry.Resubmit(id)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
656 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
657 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_CanceledJob)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
658 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
659 { |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
660 JobsRegistry::RunningJob job(registry, 0); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
661 ASSERT_TRUE(job.IsValid()); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
662 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
663 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_Success)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
664 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
665 job.MarkSuccess(); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
666 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Running)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
667 } |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
668 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
669 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Success)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
670 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_Success)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
671 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
672 ASSERT_TRUE(registry.Cancel(id)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
673 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Success)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
674 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_Success)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
675 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
676 registry.Submit(id, new DummyJob(), 10); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
677 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
678 { |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
679 JobsRegistry::RunningJob job(registry, 0); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
680 ASSERT_TRUE(job.IsValid()); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
681 ASSERT_EQ(id, job.GetId()); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
682 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
683 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_Success)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
684 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Running)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
685 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
686 job.MarkCanceled(); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
687 } |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
688 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
689 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Failure)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
690 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_CanceledJob)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
691 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
692 ASSERT_TRUE(registry.Resubmit(id)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
693 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
694 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_CanceledJob)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
695 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
696 ASSERT_TRUE(registry.Pause(id)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
697 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Paused)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
698 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_CanceledJob)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
699 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
700 ASSERT_TRUE(registry.Cancel(id)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
701 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Failure)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
702 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_CanceledJob)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
703 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
704 ASSERT_TRUE(registry.Resubmit(id)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
705 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
706 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_CanceledJob)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
707 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
708 { |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
709 JobsRegistry::RunningJob job(registry, 0); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
710 ASSERT_TRUE(job.IsValid()); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
711 ASSERT_EQ(id, job.GetId()); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
712 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
713 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_Success)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
714 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Running)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
715 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
716 job.MarkRetry(500); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
717 } |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
718 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
719 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Retry)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
720 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_Success)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
721 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
722 ASSERT_TRUE(registry.Cancel(id)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
723 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Failure)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
724 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_CanceledJob)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
725 } |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
726 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
727 |
2570
2e879c796ec7
JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
728 |
2599 | 729 TEST(JobsEngine, SubmitAndWait) |
2565 | 730 { |
731 JobsEngine engine; | |
732 engine.SetWorkersCount(3); | |
733 engine.Start(); | |
734 | |
2599 | 735 ASSERT_TRUE(engine.GetRegistry().SubmitAndWait(new DummyJob(), rand() % 10)); |
736 ASSERT_FALSE(engine.GetRegistry().SubmitAndWait(new DummyJob(true), rand() % 10)); | |
737 | |
738 engine.Stop(); | |
739 } | |
740 | |
741 | |
2566
c09ce3c038fc
improved handling of eta
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2565
diff
changeset
|
742 |
2599 | 743 |
744 | |
2603 | 745 #include "../OrthancServer/ServerJobs/LuaJobManager.h" |
2601 | 746 #include "../Core/JobsEngine/Operations/StringOperationValue.h" |
747 #include "../Core/JobsEngine/Operations/LogJobOperation.h" | |
2599 | 748 |
2600
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
749 |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
750 TEST(JobsEngine, DISABLED_SequenceOfOperationsJob) |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
751 { |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
752 JobsEngine engine; |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
753 engine.SetWorkersCount(3); |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
754 engine.Start(); |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
755 |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
756 std::string id; |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
757 SequenceOfOperationsJob* job = NULL; |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
758 |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
759 { |
2601 | 760 std::auto_ptr<SequenceOfOperationsJob> a(new SequenceOfOperationsJob); |
2600
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
761 job = a.get(); |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
762 engine.GetRegistry().Submit(id, a.release(), 0); |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
763 } |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
764 |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
765 boost::this_thread::sleep(boost::posix_time::milliseconds(500)); |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
766 |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
767 { |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
768 SequenceOfOperationsJob::Lock lock(*job); |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
769 size_t i = lock.AddOperation(new LogJobOperation); |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
770 size_t j = lock.AddOperation(new LogJobOperation); |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
771 size_t k = lock.AddOperation(new LogJobOperation); |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
772 lock.AddInput(i, StringOperationValue("Hello")); |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
773 lock.AddInput(i, StringOperationValue("World")); |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
774 lock.Connect(i, j); |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
775 lock.Connect(j, k); |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
776 } |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
777 |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
778 boost::this_thread::sleep(boost::posix_time::milliseconds(2000)); |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
779 |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
780 engine.Stop(); |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
781 |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
782 } |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
783 |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
784 |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
785 TEST(JobsEngine, Lua) |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
786 { |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
787 JobsEngine engine; |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
788 engine.SetWorkersCount(2); |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
789 engine.Start(); |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
790 |
2604
76ef12fa136c
fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2603
diff
changeset
|
791 LuaJobManager lua; |
2600
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
792 lua.SetMaxOperationsPerJob(5); |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
793 lua.SetTrailingOperationTimeout(200); |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
794 |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
795 for (size_t i = 0; i < 30; i++) |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
796 { |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
797 boost::this_thread::sleep(boost::posix_time::milliseconds(150)); |
2604
76ef12fa136c
fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2603
diff
changeset
|
798 |
76ef12fa136c
fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2603
diff
changeset
|
799 LuaJobManager::Lock lock(lua, engine); |
76ef12fa136c
fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2603
diff
changeset
|
800 size_t a = lock.AddLogOperation(); |
76ef12fa136c
fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2603
diff
changeset
|
801 size_t b = lock.AddLogOperation(); |
76ef12fa136c
fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2603
diff
changeset
|
802 lock.AddStringInput(a, boost::lexical_cast<std::string>(i)); |
76ef12fa136c
fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2603
diff
changeset
|
803 lock.AddNullInput(a); |
76ef12fa136c
fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2603
diff
changeset
|
804 lock.Connect(a, b); |
2600
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
805 } |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
806 |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
807 boost::this_thread::sleep(boost::posix_time::milliseconds(2000)); |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
808 |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
809 engine.Stop(); |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
810 |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
811 } |