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