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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
827
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 776
diff changeset
1 /**
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 776
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1681
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1288
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1009
diff changeset
4 * Department, University Hospital of Liege, Belgium
2447
878b59270859 upgrade to year 2018
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2382
diff changeset
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium
827
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 776
diff changeset
6 *
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 776
diff changeset
7 * This program is free software: you can redistribute it and/or
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 776
diff changeset
8 * modify it under the terms of the GNU General Public License as
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 776
diff changeset
9 * published by the Free Software Foundation, either version 3 of the
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 776
diff changeset
10 * License, or (at your option) any later version.
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 776
diff changeset
11 *
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 776
diff changeset
12 * In addition, as a special exception, the copyright holders of this
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 776
diff changeset
13 * program give permission to link the code of its release with the
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 776
diff changeset
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 776
diff changeset
15 * that use the same license as the "OpenSSL" library), and distribute
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 776
diff changeset
16 * the linked executables. You must obey the GNU General Public License
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 776
diff changeset
17 * in all respects for all of the code used other than "OpenSSL". If you
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 776
diff changeset
18 * modify file(s) with this exception, you may extend this exception to
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 776
diff changeset
19 * your version of the file(s), but you are not obligated to do so. If
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 776
diff changeset
20 * you do not wish to do so, delete this exception statement from your
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 776
diff changeset
21 * version. If you delete this exception statement from all source files
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 776
diff changeset
22 * in the program, then also delete it here.
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 776
diff changeset
23 *
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 776
diff changeset
24 * This program is distributed in the hope that it will be useful, but
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 776
diff changeset
25 * WITHOUT ANY WARRANTY; without even the implied warranty of
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 776
diff changeset
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 776
diff changeset
27 * General Public License for more details.
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 776
diff changeset
28 *
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 776
diff changeset
29 * You should have received a copy of the GNU General Public License
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 776
diff changeset
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 776
diff changeset
31 **/
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 776
diff changeset
32
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 776
diff changeset
33
831
84513f2ee1f3 pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 827
diff changeset
34 #include "PrecompiledHeadersUnitTests.h"
723
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 #include "gtest/gtest.h"
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
2569
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2568
diff changeset
37 #include "../Core/JobsEngine/JobStepRetry.h"
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2568
diff changeset
38 #include "../Core/JobsEngine/JobsEngine.h"
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2568
diff changeset
39 #include "../Core/MultiThreading/Locker.h"
723
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 #include "../Core/Toolbox.h"
2569
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2568
diff changeset
43 #include "../OrthancServer/Scheduler/ServerScheduler.h"
723
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 using namespace Orthanc;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 namespace
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 private:
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 int value_;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 std::set<int>& target_;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 public:
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 DynamicInteger(int value, std::set<int>& target) :
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 value_(value), target_(target)
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 }
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 int GetValue() const
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 return value_;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 }
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 };
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 }
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 TEST(MultiThreading, SharedMessageQueueBasic)
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 std::set<int> s;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 SharedMessageQueue q;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 ASSERT_TRUE(q.WaitEmpty(0));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 q.Enqueue(new DynamicInteger(10, s));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 ASSERT_FALSE(q.WaitEmpty(1));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 q.Enqueue(new DynamicInteger(20, s));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 q.Enqueue(new DynamicInteger(30, s));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 q.Enqueue(new DynamicInteger(40, s));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 std::auto_ptr<DynamicInteger> i;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 i.reset(dynamic_cast<DynamicInteger*>(q.Dequeue(1))); ASSERT_EQ(10, i->GetValue());
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 i.reset(dynamic_cast<DynamicInteger*>(q.Dequeue(1))); ASSERT_EQ(20, i->GetValue());
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 i.reset(dynamic_cast<DynamicInteger*>(q.Dequeue(1))); ASSERT_EQ(30, i->GetValue());
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 ASSERT_FALSE(q.WaitEmpty(1));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 i.reset(dynamic_cast<DynamicInteger*>(q.Dequeue(1))); ASSERT_EQ(40, i->GetValue());
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 ASSERT_TRUE(q.WaitEmpty(0));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 ASSERT_EQ(NULL, q.Dequeue(1));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 }
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 TEST(MultiThreading, SharedMessageQueueClean)
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 std::set<int> s;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 try
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 SharedMessageQueue q;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 q.Enqueue(new DynamicInteger(10, s));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 }
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 catch (OrthancException&)
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 }
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 }
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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>
parents: 770 769
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
aa4b8895cd23 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1907
diff changeset
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
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
138
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
139
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
140
1000
13e230bbd882 rename filter to command
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
141 class Tutu : public IServerCommand
765
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
142 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
143 private:
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
144 int factor_;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
145
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
146 public:
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
147 Tutu(int f) : factor_(f)
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
148 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
149 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
150
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
151 virtual bool Apply(ListOfStrings& outputs,
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
152 const ListOfStrings& inputs)
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
153 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
154 for (ListOfStrings::const_iterator
1304
7b6925b0890d cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
155 it = inputs.begin(); it != inputs.end(); ++it)
765
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
156 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
157 int a = boost::lexical_cast<int>(*it);
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
158 int b = factor_ * a;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
159
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
160 printf("%d * %d = %d\n", a, factor_, b);
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
161
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
162 //if (a == 84) { printf("BREAK\n"); return false; }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
163
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
164 outputs.push_back(boost::lexical_cast<std::string>(b));
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
165 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
166
2242
4e8e0ad2001c move USleep() in SystemToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2222
diff changeset
167 SystemToolbox::USleep(30000);
765
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
168
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
169 return true;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
170 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
171 };
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
172
768
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
173
770
a64ca424e0e2 fix test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 768
diff changeset
174 static void Tata(ServerScheduler* s, ServerJob* j, bool* done)
768
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
175 {
1000
13e230bbd882 rename filter to command
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
176 typedef IServerCommand::ListOfStrings ListOfStrings;
779
76eb563f08f0 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 777
diff changeset
177
770
a64ca424e0e2 fix test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 768
diff changeset
178 while (!(*done))
768
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
179 {
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
180 ListOfStrings l;
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
181 s->GetListOfJobs(l);
1304
7b6925b0890d cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
182 for (ListOfStrings::iterator it = l.begin(); it != l.end(); ++it)
7b6925b0890d cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
183 {
7b6925b0890d cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
184 printf(">> %s: %0.1f\n", it->c_str(), 100.0f * s->GetProgress(*it));
7b6925b0890d cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
185 }
2242
4e8e0ad2001c move USleep() in SystemToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2222
diff changeset
186 SystemToolbox::USleep(3000);
768
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
187 }
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
188 }
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
189
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
190
1009
26642cecd36d clearer job interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1005
diff changeset
191 TEST(MultiThreading, ServerScheduler)
765
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
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
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
194
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
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
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
200 f2.AddInput(boost::lexical_cast<std::string>(42));
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
201 //f3.AddInput(boost::lexical_cast<std::string>(42));
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
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
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
209
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
210 job.SetDescription("tutu");
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
211
770
a64ca424e0e2 fix test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 768
diff changeset
212 bool done = false;
a64ca424e0e2 fix test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 768
diff changeset
213 boost::thread t(Tata, &scheduler, &job, &done);
768
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
214
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
215
765
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
216 //scheduler.Submit(job);
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
217
1000
13e230bbd882 rename filter to command
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
218 IServerCommand::ListOfStrings l;
765
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
219 scheduler.SubmitAndWait(l, job);
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
220
1492
9f66a12eb8fc fix warnings for gcc 5
jodogne
parents: 1486
diff changeset
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
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
226 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
227 printf("** %s\n", i->c_str());
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
228 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
229
2140
aa4b8895cd23 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1907
diff changeset
230 //SystemToolbox::ServerBarrier();
2242
4e8e0ad2001c move USleep() in SystemToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2222
diff changeset
231 //SystemToolbox::USleep(3000000);
768
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
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
a64ca424e0e2 fix test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 768
diff changeset
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
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
240 }
2556
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
241
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
242
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
243
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
244 class DummyJob : public Orthanc::IJob
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
245 {
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
246 private:
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
247 JobStepResult result_;
2565
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
248 unsigned int count_;
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
249 unsigned int steps_;
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
250
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
251 public:
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
252 DummyJob() :
2565
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
253 result_(Orthanc::JobStepCode_Success),
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
254 count_(0),
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
255 steps_(4)
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
256 {
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
257 }
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
258
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
259 explicit DummyJob(JobStepResult result) :
2565
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
260 result_(result),
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
261 count_(0),
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
262 steps_(4)
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
263 {
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
264 }
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
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
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
274 virtual JobStepResult* ExecuteStep()
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
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
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
277
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
278 if (count_ == steps_ - 1)
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
279 {
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
280 return new JobStepResult(result_);
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
281 }
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
282 else
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
283 {
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
284 count_++;
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
285 return new JobStepResult(JobStepCode_Continue);
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
286 }
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
287 }
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
288
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
289 virtual void ReleaseResources()
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
290 {
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
291 }
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
292
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
293 virtual float GetProgress()
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
294 {
2565
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
295 return static_cast<float>(count_) / static_cast<float>(steps_ - 1);
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
296 }
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
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
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
308 {
2565
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
309 value["hello"] = "world";
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
310 }
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
311 };
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
312
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
313
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
314 static bool CheckState(Orthanc::JobsRegistry& registry,
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
315 const std::string& id,
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
316 Orthanc::JobState state)
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
317 {
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
318 Orthanc::JobState s;
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
319 if (registry.GetState(s, id))
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
320 {
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
321 return state == s;
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
322 }
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
323 else
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
324 {
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
325 return false;
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
326 }
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
327 }
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
328
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
346 TEST(JobsRegistry, Priority)
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
347 {
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
348 JobsRegistry registry;
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
349
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
350 std::string i1, i2, i3, i4;
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
351 registry.Submit(i1, new DummyJob(), 10);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
352 registry.Submit(i2, new DummyJob(), 30);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
353 registry.Submit(i3, new DummyJob(), 20);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
354 registry.Submit(i4, new DummyJob(), 5);
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
355
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
356 registry.SetMaxCompletedJobs(2);
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
357
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
358 std::set<std::string> id;
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
359 registry.ListJobs(id);
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
360
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
361 ASSERT_EQ(4u, id.size());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
362 ASSERT_TRUE(id.find(i1) != id.end());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
363 ASSERT_TRUE(id.find(i2) != id.end());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
364 ASSERT_TRUE(id.find(i3) != id.end());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
365 ASSERT_TRUE(id.find(i4) != id.end());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
366
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
367 ASSERT_TRUE(CheckState(registry, i2, Orthanc::JobState_Pending));
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
368
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
369 {
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
370 JobsRegistry::RunningJob job(registry, 0);
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
371 ASSERT_TRUE(job.IsValid());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
372 ASSERT_EQ(30, job.GetPriority());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
373 ASSERT_EQ(i2, job.GetId());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
374
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
375 ASSERT_TRUE(CheckState(registry, i2, Orthanc::JobState_Running));
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
376 }
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
377
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
378 ASSERT_TRUE(CheckState(registry, i2, Orthanc::JobState_Failure));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
379 ASSERT_TRUE(CheckState(registry, i3, Orthanc::JobState_Pending));
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
380
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
381 {
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
382 JobsRegistry::RunningJob job(registry, 0);
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
383 ASSERT_TRUE(job.IsValid());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
384 ASSERT_EQ(20, job.GetPriority());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
385 ASSERT_EQ(i3, job.GetId());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
386
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
387 job.MarkSuccess();
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
388
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
389 ASSERT_TRUE(CheckState(registry, i3, Orthanc::JobState_Running));
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
390 }
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
391
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
392 ASSERT_TRUE(CheckState(registry, i3, Orthanc::JobState_Success));
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
393
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
394 {
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
395 JobsRegistry::RunningJob job(registry, 0);
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
396 ASSERT_TRUE(job.IsValid());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
397 ASSERT_EQ(10, job.GetPriority());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
398 ASSERT_EQ(i1, job.GetId());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
399 }
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
400
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
401 {
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
402 JobsRegistry::RunningJob job(registry, 0);
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
403 ASSERT_TRUE(job.IsValid());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
404 ASSERT_EQ(5, job.GetPriority());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
405 ASSERT_EQ(i4, job.GetId());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
406 }
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
407
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
408 {
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
409 JobsRegistry::RunningJob job(registry, 1);
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
410 ASSERT_FALSE(job.IsValid());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
411 }
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
412
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
413 Orthanc::JobState s;
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
414 ASSERT_TRUE(registry.GetState(s, i1));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
415 ASSERT_FALSE(registry.GetState(s, i2)); // Removed because oldest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
416 ASSERT_FALSE(registry.GetState(s, i3)); // Removed because second oldest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
417 ASSERT_TRUE(registry.GetState(s, i4));
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
418
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
419 registry.SetMaxCompletedJobs(1); // (*)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
420 ASSERT_FALSE(registry.GetState(s, i1)); // Just discarded by (*)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
421 ASSERT_TRUE(registry.GetState(s, i4));
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
422 }
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
423
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
424
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
425 TEST(JobsRegistry, Simultaneous)
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
426 {
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
427 JobsRegistry registry;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
428
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
429 std::string i1, i2;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
430 registry.Submit(i1, new DummyJob(), 20);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
431 registry.Submit(i2, new DummyJob(), 10);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
432
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
433 ASSERT_TRUE(CheckState(registry, i1, Orthanc::JobState_Pending));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
434 ASSERT_TRUE(CheckState(registry, i2, Orthanc::JobState_Pending));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
435
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
436 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
437 JobsRegistry::RunningJob job1(registry, 0);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
438 JobsRegistry::RunningJob job2(registry, 0);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
439
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
440 ASSERT_TRUE(job1.IsValid());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
441 ASSERT_TRUE(job2.IsValid());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
442
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
443 job1.MarkFailure();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
444 job2.MarkSuccess();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
445
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
446 ASSERT_TRUE(CheckState(registry, i1, Orthanc::JobState_Running));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
447 ASSERT_TRUE(CheckState(registry, i2, Orthanc::JobState_Running));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
448 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
449
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
450 ASSERT_TRUE(CheckState(registry, i1, Orthanc::JobState_Failure));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
451 ASSERT_TRUE(CheckState(registry, i2, Orthanc::JobState_Success));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
452 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
453
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
454
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
455 TEST(JobsRegistry, Resubmit)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
456 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
457 JobsRegistry registry;
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
458
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
459 std::string id;
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
460 registry.Submit(id, new DummyJob(), 10);
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
461
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
462 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending));
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
463
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
464 registry.Resubmit(id);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
465 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending));
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
466
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
467 {
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
468 JobsRegistry::RunningJob job(registry, 0);
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
469 ASSERT_TRUE(job.IsValid());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
470 job.MarkFailure();
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
471
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
472 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Running));
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
473
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
474 registry.Resubmit(id);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
475 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Running));
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
476 }
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
477
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
478 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Failure));
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
479
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
480 registry.Resubmit(id);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
481 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending));
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
482
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
483 {
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
484 JobsRegistry::RunningJob job(registry, 0);
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
485 ASSERT_TRUE(job.IsValid());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
486 ASSERT_EQ(id, job.GetId());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
487
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
488 job.MarkSuccess();
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
489 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Running));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
490 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
491
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
492 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Success));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
493
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
494 registry.Resubmit(id);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
495 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Success));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
496 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
497
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
498
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
499 TEST(JobsRegistry, Retry)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
500 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
501 JobsRegistry registry;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
502
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
503 std::string id;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
504 registry.Submit(id, new DummyJob(), 10);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
505
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
506 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
507
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
508 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
509 JobsRegistry::RunningJob job(registry, 0);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
510 ASSERT_TRUE(job.IsValid());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
511 job.MarkRetry(0);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
512
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
513 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Running));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
514 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
515
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
516 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Retry));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
517
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
518 registry.Resubmit(id);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
519 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Retry));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
520
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
521 registry.ScheduleRetries();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
522 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
523
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
524 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
525 JobsRegistry::RunningJob job(registry, 0);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
526 ASSERT_TRUE(job.IsValid());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
527 job.MarkSuccess();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
528
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
529 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Running));
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
530 }
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
531
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
532 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Success));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
533 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
534
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
535
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
536 TEST(JobsRegistry, PausePending)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
537 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
538 JobsRegistry registry;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
539
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
540 std::string id;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
541 registry.Submit(id, new DummyJob(), 10);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
542
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
543 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
544
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
545 registry.Pause(id);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
546 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Paused));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
547
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
548 registry.Pause(id);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
549 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Paused));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
550
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
551 registry.Resubmit(id);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
552 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Paused));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
553
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
554 registry.Resume(id);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
555 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending));
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
556 }
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
557
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
559 TEST(JobsRegistry, PauseRunning)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
560 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
561 JobsRegistry registry;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
562
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
563 std::string id;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
564 registry.Submit(id, new DummyJob(), 10);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
565
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
566 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
567
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
568 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
569 JobsRegistry::RunningJob job(registry, 0);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
570 ASSERT_TRUE(job.IsValid());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
571
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
572 registry.Resubmit(id);
2562
1e66fe3ddf9f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2559
diff changeset
573 job.MarkPause();
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
574 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Running));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
575 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
576
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
577 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Paused));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
578
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
579 registry.Resubmit(id);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
580 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Paused));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
581
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
582 registry.Resume(id);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
583 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
584
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
585 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
586 JobsRegistry::RunningJob job(registry, 0);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
587 ASSERT_TRUE(job.IsValid());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
588
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
589 job.MarkSuccess();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
590 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Running));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
591 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
592
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
593 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Success));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
594 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
595
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
596
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
597 TEST(JobsRegistry, PauseRetry)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
598 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
599 JobsRegistry registry;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
600
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
601 std::string id;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
602 registry.Submit(id, new DummyJob(), 10);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
603
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
604 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
605
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
606 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
607 JobsRegistry::RunningJob job(registry, 0);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
608 ASSERT_TRUE(job.IsValid());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
609
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
610 job.MarkRetry(0);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
611 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Running));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
612 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
613
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
614 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Retry));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
615
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
616 registry.Pause(id);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
617 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Paused));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
618
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
619 registry.Resume(id);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
620 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
621
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
622 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
623 JobsRegistry::RunningJob job(registry, 0);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
624 ASSERT_TRUE(job.IsValid());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
625
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
626 job.MarkSuccess();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
627 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Running));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
628 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
629
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
630 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Success));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
631 }
2565
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
632
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
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
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
729 TEST(JobsEngine, Basic)
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
730 {
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
731 JobsEngine engine;
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
732
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
733 std::string s;
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
734
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
735 for (size_t i = 0; i < 20; i++)
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
736 engine.GetRegistry().Submit(s, new DummyJob(), rand() % 10);
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
737
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
738 engine.SetWorkersCount(3);
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
739 engine.Start();
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
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
a46094602346 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2567
diff changeset
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
a46094602346 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2567
diff changeset
747 engine.GetRegistry().ListJobs(jobs);
2566
c09ce3c038fc improved handling of eta
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2565
diff changeset
748
2568
a46094602346 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2567
diff changeset
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
a46094602346 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2567
diff changeset
752 JobInfo info;
a46094602346 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2567
diff changeset
753
a46094602346 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2567
diff changeset
754 if (engine.GetRegistry().GetJobInfo(info, *it))
a46094602346 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2567
diff changeset
755 {
a46094602346 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2567
diff changeset
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
a46094602346 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2567
diff changeset
758 v.append(vv);
a46094602346 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2567
diff changeset
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
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
775
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
776 engine.Stop();
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
777
2570
2e879c796ec7 JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2569
diff changeset
778 if (0)
2565
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
779 {
2568
a46094602346 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2567
diff changeset
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
a46094602346 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2567
diff changeset
783 engine.GetRegistry().ListJobs(jobs);
2566
c09ce3c038fc improved handling of eta
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2565
diff changeset
784
2568
a46094602346 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2567
diff changeset
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
a46094602346 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2567
diff changeset
788 JobInfo info;
a46094602346 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2567
diff changeset
789
a46094602346 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2567
diff changeset
790 if (engine.GetRegistry().GetJobInfo(info, *it))
a46094602346 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2567
diff changeset
791 {
a46094602346 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2567
diff changeset
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
a46094602346 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2567
diff changeset
794 v.append(vv);
a46094602346 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2567
diff changeset
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
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
799 }
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
800 }