annotate UnitTestsSources/MultiThreadingTests.cpp @ 2624:714dcddeb65f jobs

asynchronous c-movoe
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 24 May 2018 21:44:22 +0200
parents 83ac5a05ce84
children e1893d31652a
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/JobsEngine.h"
2610
3ff4c50647ea moving the old scheduler to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2606
diff changeset
38 #include "../Core/MultiThreading/SharedMessageQueue.h"
723
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 #include "../Core/OrthancException.h"
2143
fd5875662670 creation of namespace SystemToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2140
diff changeset
40 #include "../Core/SystemToolbox.h"
723
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 #include "../Core/Toolbox.h"
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 using namespace Orthanc;
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 namespace
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 {
1396
ac4efabeb80c Migration of the orthanc-client as a separate project
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1304
diff changeset
47 class DynamicInteger : public IDynamicObject
723
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 private:
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 int value_;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 std::set<int>& target_;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 public:
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 DynamicInteger(int value, std::set<int>& target) :
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 value_(value), target_(target)
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 }
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 int GetValue() const
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 return value_;
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 };
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 TEST(MultiThreading, SharedMessageQueueBasic)
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 std::set<int> s;
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 SharedMessageQueue q;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 ASSERT_TRUE(q.WaitEmpty(0));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 q.Enqueue(new DynamicInteger(10, s));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 ASSERT_FALSE(q.WaitEmpty(1));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 q.Enqueue(new DynamicInteger(20, s));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 q.Enqueue(new DynamicInteger(30, s));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 q.Enqueue(new DynamicInteger(40, s));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 std::auto_ptr<DynamicInteger> i;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 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
81 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
82 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
83 ASSERT_FALSE(q.WaitEmpty(1));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 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
85 ASSERT_TRUE(q.WaitEmpty(0));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 ASSERT_EQ(NULL, q.Dequeue(1));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 }
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88
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 TEST(MultiThreading, SharedMessageQueueClean)
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 std::set<int> s;
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 try
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 SharedMessageQueue q;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 q.Enqueue(new DynamicInteger(10, s));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 q.Enqueue(new DynamicInteger(20, s));
1583
9ea3d082b064 got rid of custom exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1582
diff changeset
99 throw OrthancException(ErrorCode_InternalError);
723
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 }
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 catch (OrthancException&)
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 }
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
769
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
107
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
108
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
109 class DummyJob : public Orthanc::IJob
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
110 {
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
111 private:
2598
34dc57f4a7d2 simplification of JobStepResult
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2589
diff changeset
112 bool fails_;
2565
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
113 unsigned int count_;
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
114 unsigned int steps_;
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
115
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
116 public:
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
117 DummyJob() :
2598
34dc57f4a7d2 simplification of JobStepResult
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2589
diff changeset
118 fails_(false),
2565
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
119 count_(0),
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
120 steps_(4)
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
121 {
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
122 }
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
123
2598
34dc57f4a7d2 simplification of JobStepResult
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2589
diff changeset
124 explicit DummyJob(bool fails) :
34dc57f4a7d2 simplification of JobStepResult
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2589
diff changeset
125 fails_(fails),
2565
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
126 count_(0),
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
127 steps_(4)
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
128 {
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
129 }
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
130
2570
2e879c796ec7 JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2569
diff changeset
131 virtual void Start()
2e879c796ec7 JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2569
diff changeset
132 {
2e879c796ec7 JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2569
diff changeset
133 }
2583
1b6a6d80b6f2 OrthancPeerStoreJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2581
diff changeset
134
1b6a6d80b6f2 OrthancPeerStoreJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2581
diff changeset
135 virtual void SignalResubmit()
1b6a6d80b6f2 OrthancPeerStoreJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2581
diff changeset
136 {
1b6a6d80b6f2 OrthancPeerStoreJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2581
diff changeset
137 }
2570
2e879c796ec7 JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2569
diff changeset
138
2598
34dc57f4a7d2 simplification of JobStepResult
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2589
diff changeset
139 virtual JobStepResult ExecuteStep()
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
140 {
2598
34dc57f4a7d2 simplification of JobStepResult
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2589
diff changeset
141 if (fails_)
2565
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
142 {
2598
34dc57f4a7d2 simplification of JobStepResult
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2589
diff changeset
143 return JobStepResult::Failure(ErrorCode_ParameterOutOfRange);
34dc57f4a7d2 simplification of JobStepResult
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2589
diff changeset
144 }
34dc57f4a7d2 simplification of JobStepResult
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2589
diff changeset
145 else if (count_ == steps_ - 1)
34dc57f4a7d2 simplification of JobStepResult
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2589
diff changeset
146 {
34dc57f4a7d2 simplification of JobStepResult
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2589
diff changeset
147 return JobStepResult::Success();
2565
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
148 }
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
149 else
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
150 {
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
151 count_++;
2598
34dc57f4a7d2 simplification of JobStepResult
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2589
diff changeset
152 return JobStepResult::Continue();
2565
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
153 }
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
154 }
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
155
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
156 virtual void ReleaseResources()
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
157 {
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
158 }
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
159
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
160 virtual float GetProgress()
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
161 {
2565
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
162 return static_cast<float>(count_) / static_cast<float>(steps_ - 1);
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
163 }
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
164
2580
055d7d4a823f avoid unecessary openings of DICOM connection for C-Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2573
diff changeset
165 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
166 {
055d7d4a823f avoid unecessary openings of DICOM connection for C-Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2573
diff changeset
167 type = "DummyJob";
055d7d4a823f avoid unecessary openings of DICOM connection for C-Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2573
diff changeset
168 }
055d7d4a823f avoid unecessary openings of DICOM connection for C-Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2573
diff changeset
169
055d7d4a823f avoid unecessary openings of DICOM connection for C-Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2573
diff changeset
170 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
171 {
055d7d4a823f avoid unecessary openings of DICOM connection for C-Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2573
diff changeset
172 }
055d7d4a823f avoid unecessary openings of DICOM connection for C-Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2573
diff changeset
173
055d7d4a823f avoid unecessary openings of DICOM connection for C-Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2573
diff changeset
174 virtual void GetPublicContent(Json::Value& value)
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
175 {
2565
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
176 value["hello"] = "world";
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
177 }
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
178 };
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
179
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
180
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
181 static bool CheckState(Orthanc::JobsRegistry& registry,
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
182 const std::string& id,
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
183 Orthanc::JobState state)
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
184 {
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
185 Orthanc::JobState s;
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
186 if (registry.GetState(s, id))
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
187 {
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
188 return state == s;
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
189 }
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
190 else
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
191 {
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
192 return false;
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
193 }
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
194 }
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
195
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
196
2581
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
197 static bool CheckErrorCode(Orthanc::JobsRegistry& registry,
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
198 const std::string& id,
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
199 Orthanc::ErrorCode code)
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
200 {
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
201 Orthanc::JobInfo s;
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
202 if (registry.GetJobInfo(s, id))
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
203 {
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
204 return code == s.GetStatus().GetErrorCode();
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
205 }
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
206 else
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
207 {
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
208 return false;
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
209 }
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
210 }
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
211
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
212
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
213 TEST(JobsRegistry, Priority)
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
214 {
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
215 JobsRegistry registry;
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
216
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
217 std::string i1, i2, i3, i4;
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
218 registry.Submit(i1, new DummyJob(), 10);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
219 registry.Submit(i2, new DummyJob(), 30);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
220 registry.Submit(i3, new DummyJob(), 20);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
221 registry.Submit(i4, new DummyJob(), 5);
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
222
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
223 registry.SetMaxCompletedJobs(2);
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
224
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
225 std::set<std::string> id;
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
226 registry.ListJobs(id);
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
227
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
228 ASSERT_EQ(4u, id.size());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
229 ASSERT_TRUE(id.find(i1) != id.end());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
230 ASSERT_TRUE(id.find(i2) != id.end());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
231 ASSERT_TRUE(id.find(i3) != id.end());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
232 ASSERT_TRUE(id.find(i4) != id.end());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
233
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
234 ASSERT_TRUE(CheckState(registry, i2, Orthanc::JobState_Pending));
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
235
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
236 {
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
237 JobsRegistry::RunningJob job(registry, 0);
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
238 ASSERT_TRUE(job.IsValid());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
239 ASSERT_EQ(30, job.GetPriority());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
240 ASSERT_EQ(i2, job.GetId());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
241
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
242 ASSERT_TRUE(CheckState(registry, i2, Orthanc::JobState_Running));
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
243 }
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
244
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
245 ASSERT_TRUE(CheckState(registry, i2, Orthanc::JobState_Failure));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
246 ASSERT_TRUE(CheckState(registry, i3, Orthanc::JobState_Pending));
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
247
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
248 {
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
249 JobsRegistry::RunningJob job(registry, 0);
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
250 ASSERT_TRUE(job.IsValid());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
251 ASSERT_EQ(20, job.GetPriority());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
252 ASSERT_EQ(i3, job.GetId());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
253
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
254 job.MarkSuccess();
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
255
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
256 ASSERT_TRUE(CheckState(registry, i3, Orthanc::JobState_Running));
2557
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
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
259 ASSERT_TRUE(CheckState(registry, i3, Orthanc::JobState_Success));
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
260
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
261 {
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
262 JobsRegistry::RunningJob job(registry, 0);
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
263 ASSERT_TRUE(job.IsValid());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
264 ASSERT_EQ(10, job.GetPriority());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
265 ASSERT_EQ(i1, job.GetId());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
266 }
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
267
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
268 {
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
269 JobsRegistry::RunningJob job(registry, 0);
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
270 ASSERT_TRUE(job.IsValid());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
271 ASSERT_EQ(5, job.GetPriority());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
272 ASSERT_EQ(i4, job.GetId());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
273 }
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
274
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
275 {
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
276 JobsRegistry::RunningJob job(registry, 1);
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
277 ASSERT_FALSE(job.IsValid());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
278 }
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
279
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
280 Orthanc::JobState s;
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
281 ASSERT_TRUE(registry.GetState(s, i1));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
282 ASSERT_FALSE(registry.GetState(s, i2)); // Removed because oldest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
283 ASSERT_FALSE(registry.GetState(s, i3)); // Removed because second oldest
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
284 ASSERT_TRUE(registry.GetState(s, i4));
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
285
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
286 registry.SetMaxCompletedJobs(1); // (*)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
287 ASSERT_FALSE(registry.GetState(s, i1)); // Just discarded by (*)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
288 ASSERT_TRUE(registry.GetState(s, i4));
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
289 }
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
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
292 TEST(JobsRegistry, Simultaneous)
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
293 {
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
294 JobsRegistry registry;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
295
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
296 std::string i1, i2;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
297 registry.Submit(i1, new DummyJob(), 20);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
298 registry.Submit(i2, new DummyJob(), 10);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
299
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
300 ASSERT_TRUE(CheckState(registry, i1, Orthanc::JobState_Pending));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
301 ASSERT_TRUE(CheckState(registry, i2, Orthanc::JobState_Pending));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
302
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
303 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
304 JobsRegistry::RunningJob job1(registry, 0);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
305 JobsRegistry::RunningJob job2(registry, 0);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
306
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
307 ASSERT_TRUE(job1.IsValid());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
308 ASSERT_TRUE(job2.IsValid());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
309
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
310 job1.MarkFailure();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
311 job2.MarkSuccess();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
312
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
313 ASSERT_TRUE(CheckState(registry, i1, Orthanc::JobState_Running));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
314 ASSERT_TRUE(CheckState(registry, i2, Orthanc::JobState_Running));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
315 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
316
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
317 ASSERT_TRUE(CheckState(registry, i1, Orthanc::JobState_Failure));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
318 ASSERT_TRUE(CheckState(registry, i2, Orthanc::JobState_Success));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
319 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
320
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
321
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
322 TEST(JobsRegistry, Resubmit)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
323 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
324 JobsRegistry registry;
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
325
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
326 std::string id;
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
327 registry.Submit(id, new DummyJob(), 10);
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
328
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
329 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending));
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
330
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
331 registry.Resubmit(id);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
332 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending));
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
333
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
334 {
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
335 JobsRegistry::RunningJob job(registry, 0);
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
336 ASSERT_TRUE(job.IsValid());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
337 job.MarkFailure();
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
338
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
339 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Running));
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
340
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
341 registry.Resubmit(id);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
342 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Running));
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
343 }
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
344
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
345 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Failure));
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
346
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
347 registry.Resubmit(id);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
348 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending));
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 {
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
351 JobsRegistry::RunningJob job(registry, 0);
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
352 ASSERT_TRUE(job.IsValid());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
353 ASSERT_EQ(id, job.GetId());
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
354
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
355 job.MarkSuccess();
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
356 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Running));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
357 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
358
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
359 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Success));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
360
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
361 registry.Resubmit(id);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
362 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Success));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
363 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
364
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
365
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
366 TEST(JobsRegistry, Retry)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
367 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
368 JobsRegistry registry;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
369
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
370 std::string id;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
371 registry.Submit(id, new DummyJob(), 10);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
372
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
373 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
374
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
375 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
376 JobsRegistry::RunningJob job(registry, 0);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
377 ASSERT_TRUE(job.IsValid());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
378 job.MarkRetry(0);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
379
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
380 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Running));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
381 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
382
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
383 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Retry));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
384
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
385 registry.Resubmit(id);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
386 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Retry));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
387
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
388 registry.ScheduleRetries();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
389 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
390
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
391 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
392 JobsRegistry::RunningJob job(registry, 0);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
393 ASSERT_TRUE(job.IsValid());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
394 job.MarkSuccess();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
395
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
396 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Running));
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
397 }
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
398
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
399 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Success));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
400 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
401
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
402
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
403 TEST(JobsRegistry, PausePending)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
404 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
405 JobsRegistry registry;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
406
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
407 std::string id;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
408 registry.Submit(id, new DummyJob(), 10);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
409
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
410 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
411
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
412 registry.Pause(id);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
413 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Paused));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
414
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
415 registry.Pause(id);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
416 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Paused));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
417
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
418 registry.Resubmit(id);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
419 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Paused));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
420
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
421 registry.Resume(id);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
422 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending));
2557
b4516a6f214b state machine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2556
diff changeset
423 }
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
424
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
425
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
426 TEST(JobsRegistry, PauseRunning)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
427 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
428 JobsRegistry registry;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
429
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
430 std::string id;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
431 registry.Submit(id, 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, id, Orthanc::JobState_Pending));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
434
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
435 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
436 JobsRegistry::RunningJob job(registry, 0);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
437 ASSERT_TRUE(job.IsValid());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
438
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
439 registry.Resubmit(id);
2562
1e66fe3ddf9f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2559
diff changeset
440 job.MarkPause();
2558
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
441 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Running));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
442 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
443
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
444 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Paused));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
445
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
446 registry.Resubmit(id);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
447 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Paused));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
448
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
449 registry.Resume(id);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
450 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
451
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
452 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
453 JobsRegistry::RunningJob job(registry, 0);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
454 ASSERT_TRUE(job.IsValid());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
455
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
456 job.MarkSuccess();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
457 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Running));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
458 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
459
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
460 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Success));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
461 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
462
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
463
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
464 TEST(JobsRegistry, PauseRetry)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
465 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
466 JobsRegistry registry;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
467
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
468 std::string id;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
469 registry.Submit(id, new DummyJob(), 10);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
470
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
471 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
472
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
473 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
474 JobsRegistry::RunningJob job(registry, 0);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
475 ASSERT_TRUE(job.IsValid());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
476
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
477 job.MarkRetry(0);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
478 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Running));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
479 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
480
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
481 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Retry));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
482
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
483 registry.Pause(id);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
484 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Paused));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
485
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
486 registry.Resume(id);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
487 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
488
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
489 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
490 JobsRegistry::RunningJob job(registry, 0);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
491 ASSERT_TRUE(job.IsValid());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
492
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
493 job.MarkSuccess();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
494 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Running));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
495 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
496
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
497 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Success));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2557
diff changeset
498 }
2565
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
499
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
500
2581
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
501 TEST(JobsRegistry, Cancel)
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
502 {
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
503 JobsRegistry registry;
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
504
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
505 std::string id;
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
506 registry.Submit(id, new DummyJob(), 10);
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
507
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
508 ASSERT_FALSE(registry.Cancel("nope"));
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
509
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
510 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending));
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
511 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_Success));
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
512
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
513 ASSERT_TRUE(registry.Cancel(id));
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
514 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Failure));
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
515 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_CanceledJob));
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
516
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
517 ASSERT_TRUE(registry.Cancel(id));
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
518 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Failure));
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
519 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_CanceledJob));
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
520
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
521 ASSERT_TRUE(registry.Resubmit(id));
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
522 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending));
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
523 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_CanceledJob));
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
524
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
525 {
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
526 JobsRegistry::RunningJob job(registry, 0);
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
527 ASSERT_TRUE(job.IsValid());
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
528
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
529 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_Success));
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
530
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
531 job.MarkSuccess();
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
532 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Running));
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
533 }
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
534
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
535 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Success));
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
536 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_Success));
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
537
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
538 ASSERT_TRUE(registry.Cancel(id));
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
539 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Success));
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
540 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_Success));
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
541
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
542 registry.Submit(id, new DummyJob(), 10);
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
543
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
544 {
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
545 JobsRegistry::RunningJob job(registry, 0);
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
546 ASSERT_TRUE(job.IsValid());
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
547 ASSERT_EQ(id, job.GetId());
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
548
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
549 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_Success));
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
550 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Running));
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
551
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
552 job.MarkCanceled();
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
553 }
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
554
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
555 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Failure));
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
556 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_CanceledJob));
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
557
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
558 ASSERT_TRUE(registry.Resubmit(id));
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
559 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending));
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
560 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_CanceledJob));
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
561
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
562 ASSERT_TRUE(registry.Pause(id));
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
563 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Paused));
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
564 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_CanceledJob));
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
565
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
566 ASSERT_TRUE(registry.Cancel(id));
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
567 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Failure));
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
568 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_CanceledJob));
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
569
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
570 ASSERT_TRUE(registry.Resubmit(id));
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
571 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending));
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
572 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_CanceledJob));
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
573
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
574 {
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
575 JobsRegistry::RunningJob job(registry, 0);
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
576 ASSERT_TRUE(job.IsValid());
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
577 ASSERT_EQ(id, job.GetId());
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
578
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
579 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_Success));
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
580 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Running));
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
581
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
582 job.MarkRetry(500);
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
583 }
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
584
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
585 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Retry));
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
586 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_Success));
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
587
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
588 ASSERT_TRUE(registry.Cancel(id));
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
589 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Failure));
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
590 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_CanceledJob));
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
591 }
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
592
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2580
diff changeset
593
2570
2e879c796ec7 JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2569
diff changeset
594
2599
593d6b0f4cba IJobOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2598
diff changeset
595 TEST(JobsEngine, SubmitAndWait)
2565
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
596 {
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
597 JobsEngine engine;
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
598 engine.SetWorkersCount(3);
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
599 engine.Start();
0f06b4d5b3d0 JobsEngine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2564
diff changeset
600
2599
593d6b0f4cba IJobOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2598
diff changeset
601 ASSERT_TRUE(engine.GetRegistry().SubmitAndWait(new DummyJob(), rand() % 10));
593d6b0f4cba IJobOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2598
diff changeset
602 ASSERT_FALSE(engine.GetRegistry().SubmitAndWait(new DummyJob(true), rand() % 10));
593d6b0f4cba IJobOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2598
diff changeset
603
593d6b0f4cba IJobOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2598
diff changeset
604 engine.Stop();
593d6b0f4cba IJobOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2598
diff changeset
605 }
593d6b0f4cba IJobOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2598
diff changeset
606
593d6b0f4cba IJobOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2598
diff changeset
607
2566
c09ce3c038fc improved handling of eta
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2565
diff changeset
608
2599
593d6b0f4cba IJobOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2598
diff changeset
609
593d6b0f4cba IJobOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2598
diff changeset
610
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2601
diff changeset
611 #include "../OrthancServer/ServerJobs/LuaJobManager.h"
2601
5b6c3d77a2a1 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2600
diff changeset
612 #include "../Core/JobsEngine/Operations/StringOperationValue.h"
5b6c3d77a2a1 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2600
diff changeset
613 #include "../Core/JobsEngine/Operations/LogJobOperation.h"
2599
593d6b0f4cba IJobOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2598
diff changeset
614
2600
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
615
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
616 TEST(JobsEngine, DISABLED_SequenceOfOperationsJob)
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
617 {
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
618 JobsEngine engine;
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
619 engine.SetWorkersCount(3);
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
620 engine.Start();
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
621
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
622 std::string id;
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
623 SequenceOfOperationsJob* job = NULL;
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
624
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
625 {
2601
5b6c3d77a2a1 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2600
diff changeset
626 std::auto_ptr<SequenceOfOperationsJob> a(new SequenceOfOperationsJob);
2600
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
627 job = a.get();
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
628 engine.GetRegistry().Submit(id, a.release(), 0);
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
629 }
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
630
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
631 boost::this_thread::sleep(boost::posix_time::milliseconds(500));
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
632
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
633 {
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
634 SequenceOfOperationsJob::Lock lock(*job);
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
635 size_t i = lock.AddOperation(new LogJobOperation);
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
636 size_t j = lock.AddOperation(new LogJobOperation);
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
637 size_t k = lock.AddOperation(new LogJobOperation);
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
638 lock.AddInput(i, StringOperationValue("Hello"));
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
639 lock.AddInput(i, StringOperationValue("World"));
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
640 lock.Connect(i, j);
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
641 lock.Connect(j, k);
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
642 }
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
643
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
644 boost::this_thread::sleep(boost::posix_time::milliseconds(2000));
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
645
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
646 engine.Stop();
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
647
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
648 }
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
649
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
650
2621
83ac5a05ce84 primitives for unserializing jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2610
diff changeset
651 TEST(JobsEngine, DISABLED_Lua)
2600
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
652 {
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
653 JobsEngine engine;
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
654 engine.SetWorkersCount(2);
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
655 engine.Start();
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
656
2604
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
657 LuaJobManager lua;
2600
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
658 lua.SetMaxOperationsPerJob(5);
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
659 lua.SetTrailingOperationTimeout(200);
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
660
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
661 for (size_t i = 0; i < 30; i++)
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
662 {
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
663 boost::this_thread::sleep(boost::posix_time::milliseconds(150));
2604
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
664
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
665 LuaJobManager::Lock lock(lua, engine);
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
666 size_t a = lock.AddLogOperation();
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
667 size_t b = lock.AddLogOperation();
2606
f2b9d3256060 SystemCallOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2604
diff changeset
668 size_t c = lock.AddSystemCallOperation("echo");
2604
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
669 lock.AddStringInput(a, boost::lexical_cast<std::string>(i));
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
670 lock.AddNullInput(a);
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
671 lock.Connect(a, b);
2606
f2b9d3256060 SystemCallOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2604
diff changeset
672 lock.Connect(a, c);
2600
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
673 }
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
674
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
675 boost::this_thread::sleep(boost::posix_time::milliseconds(2000));
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
676
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
677 engine.Stop();
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
678
140a539b4eba SequenceOfOperationsJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2599
diff changeset
679 }