annotate UnitTestsSources/MultiThreadingTests.cpp @ 2658:ce770f095092 jobs

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