annotate UnitTestsSources/MultiThreadingTests.cpp @ 2715:73bc0c32547c jobs

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