annotate UnitTestsSources/MultiThreadingTests.cpp @ 1010:160dfe770618 lua-scripting

refactoring
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 09 Jul 2014 17:05:00 +0200
parents 26642cecd36d
children 6e7e5ed91c2d
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
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 776
diff changeset
3 * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege,
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 776
diff changeset
4 * Belgium
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"
769
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
35 #include <glog/logging.h>
723
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
781
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 779
diff changeset
37 #include "../OrthancServer/Scheduler/ServerScheduler.h"
769
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
38
723
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 #include "../Core/OrthancException.h"
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 #include "../Core/Toolbox.h"
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 #include "../Core/MultiThreading/ArrayFilledByThreads.h"
760
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
42 #include "../Core/MultiThreading/Locker.h"
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
43 #include "../Core/MultiThreading/Mutex.h"
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
44 #include "../Core/MultiThreading/ReaderWriterLock.h"
723
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 #include "../Core/MultiThreading/ThreadedCommandProcessor.h"
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 using namespace Orthanc;
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 namespace
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 class DynamicInteger : public ICommand
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 private:
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 int value_;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 std::set<int>& 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 public:
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 DynamicInteger(int value, std::set<int>& target) :
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 value_(value), target_(target)
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 }
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 int GetValue() const
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 return value_;
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 virtual bool Execute()
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 static boost::mutex mutex;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 boost::mutex::scoped_lock lock(mutex);
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 target_.insert(value_);
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 return true;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 }
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 };
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 class MyFiller : public ArrayFilledByThreads::IFiller
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 private:
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 int size_;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 unsigned int created_;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 std::set<int> set_;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 public:
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 MyFiller(int size) : size_(size), created_(0)
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 {
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 virtual size_t GetFillerSize()
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 return size_;
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
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 virtual IDynamicObject* GetFillerItem(size_t index)
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 static boost::mutex mutex;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 boost::mutex::scoped_lock lock(mutex);
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 created_++;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 return new DynamicInteger(index * 2, set_);
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
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 unsigned int GetCreatedCount() const
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 return created_;
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 std::set<int> GetSet()
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 return set_;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 }
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 };
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 }
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 TEST(MultiThreading, SharedMessageQueueBasic)
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 std::set<int> s;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 SharedMessageQueue q;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 ASSERT_TRUE(q.WaitEmpty(0));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 q.Enqueue(new DynamicInteger(10, s));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 ASSERT_FALSE(q.WaitEmpty(1));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 q.Enqueue(new DynamicInteger(20, s));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 q.Enqueue(new DynamicInteger(30, s));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 q.Enqueue(new DynamicInteger(40, s));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 std::auto_ptr<DynamicInteger> i;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 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
131 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
132 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
133 ASSERT_FALSE(q.WaitEmpty(1));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 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
135 ASSERT_TRUE(q.WaitEmpty(0));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 ASSERT_EQ(NULL, q.Dequeue(1));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 }
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 TEST(MultiThreading, SharedMessageQueueClean)
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 std::set<int> s;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 try
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 SharedMessageQueue q;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 q.Enqueue(new DynamicInteger(10, s));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 q.Enqueue(new DynamicInteger(20, s));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 throw OrthancException("Nope");
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 }
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 catch (OrthancException&)
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 }
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 }
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 TEST(MultiThreading, ArrayFilledByThreadEmpty)
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 MyFiller f(0);
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 ArrayFilledByThreads a(f);
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 a.SetThreadCount(1);
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 ASSERT_EQ(0, a.GetSize());
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 }
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 TEST(MultiThreading, ArrayFilledByThread1)
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 MyFiller f(100);
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 ArrayFilledByThreads a(f);
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 a.SetThreadCount(1);
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 ASSERT_EQ(100, a.GetSize());
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 for (size_t i = 0; i < a.GetSize(); i++)
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 ASSERT_EQ(2 * i, dynamic_cast<DynamicInteger&>(a.GetItem(i)).GetValue());
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 }
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 }
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 TEST(MultiThreading, ArrayFilledByThread4)
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 MyFiller f(100);
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 ArrayFilledByThreads a(f);
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 a.SetThreadCount(4);
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 ASSERT_EQ(100, a.GetSize());
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 for (size_t i = 0; i < a.GetSize(); i++)
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 ASSERT_EQ(2 * i, dynamic_cast<DynamicInteger&>(a.GetItem(i)).GetValue());
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 }
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 ASSERT_EQ(100u, f.GetCreatedCount());
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 a.Invalidate();
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 ASSERT_EQ(100, a.GetSize());
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 ASSERT_EQ(200u, f.GetCreatedCount());
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 ASSERT_EQ(4u, a.GetThreadCount());
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 ASSERT_TRUE(f.GetSet().empty());
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 for (size_t i = 0; i < a.GetSize(); i++)
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 ASSERT_EQ(2 * i, dynamic_cast<DynamicInteger&>(a.GetItem(i)).GetValue());
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 }
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 }
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 TEST(MultiThreading, CommandProcessor)
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 ThreadedCommandProcessor p(4);
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 std::set<int> s;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 for (size_t i = 0; i < 100; i++)
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 p.Post(new DynamicInteger(i * 2, s));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 }
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 p.Join();
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 for (size_t i = 0; i < 200; i++)
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 if (i % 2)
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 ASSERT_TRUE(s.find(i) == s.end());
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 else
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 ASSERT_TRUE(s.find(i) != s.end());
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 }
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 }
760
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
227
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
228
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
229 TEST(MultiThreading, Mutex)
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
230 {
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
231 Mutex mutex;
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
232 Locker locker(mutex);
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
233 }
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
234
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
235
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
236 TEST(MultiThreading, ReaderWriterLock)
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
237 {
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
238 ReaderWriterLock lock;
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
239
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
240 {
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
241 Locker locker1(lock.ForReader());
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
242 Locker locker2(lock.ForReader());
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
243 }
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
244
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
245 {
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
246 Locker locker3(lock.ForWriter());
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
247 }
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
248 }
769
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
249
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
250
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
251
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
252 #include "../OrthancServer/DicomProtocol/ReusableDicomUserConnection.h"
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
253
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
254 TEST(ReusableDicomUserConnection, DISABLED_Basic)
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
255 {
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
256 ReusableDicomUserConnection c;
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
257 c.SetMillisecondsBeforeClose(200);
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
258 printf("START\n"); fflush(stdout);
775
d3ba35466225 integration mainline -> lua-scripting
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 770 769
diff changeset
259
769
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
260 {
776
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 769
diff changeset
261 ReusableDicomUserConnection::Locker lock(c, "STORESCP", "localhost", 2000, ModalityManufacturer_Generic);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 769
diff changeset
262 lock.GetConnection().StoreFile("/home/jodogne/DICOM/Cardiac/MR.X.1.2.276.0.7230010.3.1.4.2831157719.2256.1336386844.676281");
769
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
263 }
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
264
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
265 printf("**\n"); fflush(stdout);
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
266 Toolbox::USleep(1000000);
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
267 printf("**\n"); fflush(stdout);
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
268
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
269 {
776
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 769
diff changeset
270 ReusableDicomUserConnection::Locker lock(c, "STORESCP", "localhost", 2000, ModalityManufacturer_Generic);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 769
diff changeset
271 lock.GetConnection().StoreFile("/home/jodogne/DICOM/Cardiac/MR.X.1.2.276.0.7230010.3.1.4.2831157719.2256.1336386844.676277");
769
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
272 }
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
273
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
274 Toolbox::ServerBarrier();
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
275 printf("DONE\n"); fflush(stdout);
3f946e5c3802 ReusableDicomUserConnection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
276 }
765
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
277
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
278
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
279
1000
13e230bbd882 rename filter to command
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
280 class Tutu : public IServerCommand
765
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
281 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
282 private:
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
283 int factor_;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
284
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
285 public:
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
286 Tutu(int f) : factor_(f)
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
287 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
288 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
289
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
290 virtual bool Apply(ListOfStrings& outputs,
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
291 const ListOfStrings& inputs)
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
292 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
293 for (ListOfStrings::const_iterator
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
294 it = inputs.begin(); it != inputs.end(); it++)
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
295 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
296 int a = boost::lexical_cast<int>(*it);
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
297 int b = factor_ * a;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
298
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
299 printf("%d * %d = %d\n", a, factor_, b);
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
300
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
301 //if (a == 84) { printf("BREAK\n"); return false; }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
302
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
303 outputs.push_back(boost::lexical_cast<std::string>(b));
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
304 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
305
1009
26642cecd36d clearer job interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1005
diff changeset
306 Toolbox::USleep(100000);
765
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
307
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
308 return true;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
309 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
310 };
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
311
768
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
312
770
a64ca424e0e2 fix test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 768
diff changeset
313 static void Tata(ServerScheduler* s, ServerJob* j, bool* done)
768
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
314 {
1000
13e230bbd882 rename filter to command
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
315 typedef IServerCommand::ListOfStrings ListOfStrings;
779
76eb563f08f0 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 777
diff changeset
316
770
a64ca424e0e2 fix test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 768
diff changeset
317 while (!(*done))
768
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
318 {
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
319 ListOfStrings l;
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
320 s->GetListOfJobs(l);
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
321 for (ListOfStrings::iterator i = l.begin(); i != l.end(); i++)
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
322 printf(">> %s: %0.1f\n", i->c_str(), 100.0f * s->GetProgress(*i));
1009
26642cecd36d clearer job interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1005
diff changeset
323 Toolbox::USleep(10000);
768
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
324 }
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
325 }
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
326
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
327
1009
26642cecd36d clearer job interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1005
diff changeset
328 TEST(MultiThreading, ServerScheduler)
765
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
329 {
995
8c67382f44a7 limit number of jobs in the scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 994
diff changeset
330 ServerScheduler scheduler(10);
765
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
331
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
332 ServerJob job;
1000
13e230bbd882 rename filter to command
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
333 ServerCommandInstance& f2 = job.AddCommand(new Tutu(2));
13e230bbd882 rename filter to command
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
334 ServerCommandInstance& f3 = job.AddCommand(new Tutu(3));
13e230bbd882 rename filter to command
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
335 ServerCommandInstance& f4 = job.AddCommand(new Tutu(4));
13e230bbd882 rename filter to command
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
336 ServerCommandInstance& f5 = job.AddCommand(new Tutu(5));
765
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
337 f2.AddInput(boost::lexical_cast<std::string>(42));
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
338 //f3.AddInput(boost::lexical_cast<std::string>(42));
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
339 //f4.AddInput(boost::lexical_cast<std::string>(42));
1009
26642cecd36d clearer job interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1005
diff changeset
340 f2.ConnectOutput(f3);
26642cecd36d clearer job interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1005
diff changeset
341 f3.ConnectOutput(f4);
26642cecd36d clearer job interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1005
diff changeset
342 f4.ConnectOutput(f5);
26642cecd36d clearer job interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1005
diff changeset
343
26642cecd36d clearer job interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1005
diff changeset
344 f3.SetConnectedToSink(true);
26642cecd36d clearer job interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1005
diff changeset
345 f5.SetConnectedToSink(true);
765
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
346
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
347 job.SetDescription("tutu");
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
348
770
a64ca424e0e2 fix test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 768
diff changeset
349 bool done = false;
a64ca424e0e2 fix test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 768
diff changeset
350 boost::thread t(Tata, &scheduler, &job, &done);
768
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
351
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
352
765
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
353 //scheduler.Submit(job);
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
354
1000
13e230bbd882 rename filter to command
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
355 IServerCommand::ListOfStrings l;
765
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
356 scheduler.SubmitAndWait(l, job);
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
357
1009
26642cecd36d clearer job interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1005
diff changeset
358 ASSERT_EQ(2, l.size());
26642cecd36d clearer job interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1005
diff changeset
359 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
360 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
361
1000
13e230bbd882 rename filter to command
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
362 for (IServerCommand::ListOfStrings::iterator i = l.begin(); i != l.end(); i++)
765
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
363 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
364 printf("** %s\n", i->c_str());
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
365 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
366
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
367 //Toolbox::ServerBarrier();
768
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
368 //Toolbox::USleep(3000000);
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
369
770
a64ca424e0e2 fix test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 768
diff changeset
370 done = true;
a64ca424e0e2 fix test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 768
diff changeset
371 t.join();
765
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
372 }