Mercurial > hg > orthanc
annotate UnitTestsSources/MultiThreadingTests.cpp @ 2581:8da2cffc2378 jobs
JobsRegistry::Cancel()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 11 May 2018 17:33:19 +0200 |
parents | 055d7d4a823f |
children | 1b6a6d80b6f2 |
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 } |
2e879c796ec7
JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
269 |
2557 | 270 virtual JobStepResult* ExecuteStep() |
271 { | |
2570
2e879c796ec7
JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
272 boost::this_thread::sleep(boost::posix_time::milliseconds(10)); |
2565 | 273 |
274 if (count_ == steps_ - 1) | |
275 { | |
276 return new JobStepResult(result_); | |
277 } | |
278 else | |
279 { | |
280 count_++; | |
281 return new JobStepResult(JobStepCode_Continue); | |
282 } | |
2557 | 283 } |
284 | |
285 virtual void ReleaseResources() | |
286 { | |
287 } | |
288 | |
289 virtual float GetProgress() | |
290 { | |
2565 | 291 return static_cast<float>(count_) / static_cast<float>(steps_ - 1); |
2557 | 292 } |
293 | |
2580
055d7d4a823f
avoid unecessary openings of DICOM connection for C-Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
294 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
|
295 { |
055d7d4a823f
avoid unecessary openings of DICOM connection for C-Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
296 type = "DummyJob"; |
055d7d4a823f
avoid unecessary openings of DICOM connection for C-Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
297 } |
055d7d4a823f
avoid unecessary openings of DICOM connection for C-Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
298 |
055d7d4a823f
avoid unecessary openings of DICOM connection for C-Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
299 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
|
300 { |
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 GetPublicContent(Json::Value& value) |
2557 | 304 { |
2565 | 305 value["hello"] = "world"; |
2557 | 306 } |
307 }; | |
308 | |
309 | |
2558 | 310 static bool CheckState(Orthanc::JobsRegistry& registry, |
2557 | 311 const std::string& id, |
312 Orthanc::JobState state) | |
313 { | |
314 Orthanc::JobState s; | |
2558 | 315 if (registry.GetState(s, id)) |
2557 | 316 { |
317 return state == s; | |
318 } | |
319 else | |
320 { | |
321 return false; | |
322 } | |
323 } | |
324 | |
325 | |
2581
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
326 static bool CheckErrorCode(Orthanc::JobsRegistry& registry, |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
327 const std::string& id, |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
328 Orthanc::ErrorCode code) |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
329 { |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
330 Orthanc::JobInfo s; |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
331 if (registry.GetJobInfo(s, id)) |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
332 { |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
333 return code == s.GetStatus().GetErrorCode(); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
334 } |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
335 else |
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 false; |
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 } |
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 |
2558 | 342 TEST(JobsRegistry, Priority) |
2557 | 343 { |
2558 | 344 JobsRegistry registry; |
2557 | 345 |
346 std::string i1, i2, i3, i4; | |
2558 | 347 registry.Submit(i1, new DummyJob(), 10); |
348 registry.Submit(i2, new DummyJob(), 30); | |
349 registry.Submit(i3, new DummyJob(), 20); | |
350 registry.Submit(i4, new DummyJob(), 5); | |
2557 | 351 |
2558 | 352 registry.SetMaxCompletedJobs(2); |
2557 | 353 |
354 std::set<std::string> id; | |
2558 | 355 registry.ListJobs(id); |
2557 | 356 |
357 ASSERT_EQ(4u, id.size()); | |
358 ASSERT_TRUE(id.find(i1) != id.end()); | |
359 ASSERT_TRUE(id.find(i2) != id.end()); | |
360 ASSERT_TRUE(id.find(i3) != id.end()); | |
361 ASSERT_TRUE(id.find(i4) != id.end()); | |
362 | |
2558 | 363 ASSERT_TRUE(CheckState(registry, i2, Orthanc::JobState_Pending)); |
2557 | 364 |
365 { | |
2558 | 366 JobsRegistry::RunningJob job(registry, 0); |
2557 | 367 ASSERT_TRUE(job.IsValid()); |
368 ASSERT_EQ(30, job.GetPriority()); | |
369 ASSERT_EQ(i2, job.GetId()); | |
370 | |
2558 | 371 ASSERT_TRUE(CheckState(registry, i2, Orthanc::JobState_Running)); |
2557 | 372 } |
373 | |
2558 | 374 ASSERT_TRUE(CheckState(registry, i2, Orthanc::JobState_Failure)); |
375 ASSERT_TRUE(CheckState(registry, i3, Orthanc::JobState_Pending)); | |
2557 | 376 |
377 { | |
2558 | 378 JobsRegistry::RunningJob job(registry, 0); |
2557 | 379 ASSERT_TRUE(job.IsValid()); |
380 ASSERT_EQ(20, job.GetPriority()); | |
381 ASSERT_EQ(i3, job.GetId()); | |
382 | |
383 job.MarkSuccess(); | |
384 | |
2558 | 385 ASSERT_TRUE(CheckState(registry, i3, Orthanc::JobState_Running)); |
2557 | 386 } |
387 | |
2558 | 388 ASSERT_TRUE(CheckState(registry, i3, Orthanc::JobState_Success)); |
2557 | 389 |
390 { | |
2558 | 391 JobsRegistry::RunningJob job(registry, 0); |
2557 | 392 ASSERT_TRUE(job.IsValid()); |
393 ASSERT_EQ(10, job.GetPriority()); | |
394 ASSERT_EQ(i1, job.GetId()); | |
395 } | |
396 | |
397 { | |
2558 | 398 JobsRegistry::RunningJob job(registry, 0); |
2557 | 399 ASSERT_TRUE(job.IsValid()); |
400 ASSERT_EQ(5, job.GetPriority()); | |
401 ASSERT_EQ(i4, job.GetId()); | |
402 } | |
403 | |
404 { | |
2558 | 405 JobsRegistry::RunningJob job(registry, 1); |
2557 | 406 ASSERT_FALSE(job.IsValid()); |
407 } | |
408 | |
409 Orthanc::JobState s; | |
2558 | 410 ASSERT_TRUE(registry.GetState(s, i1)); |
411 ASSERT_FALSE(registry.GetState(s, i2)); // Removed because oldest | |
412 ASSERT_FALSE(registry.GetState(s, i3)); // Removed because second oldest | |
413 ASSERT_TRUE(registry.GetState(s, i4)); | |
2557 | 414 |
2558 | 415 registry.SetMaxCompletedJobs(1); // (*) |
416 ASSERT_FALSE(registry.GetState(s, i1)); // Just discarded by (*) | |
417 ASSERT_TRUE(registry.GetState(s, i4)); | |
2557 | 418 } |
419 | |
420 | |
2558 | 421 TEST(JobsRegistry, Simultaneous) |
2557 | 422 { |
2558 | 423 JobsRegistry registry; |
424 | |
425 std::string i1, i2; | |
426 registry.Submit(i1, new DummyJob(), 20); | |
427 registry.Submit(i2, new DummyJob(), 10); | |
428 | |
429 ASSERT_TRUE(CheckState(registry, i1, Orthanc::JobState_Pending)); | |
430 ASSERT_TRUE(CheckState(registry, i2, Orthanc::JobState_Pending)); | |
431 | |
432 { | |
433 JobsRegistry::RunningJob job1(registry, 0); | |
434 JobsRegistry::RunningJob job2(registry, 0); | |
435 | |
436 ASSERT_TRUE(job1.IsValid()); | |
437 ASSERT_TRUE(job2.IsValid()); | |
438 | |
439 job1.MarkFailure(); | |
440 job2.MarkSuccess(); | |
441 | |
442 ASSERT_TRUE(CheckState(registry, i1, Orthanc::JobState_Running)); | |
443 ASSERT_TRUE(CheckState(registry, i2, Orthanc::JobState_Running)); | |
444 } | |
445 | |
446 ASSERT_TRUE(CheckState(registry, i1, Orthanc::JobState_Failure)); | |
447 ASSERT_TRUE(CheckState(registry, i2, Orthanc::JobState_Success)); | |
448 } | |
449 | |
450 | |
451 TEST(JobsRegistry, Resubmit) | |
452 { | |
453 JobsRegistry registry; | |
2557 | 454 |
455 std::string id; | |
2558 | 456 registry.Submit(id, new DummyJob(), 10); |
2557 | 457 |
2558 | 458 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending)); |
2557 | 459 |
2558 | 460 registry.Resubmit(id); |
461 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending)); | |
2557 | 462 |
463 { | |
2558 | 464 JobsRegistry::RunningJob job(registry, 0); |
2557 | 465 ASSERT_TRUE(job.IsValid()); |
466 job.MarkFailure(); | |
467 | |
2558 | 468 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Running)); |
2557 | 469 |
2558 | 470 registry.Resubmit(id); |
471 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Running)); | |
2557 | 472 } |
473 | |
2558 | 474 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Failure)); |
2557 | 475 |
2558 | 476 registry.Resubmit(id); |
477 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending)); | |
2557 | 478 |
479 { | |
2558 | 480 JobsRegistry::RunningJob job(registry, 0); |
2557 | 481 ASSERT_TRUE(job.IsValid()); |
482 ASSERT_EQ(id, job.GetId()); | |
483 | |
484 job.MarkSuccess(); | |
2558 | 485 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Running)); |
486 } | |
487 | |
488 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Success)); | |
489 | |
490 registry.Resubmit(id); | |
491 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Success)); | |
492 } | |
493 | |
494 | |
495 TEST(JobsRegistry, Retry) | |
496 { | |
497 JobsRegistry registry; | |
498 | |
499 std::string id; | |
500 registry.Submit(id, new DummyJob(), 10); | |
501 | |
502 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending)); | |
503 | |
504 { | |
505 JobsRegistry::RunningJob job(registry, 0); | |
506 ASSERT_TRUE(job.IsValid()); | |
507 job.MarkRetry(0); | |
508 | |
509 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Running)); | |
510 } | |
511 | |
512 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Retry)); | |
513 | |
514 registry.Resubmit(id); | |
515 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Retry)); | |
516 | |
517 registry.ScheduleRetries(); | |
518 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending)); | |
519 | |
520 { | |
521 JobsRegistry::RunningJob job(registry, 0); | |
522 ASSERT_TRUE(job.IsValid()); | |
523 job.MarkSuccess(); | |
524 | |
525 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Running)); | |
2557 | 526 } |
527 | |
2558 | 528 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Success)); |
529 } | |
530 | |
531 | |
532 TEST(JobsRegistry, PausePending) | |
533 { | |
534 JobsRegistry registry; | |
535 | |
536 std::string id; | |
537 registry.Submit(id, new DummyJob(), 10); | |
538 | |
539 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending)); | |
540 | |
541 registry.Pause(id); | |
542 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Paused)); | |
543 | |
544 registry.Pause(id); | |
545 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Paused)); | |
546 | |
547 registry.Resubmit(id); | |
548 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Paused)); | |
549 | |
550 registry.Resume(id); | |
551 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending)); | |
2557 | 552 } |
2558 | 553 |
554 | |
555 TEST(JobsRegistry, PauseRunning) | |
556 { | |
557 JobsRegistry registry; | |
558 | |
559 std::string id; | |
560 registry.Submit(id, new DummyJob(), 10); | |
561 | |
562 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending)); | |
563 | |
564 { | |
565 JobsRegistry::RunningJob job(registry, 0); | |
566 ASSERT_TRUE(job.IsValid()); | |
567 | |
568 registry.Resubmit(id); | |
2562 | 569 job.MarkPause(); |
2558 | 570 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Running)); |
571 } | |
572 | |
573 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Paused)); | |
574 | |
575 registry.Resubmit(id); | |
576 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Paused)); | |
577 | |
578 registry.Resume(id); | |
579 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending)); | |
580 | |
581 { | |
582 JobsRegistry::RunningJob job(registry, 0); | |
583 ASSERT_TRUE(job.IsValid()); | |
584 | |
585 job.MarkSuccess(); | |
586 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Running)); | |
587 } | |
588 | |
589 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Success)); | |
590 } | |
591 | |
592 | |
593 TEST(JobsRegistry, PauseRetry) | |
594 { | |
595 JobsRegistry registry; | |
596 | |
597 std::string id; | |
598 registry.Submit(id, new DummyJob(), 10); | |
599 | |
600 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending)); | |
601 | |
602 { | |
603 JobsRegistry::RunningJob job(registry, 0); | |
604 ASSERT_TRUE(job.IsValid()); | |
605 | |
606 job.MarkRetry(0); | |
607 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Running)); | |
608 } | |
609 | |
610 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Retry)); | |
611 | |
612 registry.Pause(id); | |
613 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Paused)); | |
614 | |
615 registry.Resume(id); | |
616 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending)); | |
617 | |
618 { | |
619 JobsRegistry::RunningJob job(registry, 0); | |
620 ASSERT_TRUE(job.IsValid()); | |
621 | |
622 job.MarkSuccess(); | |
623 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Running)); | |
624 } | |
625 | |
626 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Success)); | |
627 } | |
2565 | 628 |
629 | |
2581
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
630 TEST(JobsRegistry, Cancel) |
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 JobsRegistry registry; |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
633 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
634 std::string id; |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
635 registry.Submit(id, new DummyJob(), 10); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
636 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
637 ASSERT_FALSE(registry.Cancel("nope")); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
638 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
639 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
640 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_Success)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
641 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
642 ASSERT_TRUE(registry.Cancel(id)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
643 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Failure)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
644 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_CanceledJob)); |
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.Resubmit(id)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
651 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending)); |
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 { |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
655 JobsRegistry::RunningJob job(registry, 0); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
656 ASSERT_TRUE(job.IsValid()); |
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 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_Success)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
659 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
660 job.MarkSuccess(); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
661 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Running)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
662 } |
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 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Success)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
665 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_Success)); |
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 ASSERT_TRUE(registry.Cancel(id)); |
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 registry.Submit(id, new DummyJob(), 10); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
672 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
673 { |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
674 JobsRegistry::RunningJob job(registry, 0); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
675 ASSERT_TRUE(job.IsValid()); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
676 ASSERT_EQ(id, job.GetId()); |
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 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_Success)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
679 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Running)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
680 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
681 job.MarkCanceled(); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
682 } |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
683 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
684 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Failure)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
685 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_CanceledJob)); |
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 ASSERT_TRUE(registry.Resubmit(id)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
688 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending)); |
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.Pause(id)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
692 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Paused)); |
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.Cancel(id)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
696 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Failure)); |
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.Resubmit(id)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
700 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending)); |
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 { |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
704 JobsRegistry::RunningJob job(registry, 0); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
705 ASSERT_TRUE(job.IsValid()); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
706 ASSERT_EQ(id, job.GetId()); |
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 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_Success)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
709 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Running)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
710 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
711 job.MarkRetry(500); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
712 } |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
713 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
714 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Retry)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
715 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_Success)); |
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 ASSERT_TRUE(registry.Cancel(id)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
718 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Failure)); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
719 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_CanceledJob)); |
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 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2580
diff
changeset
|
722 |
2570
2e879c796ec7
JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
723 |
2e879c796ec7
JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
724 |
2565 | 725 TEST(JobsEngine, Basic) |
726 { | |
727 JobsEngine engine; | |
728 | |
729 std::string s; | |
730 | |
731 for (size_t i = 0; i < 20; i++) | |
732 engine.GetRegistry().Submit(s, new DummyJob(), rand() % 10); | |
733 | |
734 engine.SetWorkersCount(3); | |
735 engine.Start(); | |
736 | |
2566
c09ce3c038fc
improved handling of eta
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2565
diff
changeset
|
737 boost::this_thread::sleep(boost::posix_time::milliseconds(100)); |
c09ce3c038fc
improved handling of eta
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2565
diff
changeset
|
738 |
c09ce3c038fc
improved handling of eta
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2565
diff
changeset
|
739 { |
2568 | 740 typedef std::set<std::string> Jobs; |
2566
c09ce3c038fc
improved handling of eta
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2565
diff
changeset
|
741 |
c09ce3c038fc
improved handling of eta
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2565
diff
changeset
|
742 Jobs jobs; |
2568 | 743 engine.GetRegistry().ListJobs(jobs); |
2566
c09ce3c038fc
improved handling of eta
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2565
diff
changeset
|
744 |
2568 | 745 Json::Value v = Json::arrayValue; |
2566
c09ce3c038fc
improved handling of eta
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2565
diff
changeset
|
746 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
|
747 { |
2568 | 748 JobInfo info; |
749 | |
750 if (engine.GetRegistry().GetJobInfo(info, *it)) | |
751 { | |
752 Json::Value vv; | |
2580
055d7d4a823f
avoid unecessary openings of DICOM connection for C-Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
753 info.Serialize(vv); |
2568 | 754 v.append(vv); |
755 } | |
2566
c09ce3c038fc
improved handling of eta
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2565
diff
changeset
|
756 } |
c09ce3c038fc
improved handling of eta
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2565
diff
changeset
|
757 |
c09ce3c038fc
improved handling of eta
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2565
diff
changeset
|
758 std::cout << v << std::endl; |
c09ce3c038fc
improved handling of eta
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2565
diff
changeset
|
759 } |
c09ce3c038fc
improved handling of eta
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2565
diff
changeset
|
760 std::cout << "====================================================" << std::endl; |
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 boost::this_thread::sleep(boost::posix_time::milliseconds(100)); |
2570
2e879c796ec7
JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
763 |
2e879c796ec7
JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
764 if (1) |
2e879c796ec7
JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
765 { |
2e879c796ec7
JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
766 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
|
767 } |
2e879c796ec7
JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
768 |
2e879c796ec7
JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
769 boost::this_thread::sleep(boost::posix_time::milliseconds(100)); |
2e879c796ec7
JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
770 |
2565 | 771 |
772 engine.Stop(); | |
773 | |
2570
2e879c796ec7
JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
774 if (0) |
2565 | 775 { |
2568 | 776 typedef std::set<std::string> Jobs; |
2566
c09ce3c038fc
improved handling of eta
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2565
diff
changeset
|
777 |
c09ce3c038fc
improved handling of eta
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2565
diff
changeset
|
778 Jobs jobs; |
2568 | 779 engine.GetRegistry().ListJobs(jobs); |
2566
c09ce3c038fc
improved handling of eta
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2565
diff
changeset
|
780 |
2568 | 781 Json::Value v = Json::arrayValue; |
2566
c09ce3c038fc
improved handling of eta
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2565
diff
changeset
|
782 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
|
783 { |
2568 | 784 JobInfo info; |
785 | |
786 if (engine.GetRegistry().GetJobInfo(info, *it)) | |
787 { | |
788 Json::Value vv; | |
2580
055d7d4a823f
avoid unecessary openings of DICOM connection for C-Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
789 info.Serialize(vv); |
2568 | 790 v.append(vv); |
791 } | |
2566
c09ce3c038fc
improved handling of eta
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2565
diff
changeset
|
792 } |
c09ce3c038fc
improved handling of eta
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2565
diff
changeset
|
793 |
c09ce3c038fc
improved handling of eta
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2565
diff
changeset
|
794 std::cout << v << std::endl; |
2565 | 795 } |
796 } |