Mercurial > hg > orthanc
annotate UnitTestsSources/MultiThreadingTests.cpp @ 4116:975f1f20995b Orthanc-1.4.2-fix-build
closing Orthanc-1.4.2-fix-build
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 07 Jul 2020 13:12:40 +0200 |
parents | 925d8dc03a23 |
children | ff0ed5ea9e4e |
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" |
2666
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
39 #include "../Core/Logging.h" |
2610
3ff4c50647ea
moving the old scheduler to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2606
diff
changeset
|
40 #include "../Core/MultiThreading/SharedMessageQueue.h" |
723 | 41 #include "../Core/OrthancException.h" |
2656
a6d3e45eeff5
SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2655
diff
changeset
|
42 #include "../Core/SerializationToolbox.h" |
2143
fd5875662670
creation of namespace SystemToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2140
diff
changeset
|
43 #include "../Core/SystemToolbox.h" |
723 | 44 #include "../Core/Toolbox.h" |
2651
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
45 #include "../OrthancServer/DatabaseWrapper.h" |
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
46 #include "../OrthancServer/ServerContext.h" |
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
47 #include "../OrthancServer/ServerJobs/LuaJobManager.h" |
2655 | 48 #include "../OrthancServer/ServerJobs/OrthancJobUnserializer.h" |
49 | |
50 #include "../Core/JobsEngine/Operations/JobOperationValues.h" | |
51 #include "../Core/JobsEngine/Operations/NullOperationValue.h" | |
52 #include "../Core/JobsEngine/Operations/StringOperationValue.h" | |
2651
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
53 #include "../OrthancServer/ServerJobs/Operations/DicomInstanceOperationValue.h" |
2655 | 54 |
55 #include "../Core/JobsEngine/Operations/LogJobOperation.h" | |
56 #include "../OrthancServer/ServerJobs/Operations/DeleteResourceOperation.h" | |
57 #include "../OrthancServer/ServerJobs/Operations/ModifyInstanceOperation.h" | |
58 #include "../OrthancServer/ServerJobs/Operations/StorePeerOperation.h" | |
59 #include "../OrthancServer/ServerJobs/Operations/StoreScuOperation.h" | |
60 #include "../OrthancServer/ServerJobs/Operations/SystemCallOperation.h" | |
61 | |
2663
228e2783ce83
some jobs might not be serializable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
62 #include "../OrthancServer/ServerJobs/ArchiveJob.h" |
2664
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
63 #include "../OrthancServer/ServerJobs/DicomModalityStoreJob.h" |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
64 #include "../OrthancServer/ServerJobs/OrthancPeerStoreJob.h" |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
65 #include "../OrthancServer/ServerJobs/ResourceModificationJob.h" |
2655 | 66 |
723 | 67 |
68 using namespace Orthanc; | |
69 | |
70 namespace | |
71 { | |
2652 | 72 class DummyJob : public IJob |
73 { | |
74 private: | |
75 bool fails_; | |
76 unsigned int count_; | |
77 unsigned int steps_; | |
78 | |
79 public: | |
80 DummyJob() : | |
81 fails_(false), | |
82 count_(0), | |
83 steps_(4) | |
84 { | |
85 } | |
86 | |
87 explicit DummyJob(bool fails) : | |
88 fails_(fails), | |
89 count_(0), | |
90 steps_(4) | |
91 { | |
92 } | |
93 | |
94 virtual void Start() | |
95 { | |
96 } | |
97 | |
2812
ea7aea6f6a95
improved naming of methods in IJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2811
diff
changeset
|
98 virtual void Reset() |
2652 | 99 { |
100 } | |
101 | |
2812
ea7aea6f6a95
improved naming of methods in IJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2811
diff
changeset
|
102 virtual JobStepResult Step() |
2652 | 103 { |
104 if (fails_) | |
105 { | |
106 return JobStepResult::Failure(ErrorCode_ParameterOutOfRange); | |
107 } | |
108 else if (count_ == steps_ - 1) | |
109 { | |
110 return JobStepResult::Success(); | |
111 } | |
112 else | |
113 { | |
114 count_++; | |
115 return JobStepResult::Continue(); | |
116 } | |
117 } | |
118 | |
2812
ea7aea6f6a95
improved naming of methods in IJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2811
diff
changeset
|
119 virtual void Stop(JobStopReason reason) |
2652 | 120 { |
121 } | |
122 | |
123 virtual float GetProgress() | |
124 { | |
125 return static_cast<float>(count_) / static_cast<float>(steps_ - 1); | |
126 } | |
127 | |
128 virtual void GetJobType(std::string& type) | |
129 { | |
130 type = "DummyJob"; | |
131 } | |
132 | |
2663
228e2783ce83
some jobs might not be serializable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
133 virtual bool Serialize(Json::Value& value) |
2652 | 134 { |
2667
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2666
diff
changeset
|
135 value = Json::objectValue; |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2666
diff
changeset
|
136 value["Type"] = "DummyJob"; |
2663
228e2783ce83
some jobs might not be serializable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
137 return true; |
2652 | 138 } |
139 | |
140 virtual void GetPublicContent(Json::Value& value) | |
141 { | |
142 value["hello"] = "world"; | |
143 } | |
144 }; | |
145 | |
146 | |
147 class DummyInstancesJob : public SetOfInstancesJob | |
148 { | |
149 protected: | |
150 virtual bool HandleInstance(const std::string& instance) | |
151 { | |
2657
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
152 return (instance != "nope"); |
2652 | 153 } |
154 | |
155 public: | |
156 DummyInstancesJob() | |
157 { | |
158 } | |
159 | |
160 DummyInstancesJob(const Json::Value& value) : | |
161 SetOfInstancesJob(value) | |
162 { | |
163 } | |
164 | |
2812
ea7aea6f6a95
improved naming of methods in IJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2811
diff
changeset
|
165 virtual void Stop(JobStopReason reason) |
2652 | 166 { |
167 } | |
168 | |
169 virtual void GetJobType(std::string& s) | |
170 { | |
171 s = "DummyInstancesJob"; | |
172 } | |
173 }; | |
174 | |
175 | |
176 class DummyUnserializer : public GenericJobUnserializer | |
177 { | |
178 public: | |
179 virtual IJob* UnserializeJob(const Json::Value& value) | |
180 { | |
2656
a6d3e45eeff5
SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2655
diff
changeset
|
181 if (SerializationToolbox::ReadString(value, "Type") == "DummyInstancesJob") |
2652 | 182 { |
183 return new DummyInstancesJob(value); | |
184 } | |
2667
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2666
diff
changeset
|
185 else if (SerializationToolbox::ReadString(value, "Type") == "DummyJob") |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2666
diff
changeset
|
186 { |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2666
diff
changeset
|
187 return new DummyJob; |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2666
diff
changeset
|
188 } |
2652 | 189 else |
190 { | |
191 return GenericJobUnserializer::UnserializeJob(value); | |
192 } | |
193 } | |
194 }; | |
195 | |
196 | |
1396
ac4efabeb80c
Migration of the orthanc-client as a separate project
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1304
diff
changeset
|
197 class DynamicInteger : public IDynamicObject |
723 | 198 { |
199 private: | |
200 int value_; | |
201 std::set<int>& target_; | |
202 | |
203 public: | |
204 DynamicInteger(int value, std::set<int>& target) : | |
205 value_(value), target_(target) | |
206 { | |
207 } | |
208 | |
209 int GetValue() const | |
210 { | |
211 return value_; | |
212 } | |
213 }; | |
214 } | |
215 | |
216 | |
217 TEST(MultiThreading, SharedMessageQueueBasic) | |
218 { | |
219 std::set<int> s; | |
220 | |
221 SharedMessageQueue q; | |
222 ASSERT_TRUE(q.WaitEmpty(0)); | |
223 q.Enqueue(new DynamicInteger(10, s)); | |
224 ASSERT_FALSE(q.WaitEmpty(1)); | |
225 q.Enqueue(new DynamicInteger(20, s)); | |
226 q.Enqueue(new DynamicInteger(30, s)); | |
227 q.Enqueue(new DynamicInteger(40, s)); | |
228 | |
229 std::auto_ptr<DynamicInteger> i; | |
230 i.reset(dynamic_cast<DynamicInteger*>(q.Dequeue(1))); ASSERT_EQ(10, i->GetValue()); | |
231 i.reset(dynamic_cast<DynamicInteger*>(q.Dequeue(1))); ASSERT_EQ(20, i->GetValue()); | |
232 i.reset(dynamic_cast<DynamicInteger*>(q.Dequeue(1))); ASSERT_EQ(30, i->GetValue()); | |
233 ASSERT_FALSE(q.WaitEmpty(1)); | |
234 i.reset(dynamic_cast<DynamicInteger*>(q.Dequeue(1))); ASSERT_EQ(40, i->GetValue()); | |
235 ASSERT_TRUE(q.WaitEmpty(0)); | |
236 ASSERT_EQ(NULL, q.Dequeue(1)); | |
237 } | |
238 | |
239 | |
240 TEST(MultiThreading, SharedMessageQueueClean) | |
241 { | |
242 std::set<int> s; | |
243 | |
244 try | |
245 { | |
246 SharedMessageQueue q; | |
247 q.Enqueue(new DynamicInteger(10, s)); | |
248 q.Enqueue(new DynamicInteger(20, s)); | |
1583
9ea3d082b064
got rid of custom exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1582
diff
changeset
|
249 throw OrthancException(ErrorCode_InternalError); |
723 | 250 } |
251 catch (OrthancException&) | |
252 { | |
253 } | |
254 } | |
255 | |
256 | |
769
3f946e5c3802
ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
760
diff
changeset
|
257 |
3f946e5c3802
ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
760
diff
changeset
|
258 |
2652 | 259 static bool CheckState(JobsRegistry& registry, |
260 const std::string& id, | |
261 JobState state) | |
2557 | 262 { |
2652 | 263 JobState s; |
2558 | 264 if (registry.GetState(s, id)) |
2557 | 265 { |
266 return state == s; | |
267 } | |
268 else | |
269 { | |
270 return false; | |
271 } | |
272 } | |
273 | |
274 | |
2652 | 275 static bool CheckErrorCode(JobsRegistry& registry, |
2581
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
276 const std::string& id, |
2652 | 277 ErrorCode code) |
2581
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
278 { |
2652 | 279 JobInfo s; |
2581
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
280 if (registry.GetJobInfo(s, id)) |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
281 { |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
282 return code == s.GetStatus().GetErrorCode(); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
283 } |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
284 else |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
285 { |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
286 return false; |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
287 } |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
288 } |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
289 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
290 |
2558 | 291 TEST(JobsRegistry, Priority) |
2557 | 292 { |
2558 | 293 JobsRegistry registry; |
2557 | 294 |
295 std::string i1, i2, i3, i4; | |
2558 | 296 registry.Submit(i1, new DummyJob(), 10); |
297 registry.Submit(i2, new DummyJob(), 30); | |
298 registry.Submit(i3, new DummyJob(), 20); | |
299 registry.Submit(i4, new DummyJob(), 5); | |
2557 | 300 |
2558 | 301 registry.SetMaxCompletedJobs(2); |
2557 | 302 |
303 std::set<std::string> id; | |
2558 | 304 registry.ListJobs(id); |
2557 | 305 |
306 ASSERT_EQ(4u, id.size()); | |
307 ASSERT_TRUE(id.find(i1) != id.end()); | |
308 ASSERT_TRUE(id.find(i2) != id.end()); | |
309 ASSERT_TRUE(id.find(i3) != id.end()); | |
310 ASSERT_TRUE(id.find(i4) != id.end()); | |
311 | |
2652 | 312 ASSERT_TRUE(CheckState(registry, i2, JobState_Pending)); |
2557 | 313 |
314 { | |
2558 | 315 JobsRegistry::RunningJob job(registry, 0); |
2557 | 316 ASSERT_TRUE(job.IsValid()); |
317 ASSERT_EQ(30, job.GetPriority()); | |
318 ASSERT_EQ(i2, job.GetId()); | |
319 | |
2652 | 320 ASSERT_TRUE(CheckState(registry, i2, JobState_Running)); |
2557 | 321 } |
322 | |
2652 | 323 ASSERT_TRUE(CheckState(registry, i2, JobState_Failure)); |
324 ASSERT_TRUE(CheckState(registry, i3, JobState_Pending)); | |
2557 | 325 |
326 { | |
2558 | 327 JobsRegistry::RunningJob job(registry, 0); |
2557 | 328 ASSERT_TRUE(job.IsValid()); |
329 ASSERT_EQ(20, job.GetPriority()); | |
330 ASSERT_EQ(i3, job.GetId()); | |
331 | |
332 job.MarkSuccess(); | |
333 | |
2652 | 334 ASSERT_TRUE(CheckState(registry, i3, JobState_Running)); |
2557 | 335 } |
336 | |
2652 | 337 ASSERT_TRUE(CheckState(registry, i3, JobState_Success)); |
2557 | 338 |
339 { | |
2558 | 340 JobsRegistry::RunningJob job(registry, 0); |
2557 | 341 ASSERT_TRUE(job.IsValid()); |
342 ASSERT_EQ(10, job.GetPriority()); | |
343 ASSERT_EQ(i1, job.GetId()); | |
344 } | |
345 | |
346 { | |
2558 | 347 JobsRegistry::RunningJob job(registry, 0); |
2557 | 348 ASSERT_TRUE(job.IsValid()); |
349 ASSERT_EQ(5, job.GetPriority()); | |
350 ASSERT_EQ(i4, job.GetId()); | |
351 } | |
352 | |
353 { | |
2558 | 354 JobsRegistry::RunningJob job(registry, 1); |
2557 | 355 ASSERT_FALSE(job.IsValid()); |
356 } | |
357 | |
2652 | 358 JobState s; |
2558 | 359 ASSERT_TRUE(registry.GetState(s, i1)); |
360 ASSERT_FALSE(registry.GetState(s, i2)); // Removed because oldest | |
361 ASSERT_FALSE(registry.GetState(s, i3)); // Removed because second oldest | |
362 ASSERT_TRUE(registry.GetState(s, i4)); | |
2557 | 363 |
2558 | 364 registry.SetMaxCompletedJobs(1); // (*) |
365 ASSERT_FALSE(registry.GetState(s, i1)); // Just discarded by (*) | |
366 ASSERT_TRUE(registry.GetState(s, i4)); | |
2557 | 367 } |
368 | |
369 | |
2558 | 370 TEST(JobsRegistry, Simultaneous) |
2557 | 371 { |
2558 | 372 JobsRegistry registry; |
373 | |
374 std::string i1, i2; | |
375 registry.Submit(i1, new DummyJob(), 20); | |
376 registry.Submit(i2, new DummyJob(), 10); | |
377 | |
2652 | 378 ASSERT_TRUE(CheckState(registry, i1, JobState_Pending)); |
379 ASSERT_TRUE(CheckState(registry, i2, JobState_Pending)); | |
2558 | 380 |
381 { | |
382 JobsRegistry::RunningJob job1(registry, 0); | |
383 JobsRegistry::RunningJob job2(registry, 0); | |
384 | |
385 ASSERT_TRUE(job1.IsValid()); | |
386 ASSERT_TRUE(job2.IsValid()); | |
387 | |
388 job1.MarkFailure(); | |
389 job2.MarkSuccess(); | |
390 | |
2652 | 391 ASSERT_TRUE(CheckState(registry, i1, JobState_Running)); |
392 ASSERT_TRUE(CheckState(registry, i2, JobState_Running)); | |
2558 | 393 } |
394 | |
2652 | 395 ASSERT_TRUE(CheckState(registry, i1, JobState_Failure)); |
396 ASSERT_TRUE(CheckState(registry, i2, JobState_Success)); | |
2558 | 397 } |
398 | |
399 | |
400 TEST(JobsRegistry, Resubmit) | |
401 { | |
402 JobsRegistry registry; | |
2557 | 403 |
404 std::string id; | |
2558 | 405 registry.Submit(id, new DummyJob(), 10); |
2557 | 406 |
2652 | 407 ASSERT_TRUE(CheckState(registry, id, JobState_Pending)); |
2557 | 408 |
2558 | 409 registry.Resubmit(id); |
2652 | 410 ASSERT_TRUE(CheckState(registry, id, JobState_Pending)); |
2557 | 411 |
412 { | |
2558 | 413 JobsRegistry::RunningJob job(registry, 0); |
2557 | 414 ASSERT_TRUE(job.IsValid()); |
415 job.MarkFailure(); | |
416 | |
2652 | 417 ASSERT_TRUE(CheckState(registry, id, JobState_Running)); |
2557 | 418 |
2558 | 419 registry.Resubmit(id); |
2652 | 420 ASSERT_TRUE(CheckState(registry, id, JobState_Running)); |
2557 | 421 } |
422 | |
2652 | 423 ASSERT_TRUE(CheckState(registry, id, JobState_Failure)); |
2557 | 424 |
2558 | 425 registry.Resubmit(id); |
2652 | 426 ASSERT_TRUE(CheckState(registry, id, JobState_Pending)); |
2557 | 427 |
428 { | |
2558 | 429 JobsRegistry::RunningJob job(registry, 0); |
2557 | 430 ASSERT_TRUE(job.IsValid()); |
431 ASSERT_EQ(id, job.GetId()); | |
432 | |
433 job.MarkSuccess(); | |
2652 | 434 ASSERT_TRUE(CheckState(registry, id, JobState_Running)); |
2558 | 435 } |
436 | |
2652 | 437 ASSERT_TRUE(CheckState(registry, id, JobState_Success)); |
2558 | 438 |
439 registry.Resubmit(id); | |
2652 | 440 ASSERT_TRUE(CheckState(registry, id, JobState_Success)); |
2558 | 441 } |
442 | |
443 | |
444 TEST(JobsRegistry, Retry) | |
445 { | |
446 JobsRegistry registry; | |
447 | |
448 std::string id; | |
449 registry.Submit(id, new DummyJob(), 10); | |
450 | |
2652 | 451 ASSERT_TRUE(CheckState(registry, id, JobState_Pending)); |
2558 | 452 |
453 { | |
454 JobsRegistry::RunningJob job(registry, 0); | |
455 ASSERT_TRUE(job.IsValid()); | |
456 job.MarkRetry(0); | |
457 | |
2652 | 458 ASSERT_TRUE(CheckState(registry, id, JobState_Running)); |
2558 | 459 } |
460 | |
2652 | 461 ASSERT_TRUE(CheckState(registry, id, JobState_Retry)); |
2558 | 462 |
463 registry.Resubmit(id); | |
2652 | 464 ASSERT_TRUE(CheckState(registry, id, JobState_Retry)); |
2558 | 465 |
466 registry.ScheduleRetries(); | |
2652 | 467 ASSERT_TRUE(CheckState(registry, id, JobState_Pending)); |
2558 | 468 |
469 { | |
470 JobsRegistry::RunningJob job(registry, 0); | |
471 ASSERT_TRUE(job.IsValid()); | |
472 job.MarkSuccess(); | |
473 | |
2652 | 474 ASSERT_TRUE(CheckState(registry, id, JobState_Running)); |
2557 | 475 } |
476 | |
2652 | 477 ASSERT_TRUE(CheckState(registry, id, JobState_Success)); |
2558 | 478 } |
479 | |
480 | |
481 TEST(JobsRegistry, PausePending) | |
482 { | |
483 JobsRegistry registry; | |
484 | |
485 std::string id; | |
486 registry.Submit(id, new DummyJob(), 10); | |
487 | |
2652 | 488 ASSERT_TRUE(CheckState(registry, id, JobState_Pending)); |
2558 | 489 |
490 registry.Pause(id); | |
2652 | 491 ASSERT_TRUE(CheckState(registry, id, JobState_Paused)); |
2558 | 492 |
493 registry.Pause(id); | |
2652 | 494 ASSERT_TRUE(CheckState(registry, id, JobState_Paused)); |
2558 | 495 |
496 registry.Resubmit(id); | |
2652 | 497 ASSERT_TRUE(CheckState(registry, id, JobState_Paused)); |
2558 | 498 |
499 registry.Resume(id); | |
2652 | 500 ASSERT_TRUE(CheckState(registry, id, JobState_Pending)); |
2557 | 501 } |
2558 | 502 |
503 | |
504 TEST(JobsRegistry, PauseRunning) | |
505 { | |
506 JobsRegistry registry; | |
507 | |
508 std::string id; | |
509 registry.Submit(id, new DummyJob(), 10); | |
510 | |
2652 | 511 ASSERT_TRUE(CheckState(registry, id, JobState_Pending)); |
2558 | 512 |
513 { | |
514 JobsRegistry::RunningJob job(registry, 0); | |
515 ASSERT_TRUE(job.IsValid()); | |
516 | |
517 registry.Resubmit(id); | |
2562 | 518 job.MarkPause(); |
2652 | 519 ASSERT_TRUE(CheckState(registry, id, JobState_Running)); |
2558 | 520 } |
521 | |
2652 | 522 ASSERT_TRUE(CheckState(registry, id, JobState_Paused)); |
2558 | 523 |
524 registry.Resubmit(id); | |
2652 | 525 ASSERT_TRUE(CheckState(registry, id, JobState_Paused)); |
2558 | 526 |
527 registry.Resume(id); | |
2652 | 528 ASSERT_TRUE(CheckState(registry, id, JobState_Pending)); |
2558 | 529 |
530 { | |
531 JobsRegistry::RunningJob job(registry, 0); | |
532 ASSERT_TRUE(job.IsValid()); | |
533 | |
534 job.MarkSuccess(); | |
2652 | 535 ASSERT_TRUE(CheckState(registry, id, JobState_Running)); |
2558 | 536 } |
537 | |
2652 | 538 ASSERT_TRUE(CheckState(registry, id, JobState_Success)); |
2558 | 539 } |
540 | |
541 | |
542 TEST(JobsRegistry, PauseRetry) | |
543 { | |
544 JobsRegistry registry; | |
545 | |
546 std::string id; | |
547 registry.Submit(id, new DummyJob(), 10); | |
548 | |
2652 | 549 ASSERT_TRUE(CheckState(registry, id, JobState_Pending)); |
2558 | 550 |
551 { | |
552 JobsRegistry::RunningJob job(registry, 0); | |
553 ASSERT_TRUE(job.IsValid()); | |
554 | |
555 job.MarkRetry(0); | |
2652 | 556 ASSERT_TRUE(CheckState(registry, id, JobState_Running)); |
2558 | 557 } |
558 | |
2652 | 559 ASSERT_TRUE(CheckState(registry, id, JobState_Retry)); |
2558 | 560 |
561 registry.Pause(id); | |
2652 | 562 ASSERT_TRUE(CheckState(registry, id, JobState_Paused)); |
2558 | 563 |
564 registry.Resume(id); | |
2652 | 565 ASSERT_TRUE(CheckState(registry, id, JobState_Pending)); |
2558 | 566 |
567 { | |
568 JobsRegistry::RunningJob job(registry, 0); | |
569 ASSERT_TRUE(job.IsValid()); | |
570 | |
571 job.MarkSuccess(); | |
2652 | 572 ASSERT_TRUE(CheckState(registry, id, JobState_Running)); |
2558 | 573 } |
574 | |
2652 | 575 ASSERT_TRUE(CheckState(registry, id, JobState_Success)); |
2558 | 576 } |
2565 | 577 |
578 | |
2581
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
579 TEST(JobsRegistry, Cancel) |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
580 { |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
581 JobsRegistry registry; |
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 std::string id; |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
584 registry.Submit(id, new DummyJob(), 10); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
585 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
586 ASSERT_FALSE(registry.Cancel("nope")); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
587 |
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_Success)); |
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 ASSERT_TRUE(registry.Cancel(id)); |
2652 | 592 ASSERT_TRUE(CheckState(registry, id, JobState_Failure)); |
2581
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
593 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_CanceledJob)); |
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(registry.Cancel(id)); |
2652 | 596 ASSERT_TRUE(CheckState(registry, id, JobState_Failure)); |
2581
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
597 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_CanceledJob)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
598 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
599 ASSERT_TRUE(registry.Resubmit(id)); |
2652 | 600 ASSERT_TRUE(CheckState(registry, id, JobState_Pending)); |
2581
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
601 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_CanceledJob)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
602 |
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 JobsRegistry::RunningJob job(registry, 0); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
605 ASSERT_TRUE(job.IsValid()); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
606 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
607 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_Success)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
608 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
609 job.MarkSuccess(); |
2652 | 610 ASSERT_TRUE(CheckState(registry, id, JobState_Running)); |
2581
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
611 } |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
612 |
2652 | 613 ASSERT_TRUE(CheckState(registry, id, JobState_Success)); |
2581
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
614 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_Success)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
615 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
616 ASSERT_TRUE(registry.Cancel(id)); |
2652 | 617 ASSERT_TRUE(CheckState(registry, id, JobState_Success)); |
2581
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
618 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_Success)); |
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 registry.Submit(id, new DummyJob(), 10); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
621 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
622 { |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
623 JobsRegistry::RunningJob job(registry, 0); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
624 ASSERT_TRUE(job.IsValid()); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
625 ASSERT_EQ(id, job.GetId()); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
626 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
627 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_Success)); |
2652 | 628 ASSERT_TRUE(CheckState(registry, id, JobState_Running)); |
2581
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
629 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
630 job.MarkCanceled(); |
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 |
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 ASSERT_TRUE(registry.Pause(id)); |
2652 | 641 ASSERT_TRUE(CheckState(registry, id, JobState_Paused)); |
2581
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
642 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_CanceledJob)); |
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(registry.Cancel(id)); |
2652 | 645 ASSERT_TRUE(CheckState(registry, id, JobState_Failure)); |
2581
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
646 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_CanceledJob)); |
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 ASSERT_TRUE(registry.Resubmit(id)); |
2652 | 649 ASSERT_TRUE(CheckState(registry, id, JobState_Pending)); |
2581
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
650 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_CanceledJob)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
651 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
652 { |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
653 JobsRegistry::RunningJob job(registry, 0); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
654 ASSERT_TRUE(job.IsValid()); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
655 ASSERT_EQ(id, job.GetId()); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
656 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
657 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_Success)); |
2652 | 658 ASSERT_TRUE(CheckState(registry, id, JobState_Running)); |
2581
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 job.MarkRetry(500); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
661 } |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
662 |
2652 | 663 ASSERT_TRUE(CheckState(registry, id, JobState_Retry)); |
2581
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
664 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_Success)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
665 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
666 ASSERT_TRUE(registry.Cancel(id)); |
2652 | 667 ASSERT_TRUE(CheckState(registry, id, JobState_Failure)); |
2581
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
668 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_CanceledJob)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
669 } |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
670 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
671 |
2570
2e879c796ec7
JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
672 |
2599 | 673 TEST(JobsEngine, SubmitAndWait) |
2565 | 674 { |
675 JobsEngine engine; | |
2665
389d050a2e66
fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
676 engine.SetThreadSleep(10); |
2565 | 677 engine.SetWorkersCount(3); |
678 engine.Start(); | |
679 | |
2599 | 680 ASSERT_TRUE(engine.GetRegistry().SubmitAndWait(new DummyJob(), rand() % 10)); |
681 ASSERT_FALSE(engine.GetRegistry().SubmitAndWait(new DummyJob(true), rand() % 10)); | |
682 | |
683 engine.Stop(); | |
684 } | |
685 | |
686 | |
2600
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
687 TEST(JobsEngine, DISABLED_SequenceOfOperationsJob) |
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 JobsEngine engine; |
2665
389d050a2e66
fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
690 engine.SetThreadSleep(10); |
2600
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
691 engine.SetWorkersCount(3); |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
692 engine.Start(); |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
693 |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
694 std::string id; |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
695 SequenceOfOperationsJob* job = NULL; |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
696 |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
697 { |
2601 | 698 std::auto_ptr<SequenceOfOperationsJob> a(new SequenceOfOperationsJob); |
2600
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
699 job = a.get(); |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
700 engine.GetRegistry().Submit(id, a.release(), 0); |
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 |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
703 boost::this_thread::sleep(boost::posix_time::milliseconds(500)); |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
704 |
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 SequenceOfOperationsJob::Lock lock(*job); |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
707 size_t i = lock.AddOperation(new LogJobOperation); |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
708 size_t j = lock.AddOperation(new LogJobOperation); |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
709 size_t k = lock.AddOperation(new LogJobOperation); |
2730 | 710 |
711 StringOperationValue a("Hello"); | |
712 StringOperationValue b("World"); | |
713 lock.AddInput(i, a); | |
714 lock.AddInput(i, b); | |
715 | |
2600
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
716 lock.Connect(i, j); |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
717 lock.Connect(j, k); |
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 |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
720 boost::this_thread::sleep(boost::posix_time::milliseconds(2000)); |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
721 |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
722 engine.Stop(); |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
723 |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
724 } |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
725 |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
726 |
2621
83ac5a05ce84
primitives for unserializing jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2610
diff
changeset
|
727 TEST(JobsEngine, DISABLED_Lua) |
2600
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
728 { |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
729 JobsEngine engine; |
2665
389d050a2e66
fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
730 engine.SetThreadSleep(10); |
2600
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
731 engine.SetWorkersCount(2); |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
732 engine.Start(); |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
733 |
2604
76ef12fa136c
fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2603
diff
changeset
|
734 LuaJobManager lua; |
2600
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
735 lua.SetMaxOperationsPerJob(5); |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
736 lua.SetTrailingOperationTimeout(200); |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
737 |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
738 for (size_t i = 0; i < 30; i++) |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
739 { |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
740 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
|
741 |
76ef12fa136c
fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2603
diff
changeset
|
742 LuaJobManager::Lock lock(lua, engine); |
76ef12fa136c
fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2603
diff
changeset
|
743 size_t a = lock.AddLogOperation(); |
76ef12fa136c
fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2603
diff
changeset
|
744 size_t b = lock.AddLogOperation(); |
2606
f2b9d3256060
SystemCallOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2604
diff
changeset
|
745 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
|
746 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
|
747 lock.AddNullInput(a); |
76ef12fa136c
fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2603
diff
changeset
|
748 lock.Connect(a, b); |
2606
f2b9d3256060
SystemCallOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2604
diff
changeset
|
749 lock.Connect(a, c); |
2600
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
750 } |
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 boost::this_thread::sleep(boost::posix_time::milliseconds(2000)); |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
753 |
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
754 engine.Stop(); |
2651
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
755 } |
2600
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
756 |
2651
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
757 |
2666
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
758 static bool CheckSameJson(const Json::Value& a, |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
759 const Json::Value& b) |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
760 { |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
761 std::string s = a.toStyledString(); |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
762 std::string t = b.toStyledString(); |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
763 |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
764 if (s == t) |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
765 { |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
766 return true; |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
767 } |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
768 else |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
769 { |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
770 LOG(ERROR) << "Expected serialization: " << s; |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
771 LOG(ERROR) << "Actual serialization: " << t; |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
772 return false; |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
773 } |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
774 } |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
775 |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
776 |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
777 static bool CheckIdempotentSerialization(IJobUnserializer& unserializer, |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
778 IJob& job) |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
779 { |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
780 Json::Value a = 42; |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
781 |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
782 if (!job.Serialize(a)) |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
783 { |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
784 return false; |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
785 } |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
786 else |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
787 { |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
788 std::auto_ptr<IJob> unserialized(unserializer.UnserializeJob(a)); |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
789 |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
790 Json::Value b = 43; |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
791 if (unserialized->Serialize(b)) |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
792 { |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
793 return CheckSameJson(a, b); |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
794 } |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
795 else |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
796 { |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
797 return false; |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
798 } |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
799 } |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
800 } |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
801 |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
802 |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
803 static bool CheckIdempotentSerialization(IJobUnserializer& unserializer, |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
804 IJobOperation& operation) |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
805 { |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
806 Json::Value a = 42; |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
807 operation.Serialize(a); |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
808 |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
809 std::auto_ptr<IJobOperation> unserialized(unserializer.UnserializeOperation(a)); |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
810 |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
811 Json::Value b = 43; |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
812 unserialized->Serialize(b); |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
813 |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
814 return CheckSameJson(a, b); |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
815 } |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
816 |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
817 |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
818 static bool CheckIdempotentSerialization(IJobUnserializer& unserializer, |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
819 JobOperationValue& value) |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
820 { |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
821 Json::Value a = 42; |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
822 value.Serialize(a); |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
823 |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
824 std::auto_ptr<JobOperationValue> unserialized(unserializer.UnserializeValue(a)); |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
825 |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
826 Json::Value b = 43; |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
827 unserialized->Serialize(b); |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
828 |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
829 return CheckSameJson(a, b); |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
830 } |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
831 |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
832 |
2655 | 833 TEST(JobsSerialization, BadFileFormat) |
834 { | |
835 GenericJobUnserializer unserializer; | |
836 | |
837 Json::Value s; | |
838 | |
839 s = Json::objectValue; | |
840 ASSERT_THROW(unserializer.UnserializeValue(s), OrthancException); | |
841 ASSERT_THROW(unserializer.UnserializeJob(s), OrthancException); | |
842 ASSERT_THROW(unserializer.UnserializeOperation(s), OrthancException); | |
843 | |
844 s = Json::arrayValue; | |
845 ASSERT_THROW(unserializer.UnserializeValue(s), OrthancException); | |
846 ASSERT_THROW(unserializer.UnserializeJob(s), OrthancException); | |
847 ASSERT_THROW(unserializer.UnserializeOperation(s), OrthancException); | |
848 | |
849 s = "hello"; | |
850 ASSERT_THROW(unserializer.UnserializeValue(s), OrthancException); | |
851 ASSERT_THROW(unserializer.UnserializeJob(s), OrthancException); | |
852 ASSERT_THROW(unserializer.UnserializeOperation(s), OrthancException); | |
853 | |
854 s = 42; | |
855 ASSERT_THROW(unserializer.UnserializeValue(s), OrthancException); | |
856 ASSERT_THROW(unserializer.UnserializeJob(s), OrthancException); | |
857 ASSERT_THROW(unserializer.UnserializeOperation(s), OrthancException); | |
858 } | |
859 | |
860 | |
2657
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
861 TEST(JobsSerialization, JobOperationValues) |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
862 { |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
863 Json::Value s; |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
864 |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
865 { |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
866 JobOperationValues values; |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
867 values.Append(new NullOperationValue); |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
868 values.Append(new StringOperationValue("hello")); |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
869 values.Append(new StringOperationValue("world")); |
2665
389d050a2e66
fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
870 |
389d050a2e66
fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
871 s = 42; |
2657
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
872 values.Serialize(s); |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
873 } |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
874 |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
875 { |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
876 GenericJobUnserializer unserializer; |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
877 std::auto_ptr<JobOperationValues> values(JobOperationValues::Unserialize(unserializer, s)); |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
878 ASSERT_EQ(3u, values->GetSize()); |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
879 ASSERT_EQ(JobOperationValue::Type_Null, values->GetValue(0).GetType()); |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
880 ASSERT_EQ(JobOperationValue::Type_String, values->GetValue(1).GetType()); |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
881 ASSERT_EQ(JobOperationValue::Type_String, values->GetValue(2).GetType()); |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
882 |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
883 ASSERT_EQ("hello", dynamic_cast<const StringOperationValue&>(values->GetValue(1)).GetContent()); |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
884 ASSERT_EQ("world", dynamic_cast<const StringOperationValue&>(values->GetValue(2)).GetContent()); |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
885 } |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
886 } |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
887 |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
888 |
2651
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
889 TEST(JobsSerialization, GenericValues) |
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
890 { |
2666
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
891 GenericJobUnserializer unserializer; |
2651
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
892 Json::Value s; |
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
893 |
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
894 { |
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
895 NullOperationValue null; |
2665
389d050a2e66
fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
896 |
2666
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
897 ASSERT_TRUE(CheckIdempotentSerialization(unserializer, null)); |
2651
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
898 null.Serialize(s); |
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
899 } |
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
900 |
2652 | 901 ASSERT_THROW(unserializer.UnserializeJob(s), OrthancException); |
902 ASSERT_THROW(unserializer.UnserializeOperation(s), OrthancException); | |
2655 | 903 |
904 std::auto_ptr<JobOperationValue> value; | |
2651
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
905 value.reset(unserializer.UnserializeValue(s)); |
2652 | 906 |
2651
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
907 ASSERT_EQ(JobOperationValue::Type_Null, value->GetType()); |
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
908 |
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
909 { |
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
910 StringOperationValue str("Hello"); |
2665
389d050a2e66
fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
911 |
2666
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
912 ASSERT_TRUE(CheckIdempotentSerialization(unserializer, str)); |
2651
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
913 str.Serialize(s); |
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
914 } |
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
915 |
2652 | 916 ASSERT_THROW(unserializer.UnserializeJob(s), OrthancException); |
917 ASSERT_THROW(unserializer.UnserializeOperation(s), OrthancException); | |
2651
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
918 value.reset(unserializer.UnserializeValue(s)); |
2652 | 919 |
2651
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
920 ASSERT_EQ(JobOperationValue::Type_String, value->GetType()); |
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
921 ASSERT_EQ("Hello", dynamic_cast<StringOperationValue&>(*value).GetContent()); |
2600
140a539b4eba
SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2599
diff
changeset
|
922 } |
2651
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
923 |
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
924 |
2655 | 925 TEST(JobsSerialization, GenericOperations) |
926 { | |
2666
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
927 DummyUnserializer unserializer; |
2655 | 928 Json::Value s; |
929 | |
930 { | |
931 LogJobOperation operation; | |
2665
389d050a2e66
fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
932 |
2666
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
933 ASSERT_TRUE(CheckIdempotentSerialization(unserializer, operation)); |
2655 | 934 operation.Serialize(s); |
935 } | |
936 | |
937 ASSERT_THROW(unserializer.UnserializeJob(s), OrthancException); | |
938 ASSERT_THROW(unserializer.UnserializeValue(s), OrthancException); | |
939 | |
940 { | |
941 std::auto_ptr<IJobOperation> operation; | |
942 operation.reset(unserializer.UnserializeOperation(s)); | |
943 | |
2657
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
944 // Make sure that we have indeed unserialized a log operation |
2731 | 945 Json::Value dummy; |
946 ASSERT_THROW(dynamic_cast<DeleteResourceOperation&>(*operation).Serialize(dummy), std::bad_cast); | |
947 dynamic_cast<LogJobOperation&>(*operation).Serialize(dummy); | |
2655 | 948 } |
949 } | |
950 | |
951 | |
952 TEST(JobsSerialization, GenericJobs) | |
953 { | |
2652 | 954 Json::Value s; |
955 | |
2658 | 956 // This tests SetOfInstancesJob |
957 | |
2652 | 958 { |
959 DummyInstancesJob job; | |
960 job.SetDescription("description"); | |
2657
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
961 job.AddInstance("hello"); |
2652 | 962 job.AddInstance("nope"); |
2657
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
963 job.AddInstance("world"); |
2652 | 964 job.SetPermissive(true); |
2812
ea7aea6f6a95
improved naming of methods in IJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2811
diff
changeset
|
965 ASSERT_THROW(job.Step(), OrthancException); // Not started yet |
2657
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
966 job.Start(); |
2812
ea7aea6f6a95
improved naming of methods in IJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2811
diff
changeset
|
967 job.Step(); |
ea7aea6f6a95
improved naming of methods in IJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2811
diff
changeset
|
968 job.Step(); |
2665
389d050a2e66
fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
969 |
2666
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
970 { |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
971 DummyUnserializer unserializer; |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
972 ASSERT_TRUE(CheckIdempotentSerialization(unserializer, job)); |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
973 } |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
974 |
2663
228e2783ce83
some jobs might not be serializable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
975 ASSERT_TRUE(job.Serialize(s)); |
2652 | 976 } |
977 | |
2655 | 978 { |
979 DummyUnserializer unserializer; | |
980 ASSERT_THROW(unserializer.UnserializeValue(s), OrthancException); | |
981 ASSERT_THROW(unserializer.UnserializeOperation(s), OrthancException); | |
2652 | 982 |
2655 | 983 std::auto_ptr<IJob> job; |
984 job.reset(unserializer.UnserializeJob(s)); | |
2657
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
985 |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
986 const DummyInstancesJob& tmp = dynamic_cast<const DummyInstancesJob&>(*job); |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
987 ASSERT_FALSE(tmp.IsStarted()); |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
988 ASSERT_TRUE(tmp.IsPermissive()); |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
989 ASSERT_EQ("description", tmp.GetDescription()); |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
990 ASSERT_EQ(3u, tmp.GetInstancesCount()); |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
991 ASSERT_EQ(2u, tmp.GetPosition()); |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
992 ASSERT_EQ(1u, tmp.GetFailedInstances().size()); |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
993 ASSERT_EQ("hello", tmp.GetInstance(0)); |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
994 ASSERT_EQ("nope", tmp.GetInstance(1)); |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
995 ASSERT_EQ("world", tmp.GetInstance(2)); |
5eea2f11e8df
JobsSerialization.GenericJobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
996 ASSERT_TRUE(tmp.IsFailedInstance("nope")); |
2655 | 997 } |
2666
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
998 |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
999 // SequenceOfOperationsJob |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1000 |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1001 { |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1002 SequenceOfOperationsJob job; |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1003 job.SetDescription("hello"); |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1004 |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1005 { |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1006 SequenceOfOperationsJob::Lock lock(job); |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1007 size_t a = lock.AddOperation(new LogJobOperation); |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1008 size_t b = lock.AddOperation(new LogJobOperation); |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1009 lock.Connect(a, b); |
2730 | 1010 |
1011 StringOperationValue s1("hello"); | |
1012 StringOperationValue s2("world"); | |
1013 lock.AddInput(a, s1); | |
1014 lock.AddInput(a, s2); | |
2666
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1015 lock.SetDicomAssociationTimeout(200); |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1016 lock.SetTrailingOperationTimeout(300); |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1017 } |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1018 |
2812
ea7aea6f6a95
improved naming of methods in IJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2811
diff
changeset
|
1019 ASSERT_EQ(JobStepCode_Continue, job.Step().GetCode()); |
2666
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1020 |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1021 { |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1022 GenericJobUnserializer unserializer; |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1023 ASSERT_TRUE(CheckIdempotentSerialization(unserializer, job)); |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1024 } |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1025 |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1026 ASSERT_TRUE(job.Serialize(s)); |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1027 } |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1028 |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1029 { |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1030 GenericJobUnserializer unserializer; |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1031 ASSERT_THROW(unserializer.UnserializeValue(s), OrthancException); |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1032 ASSERT_THROW(unserializer.UnserializeOperation(s), OrthancException); |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1033 |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1034 std::auto_ptr<IJob> job; |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1035 job.reset(unserializer.UnserializeJob(s)); |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1036 |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1037 std::string tmp; |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1038 dynamic_cast<SequenceOfOperationsJob&>(*job).GetDescription(tmp); |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1039 ASSERT_EQ("hello", tmp); |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1040 } |
2658 | 1041 } |
1042 | |
1043 | |
2662
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2660
diff
changeset
|
1044 static bool IsSameTagValue(ParsedDicomFile& dicom1, |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2660
diff
changeset
|
1045 ParsedDicomFile& dicom2, |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2660
diff
changeset
|
1046 DicomTag tag) |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2660
diff
changeset
|
1047 { |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2660
diff
changeset
|
1048 std::string a, b; |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2660
diff
changeset
|
1049 return (dicom1.GetTagValue(a, tag) && |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2660
diff
changeset
|
1050 dicom2.GetTagValue(b, tag) && |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2660
diff
changeset
|
1051 (a == b)); |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2660
diff
changeset
|
1052 } |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2660
diff
changeset
|
1053 |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2660
diff
changeset
|
1054 |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2660
diff
changeset
|
1055 |
2660 | 1056 TEST(JobsSerialization, DicomModification) |
1057 { | |
2662
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2660
diff
changeset
|
1058 Json::Value s; |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2660
diff
changeset
|
1059 |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2660
diff
changeset
|
1060 ParsedDicomFile source(true); |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2660
diff
changeset
|
1061 source.Insert(DICOM_TAG_STUDY_DESCRIPTION, "Test 1", false); |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2660
diff
changeset
|
1062 source.Insert(DICOM_TAG_SERIES_DESCRIPTION, "Test 2", false); |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2660
diff
changeset
|
1063 source.Insert(DICOM_TAG_PATIENT_NAME, "Test 3", false); |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2660
diff
changeset
|
1064 |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2660
diff
changeset
|
1065 std::auto_ptr<ParsedDicomFile> modified(source.Clone(true)); |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2660
diff
changeset
|
1066 |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2660
diff
changeset
|
1067 { |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2660
diff
changeset
|
1068 DicomModification modification; |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2660
diff
changeset
|
1069 modification.SetLevel(ResourceType_Series); |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2660
diff
changeset
|
1070 modification.Clear(DICOM_TAG_STUDY_DESCRIPTION); |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2660
diff
changeset
|
1071 modification.Remove(DICOM_TAG_SERIES_DESCRIPTION); |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2660
diff
changeset
|
1072 modification.Replace(DICOM_TAG_PATIENT_NAME, "Test 4", true); |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2660
diff
changeset
|
1073 |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2660
diff
changeset
|
1074 modification.Apply(*modified); |
2665
389d050a2e66
fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
1075 |
389d050a2e66
fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
1076 s = 42; |
2662
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2660
diff
changeset
|
1077 modification.Serialize(s); |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2660
diff
changeset
|
1078 } |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2660
diff
changeset
|
1079 |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2660
diff
changeset
|
1080 { |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2660
diff
changeset
|
1081 DicomModification modification(s); |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2660
diff
changeset
|
1082 ASSERT_EQ(ResourceType_Series, modification.GetLevel()); |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2660
diff
changeset
|
1083 |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2660
diff
changeset
|
1084 std::auto_ptr<ParsedDicomFile> second(source.Clone(true)); |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2660
diff
changeset
|
1085 modification.Apply(*second); |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2660
diff
changeset
|
1086 |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2660
diff
changeset
|
1087 std::string s; |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2660
diff
changeset
|
1088 ASSERT_TRUE(second->GetTagValue(s, DICOM_TAG_STUDY_DESCRIPTION)); |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2660
diff
changeset
|
1089 ASSERT_TRUE(s.empty()); |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2660
diff
changeset
|
1090 ASSERT_FALSE(second->GetTagValue(s, DICOM_TAG_SERIES_DESCRIPTION)); |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2660
diff
changeset
|
1091 ASSERT_TRUE(second->GetTagValue(s, DICOM_TAG_PATIENT_NAME)); |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2660
diff
changeset
|
1092 ASSERT_EQ("Test 4", s); |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2660
diff
changeset
|
1093 |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2660
diff
changeset
|
1094 ASSERT_TRUE(IsSameTagValue(source, *modified, DICOM_TAG_STUDY_INSTANCE_UID)); |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2660
diff
changeset
|
1095 ASSERT_TRUE(IsSameTagValue(source, *second, DICOM_TAG_STUDY_INSTANCE_UID)); |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2660
diff
changeset
|
1096 |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2660
diff
changeset
|
1097 ASSERT_FALSE(IsSameTagValue(source, *second, DICOM_TAG_SERIES_INSTANCE_UID)); |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2660
diff
changeset
|
1098 ASSERT_TRUE(IsSameTagValue(*modified, *second, DICOM_TAG_SERIES_INSTANCE_UID)); |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2660
diff
changeset
|
1099 } |
2660 | 1100 } |
1101 | |
1102 | |
2664
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1103 TEST(JobsSerialization, DicomInstanceOrigin) |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1104 { |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1105 Json::Value s; |
2726
46061a91c88a
new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2715
diff
changeset
|
1106 std::string t; |
2664
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1107 |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1108 { |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1109 DicomInstanceOrigin origin; |
2665
389d050a2e66
fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
1110 |
389d050a2e66
fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
1111 s = 42; |
2664
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1112 origin.Serialize(s); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1113 } |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1114 |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1115 { |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1116 DicomInstanceOrigin origin(s); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1117 ASSERT_EQ(RequestOrigin_Unknown, origin.GetRequestOrigin()); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1118 ASSERT_EQ("", std::string(origin.GetRemoteAetC())); |
2726
46061a91c88a
new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2715
diff
changeset
|
1119 ASSERT_FALSE(origin.LookupRemoteIp(t)); |
46061a91c88a
new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2715
diff
changeset
|
1120 ASSERT_FALSE(origin.LookupRemoteAet(t)); |
46061a91c88a
new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2715
diff
changeset
|
1121 ASSERT_FALSE(origin.LookupCalledAet(t)); |
46061a91c88a
new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2715
diff
changeset
|
1122 ASSERT_FALSE(origin.LookupHttpUsername(t)); |
2664
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1123 } |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1124 |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1125 { |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1126 DicomInstanceOrigin origin(DicomInstanceOrigin::FromDicomProtocol("host", "aet", "called")); |
2665
389d050a2e66
fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
1127 |
389d050a2e66
fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
1128 s = 42; |
2664
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1129 origin.Serialize(s); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1130 } |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1131 |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1132 { |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1133 DicomInstanceOrigin origin(s); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1134 ASSERT_EQ(RequestOrigin_DicomProtocol, origin.GetRequestOrigin()); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1135 ASSERT_EQ("aet", std::string(origin.GetRemoteAetC())); |
2726
46061a91c88a
new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2715
diff
changeset
|
1136 ASSERT_TRUE(origin.LookupRemoteIp(t)); ASSERT_EQ("host", t); |
46061a91c88a
new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2715
diff
changeset
|
1137 ASSERT_TRUE(origin.LookupRemoteAet(t)); ASSERT_EQ("aet", t); |
46061a91c88a
new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2715
diff
changeset
|
1138 ASSERT_TRUE(origin.LookupCalledAet(t)); ASSERT_EQ("called", t); |
46061a91c88a
new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2715
diff
changeset
|
1139 ASSERT_FALSE(origin.LookupHttpUsername(t)); |
2664
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1140 } |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1141 |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1142 { |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1143 DicomInstanceOrigin origin(DicomInstanceOrigin::FromHttp("host", "username")); |
2665
389d050a2e66
fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
1144 |
389d050a2e66
fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
1145 s = 42; |
2664
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1146 origin.Serialize(s); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1147 } |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1148 |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1149 { |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1150 DicomInstanceOrigin origin(s); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1151 ASSERT_EQ(RequestOrigin_RestApi, origin.GetRequestOrigin()); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1152 ASSERT_EQ("", std::string(origin.GetRemoteAetC())); |
2726
46061a91c88a
new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2715
diff
changeset
|
1153 ASSERT_TRUE(origin.LookupRemoteIp(t)); ASSERT_EQ("host", t); |
46061a91c88a
new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2715
diff
changeset
|
1154 ASSERT_FALSE(origin.LookupRemoteAet(t)); |
46061a91c88a
new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2715
diff
changeset
|
1155 ASSERT_FALSE(origin.LookupCalledAet(t)); |
46061a91c88a
new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2715
diff
changeset
|
1156 ASSERT_TRUE(origin.LookupHttpUsername(t)); ASSERT_EQ("username", t); |
2664
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1157 } |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1158 |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1159 { |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1160 DicomInstanceOrigin origin(DicomInstanceOrigin::FromLua()); |
2665
389d050a2e66
fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
1161 |
389d050a2e66
fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
1162 s = 42; |
2664
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1163 origin.Serialize(s); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1164 } |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1165 |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1166 { |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1167 DicomInstanceOrigin origin(s); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1168 ASSERT_EQ(RequestOrigin_Lua, origin.GetRequestOrigin()); |
2726
46061a91c88a
new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2715
diff
changeset
|
1169 ASSERT_FALSE(origin.LookupRemoteIp(t)); |
46061a91c88a
new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2715
diff
changeset
|
1170 ASSERT_FALSE(origin.LookupRemoteAet(t)); |
46061a91c88a
new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2715
diff
changeset
|
1171 ASSERT_FALSE(origin.LookupCalledAet(t)); |
46061a91c88a
new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2715
diff
changeset
|
1172 ASSERT_FALSE(origin.LookupHttpUsername(t)); |
2664
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1173 } |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1174 |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1175 { |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1176 DicomInstanceOrigin origin(DicomInstanceOrigin::FromPlugins()); |
2665
389d050a2e66
fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
1177 |
389d050a2e66
fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
1178 s = 42; |
2664
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1179 origin.Serialize(s); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1180 } |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1181 |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1182 { |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1183 DicomInstanceOrigin origin(s); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1184 ASSERT_EQ(RequestOrigin_Plugins, origin.GetRequestOrigin()); |
2726
46061a91c88a
new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2715
diff
changeset
|
1185 ASSERT_FALSE(origin.LookupRemoteIp(t)); |
46061a91c88a
new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2715
diff
changeset
|
1186 ASSERT_FALSE(origin.LookupRemoteAet(t)); |
46061a91c88a
new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2715
diff
changeset
|
1187 ASSERT_FALSE(origin.LookupCalledAet(t)); |
46061a91c88a
new metadata (RemoteIP, CalledAET, HttpUsername), "?expand" metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2715
diff
changeset
|
1188 ASSERT_FALSE(origin.LookupHttpUsername(t)); |
2664
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1189 } |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1190 } |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1191 |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1192 |
2655 | 1193 namespace |
2651
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
1194 { |
2655 | 1195 class OrthancJobsSerialization : public testing::Test |
1196 { | |
1197 private: | |
1198 MemoryStorageArea storage_; | |
1199 DatabaseWrapper db_; // The SQLite DB is in memory | |
1200 std::auto_ptr<ServerContext> context_; | |
1201 TimeoutDicomConnectionManager manager_; | |
1202 | |
1203 public: | |
1204 OrthancJobsSerialization() | |
1205 { | |
1206 db_.Open(); | |
2815
925d8dc03a23
unserialization of jobs from plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2812
diff
changeset
|
1207 context_.reset(new ServerContext(db_, storage_, true /* running unit tests */)); |
925d8dc03a23
unserialization of jobs from plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2812
diff
changeset
|
1208 context_->SetupJobsEngine(true, false); |
2655 | 1209 } |
1210 | |
1211 virtual ~OrthancJobsSerialization() | |
1212 { | |
1213 context_->Stop(); | |
1214 context_.reset(NULL); | |
1215 db_.Close(); | |
1216 } | |
2651
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
1217 |
2655 | 1218 ServerContext& GetContext() |
1219 { | |
1220 return *context_; | |
1221 } | |
1222 | |
1223 bool CreateInstance(std::string& id) | |
1224 { | |
1225 // Create a sample DICOM file | |
1226 ParsedDicomFile dicom(true); | |
1227 dicom.Replace(DICOM_TAG_PATIENT_NAME, std::string("JODOGNE"), | |
1228 false, DicomReplaceMode_InsertIfAbsent); | |
1229 | |
1230 DicomInstanceToStore toStore; | |
1231 toStore.SetParsedDicomFile(dicom); | |
1232 | |
1233 return (context_->Store(id, toStore) == StoreStatus_Success); | |
1234 } | |
1235 }; | |
1236 } | |
1237 | |
1238 | |
1239 TEST_F(OrthancJobsSerialization, Values) | |
1240 { | |
2651
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
1241 std::string id; |
2655 | 1242 ASSERT_TRUE(CreateInstance(id)); |
2651
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
1243 |
2655 | 1244 Json::Value s; |
2666
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1245 OrthancJobUnserializer unserializer(GetContext()); |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1246 |
2651
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
1247 { |
2655 | 1248 DicomInstanceOperationValue instance(GetContext(), id); |
2665
389d050a2e66
fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
1249 |
2666
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1250 ASSERT_TRUE(CheckIdempotentSerialization(unserializer, instance)); |
2655 | 1251 instance.Serialize(s); |
2651
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
1252 } |
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
1253 |
2655 | 1254 std::auto_ptr<JobOperationValue> value; |
1255 value.reset(unserializer.UnserializeValue(s)); | |
1256 ASSERT_EQ(JobOperationValue::Type_DicomInstance, value->GetType()); | |
1257 ASSERT_EQ(id, dynamic_cast<DicomInstanceOperationValue&>(*value).GetId()); | |
1258 | |
1259 { | |
1260 std::string content; | |
1261 dynamic_cast<DicomInstanceOperationValue&>(*value).ReadDicom(content); | |
1262 | |
1263 ParsedDicomFile dicom(content); | |
1264 ASSERT_TRUE(dicom.GetTagValue(content, DICOM_TAG_PATIENT_NAME)); | |
1265 ASSERT_EQ("JODOGNE", content); | |
1266 } | |
2651
1da5a052c777
testing value serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2648
diff
changeset
|
1267 } |
2655 | 1268 |
1269 | |
1270 TEST_F(OrthancJobsSerialization, Operations) | |
1271 { | |
1272 std::string id; | |
1273 ASSERT_TRUE(CreateInstance(id)); | |
1274 | |
1275 Json::Value s; | |
2666
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1276 OrthancJobUnserializer unserializer(GetContext()); |
2655 | 1277 |
2659 | 1278 // DeleteResourceOperation |
1279 | |
2655 | 1280 { |
1281 DeleteResourceOperation operation(GetContext()); | |
2665
389d050a2e66
fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
1282 |
2666
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1283 ASSERT_TRUE(CheckIdempotentSerialization(unserializer, operation)); |
2655 | 1284 operation.Serialize(s); |
1285 } | |
1286 | |
1287 std::auto_ptr<IJobOperation> operation; | |
2659 | 1288 |
1289 { | |
1290 operation.reset(unserializer.UnserializeOperation(s)); | |
1291 | |
2731 | 1292 Json::Value dummy; |
1293 ASSERT_THROW(dynamic_cast<LogJobOperation&>(*operation).Serialize(dummy), std::bad_cast); | |
1294 dynamic_cast<DeleteResourceOperation&>(*operation).Serialize(dummy); | |
2659 | 1295 } |
1296 | |
1297 // StorePeerOperation | |
1298 | |
1299 { | |
1300 WebServiceParameters peer; | |
1301 peer.SetUrl("http://localhost/"); | |
2800
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2731
diff
changeset
|
1302 peer.SetCredentials("username", "password"); |
2659 | 1303 peer.SetPkcs11Enabled(true); |
1304 | |
1305 StorePeerOperation operation(peer); | |
2665
389d050a2e66
fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
1306 |
2666
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1307 ASSERT_TRUE(CheckIdempotentSerialization(unserializer, operation)); |
2659 | 1308 operation.Serialize(s); |
1309 } | |
1310 | |
1311 { | |
1312 operation.reset(unserializer.UnserializeOperation(s)); | |
1313 | |
1314 const StorePeerOperation& tmp = dynamic_cast<StorePeerOperation&>(*operation); | |
1315 ASSERT_EQ("http://localhost/", tmp.GetPeer().GetUrl()); | |
1316 ASSERT_EQ("username", tmp.GetPeer().GetUsername()); | |
1317 ASSERT_EQ("password", tmp.GetPeer().GetPassword()); | |
1318 ASSERT_TRUE(tmp.GetPeer().IsPkcs11Enabled()); | |
1319 } | |
1320 | |
1321 // StoreScuOperation | |
2658 | 1322 |
2659 | 1323 { |
1324 RemoteModalityParameters modality; | |
1325 modality.SetApplicationEntityTitle("REMOTE"); | |
1326 modality.SetHost("192.168.1.1"); | |
2715
73bc0c32547c
fix embedding openssl within a DLL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2671
diff
changeset
|
1327 modality.SetPortNumber(1000); |
2659 | 1328 modality.SetManufacturer(ModalityManufacturer_StoreScp); |
1329 | |
1330 StoreScuOperation operation("TEST", modality); | |
2665
389d050a2e66
fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
1331 |
2666
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1332 ASSERT_TRUE(CheckIdempotentSerialization(unserializer, operation)); |
2659 | 1333 operation.Serialize(s); |
1334 } | |
1335 | |
1336 { | |
1337 operation.reset(unserializer.UnserializeOperation(s)); | |
1338 | |
1339 const StoreScuOperation& tmp = dynamic_cast<StoreScuOperation&>(*operation); | |
1340 ASSERT_EQ("REMOTE", tmp.GetRemoteModality().GetApplicationEntityTitle()); | |
1341 ASSERT_EQ("192.168.1.1", tmp.GetRemoteModality().GetHost()); | |
2715
73bc0c32547c
fix embedding openssl within a DLL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2671
diff
changeset
|
1342 ASSERT_EQ(1000, tmp.GetRemoteModality().GetPortNumber()); |
2659 | 1343 ASSERT_EQ(ModalityManufacturer_StoreScp, tmp.GetRemoteModality().GetManufacturer()); |
1344 ASSERT_EQ("TEST", tmp.GetLocalAet()); | |
1345 } | |
2658 | 1346 |
2659 | 1347 // SystemCallOperation |
1348 | |
1349 { | |
1350 SystemCallOperation operation(std::string("echo")); | |
1351 operation.AddPreArgument("a"); | |
1352 operation.AddPreArgument("b"); | |
1353 operation.AddPostArgument("c"); | |
2665
389d050a2e66
fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
1354 |
2666
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1355 ASSERT_TRUE(CheckIdempotentSerialization(unserializer, operation)); |
2659 | 1356 operation.Serialize(s); |
1357 } | |
2658 | 1358 |
2659 | 1359 { |
1360 operation.reset(unserializer.UnserializeOperation(s)); | |
1361 | |
1362 const SystemCallOperation& tmp = dynamic_cast<SystemCallOperation&>(*operation); | |
1363 ASSERT_EQ("echo", tmp.GetCommand()); | |
1364 ASSERT_EQ(2u, tmp.GetPreArgumentsCount()); | |
1365 ASSERT_EQ(1u, tmp.GetPostArgumentsCount()); | |
1366 ASSERT_EQ("a", tmp.GetPreArgument(0)); | |
1367 ASSERT_EQ("b", tmp.GetPreArgument(1)); | |
1368 ASSERT_EQ("c", tmp.GetPostArgument(0)); | |
1369 } | |
2658 | 1370 |
2662
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2660
diff
changeset
|
1371 // ModifyInstanceOperation |
2659 | 1372 |
1373 { | |
1374 std::auto_ptr<DicomModification> modification(new DicomModification); | |
2662
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2660
diff
changeset
|
1375 modification->SetupAnonymization(DicomVersion_2008); |
2659 | 1376 |
1377 ModifyInstanceOperation operation(GetContext(), RequestOrigin_Lua, modification.release()); | |
2665
389d050a2e66
fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
1378 |
2666
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1379 ASSERT_TRUE(CheckIdempotentSerialization(unserializer, operation)); |
2659 | 1380 operation.Serialize(s); |
1381 } | |
1382 | |
1383 { | |
1384 operation.reset(unserializer.UnserializeOperation(s)); | |
1385 | |
1386 const ModifyInstanceOperation& tmp = dynamic_cast<ModifyInstanceOperation&>(*operation); | |
1387 ASSERT_EQ(RequestOrigin_Lua, tmp.GetRequestOrigin()); | |
2662
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2660
diff
changeset
|
1388 ASSERT_TRUE(tmp.GetModification().IsRemoved(DICOM_TAG_STUDY_DESCRIPTION)); |
47d812308d63
serialization of DicomModification
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2660
diff
changeset
|
1389 } |
2655 | 1390 } |
2658 | 1391 |
1392 | |
1393 TEST_F(OrthancJobsSerialization, Jobs) | |
1394 { | |
2663
228e2783ce83
some jobs might not be serializable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
1395 // ArchiveJob |
228e2783ce83
some jobs might not be serializable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
1396 |
228e2783ce83
some jobs might not be serializable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
1397 Json::Value s; |
228e2783ce83
some jobs might not be serializable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
1398 |
228e2783ce83
some jobs might not be serializable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
1399 { |
228e2783ce83
some jobs might not be serializable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
1400 boost::shared_ptr<TemporaryFile> tmp(new TemporaryFile); |
228e2783ce83
some jobs might not be serializable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
1401 ArchiveJob job(tmp, GetContext(), false, false); |
2664
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1402 ASSERT_FALSE(job.Serialize(s)); // Cannot serialize this |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1403 } |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1404 |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1405 // DicomModalityStoreJob |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1406 |
2666
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1407 OrthancJobUnserializer unserializer(GetContext()); |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1408 |
2664
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1409 { |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1410 RemoteModalityParameters modality; |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1411 modality.SetApplicationEntityTitle("REMOTE"); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1412 modality.SetHost("192.168.1.1"); |
2715
73bc0c32547c
fix embedding openssl within a DLL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2671
diff
changeset
|
1413 modality.SetPortNumber(1000); |
2664
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1414 modality.SetManufacturer(ModalityManufacturer_StoreScp); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1415 |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1416 DicomModalityStoreJob job(GetContext()); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1417 job.SetLocalAet("LOCAL"); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1418 job.SetRemoteModality(modality); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1419 job.SetMoveOriginator("MOVESCU", 42); |
2665
389d050a2e66
fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
1420 |
2666
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1421 ASSERT_TRUE(CheckIdempotentSerialization(unserializer, job)); |
2664
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1422 ASSERT_TRUE(job.Serialize(s)); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1423 } |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1424 |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1425 { |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1426 std::auto_ptr<IJob> job; |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1427 job.reset(unserializer.UnserializeJob(s)); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1428 |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1429 DicomModalityStoreJob& tmp = dynamic_cast<DicomModalityStoreJob&>(*job); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1430 ASSERT_EQ("LOCAL", tmp.GetLocalAet()); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1431 ASSERT_EQ("REMOTE", tmp.GetRemoteModality().GetApplicationEntityTitle()); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1432 ASSERT_EQ("192.168.1.1", tmp.GetRemoteModality().GetHost()); |
2715
73bc0c32547c
fix embedding openssl within a DLL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2671
diff
changeset
|
1433 ASSERT_EQ(1000, tmp.GetRemoteModality().GetPortNumber()); |
2664
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1434 ASSERT_EQ(ModalityManufacturer_StoreScp, tmp.GetRemoteModality().GetManufacturer()); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1435 ASSERT_TRUE(tmp.HasMoveOriginator()); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1436 ASSERT_EQ("MOVESCU", tmp.GetMoveOriginatorAet()); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1437 ASSERT_EQ(42, tmp.GetMoveOriginatorId()); |
2663
228e2783ce83
some jobs might not be serializable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2662
diff
changeset
|
1438 } |
2658 | 1439 |
2664
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1440 // OrthancPeerStoreJob |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1441 |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1442 { |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1443 WebServiceParameters peer; |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1444 peer.SetUrl("http://localhost/"); |
2800
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2731
diff
changeset
|
1445 peer.SetCredentials("username", "password"); |
2664
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1446 peer.SetPkcs11Enabled(true); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1447 |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1448 OrthancPeerStoreJob job(GetContext()); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1449 job.SetPeer(peer); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1450 |
2666
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1451 ASSERT_TRUE(CheckIdempotentSerialization(unserializer, job)); |
2664
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1452 ASSERT_TRUE(job.Serialize(s)); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1453 } |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1454 |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1455 { |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1456 std::auto_ptr<IJob> job; |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1457 job.reset(unserializer.UnserializeJob(s)); |
2658 | 1458 |
2664
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1459 OrthancPeerStoreJob& tmp = dynamic_cast<OrthancPeerStoreJob&>(*job); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1460 ASSERT_EQ("http://localhost/", tmp.GetPeer().GetUrl()); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1461 ASSERT_EQ("username", tmp.GetPeer().GetUsername()); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1462 ASSERT_EQ("password", tmp.GetPeer().GetPassword()); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1463 ASSERT_TRUE(tmp.GetPeer().IsPkcs11Enabled()); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1464 } |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1465 |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1466 // ResourceModificationJob |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1467 |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1468 { |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1469 std::auto_ptr<DicomModification> modification(new DicomModification); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1470 modification->SetupAnonymization(DicomVersion_2008); |
2658 | 1471 |
2664
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1472 ResourceModificationJob job(GetContext()); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1473 job.SetModification(modification.release(), true); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1474 job.SetOrigin(DicomInstanceOrigin::FromLua()); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1475 |
2666
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1476 ASSERT_TRUE(CheckIdempotentSerialization(unserializer, job)); |
2664
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1477 ASSERT_TRUE(job.Serialize(s)); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1478 } |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1479 |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1480 { |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1481 std::auto_ptr<IJob> job; |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1482 job.reset(unserializer.UnserializeJob(s)); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1483 |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1484 ResourceModificationJob& tmp = dynamic_cast<ResourceModificationJob&>(*job); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1485 ASSERT_TRUE(tmp.IsAnonymization()); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1486 ASSERT_EQ(RequestOrigin_Lua, tmp.GetOrigin().GetRequestOrigin()); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1487 ASSERT_TRUE(tmp.GetModification().IsRemoved(DICOM_TAG_STUDY_DESCRIPTION)); |
a21b244efb37
serialization of DicomModalityStoreJob, OrthancPeerStoreJob and ResourceModificationJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1488 } |
2666
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1489 } |
2665
389d050a2e66
fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
1490 |
389d050a2e66
fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2664
diff
changeset
|
1491 |
2666
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1492 TEST(JobsSerialization, Registry) |
2540ac79ab6c
SequenceOfOperationsJob serialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2665
diff
changeset
|
1493 { |
2667
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2666
diff
changeset
|
1494 Json::Value s; |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2666
diff
changeset
|
1495 std::string i1, i2; |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2666
diff
changeset
|
1496 |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2666
diff
changeset
|
1497 { |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2666
diff
changeset
|
1498 JobsRegistry registry; |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2666
diff
changeset
|
1499 registry.Submit(i1, new DummyJob(), 10); |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2666
diff
changeset
|
1500 registry.Submit(i2, new SequenceOfOperationsJob(), 30); |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2666
diff
changeset
|
1501 registry.Serialize(s); |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2666
diff
changeset
|
1502 } |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2666
diff
changeset
|
1503 |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2666
diff
changeset
|
1504 { |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2666
diff
changeset
|
1505 DummyUnserializer unserializer; |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2666
diff
changeset
|
1506 JobsRegistry registry(unserializer, s); |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2666
diff
changeset
|
1507 |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2666
diff
changeset
|
1508 Json::Value t; |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2666
diff
changeset
|
1509 registry.Serialize(t); |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2666
diff
changeset
|
1510 ASSERT_TRUE(CheckSameJson(s, t)); |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2666
diff
changeset
|
1511 } |
2658 | 1512 } |