Mercurial > hg > orthanc
annotate UnitTestsSources/MultiThreadingTests.cpp @ 2660:27b7884512be jobs
todo
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 07 Jun 2018 12:51:44 +0200 |
parents | c27f7ecf9b54 |
children | 47d812308d63 |
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 | |
2651
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
37 #include "../Core/FileStorage/MemoryStorageArea.h" |
2569 | 38 #include "../Core/JobsEngine/JobsEngine.h" |
2610
3ff4c50647ea
moving the old scheduler to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2606
diff
changeset
|
39 #include "../Core/MultiThreading/SharedMessageQueue.h" |
723 | 40 #include "../Core/OrthancException.h" |
2656
a6d3e45eeff5
SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2655
diff
changeset
|
41 #include "../Core/SerializationToolbox.h" |
2143
fd5875662670
creation of namespace SystemToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2140
diff
changeset
|
42 #include "../Core/SystemToolbox.h" |
723 | 43 #include "../Core/Toolbox.h" |
2651
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
44 #include "../OrthancServer/DatabaseWrapper.h" |
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
45 #include "../OrthancServer/ServerContext.h" |
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
46 #include "../OrthancServer/ServerJobs/LuaJobManager.h" |
2655 | 47 #include "../OrthancServer/ServerJobs/OrthancJobUnserializer.h" |
48 | |
49 #include "../Core/JobsEngine/Operations/JobOperationValues.h" | |
50 #include "../Core/JobsEngine/Operations/NullOperationValue.h" | |
51 #include "../Core/JobsEngine/Operations/StringOperationValue.h" | |
2651
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
52 #include "../OrthancServer/ServerJobs/Operations/DicomInstanceOperationValue.h" |
2655 | 53 |
54 #include "../Core/JobsEngine/Operations/LogJobOperation.h" | |
55 #include "../OrthancServer/ServerJobs/Operations/DeleteResourceOperation.h" | |
56 #include "../OrthancServer/ServerJobs/Operations/ModifyInstanceOperation.h" | |
57 #include "../OrthancServer/ServerJobs/Operations/StorePeerOperation.h" | |
58 #include "../OrthancServer/ServerJobs/Operations/StoreScuOperation.h" | |
59 #include "../OrthancServer/ServerJobs/Operations/SystemCallOperation.h" | |
60 | |
61 | |
723 | 62 |
63 using namespace Orthanc; | |
64 | |
65 namespace | |
66 { | |
2652 | 67 class DummyJob : public IJob |
68 { | |
69 private: | |
70 bool fails_; | |
71 unsigned int count_; | |
72 unsigned int steps_; | |
73 | |
74 public: | |
75 DummyJob() : | |
76 fails_(false), | |
77 count_(0), | |
78 steps_(4) | |
79 { | |
80 } | |
81 | |
82 explicit DummyJob(bool fails) : | |
83 fails_(fails), | |
84 count_(0), | |
85 steps_(4) | |
86 { | |
87 } | |
88 | |
89 virtual void Start() | |
90 { | |
91 } | |
92 | |
93 virtual void SignalResubmit() | |
94 { | |
95 } | |
96 | |
97 virtual JobStepResult ExecuteStep() | |
98 { | |
99 if (fails_) | |
100 { | |
101 return JobStepResult::Failure(ErrorCode_ParameterOutOfRange); | |
102 } | |
103 else if (count_ == steps_ - 1) | |
104 { | |
105 return JobStepResult::Success(); | |
106 } | |
107 else | |
108 { | |
109 count_++; | |
110 return JobStepResult::Continue(); | |
111 } | |
112 } | |
113 | |
114 virtual void ReleaseResources() | |
115 { | |
116 } | |
117 | |
118 virtual float GetProgress() | |
119 { | |
120 return static_cast<float>(count_) / static_cast<float>(steps_ - 1); | |
121 } | |
122 | |
123 virtual void GetJobType(std::string& type) | |
124 { | |
125 type = "DummyJob"; | |
126 } | |
127 | |
128 virtual void Serialize(Json::Value& value) | |
129 { | |
130 } | |
131 | |
132 virtual void GetPublicContent(Json::Value& value) | |
133 { | |
134 value["hello"] = "world"; | |
135 } | |
136 }; | |
137 | |
138 | |
139 class DummyInstancesJob : public SetOfInstancesJob | |
140 { | |
141 protected: | |
142 virtual bool HandleInstance(const std::string& instance) | |
143 { | |
2657
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
144 return (instance != "nope"); |
2652 | 145 } |
146 | |
147 public: | |
148 DummyInstancesJob() | |
149 { | |
150 } | |
151 | |
152 DummyInstancesJob(const Json::Value& value) : | |
153 SetOfInstancesJob(value) | |
154 { | |
155 } | |
156 | |
157 virtual void ReleaseResources() | |
158 { | |
159 } | |
160 | |
161 virtual void GetJobType(std::string& s) | |
162 { | |
163 s = "DummyInstancesJob"; | |
164 } | |
165 }; | |
166 | |
167 | |
168 class DummyUnserializer : public GenericJobUnserializer | |
169 { | |
170 public: | |
171 virtual IJob* UnserializeJob(const Json::Value& value) | |
172 { | |
2656
a6d3e45eeff5
SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2655
diff
changeset
|
173 if (SerializationToolbox::ReadString(value, "Type") == "DummyInstancesJob") |
2652 | 174 { |
175 return new DummyInstancesJob(value); | |
176 } | |
177 else | |
178 { | |
179 return GenericJobUnserializer::UnserializeJob(value); | |
180 } | |
181 } | |
182 }; | |
183 | |
184 | |
1396
ac4efabeb80c
Migration of the orthanc-client as a separate project
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1304
diff
changeset
|
185 class DynamicInteger : public IDynamicObject |
723 | 186 { |
187 private: | |
188 int value_; | |
189 std::set<int>& target_; | |
190 | |
191 public: | |
192 DynamicInteger(int value, std::set<int>& target) : | |
193 value_(value), target_(target) | |
194 { | |
195 } | |
196 | |
197 int GetValue() const | |
198 { | |
199 return value_; | |
200 } | |
201 }; | |
202 } | |
203 | |
204 | |
205 TEST(MultiThreading, SharedMessageQueueBasic) | |
206 { | |
207 std::set<int> s; | |
208 | |
209 SharedMessageQueue q; | |
210 ASSERT_TRUE(q.WaitEmpty(0)); | |
211 q.Enqueue(new DynamicInteger(10, s)); | |
212 ASSERT_FALSE(q.WaitEmpty(1)); | |
213 q.Enqueue(new DynamicInteger(20, s)); | |
214 q.Enqueue(new DynamicInteger(30, s)); | |
215 q.Enqueue(new DynamicInteger(40, s)); | |
216 | |
217 std::auto_ptr<DynamicInteger> i; | |
218 i.reset(dynamic_cast<DynamicInteger*>(q.Dequeue(1))); ASSERT_EQ(10, i->GetValue()); | |
219 i.reset(dynamic_cast<DynamicInteger*>(q.Dequeue(1))); ASSERT_EQ(20, i->GetValue()); | |
220 i.reset(dynamic_cast<DynamicInteger*>(q.Dequeue(1))); ASSERT_EQ(30, i->GetValue()); | |
221 ASSERT_FALSE(q.WaitEmpty(1)); | |
222 i.reset(dynamic_cast<DynamicInteger*>(q.Dequeue(1))); ASSERT_EQ(40, i->GetValue()); | |
223 ASSERT_TRUE(q.WaitEmpty(0)); | |
224 ASSERT_EQ(NULL, q.Dequeue(1)); | |
225 } | |
226 | |
227 | |
228 TEST(MultiThreading, SharedMessageQueueClean) | |
229 { | |
230 std::set<int> s; | |
231 | |
232 try | |
233 { | |
234 SharedMessageQueue q; | |
235 q.Enqueue(new DynamicInteger(10, s)); | |
236 q.Enqueue(new DynamicInteger(20, s)); | |
1583
9ea3d082b064
got rid of custom exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1582
diff
changeset
|
237 throw OrthancException(ErrorCode_InternalError); |
723 | 238 } |
239 catch (OrthancException&) | |
240 { | |
241 } | |
242 } | |
243 | |
244 | |
769
3f946e5c3802
ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
760
diff
changeset
|
245 |
3f946e5c3802
ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
760
diff
changeset
|
246 |
2652 | 247 static bool CheckState(JobsRegistry& registry, |
248 const std::string& id, | |
249 JobState state) | |
2557 | 250 { |
2652 | 251 JobState s; |
2558 | 252 if (registry.GetState(s, id)) |
2557 | 253 { |
254 return state == s; | |
255 } | |
256 else | |
257 { | |
258 return false; | |
259 } | |
260 } | |
261 | |
262 | |
2652 | 263 static bool CheckErrorCode(JobsRegistry& registry, |
2581
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
264 const std::string& id, |
2652 | 265 ErrorCode code) |
2581
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
266 { |
2652 | 267 JobInfo s; |
2581
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
268 if (registry.GetJobInfo(s, id)) |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
269 { |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
270 return code == s.GetStatus().GetErrorCode(); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
271 } |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
272 else |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
273 { |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
274 return false; |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
275 } |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
276 } |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
277 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
278 |
2558 | 279 TEST(JobsRegistry, Priority) |
2557 | 280 { |
2558 | 281 JobsRegistry registry; |
2557 | 282 |
283 std::string i1, i2, i3, i4; | |
2558 | 284 registry.Submit(i1, new DummyJob(), 10); |
285 registry.Submit(i2, new DummyJob(), 30); | |
286 registry.Submit(i3, new DummyJob(), 20); | |
287 registry.Submit(i4, new DummyJob(), 5); | |
2557 | 288 |
2558 | 289 registry.SetMaxCompletedJobs(2); |
2557 | 290 |
291 std::set<std::string> id; | |
2558 | 292 registry.ListJobs(id); |
2557 | 293 |
294 ASSERT_EQ(4u, id.size()); | |
295 ASSERT_TRUE(id.find(i1) != id.end()); | |
296 ASSERT_TRUE(id.find(i2) != id.end()); | |
297 ASSERT_TRUE(id.find(i3) != id.end()); | |
298 ASSERT_TRUE(id.find(i4) != id.end()); | |
299 | |
2652 | 300 ASSERT_TRUE(CheckState(registry, i2, JobState_Pending)); |
2557 | 301 |
302 { | |
2558 | 303 JobsRegistry::RunningJob job(registry, 0); |
2557 | 304 ASSERT_TRUE(job.IsValid()); |
305 ASSERT_EQ(30, job.GetPriority()); | |
306 ASSERT_EQ(i2, job.GetId()); | |
307 | |
2652 | 308 ASSERT_TRUE(CheckState(registry, i2, JobState_Running)); |
2557 | 309 } |
310 | |
2652 | 311 ASSERT_TRUE(CheckState(registry, i2, JobState_Failure)); |
312 ASSERT_TRUE(CheckState(registry, i3, JobState_Pending)); | |
2557 | 313 |
314 { | |
2558 | 315 JobsRegistry::RunningJob job(registry, 0); |
2557 | 316 ASSERT_TRUE(job.IsValid()); |
317 ASSERT_EQ(20, job.GetPriority()); | |
318 ASSERT_EQ(i3, job.GetId()); | |
319 | |
320 job.MarkSuccess(); | |
321 | |
2652 | 322 ASSERT_TRUE(CheckState(registry, i3, JobState_Running)); |
2557 | 323 } |
324 | |
2652 | 325 ASSERT_TRUE(CheckState(registry, i3, JobState_Success)); |
2557 | 326 |
327 { | |
2558 | 328 JobsRegistry::RunningJob job(registry, 0); |
2557 | 329 ASSERT_TRUE(job.IsValid()); |
330 ASSERT_EQ(10, job.GetPriority()); | |
331 ASSERT_EQ(i1, job.GetId()); | |
332 } | |
333 | |
334 { | |
2558 | 335 JobsRegistry::RunningJob job(registry, 0); |
2557 | 336 ASSERT_TRUE(job.IsValid()); |
337 ASSERT_EQ(5, job.GetPriority()); | |
338 ASSERT_EQ(i4, job.GetId()); | |
339 } | |
340 | |
341 { | |
2558 | 342 JobsRegistry::RunningJob job(registry, 1); |
2557 | 343 ASSERT_FALSE(job.IsValid()); |
344 } | |
345 | |
2652 | 346 JobState s; |
2558 | 347 ASSERT_TRUE(registry.GetState(s, i1)); |
348 ASSERT_FALSE(registry.GetState(s, i2)); // Removed because oldest | |
349 ASSERT_FALSE(registry.GetState(s, i3)); // Removed because second oldest | |
350 ASSERT_TRUE(registry.GetState(s, i4)); | |
2557 | 351 |
2558 | 352 registry.SetMaxCompletedJobs(1); // (*) |
353 ASSERT_FALSE(registry.GetState(s, i1)); // Just discarded by (*) | |
354 ASSERT_TRUE(registry.GetState(s, i4)); | |
2557 | 355 } |
356 | |
357 | |
2558 | 358 TEST(JobsRegistry, Simultaneous) |
2557 | 359 { |
2558 | 360 JobsRegistry registry; |
361 | |
362 std::string i1, i2; | |
363 registry.Submit(i1, new DummyJob(), 20); | |
364 registry.Submit(i2, new DummyJob(), 10); | |
365 | |
2652 | 366 ASSERT_TRUE(CheckState(registry, i1, JobState_Pending)); |
367 ASSERT_TRUE(CheckState(registry, i2, JobState_Pending)); | |
2558 | 368 |
369 { | |
370 JobsRegistry::RunningJob job1(registry, 0); | |
371 JobsRegistry::RunningJob job2(registry, 0); | |
372 | |
373 ASSERT_TRUE(job1.IsValid()); | |
374 ASSERT_TRUE(job2.IsValid()); | |
375 | |
376 job1.MarkFailure(); | |
377 job2.MarkSuccess(); | |
378 | |
2652 | 379 ASSERT_TRUE(CheckState(registry, i1, JobState_Running)); |
380 ASSERT_TRUE(CheckState(registry, i2, JobState_Running)); | |
2558 | 381 } |
382 | |
2652 | 383 ASSERT_TRUE(CheckState(registry, i1, JobState_Failure)); |
384 ASSERT_TRUE(CheckState(registry, i2, JobState_Success)); | |
2558 | 385 } |
386 | |
387 | |
388 TEST(JobsRegistry, Resubmit) | |
389 { | |
390 JobsRegistry registry; | |
2557 | 391 |
392 std::string id; | |
2558 | 393 registry.Submit(id, new DummyJob(), 10); |
2557 | 394 |
2652 | 395 ASSERT_TRUE(CheckState(registry, id, JobState_Pending)); |
2557 | 396 |
2558 | 397 registry.Resubmit(id); |
2652 | 398 ASSERT_TRUE(CheckState(registry, id, JobState_Pending)); |
2557 | 399 |
400 { | |
2558 | 401 JobsRegistry::RunningJob job(registry, 0); |
2557 | 402 ASSERT_TRUE(job.IsValid()); |
403 job.MarkFailure(); | |
404 | |
2652 | 405 ASSERT_TRUE(CheckState(registry, id, JobState_Running)); |
2557 | 406 |
2558 | 407 registry.Resubmit(id); |
2652 | 408 ASSERT_TRUE(CheckState(registry, id, JobState_Running)); |
2557 | 409 } |
410 | |
2652 | 411 ASSERT_TRUE(CheckState(registry, id, JobState_Failure)); |
2557 | 412 |
2558 | 413 registry.Resubmit(id); |
2652 | 414 ASSERT_TRUE(CheckState(registry, id, JobState_Pending)); |
2557 | 415 |
416 { | |
2558 | 417 JobsRegistry::RunningJob job(registry, 0); |
2557 | 418 ASSERT_TRUE(job.IsValid()); |
419 ASSERT_EQ(id, job.GetId()); | |
420 | |
421 job.MarkSuccess(); | |
2652 | 422 ASSERT_TRUE(CheckState(registry, id, JobState_Running)); |
2558 | 423 } |
424 | |
2652 | 425 ASSERT_TRUE(CheckState(registry, id, JobState_Success)); |
2558 | 426 |
427 registry.Resubmit(id); | |
2652 | 428 ASSERT_TRUE(CheckState(registry, id, JobState_Success)); |
2558 | 429 } |
430 | |
431 | |
432 TEST(JobsRegistry, Retry) | |
433 { | |
434 JobsRegistry registry; | |
435 | |
436 std::string id; | |
437 registry.Submit(id, new DummyJob(), 10); | |
438 | |
2652 | 439 ASSERT_TRUE(CheckState(registry, id, JobState_Pending)); |
2558 | 440 |
441 { | |
442 JobsRegistry::RunningJob job(registry, 0); | |
443 ASSERT_TRUE(job.IsValid()); | |
444 job.MarkRetry(0); | |
445 | |
2652 | 446 ASSERT_TRUE(CheckState(registry, id, JobState_Running)); |
2558 | 447 } |
448 | |
2652 | 449 ASSERT_TRUE(CheckState(registry, id, JobState_Retry)); |
2558 | 450 |
451 registry.Resubmit(id); | |
2652 | 452 ASSERT_TRUE(CheckState(registry, id, JobState_Retry)); |
2558 | 453 |
454 registry.ScheduleRetries(); | |
2652 | 455 ASSERT_TRUE(CheckState(registry, id, JobState_Pending)); |
2558 | 456 |
457 { | |
458 JobsRegistry::RunningJob job(registry, 0); | |
459 ASSERT_TRUE(job.IsValid()); | |
460 job.MarkSuccess(); | |
461 | |
2652 | 462 ASSERT_TRUE(CheckState(registry, id, JobState_Running)); |
2557 | 463 } |
464 | |
2652 | 465 ASSERT_TRUE(CheckState(registry, id, JobState_Success)); |
2558 | 466 } |
467 | |
468 | |
469 TEST(JobsRegistry, PausePending) | |
470 { | |
471 JobsRegistry registry; | |
472 | |
473 std::string id; | |
474 registry.Submit(id, new DummyJob(), 10); | |
475 | |
2652 | 476 ASSERT_TRUE(CheckState(registry, id, JobState_Pending)); |
2558 | 477 |
478 registry.Pause(id); | |
2652 | 479 ASSERT_TRUE(CheckState(registry, id, JobState_Paused)); |
2558 | 480 |
481 registry.Pause(id); | |
2652 | 482 ASSERT_TRUE(CheckState(registry, id, JobState_Paused)); |
2558 | 483 |
484 registry.Resubmit(id); | |
2652 | 485 ASSERT_TRUE(CheckState(registry, id, JobState_Paused)); |
2558 | 486 |
487 registry.Resume(id); | |
2652 | 488 ASSERT_TRUE(CheckState(registry, id, JobState_Pending)); |
2557 | 489 } |
2558 | 490 |
491 | |
492 TEST(JobsRegistry, PauseRunning) | |
493 { | |
494 JobsRegistry registry; | |
495 | |
496 std::string id; | |
497 registry.Submit(id, new DummyJob(), 10); | |
498 | |
2652 | 499 ASSERT_TRUE(CheckState(registry, id, JobState_Pending)); |
2558 | 500 |
501 { | |
502 JobsRegistry::RunningJob job(registry, 0); | |
503 ASSERT_TRUE(job.IsValid()); | |
504 | |
505 registry.Resubmit(id); | |
2562 | 506 job.MarkPause(); |
2652 | 507 ASSERT_TRUE(CheckState(registry, id, JobState_Running)); |
2558 | 508 } |
509 | |
2652 | 510 ASSERT_TRUE(CheckState(registry, id, JobState_Paused)); |
2558 | 511 |
512 registry.Resubmit(id); | |
2652 | 513 ASSERT_TRUE(CheckState(registry, id, JobState_Paused)); |
2558 | 514 |
515 registry.Resume(id); | |
2652 | 516 ASSERT_TRUE(CheckState(registry, id, JobState_Pending)); |
2558 | 517 |
518 { | |
519 JobsRegistry::RunningJob job(registry, 0); | |
520 ASSERT_TRUE(job.IsValid()); | |
521 | |
522 job.MarkSuccess(); | |
2652 | 523 ASSERT_TRUE(CheckState(registry, id, JobState_Running)); |
2558 | 524 } |
525 | |
2652 | 526 ASSERT_TRUE(CheckState(registry, id, JobState_Success)); |
2558 | 527 } |
528 | |
529 | |
530 TEST(JobsRegistry, PauseRetry) | |
531 { | |
532 JobsRegistry registry; | |
533 | |
534 std::string id; | |
535 registry.Submit(id, new DummyJob(), 10); | |
536 | |
2652 | 537 ASSERT_TRUE(CheckState(registry, id, JobState_Pending)); |
2558 | 538 |
539 { | |
540 JobsRegistry::RunningJob job(registry, 0); | |
541 ASSERT_TRUE(job.IsValid()); | |
542 | |
543 job.MarkRetry(0); | |
2652 | 544 ASSERT_TRUE(CheckState(registry, id, JobState_Running)); |
2558 | 545 } |
546 | |
2652 | 547 ASSERT_TRUE(CheckState(registry, id, JobState_Retry)); |
2558 | 548 |
549 registry.Pause(id); | |
2652 | 550 ASSERT_TRUE(CheckState(registry, id, JobState_Paused)); |
2558 | 551 |
552 registry.Resume(id); | |
2652 | 553 ASSERT_TRUE(CheckState(registry, id, JobState_Pending)); |
2558 | 554 |
555 { | |
556 JobsRegistry::RunningJob job(registry, 0); | |
557 ASSERT_TRUE(job.IsValid()); | |
558 | |
559 job.MarkSuccess(); | |
2652 | 560 ASSERT_TRUE(CheckState(registry, id, JobState_Running)); |
2558 | 561 } |
562 | |
2652 | 563 ASSERT_TRUE(CheckState(registry, id, JobState_Success)); |
2558 | 564 } |
2565 | 565 |
566 | |
2581
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
567 TEST(JobsRegistry, Cancel) |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
568 { |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
569 JobsRegistry registry; |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
570 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
571 std::string id; |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
572 registry.Submit(id, new DummyJob(), 10); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
573 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
574 ASSERT_FALSE(registry.Cancel("nope")); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
575 |
2652 | 576 ASSERT_TRUE(CheckState(registry, id, JobState_Pending)); |
2581
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
577 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_Success)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
578 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
579 ASSERT_TRUE(registry.Cancel(id)); |
2652 | 580 ASSERT_TRUE(CheckState(registry, id, JobState_Failure)); |
2581
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
581 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_CanceledJob)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
582 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
583 ASSERT_TRUE(registry.Cancel(id)); |
2652 | 584 ASSERT_TRUE(CheckState(registry, id, JobState_Failure)); |
2581
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
585 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_CanceledJob)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
586 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
587 ASSERT_TRUE(registry.Resubmit(id)); |
2652 | 588 ASSERT_TRUE(CheckState(registry, id, JobState_Pending)); |
2581
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
589 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_CanceledJob)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
590 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
591 { |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
592 JobsRegistry::RunningJob job(registry, 0); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
593 ASSERT_TRUE(job.IsValid()); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
594 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
595 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_Success)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
596 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
597 job.MarkSuccess(); |
2652 | 598 ASSERT_TRUE(CheckState(registry, id, JobState_Running)); |
2581
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
599 } |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
600 |
2652 | 601 ASSERT_TRUE(CheckState(registry, id, JobState_Success)); |
2581
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
602 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_Success)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
603 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
604 ASSERT_TRUE(registry.Cancel(id)); |
2652 | 605 ASSERT_TRUE(CheckState(registry, id, JobState_Success)); |
2581
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
606 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_Success)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
607 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
608 registry.Submit(id, new DummyJob(), 10); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
609 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
610 { |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
611 JobsRegistry::RunningJob job(registry, 0); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
612 ASSERT_TRUE(job.IsValid()); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
613 ASSERT_EQ(id, job.GetId()); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
614 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
615 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_Success)); |
2652 | 616 ASSERT_TRUE(CheckState(registry, id, JobState_Running)); |
2581
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
617 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
618 job.MarkCanceled(); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
619 } |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
620 |
2652 | 621 ASSERT_TRUE(CheckState(registry, id, JobState_Failure)); |
2581
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
622 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_CanceledJob)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
623 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
624 ASSERT_TRUE(registry.Resubmit(id)); |
2652 | 625 ASSERT_TRUE(CheckState(registry, id, JobState_Pending)); |
2581
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
626 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_CanceledJob)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
627 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
628 ASSERT_TRUE(registry.Pause(id)); |
2652 | 629 ASSERT_TRUE(CheckState(registry, id, JobState_Paused)); |
2581
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
630 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_CanceledJob)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
631 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
632 ASSERT_TRUE(registry.Cancel(id)); |
2652 | 633 ASSERT_TRUE(CheckState(registry, id, JobState_Failure)); |
2581
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
634 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_CanceledJob)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
635 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
636 ASSERT_TRUE(registry.Resubmit(id)); |
2652 | 637 ASSERT_TRUE(CheckState(registry, id, JobState_Pending)); |
2581
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
638 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_CanceledJob)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
639 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
640 { |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
641 JobsRegistry::RunningJob job(registry, 0); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
642 ASSERT_TRUE(job.IsValid()); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
643 ASSERT_EQ(id, job.GetId()); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
644 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
645 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_Success)); |
2652 | 646 ASSERT_TRUE(CheckState(registry, id, JobState_Running)); |
2581
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
647 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
648 job.MarkRetry(500); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
649 } |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
650 |
2652 | 651 ASSERT_TRUE(CheckState(registry, id, JobState_Retry)); |
2581
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
652 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_Success)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
653 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
654 ASSERT_TRUE(registry.Cancel(id)); |
2652 | 655 ASSERT_TRUE(CheckState(registry, id, JobState_Failure)); |
2581
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
656 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_CanceledJob)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
657 } |
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 |
2570
2e879c796ec7
JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
660 |
2599 | 661 TEST(JobsEngine, SubmitAndWait) |
2565 | 662 { |
663 JobsEngine engine; | |
664 engine.SetWorkersCount(3); | |
665 engine.Start(); | |
666 | |
2599 | 667 ASSERT_TRUE(engine.GetRegistry().SubmitAndWait(new DummyJob(), rand() % 10)); |
668 ASSERT_FALSE(engine.GetRegistry().SubmitAndWait(new DummyJob(true), rand() % 10)); | |
669 | |
670 engine.Stop(); | |
671 } | |
672 | |
673 | |
2600
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
674 TEST(JobsEngine, DISABLED_SequenceOfOperationsJob) |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
675 { |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
676 JobsEngine engine; |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
677 engine.SetWorkersCount(3); |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
678 engine.Start(); |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
679 |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
680 std::string id; |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
681 SequenceOfOperationsJob* job = NULL; |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
682 |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
683 { |
2601 | 684 std::auto_ptr<SequenceOfOperationsJob> a(new SequenceOfOperationsJob); |
2600
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
685 job = a.get(); |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
686 engine.GetRegistry().Submit(id, a.release(), 0); |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
687 } |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
688 |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
689 boost::this_thread::sleep(boost::posix_time::milliseconds(500)); |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
690 |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
691 { |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
692 SequenceOfOperationsJob::Lock lock(*job); |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
693 size_t i = lock.AddOperation(new LogJobOperation); |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
694 size_t j = lock.AddOperation(new LogJobOperation); |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
695 size_t k = lock.AddOperation(new LogJobOperation); |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
696 lock.AddInput(i, StringOperationValue("Hello")); |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
697 lock.AddInput(i, StringOperationValue("World")); |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
698 lock.Connect(i, j); |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
699 lock.Connect(j, k); |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
700 } |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
701 |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
702 boost::this_thread::sleep(boost::posix_time::milliseconds(2000)); |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
703 |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
704 engine.Stop(); |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
705 |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
706 } |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
707 |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
708 |
2621
83ac5a05ce84
primitives for unserializing jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2610
diff
changeset
|
709 TEST(JobsEngine, DISABLED_Lua) |
2600
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
710 { |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
711 JobsEngine engine; |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
712 engine.SetWorkersCount(2); |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
713 engine.Start(); |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
714 |
2604
76ef12fa136c
fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2603
diff
changeset
|
715 LuaJobManager lua; |
2600
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
716 lua.SetMaxOperationsPerJob(5); |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
717 lua.SetTrailingOperationTimeout(200); |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
718 |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
719 for (size_t i = 0; i < 30; i++) |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
720 { |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
721 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
|
722 |
76ef12fa136c
fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2603
diff
changeset
|
723 LuaJobManager::Lock lock(lua, engine); |
76ef12fa136c
fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2603
diff
changeset
|
724 size_t a = lock.AddLogOperation(); |
76ef12fa136c
fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2603
diff
changeset
|
725 size_t b = lock.AddLogOperation(); |
2606
f2b9d3256060
SystemCallOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2604
diff
changeset
|
726 size_t c = lock.AddSystemCallOperation("echo"); |
2604
76ef12fa136c
fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2603
diff
changeset
|
727 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
|
728 lock.AddNullInput(a); |
76ef12fa136c
fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2603
diff
changeset
|
729 lock.Connect(a, b); |
2606
f2b9d3256060
SystemCallOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2604
diff
changeset
|
730 lock.Connect(a, c); |
2600
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
731 } |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
732 |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
733 boost::this_thread::sleep(boost::posix_time::milliseconds(2000)); |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
734 |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
735 engine.Stop(); |
2651
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
736 } |
2600
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
737 |
2651
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
738 |
2655 | 739 TEST(JobsSerialization, BadFileFormat) |
740 { | |
741 GenericJobUnserializer unserializer; | |
742 | |
743 Json::Value s; | |
744 | |
745 s = Json::objectValue; | |
746 ASSERT_THROW(unserializer.UnserializeValue(s), OrthancException); | |
747 ASSERT_THROW(unserializer.UnserializeJob(s), OrthancException); | |
748 ASSERT_THROW(unserializer.UnserializeOperation(s), OrthancException); | |
749 | |
750 s = Json::arrayValue; | |
751 ASSERT_THROW(unserializer.UnserializeValue(s), OrthancException); | |
752 ASSERT_THROW(unserializer.UnserializeJob(s), OrthancException); | |
753 ASSERT_THROW(unserializer.UnserializeOperation(s), OrthancException); | |
754 | |
755 s = "hello"; | |
756 ASSERT_THROW(unserializer.UnserializeValue(s), OrthancException); | |
757 ASSERT_THROW(unserializer.UnserializeJob(s), OrthancException); | |
758 ASSERT_THROW(unserializer.UnserializeOperation(s), OrthancException); | |
759 | |
760 s = 42; | |
761 ASSERT_THROW(unserializer.UnserializeValue(s), OrthancException); | |
762 ASSERT_THROW(unserializer.UnserializeJob(s), OrthancException); | |
763 ASSERT_THROW(unserializer.UnserializeOperation(s), OrthancException); | |
764 } | |
765 | |
766 | |
2657
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
767 TEST(JobsSerialization, JobOperationValues) |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
768 { |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
769 Json::Value s; |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
770 |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
771 { |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
772 JobOperationValues values; |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
773 values.Append(new NullOperationValue); |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
774 values.Append(new StringOperationValue("hello")); |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
775 values.Append(new StringOperationValue("world")); |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
776 values.Serialize(s); |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
777 } |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
778 |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
779 { |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
780 GenericJobUnserializer unserializer; |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
781 std::auto_ptr<JobOperationValues> values(JobOperationValues::Unserialize(unserializer, s)); |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
782 ASSERT_EQ(3u, values->GetSize()); |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
783 ASSERT_EQ(JobOperationValue::Type_Null, values->GetValue(0).GetType()); |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
784 ASSERT_EQ(JobOperationValue::Type_String, values->GetValue(1).GetType()); |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
785 ASSERT_EQ(JobOperationValue::Type_String, values->GetValue(2).GetType()); |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
786 |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
787 ASSERT_EQ("hello", dynamic_cast<const StringOperationValue&>(values->GetValue(1)).GetContent()); |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
788 ASSERT_EQ("world", dynamic_cast<const StringOperationValue&>(values->GetValue(2)).GetContent()); |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
789 } |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
790 } |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
791 |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
792 |
2651
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
793 TEST(JobsSerialization, GenericValues) |
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
794 { |
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
795 Json::Value s; |
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
796 |
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
797 { |
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
798 NullOperationValue null; |
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
799 null.Serialize(s); |
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
800 } |
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
801 |
2655 | 802 GenericJobUnserializer unserializer; |
2652 | 803 ASSERT_THROW(unserializer.UnserializeJob(s), OrthancException); |
804 ASSERT_THROW(unserializer.UnserializeOperation(s), OrthancException); | |
2655 | 805 |
806 std::auto_ptr<JobOperationValue> value; | |
2651
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
807 value.reset(unserializer.UnserializeValue(s)); |
2652 | 808 |
2651
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
809 ASSERT_EQ(JobOperationValue::Type_Null, value->GetType()); |
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
810 |
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
811 { |
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
812 StringOperationValue str("Hello"); |
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
813 str.Serialize(s); |
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
814 } |
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
815 |
2652 | 816 ASSERT_THROW(unserializer.UnserializeJob(s), OrthancException); |
817 ASSERT_THROW(unserializer.UnserializeOperation(s), OrthancException); | |
2651
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
818 value.reset(unserializer.UnserializeValue(s)); |
2652 | 819 |
2651
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
820 ASSERT_EQ(JobOperationValue::Type_String, value->GetType()); |
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
821 ASSERT_EQ("Hello", dynamic_cast<StringOperationValue&>(*value).GetContent()); |
2600
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
822 } |
2651
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
823 |
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
824 |
2655 | 825 TEST(JobsSerialization, GenericOperations) |
826 { | |
827 Json::Value s; | |
828 | |
829 { | |
830 LogJobOperation operation; | |
831 operation.Serialize(s); | |
832 } | |
833 | |
2652 | 834 DummyUnserializer unserializer; |
2655 | 835 ASSERT_THROW(unserializer.UnserializeJob(s), OrthancException); |
836 ASSERT_THROW(unserializer.UnserializeValue(s), OrthancException); | |
837 | |
838 { | |
839 std::auto_ptr<IJobOperation> operation; | |
840 operation.reset(unserializer.UnserializeOperation(s)); | |
841 | |
2657
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
842 // Make sure that we have indeed unserialized a log operation |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
843 ASSERT_THROW(dynamic_cast<DeleteResourceOperation&>(*operation), std::bad_cast); |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
844 dynamic_cast<LogJobOperation&>(*operation); |
2655 | 845 } |
846 } | |
847 | |
848 | |
849 TEST(JobsSerialization, GenericJobs) | |
850 { | |
2652 | 851 Json::Value s; |
852 | |
2658 | 853 // This tests SetOfInstancesJob |
854 | |
2652 | 855 { |
856 DummyInstancesJob job; | |
857 job.SetDescription("description"); | |
2657
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
858 job.AddInstance("hello"); |
2652 | 859 job.AddInstance("nope"); |
2657
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
860 job.AddInstance("world"); |
2652 | 861 job.SetPermissive(true); |
2657
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
862 ASSERT_THROW(job.ExecuteStep(), OrthancException); // Not started yet |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
863 job.Start(); |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
864 job.ExecuteStep(); |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
865 job.ExecuteStep(); |
2652 | 866 job.Serialize(s); |
867 } | |
868 | |
2655 | 869 { |
870 DummyUnserializer unserializer; | |
871 ASSERT_THROW(unserializer.UnserializeValue(s), OrthancException); | |
872 ASSERT_THROW(unserializer.UnserializeOperation(s), OrthancException); | |
2652 | 873 |
2655 | 874 std::auto_ptr<IJob> job; |
875 job.reset(unserializer.UnserializeJob(s)); | |
2657
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
876 |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
877 const DummyInstancesJob& tmp = dynamic_cast<const DummyInstancesJob&>(*job); |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
878 ASSERT_FALSE(tmp.IsStarted()); |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
879 ASSERT_TRUE(tmp.IsPermissive()); |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
880 ASSERT_EQ("description", tmp.GetDescription()); |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
881 ASSERT_EQ(3u, tmp.GetInstancesCount()); |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
882 ASSERT_EQ(2u, tmp.GetPosition()); |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
883 ASSERT_EQ(1u, tmp.GetFailedInstances().size()); |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
884 ASSERT_EQ("hello", tmp.GetInstance(0)); |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
885 ASSERT_EQ("nope", tmp.GetInstance(1)); |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
886 ASSERT_EQ("world", tmp.GetInstance(2)); |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
887 ASSERT_TRUE(tmp.IsFailedInstance("nope")); |
2655 | 888 } |
2658 | 889 |
890 // TODO : Test SequenceOfOperationsJob.h | |
891 } | |
892 | |
893 | |
2660 | 894 TEST(JobsSerialization, DicomModification) |
895 { | |
896 // TODO : Test serialization of DicomModification | |
897 } | |
898 | |
899 | |
2658 | 900 TEST(JobsSerialization, Registry) |
901 { | |
902 // TODO : Test serialization of JobsRegistry | |
2652 | 903 } |
904 | |
905 | |
2655 | 906 namespace |
2651
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
907 { |
2655 | 908 class OrthancJobsSerialization : public testing::Test |
909 { | |
910 private: | |
911 MemoryStorageArea storage_; | |
912 DatabaseWrapper db_; // The SQLite DB is in memory | |
913 std::auto_ptr<ServerContext> context_; | |
914 TimeoutDicomConnectionManager manager_; | |
915 | |
916 public: | |
917 OrthancJobsSerialization() | |
918 { | |
919 db_.Open(); | |
920 context_.reset(new ServerContext(db_, storage_)); | |
921 } | |
922 | |
923 virtual ~OrthancJobsSerialization() | |
924 { | |
925 context_->Stop(); | |
926 context_.reset(NULL); | |
927 db_.Close(); | |
928 } | |
2651
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
929 |
2655 | 930 ServerContext& GetContext() |
931 { | |
932 return *context_; | |
933 } | |
934 | |
935 bool CreateInstance(std::string& id) | |
936 { | |
937 // Create a sample DICOM file | |
938 ParsedDicomFile dicom(true); | |
939 dicom.Replace(DICOM_TAG_PATIENT_NAME, std::string("JODOGNE"), | |
940 false, DicomReplaceMode_InsertIfAbsent); | |
941 | |
942 DicomInstanceToStore toStore; | |
943 toStore.SetParsedDicomFile(dicom); | |
944 | |
945 return (context_->Store(id, toStore) == StoreStatus_Success); | |
946 } | |
947 }; | |
948 } | |
949 | |
950 | |
951 TEST_F(OrthancJobsSerialization, Values) | |
952 { | |
2651
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
953 std::string id; |
2655 | 954 ASSERT_TRUE(CreateInstance(id)); |
2651
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
955 |
2655 | 956 Json::Value s; |
2651
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
957 |
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
958 { |
2655 | 959 DicomInstanceOperationValue instance(GetContext(), id); |
960 instance.Serialize(s); | |
2651
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
961 } |
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
962 |
2655 | 963 OrthancJobUnserializer unserializer(GetContext()); |
964 | |
965 std::auto_ptr<JobOperationValue> value; | |
966 value.reset(unserializer.UnserializeValue(s)); | |
967 ASSERT_EQ(JobOperationValue::Type_DicomInstance, value->GetType()); | |
968 ASSERT_EQ(id, dynamic_cast<DicomInstanceOperationValue&>(*value).GetId()); | |
969 | |
970 { | |
971 std::string content; | |
972 dynamic_cast<DicomInstanceOperationValue&>(*value).ReadDicom(content); | |
973 | |
974 ParsedDicomFile dicom(content); | |
975 ASSERT_TRUE(dicom.GetTagValue(content, DICOM_TAG_PATIENT_NAME)); | |
976 ASSERT_EQ("JODOGNE", content); | |
977 } | |
2651
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
978 } |
2655 | 979 |
980 | |
981 TEST_F(OrthancJobsSerialization, Operations) | |
982 { | |
983 std::string id; | |
984 ASSERT_TRUE(CreateInstance(id)); | |
985 | |
986 Json::Value s; | |
987 | |
2659 | 988 // DeleteResourceOperation |
989 | |
2655 | 990 { |
991 DeleteResourceOperation operation(GetContext()); | |
992 operation.Serialize(s); | |
993 } | |
994 | |
2659 | 995 OrthancJobUnserializer unserializer(GetContext()); |
2655 | 996 std::auto_ptr<IJobOperation> operation; |
2659 | 997 |
998 { | |
999 operation.reset(unserializer.UnserializeOperation(s)); | |
1000 | |
1001 ASSERT_THROW(dynamic_cast<LogJobOperation&>(*operation), std::bad_cast); | |
1002 dynamic_cast<DeleteResourceOperation&>(*operation); | |
1003 } | |
1004 | |
1005 // StorePeerOperation | |
1006 | |
1007 { | |
1008 WebServiceParameters peer; | |
1009 peer.SetUrl("http://localhost/"); | |
1010 peer.SetUsername("username"); | |
1011 peer.SetPassword("password"); | |
1012 peer.SetPkcs11Enabled(true); | |
1013 | |
1014 StorePeerOperation operation(peer); | |
1015 operation.Serialize(s); | |
1016 } | |
1017 | |
1018 { | |
1019 operation.reset(unserializer.UnserializeOperation(s)); | |
1020 | |
1021 const StorePeerOperation& tmp = dynamic_cast<StorePeerOperation&>(*operation); | |
1022 ASSERT_EQ("http://localhost/", tmp.GetPeer().GetUrl()); | |
1023 ASSERT_EQ("username", tmp.GetPeer().GetUsername()); | |
1024 ASSERT_EQ("password", tmp.GetPeer().GetPassword()); | |
1025 ASSERT_TRUE(tmp.GetPeer().IsPkcs11Enabled()); | |
1026 } | |
1027 | |
1028 // StoreScuOperation | |
2658 | 1029 |
2659 | 1030 { |
1031 RemoteModalityParameters modality; | |
1032 modality.SetApplicationEntityTitle("REMOTE"); | |
1033 modality.SetHost("192.168.1.1"); | |
1034 modality.SetPort(1000); | |
1035 modality.SetManufacturer(ModalityManufacturer_StoreScp); | |
1036 | |
1037 StoreScuOperation operation("TEST", modality); | |
1038 operation.Serialize(s); | |
1039 } | |
1040 | |
1041 { | |
1042 operation.reset(unserializer.UnserializeOperation(s)); | |
1043 | |
1044 const StoreScuOperation& tmp = dynamic_cast<StoreScuOperation&>(*operation); | |
1045 ASSERT_EQ("REMOTE", tmp.GetRemoteModality().GetApplicationEntityTitle()); | |
1046 ASSERT_EQ("192.168.1.1", tmp.GetRemoteModality().GetHost()); | |
1047 ASSERT_EQ(1000, tmp.GetRemoteModality().GetPort()); | |
1048 ASSERT_EQ(ModalityManufacturer_StoreScp, tmp.GetRemoteModality().GetManufacturer()); | |
1049 ASSERT_EQ("TEST", tmp.GetLocalAet()); | |
1050 } | |
2658 | 1051 |
2659 | 1052 // SystemCallOperation |
1053 | |
1054 { | |
1055 SystemCallOperation operation(std::string("echo")); | |
1056 operation.AddPreArgument("a"); | |
1057 operation.AddPreArgument("b"); | |
1058 operation.AddPostArgument("c"); | |
1059 operation.Serialize(s); | |
1060 } | |
2658 | 1061 |
2659 | 1062 { |
1063 operation.reset(unserializer.UnserializeOperation(s)); | |
1064 | |
1065 const SystemCallOperation& tmp = dynamic_cast<SystemCallOperation&>(*operation); | |
1066 ASSERT_EQ("echo", tmp.GetCommand()); | |
1067 ASSERT_EQ(2u, tmp.GetPreArgumentsCount()); | |
1068 ASSERT_EQ(1u, tmp.GetPostArgumentsCount()); | |
1069 ASSERT_EQ("a", tmp.GetPreArgument(0)); | |
1070 ASSERT_EQ("b", tmp.GetPreArgument(1)); | |
1071 ASSERT_EQ("c", tmp.GetPostArgument(0)); | |
1072 } | |
2658 | 1073 |
1074 // TODO : ModifyInstanceOperation | |
2659 | 1075 |
1076 /* | |
1077 { | |
1078 std::auto_ptr<DicomModification> modification(new DicomModification); | |
1079 | |
1080 ModifyInstanceOperation operation(GetContext(), RequestOrigin_Lua, modification.release()); | |
1081 operation.Serialize(s); | |
1082 } | |
1083 | |
1084 { | |
1085 operation.reset(unserializer.UnserializeOperation(s)); | |
1086 | |
1087 const ModifyInstanceOperation& tmp = dynamic_cast<ModifyInstanceOperation&>(*operation); | |
1088 ASSERT_EQ(RequestOrigin_Lua, tmp.GetRequestOrigin()); | |
1089 }*/ | |
2655 | 1090 } |
2658 | 1091 |
1092 | |
1093 TEST_F(OrthancJobsSerialization, Jobs) | |
1094 { | |
1095 // TODO : ArchiveJob | |
1096 | |
1097 // TODO : DicomModalityStoreJob | |
1098 | |
1099 // TODO : OrthancPeerStoreJob | |
1100 | |
1101 // TODO : ResourceModificationJob | |
1102 } |