annotate UnitTestsSources/MultiThreadingTests.cpp @ 2217:4f39ab2cb453

flush
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 12 Dec 2016 11:56:26 +0100
parents fd5875662670
children 21713ce8717b
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
827
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 776
diff changeset
5 *
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 776
diff changeset
6 * 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
7 * 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
8 * 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
9 * License, or (at your option) any later version.
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 776
diff changeset
10 *
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 776
diff changeset
11 * 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
12 * 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
13 * 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
14 * 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
15 * 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
16 * 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
17 * 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
18 * 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
19 * 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
20 * 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
21 * in the program, then also delete it here.
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 776
diff changeset
22 *
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 776
diff changeset
23 * 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
24 * 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
25 * 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
26 * General Public License for more details.
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 776
diff changeset
27 *
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 776
diff changeset
28 * 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
29 * 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
30 **/
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
831
84513f2ee1f3 pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 827
diff changeset
33 #include "PrecompiledHeadersUnitTests.h"
723
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include "gtest/gtest.h"
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
781
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 779
diff changeset
36 #include "../OrthancServer/Scheduler/ServerScheduler.h"
723
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 #include "../Core/OrthancException.h"
2143
fd5875662670 creation of namespace SystemToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2140
diff changeset
38 #include "../Core/SystemToolbox.h"
723
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 #include "../Core/Toolbox.h"
760
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
40 #include "../Core/MultiThreading/Locker.h"
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
41 #include "../Core/MultiThreading/Mutex.h"
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
42 #include "../Core/MultiThreading/ReaderWriterLock.h"
723
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 using namespace Orthanc;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 namespace
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 {
1396
ac4efabeb80c Migration of the orthanc-client as a separate project
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1304
diff changeset
48 class DynamicInteger : public IDynamicObject
723
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 private:
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 int value_;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 std::set<int>& target_;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 public:
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 DynamicInteger(int value, std::set<int>& target) :
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 value_(value), target_(target)
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
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 int GetValue() const
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 return value_;
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
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 TEST(MultiThreading, SharedMessageQueueBasic)
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 std::set<int> s;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 SharedMessageQueue q;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 ASSERT_TRUE(q.WaitEmpty(0));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 q.Enqueue(new DynamicInteger(10, s));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 ASSERT_FALSE(q.WaitEmpty(1));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 q.Enqueue(new DynamicInteger(20, s));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 q.Enqueue(new DynamicInteger(30, s));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 q.Enqueue(new DynamicInteger(40, s));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 std::auto_ptr<DynamicInteger> i;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 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
82 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
83 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
84 ASSERT_FALSE(q.WaitEmpty(1));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 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
86 ASSERT_TRUE(q.WaitEmpty(0));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 ASSERT_EQ(NULL, q.Dequeue(1));
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
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 TEST(MultiThreading, SharedMessageQueueClean)
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 std::set<int> s;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 try
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 SharedMessageQueue q;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 q.Enqueue(new DynamicInteger(10, s));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 q.Enqueue(new DynamicInteger(20, s));
1583
9ea3d082b064 got rid of custom exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1582
diff changeset
100 throw OrthancException(ErrorCode_InternalError);
723
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 }
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 catch (OrthancException&)
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
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107
760
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
108 TEST(MultiThreading, Mutex)
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
109 {
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
110 Mutex mutex;
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
111 Locker locker(mutex);
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
112 }
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
113
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
114
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
115 TEST(MultiThreading, ReaderWriterLock)
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
116 {
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
117 ReaderWriterLock lock;
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
118
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
119 {
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
120 Locker locker1(lock.ForReader());
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
121 Locker locker2(lock.ForReader());
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
122 }
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
123
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
124 {
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
125 Locker locker3(lock.ForWriter());
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
126 }
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
127 }
769
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
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
130
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
131 #include "../OrthancServer/DicomProtocol/ReusableDicomUserConnection.h"
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
132
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
133 TEST(ReusableDicomUserConnection, DISABLED_Basic)
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
134 {
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
135 ReusableDicomUserConnection c;
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
136 c.SetMillisecondsBeforeClose(200);
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
137 printf("START\n"); fflush(stdout);
775
d3ba35466225 integration mainline -> lua-scripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 770 769
diff changeset
138
769
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
139 {
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
140 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
141 ReusableDicomUserConnection::Locker lock(c, "ORTHANC", remote);
1907
5011a597b6ce Support of Move Originator Message ID (0000,1031) in C-Store responses driven by C-Move
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
142 lock.GetConnection().StoreFile("/home/jodogne/DICOM/Cardiac/MR.X.1.2.276.0.7230010.3.1.4.2831157719.2256.1336386844.676281", 0);
769
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
143 }
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
144
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
145 printf("**\n"); fflush(stdout);
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
146 Toolbox::USleep(1000000);
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
147 printf("**\n"); fflush(stdout);
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
148
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
149 {
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
150 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
151 ReusableDicomUserConnection::Locker lock(c, "ORTHANC", remote);
1907
5011a597b6ce Support of Move Originator Message ID (0000,1031) in C-Store responses driven by C-Move
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
152 lock.GetConnection().StoreFile("/home/jodogne/DICOM/Cardiac/MR.X.1.2.276.0.7230010.3.1.4.2831157719.2256.1336386844.676277", 0);
769
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
153 }
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
154
2140
aa4b8895cd23 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1907
diff changeset
155 SystemToolbox::ServerBarrier();
769
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
156 printf("DONE\n"); fflush(stdout);
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
157 }
765
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
158
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
1000
13e230bbd882 rename filter to command
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
161 class Tutu : public IServerCommand
765
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
162 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
163 private:
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
164 int factor_;
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 public:
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
167 Tutu(int f) : factor_(f)
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 }
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 virtual bool Apply(ListOfStrings& outputs,
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
172 const ListOfStrings& inputs)
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
173 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
174 for (ListOfStrings::const_iterator
1304
7b6925b0890d cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
175 it = inputs.begin(); it != inputs.end(); ++it)
765
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
176 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
177 int a = boost::lexical_cast<int>(*it);
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
178 int b = factor_ * a;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
179
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
180 printf("%d * %d = %d\n", a, factor_, b);
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
181
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
182 //if (a == 84) { printf("BREAK\n"); return false; }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
183
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
184 outputs.push_back(boost::lexical_cast<std::string>(b));
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
185 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
186
1679
15acdb19d520 RunnableWorkersPool
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
187 Toolbox::USleep(30000);
765
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
188
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
189 return true;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
190 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
191 };
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
192
768
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
193
770
a64ca424e0e2 fix test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 768
diff changeset
194 static void Tata(ServerScheduler* s, ServerJob* j, bool* done)
768
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
195 {
1000
13e230bbd882 rename filter to command
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
196 typedef IServerCommand::ListOfStrings ListOfStrings;
779
76eb563f08f0 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 777
diff changeset
197
770
a64ca424e0e2 fix test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 768
diff changeset
198 while (!(*done))
768
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
199 {
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
200 ListOfStrings l;
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
201 s->GetListOfJobs(l);
1304
7b6925b0890d cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
202 for (ListOfStrings::iterator it = l.begin(); it != l.end(); ++it)
7b6925b0890d cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
203 {
7b6925b0890d cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
204 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
205 }
1679
15acdb19d520 RunnableWorkersPool
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1583
diff changeset
206 Toolbox::USleep(3000);
768
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
207 }
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
208 }
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
209
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
210
1009
26642cecd36d clearer job interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1005
diff changeset
211 TEST(MultiThreading, ServerScheduler)
765
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
212 {
995
8c67382f44a7 limit number of jobs in the scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 994
diff changeset
213 ServerScheduler scheduler(10);
765
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
214
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
215 ServerJob job;
1000
13e230bbd882 rename filter to command
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
216 ServerCommandInstance& f2 = job.AddCommand(new Tutu(2));
13e230bbd882 rename filter to command
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
217 ServerCommandInstance& f3 = job.AddCommand(new Tutu(3));
13e230bbd882 rename filter to command
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
218 ServerCommandInstance& f4 = job.AddCommand(new Tutu(4));
13e230bbd882 rename filter to command
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
219 ServerCommandInstance& f5 = job.AddCommand(new Tutu(5));
765
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
220 f2.AddInput(boost::lexical_cast<std::string>(42));
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
221 //f3.AddInput(boost::lexical_cast<std::string>(42));
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
222 //f4.AddInput(boost::lexical_cast<std::string>(42));
1009
26642cecd36d clearer job interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1005
diff changeset
223 f2.ConnectOutput(f3);
26642cecd36d clearer job interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1005
diff changeset
224 f3.ConnectOutput(f4);
26642cecd36d clearer job interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1005
diff changeset
225 f4.ConnectOutput(f5);
26642cecd36d clearer job interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1005
diff changeset
226
26642cecd36d clearer job interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1005
diff changeset
227 f3.SetConnectedToSink(true);
26642cecd36d clearer job interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1005
diff changeset
228 f5.SetConnectedToSink(true);
765
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
229
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
230 job.SetDescription("tutu");
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
231
770
a64ca424e0e2 fix test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 768
diff changeset
232 bool done = false;
a64ca424e0e2 fix test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 768
diff changeset
233 boost::thread t(Tata, &scheduler, &job, &done);
768
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
234
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
235
765
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
236 //scheduler.Submit(job);
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
237
1000
13e230bbd882 rename filter to command
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
238 IServerCommand::ListOfStrings l;
765
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
239 scheduler.SubmitAndWait(l, job);
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
240
1492
9f66a12eb8fc fix warnings for gcc 5
jodogne
parents: 1486
diff changeset
241 ASSERT_EQ(2u, l.size());
1009
26642cecd36d clearer job interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1005
diff changeset
242 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
243 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
244
1000
13e230bbd882 rename filter to command
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
245 for (IServerCommand::ListOfStrings::iterator i = l.begin(); i != l.end(); i++)
765
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
246 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
247 printf("** %s\n", i->c_str());
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
248 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
249
2140
aa4b8895cd23 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1907
diff changeset
250 //SystemToolbox::ServerBarrier();
768
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
251 //Toolbox::USleep(3000000);
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
252
1453
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1427
diff changeset
253 scheduler.Stop();
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1427
diff changeset
254
770
a64ca424e0e2 fix test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 768
diff changeset
255 done = true;
1453
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1427
diff changeset
256 if (t.joinable())
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1427
diff changeset
257 {
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1427
diff changeset
258 t.join();
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1427
diff changeset
259 }
765
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
260 }