Mercurial > hg > orthanc
annotate OrthancFramework/UnitTestsSources/MemoryCacheTests.cpp @ 5431:4be5f117aa0d
metrics
author | Alain Mazy <am@osimis.io> |
---|---|
date | Tue, 21 Nov 2023 10:32:42 +0100 |
parents | d37dff2c0028 |
children | 48b8dae6dc77 |
rev | line source |
---|---|
827
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
1 /** |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
2 * Orthanc - A Lightweight, RESTful DICOM Store |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
5185
0ea402b4d901
upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4870
diff
changeset
|
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
0ea402b4d901
upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4870
diff
changeset
|
6 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
827
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
7 * |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
8 * This program is free software: you can redistribute it and/or |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
9 * modify it under the terms of the GNU Lesser General Public License |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
10 * as published by the Free Software Foundation, either version 3 of |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
11 * the License, or (at your option) any later version. |
827
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
12 * |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
13 * 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:
632
diff
changeset
|
14 * WITHOUT ANY WARRANTY; without even the implied warranty of |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
16 * Lesser General Public License for more details. |
827
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
17 * |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
18 * You should have received a copy of the GNU Lesser General Public |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
19 * License along with this program. If not, see |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
20 * <http://www.gnu.org/licenses/>. |
827
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
21 **/ |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
22 |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
23 |
4059
e241e5f3f088
moved LuaTests and MemoryCacheTests from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
24 #if ORTHANC_UNIT_TESTS_LINK_FRAMEWORK == 1 |
4063
e00f3d089991
shared library of orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4062
diff
changeset
|
25 // Must be the first to be sure to use the Orthanc framework shared library |
4059
e241e5f3f088
moved LuaTests and MemoryCacheTests from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
26 # include <OrthancFramework.h> |
e241e5f3f088
moved LuaTests and MemoryCacheTests from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
27 #endif |
e241e5f3f088
moved LuaTests and MemoryCacheTests from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
28 |
4062 | 29 #include <gtest/gtest.h> |
1486
f967bdf8534e
refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1367
diff
changeset
|
30 |
4059
e241e5f3f088
moved LuaTests and MemoryCacheTests from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
31 #include "../Sources/Cache/MemoryCache.h" |
e241e5f3f088
moved LuaTests and MemoryCacheTests from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
32 #include "../Sources/Cache/MemoryStringCache.h" |
e241e5f3f088
moved LuaTests and MemoryCacheTests from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
33 #include "../Sources/Cache/SharedArchive.h" |
e241e5f3f088
moved LuaTests and MemoryCacheTests from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
34 #include "../Sources/IDynamicObject.h" |
e241e5f3f088
moved LuaTests and MemoryCacheTests from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
35 #include "../Sources/Logging.h" |
5420
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
36 #include "../Sources/SystemToolbox.h" |
282 | 37 |
4062 | 38 #include <memory> |
39 #include <algorithm> | |
40 #include <boost/thread.hpp> | |
41 #include <boost/lexical_cast.hpp> | |
42 | |
282 | 43 |
505
f59e4518fd57
rename CacheIndex as LeastRecentlyUsedIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
44 TEST(LRU, Basic) |
282 | 45 { |
505
f59e4518fd57
rename CacheIndex as LeastRecentlyUsedIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
46 Orthanc::LeastRecentlyUsedIndex<std::string> r; |
282 | 47 |
48 r.Add("d"); | |
49 r.Add("a"); | |
50 r.Add("c"); | |
51 r.Add("b"); | |
52 | |
509
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
53 r.MakeMostRecent("a"); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
54 r.MakeMostRecent("d"); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
55 r.MakeMostRecent("b"); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
56 r.MakeMostRecent("c"); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
57 r.MakeMostRecent("d"); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
58 r.MakeMostRecent("c"); |
282 | 59 |
507
c4122c3a47c1
access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
505
diff
changeset
|
60 ASSERT_EQ("a", r.GetOldest()); |
282 | 61 ASSERT_EQ("a", r.RemoveOldest()); |
507
c4122c3a47c1
access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
505
diff
changeset
|
62 ASSERT_EQ("b", r.GetOldest()); |
282 | 63 ASSERT_EQ("b", r.RemoveOldest()); |
507
c4122c3a47c1
access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
505
diff
changeset
|
64 ASSERT_EQ("d", r.GetOldest()); |
282 | 65 ASSERT_EQ("d", r.RemoveOldest()); |
507
c4122c3a47c1
access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
505
diff
changeset
|
66 ASSERT_EQ("c", r.GetOldest()); |
282 | 67 ASSERT_EQ("c", r.RemoveOldest()); |
68 | |
69 ASSERT_TRUE(r.IsEmpty()); | |
507
c4122c3a47c1
access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
505
diff
changeset
|
70 |
c4122c3a47c1
access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
505
diff
changeset
|
71 ASSERT_THROW(r.GetOldest(), Orthanc::OrthancException); |
c4122c3a47c1
access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
505
diff
changeset
|
72 ASSERT_THROW(r.RemoveOldest(), Orthanc::OrthancException); |
282 | 73 } |
74 | |
75 | |
505
f59e4518fd57
rename CacheIndex as LeastRecentlyUsedIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
76 TEST(LRU, Payload) |
282 | 77 { |
505
f59e4518fd57
rename CacheIndex as LeastRecentlyUsedIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
78 Orthanc::LeastRecentlyUsedIndex<std::string, int> r; |
282 | 79 |
80 r.Add("a", 420); | |
81 r.Add("b", 421); | |
82 r.Add("c", 422); | |
83 r.Add("d", 423); | |
84 | |
509
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
85 r.MakeMostRecent("a"); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
86 r.MakeMostRecent("d"); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
87 r.MakeMostRecent("b"); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
88 r.MakeMostRecent("c"); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
89 r.MakeMostRecent("d"); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
90 r.MakeMostRecent("c"); |
282 | 91 |
92 ASSERT_TRUE(r.Contains("b")); | |
93 ASSERT_EQ(421, r.Invalidate("b")); | |
94 ASSERT_FALSE(r.Contains("b")); | |
95 | |
96 int p; | |
283 | 97 ASSERT_TRUE(r.Contains("a", p)); ASSERT_EQ(420, p); |
98 ASSERT_TRUE(r.Contains("c", p)); ASSERT_EQ(422, p); | |
99 ASSERT_TRUE(r.Contains("d", p)); ASSERT_EQ(423, p); | |
100 | |
507
c4122c3a47c1
access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
505
diff
changeset
|
101 ASSERT_EQ("a", r.GetOldest()); |
c4122c3a47c1
access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
505
diff
changeset
|
102 ASSERT_EQ(420, r.GetOldestPayload()); |
282 | 103 ASSERT_EQ("a", r.RemoveOldest(p)); ASSERT_EQ(420, p); |
507
c4122c3a47c1
access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
505
diff
changeset
|
104 |
c4122c3a47c1
access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
505
diff
changeset
|
105 ASSERT_EQ("d", r.GetOldest()); |
c4122c3a47c1
access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
505
diff
changeset
|
106 ASSERT_EQ(423, r.GetOldestPayload()); |
282 | 107 ASSERT_EQ("d", r.RemoveOldest(p)); ASSERT_EQ(423, p); |
507
c4122c3a47c1
access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
505
diff
changeset
|
108 |
c4122c3a47c1
access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
505
diff
changeset
|
109 ASSERT_EQ("c", r.GetOldest()); |
c4122c3a47c1
access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
505
diff
changeset
|
110 ASSERT_EQ(422, r.GetOldestPayload()); |
282 | 111 ASSERT_EQ("c", r.RemoveOldest(p)); ASSERT_EQ(422, p); |
112 | |
113 ASSERT_TRUE(r.IsEmpty()); | |
114 } | |
115 | |
116 | |
509
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
117 TEST(LRU, PayloadUpdate) |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
118 { |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
119 Orthanc::LeastRecentlyUsedIndex<std::string, int> r; |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
120 |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
121 r.Add("a", 420); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
122 r.Add("b", 421); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
123 r.Add("d", 423); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
124 |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
125 r.MakeMostRecent("a", 424); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
126 r.MakeMostRecent("d", 421); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
127 |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
128 ASSERT_EQ("b", r.GetOldest()); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
129 ASSERT_EQ(421, r.GetOldestPayload()); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
130 r.RemoveOldest(); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
131 |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
132 ASSERT_EQ("a", r.GetOldest()); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
133 ASSERT_EQ(424, r.GetOldestPayload()); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
134 r.RemoveOldest(); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
135 |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
136 ASSERT_EQ("d", r.GetOldest()); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
137 ASSERT_EQ(421, r.GetOldestPayload()); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
138 r.RemoveOldest(); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
139 |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
140 ASSERT_TRUE(r.IsEmpty()); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
141 } |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
142 |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
143 |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
144 |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
145 TEST(LRU, PayloadUpdateBis) |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
146 { |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
147 Orthanc::LeastRecentlyUsedIndex<std::string, int> r; |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
148 |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
149 r.AddOrMakeMostRecent("a", 420); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
150 r.AddOrMakeMostRecent("b", 421); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
151 r.AddOrMakeMostRecent("d", 423); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
152 r.AddOrMakeMostRecent("a", 424); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
153 r.AddOrMakeMostRecent("d", 421); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
154 |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
155 ASSERT_EQ("b", r.GetOldest()); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
156 ASSERT_EQ(421, r.GetOldestPayload()); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
157 r.RemoveOldest(); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
158 |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
159 ASSERT_EQ("a", r.GetOldest()); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
160 ASSERT_EQ(424, r.GetOldestPayload()); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
161 r.RemoveOldest(); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
162 |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
163 ASSERT_EQ("d", r.GetOldest()); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
164 ASSERT_EQ(421, r.GetOldestPayload()); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
165 r.RemoveOldest(); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
166 |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
167 ASSERT_TRUE(r.IsEmpty()); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
168 } |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
169 |
3454
0e3c26e4b8ec
LeastRecentlyUsedIndex::GetAllKeys (test)
Alain Mazy <alain@mazy.be>
parents:
3060
diff
changeset
|
170 TEST(LRU, GetAllKeys) |
0e3c26e4b8ec
LeastRecentlyUsedIndex::GetAllKeys (test)
Alain Mazy <alain@mazy.be>
parents:
3060
diff
changeset
|
171 { |
0e3c26e4b8ec
LeastRecentlyUsedIndex::GetAllKeys (test)
Alain Mazy <alain@mazy.be>
parents:
3060
diff
changeset
|
172 Orthanc::LeastRecentlyUsedIndex<std::string, int> r; |
0e3c26e4b8ec
LeastRecentlyUsedIndex::GetAllKeys (test)
Alain Mazy <alain@mazy.be>
parents:
3060
diff
changeset
|
173 std::vector<std::string> keys; |
0e3c26e4b8ec
LeastRecentlyUsedIndex::GetAllKeys (test)
Alain Mazy <alain@mazy.be>
parents:
3060
diff
changeset
|
174 |
0e3c26e4b8ec
LeastRecentlyUsedIndex::GetAllKeys (test)
Alain Mazy <alain@mazy.be>
parents:
3060
diff
changeset
|
175 r.AddOrMakeMostRecent("a", 420); |
0e3c26e4b8ec
LeastRecentlyUsedIndex::GetAllKeys (test)
Alain Mazy <alain@mazy.be>
parents:
3060
diff
changeset
|
176 r.GetAllKeys(keys); |
0e3c26e4b8ec
LeastRecentlyUsedIndex::GetAllKeys (test)
Alain Mazy <alain@mazy.be>
parents:
3060
diff
changeset
|
177 |
3497
db71bd11affc
fix unit tests if dcmtk != 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3454
diff
changeset
|
178 ASSERT_EQ(1u, keys.size()); |
3454
0e3c26e4b8ec
LeastRecentlyUsedIndex::GetAllKeys (test)
Alain Mazy <alain@mazy.be>
parents:
3060
diff
changeset
|
179 ASSERT_EQ("a", keys[0]); |
0e3c26e4b8ec
LeastRecentlyUsedIndex::GetAllKeys (test)
Alain Mazy <alain@mazy.be>
parents:
3060
diff
changeset
|
180 |
0e3c26e4b8ec
LeastRecentlyUsedIndex::GetAllKeys (test)
Alain Mazy <alain@mazy.be>
parents:
3060
diff
changeset
|
181 r.AddOrMakeMostRecent("b", 421); |
0e3c26e4b8ec
LeastRecentlyUsedIndex::GetAllKeys (test)
Alain Mazy <alain@mazy.be>
parents:
3060
diff
changeset
|
182 r.GetAllKeys(keys); |
0e3c26e4b8ec
LeastRecentlyUsedIndex::GetAllKeys (test)
Alain Mazy <alain@mazy.be>
parents:
3060
diff
changeset
|
183 |
3497
db71bd11affc
fix unit tests if dcmtk != 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3454
diff
changeset
|
184 ASSERT_EQ(2u, keys.size()); |
3454
0e3c26e4b8ec
LeastRecentlyUsedIndex::GetAllKeys (test)
Alain Mazy <alain@mazy.be>
parents:
3060
diff
changeset
|
185 ASSERT_TRUE(std::find(keys.begin(), keys.end(),"a") != keys.end()); |
0e3c26e4b8ec
LeastRecentlyUsedIndex::GetAllKeys (test)
Alain Mazy <alain@mazy.be>
parents:
3060
diff
changeset
|
186 ASSERT_TRUE(std::find(keys.begin(), keys.end(),"b") != keys.end()); |
0e3c26e4b8ec
LeastRecentlyUsedIndex::GetAllKeys (test)
Alain Mazy <alain@mazy.be>
parents:
3060
diff
changeset
|
187 } |
509
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
188 |
283 | 189 |
190 | |
191 namespace | |
192 { | |
193 class Integer : public Orthanc::IDynamicObject | |
194 { | |
195 private: | |
196 std::string& log_; | |
197 int value_; | |
282 | 198 |
199 public: | |
283 | 200 Integer(std::string& log, int v) : log_(log), value_(v) |
201 { | |
202 } | |
203 | |
2924
22524fd06225
macros ORTHANC_OVERRIDE and ORTHANC_FINAL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
204 virtual ~Integer() ORTHANC_OVERRIDE |
283 | 205 { |
206 LOG(INFO) << "Removing cache entry for " << value_; | |
207 log_ += boost::lexical_cast<std::string>(value_) + " "; | |
208 } | |
209 }; | |
210 | |
3557
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
211 class IntegerProvider : public Orthanc::Deprecated::ICachePageProvider |
283 | 212 { |
213 public: | |
214 std::string log_; | |
215 | |
2924
22524fd06225
macros ORTHANC_OVERRIDE and ORTHANC_FINAL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
216 virtual Orthanc::IDynamicObject* Provide(const std::string& s) ORTHANC_OVERRIDE |
283 | 217 { |
218 LOG(INFO) << "Providing " << s; | |
219 return new Integer(log_, boost::lexical_cast<int>(s)); | |
220 } | |
282 | 221 }; |
222 } | |
283 | 223 |
224 | |
225 TEST(MemoryCache, Basic) | |
226 { | |
227 IntegerProvider provider; | |
228 | |
229 { | |
3557
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
230 Orthanc::Deprecated::MemoryCache cache(provider, 3); |
285
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
284
diff
changeset
|
231 cache.Access("42"); // 42 -> exit |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
284
diff
changeset
|
232 cache.Access("43"); // 43, 42 -> exit |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
284
diff
changeset
|
233 cache.Access("45"); // 45, 43, 42 -> exit |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
284
diff
changeset
|
234 cache.Access("42"); // 42, 45, 43 -> exit |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
284
diff
changeset
|
235 cache.Access("43"); // 43, 42, 45 -> exit |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
284
diff
changeset
|
236 cache.Access("47"); // 45 is removed; 47, 43, 42 -> exit |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
284
diff
changeset
|
237 cache.Access("44"); // 42 is removed; 44, 47, 43 -> exit |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
284
diff
changeset
|
238 cache.Access("42"); // 43 is removed; 42, 44, 47 -> exit |
283 | 239 // Closing the cache: 47, 44, 42 are successively removed |
240 } | |
241 | |
242 ASSERT_EQ("45 42 43 47 44 42 ", provider.log_); | |
243 } | |
1367 | 244 |
245 | |
246 | |
247 | |
248 | |
249 namespace | |
250 { | |
251 class S : public Orthanc::IDynamicObject | |
252 { | |
253 private: | |
254 std::string value_; | |
255 | |
256 public: | |
4204 | 257 explicit S(const std::string& value) : value_(value) |
1367 | 258 { |
259 } | |
260 | |
261 const std::string& GetValue() const | |
262 { | |
263 return value_; | |
264 } | |
265 }; | |
266 } | |
267 | |
268 | |
269 TEST(LRU, SharedArchive) | |
270 { | |
271 std::string first, second; | |
272 Orthanc::SharedArchive a(3); | |
273 first = a.Add(new S("First item")); | |
274 second = a.Add(new S("Second item")); | |
275 | |
276 for (int i = 1; i < 100; i++) | |
277 { | |
278 a.Add(new S("Item " + boost::lexical_cast<std::string>(i))); | |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2924
diff
changeset
|
279 |
1367 | 280 // Continuously protect the two first items |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2924
diff
changeset
|
281 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2924
diff
changeset
|
282 Orthanc::SharedArchive::Accessor accessor(a, first); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2924
diff
changeset
|
283 ASSERT_TRUE(accessor.IsValid()); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2924
diff
changeset
|
284 ASSERT_EQ("First item", dynamic_cast<S&>(accessor.GetItem()).GetValue()); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2924
diff
changeset
|
285 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2924
diff
changeset
|
286 |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2924
diff
changeset
|
287 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2924
diff
changeset
|
288 Orthanc::SharedArchive::Accessor accessor(a, second); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2924
diff
changeset
|
289 ASSERT_TRUE(accessor.IsValid()); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2924
diff
changeset
|
290 ASSERT_EQ("Second item", dynamic_cast<S&>(accessor.GetItem()).GetValue()); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2924
diff
changeset
|
291 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2924
diff
changeset
|
292 |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2924
diff
changeset
|
293 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2924
diff
changeset
|
294 Orthanc::SharedArchive::Accessor accessor(a, "nope"); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2924
diff
changeset
|
295 ASSERT_FALSE(accessor.IsValid()); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2924
diff
changeset
|
296 ASSERT_THROW(accessor.GetItem(), Orthanc::OrthancException); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2924
diff
changeset
|
297 } |
1367 | 298 } |
299 | |
300 std::list<std::string> i; | |
301 a.List(i); | |
302 | |
303 size_t count = 0; | |
304 for (std::list<std::string>::const_iterator | |
4204 | 305 it = i.begin(); it != i.end(); ++it) |
1367 | 306 { |
307 if (*it == first || | |
308 *it == second) | |
309 { | |
310 count++; | |
311 } | |
312 } | |
313 | |
1492 | 314 ASSERT_EQ(2u, count); |
1367 | 315 } |
3557
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
316 |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
317 |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
318 TEST(MemoryStringCache, Basic) |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
319 { |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
320 Orthanc::MemoryStringCache c; |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
321 ASSERT_THROW(c.SetMaximumSize(0), Orthanc::OrthancException); |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
322 |
5420
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
323 c.SetMaximumSize(3); |
3557
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
324 |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
325 std::string v; |
5420
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
326 { |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
327 Orthanc::MemoryStringCache::Accessor a(c); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
328 ASSERT_FALSE(a.Fetch(v, "key1")); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
329 } |
3557
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
330 |
5420
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
331 { |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
332 Orthanc::MemoryStringCache::Accessor a(c); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
333 ASSERT_FALSE(a.Fetch(v, "key1")); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
334 a.Add("key1", "a"); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
335 ASSERT_TRUE(a.Fetch(v, "key1")); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
336 ASSERT_EQ("a", v); |
3557
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
337 |
5420
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
338 ASSERT_FALSE(a.Fetch(v, "key2")); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
339 ASSERT_FALSE(a.Fetch(v, "key3")); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
340 |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
341 a.Add("key2", "b"); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
342 ASSERT_TRUE(a.Fetch(v, "key1")); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
343 ASSERT_EQ("a", v); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
344 ASSERT_TRUE(a.Fetch(v, "key2")); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
345 ASSERT_EQ("b", v); |
3557
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
346 |
5420
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
347 a.Add("key3", "too-large-value"); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
348 ASSERT_TRUE(a.Fetch(v, "key1")); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
349 ASSERT_EQ("a", v); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
350 ASSERT_TRUE(a.Fetch(v, "key2")); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
351 ASSERT_EQ("b", v); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
352 ASSERT_FALSE(a.Fetch(v, "key3")); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
353 |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
354 a.Add("key3", "c"); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
355 ASSERT_TRUE(a.Fetch(v, "key2")); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
356 ASSERT_EQ("b", v); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
357 ASSERT_TRUE(a.Fetch(v, "key1")); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
358 ASSERT_EQ("a", v); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
359 ASSERT_TRUE(a.Fetch(v, "key3")); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
360 ASSERT_EQ("c", v); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
361 |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
362 // adding a fourth value should remove the oldest accessed value (key2) |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
363 a.Add("key4", "d"); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
364 ASSERT_FALSE(a.Fetch(v, "key2")); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
365 ASSERT_TRUE(a.Fetch(v, "key1")); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
366 ASSERT_EQ("a", v); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
367 ASSERT_TRUE(a.Fetch(v, "key3")); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
368 ASSERT_EQ("c", v); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
369 ASSERT_TRUE(a.Fetch(v, "key4")); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
370 ASSERT_EQ("d", v); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
371 |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
372 } |
3557
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
373 } |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
374 |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
375 TEST(MemoryStringCache, Invalidate) |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
376 { |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
377 Orthanc::MemoryStringCache c; |
5420
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
378 Orthanc::MemoryStringCache::Accessor a(c); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
379 |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
380 a.Add("hello", "a"); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
381 a.Add("hello2", "b"); |
3557
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
382 |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
383 std::string v; |
5420
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
384 ASSERT_TRUE(a.Fetch(v, "hello")); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
385 ASSERT_EQ("a", v); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
386 ASSERT_TRUE(a.Fetch(v, "hello2")); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
387 ASSERT_EQ("b", v); |
3557
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
388 |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
389 c.Invalidate("hello"); |
5420
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
390 ASSERT_FALSE(a.Fetch(v, "hello")); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
391 ASSERT_TRUE(a.Fetch(v, "hello2")); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
392 ASSERT_EQ("b", v); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
393 } |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
394 |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
395 |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
396 static int ThreadingScenarioHappyStep = 0; |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
397 static Orthanc::MemoryStringCache ThreadingScenarioHappyCache; |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
398 |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
399 void ThreadingScenarioHappyThread1() |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
400 { |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
401 // the first thread to call Fetch (will be in charge of adding) |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
402 Orthanc::MemoryStringCache::Accessor a(ThreadingScenarioHappyCache); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
403 std::string v; |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
404 |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
405 LOG(INFO) << "Thread1 will fetch"; |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
406 if (!a.Fetch(v, "key1")) |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
407 { |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
408 LOG(INFO) << "Thread1 has fetch"; |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
409 ThreadingScenarioHappyStep = 1; |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
410 |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
411 // wait for the other thread to fetch too |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
412 while (ThreadingScenarioHappyStep < 2) |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
413 { |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
414 Orthanc::SystemToolbox::USleep(10000); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
415 } |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
416 LOG(INFO) << "Thread1 will add after a short sleep"; |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
417 Orthanc::SystemToolbox::USleep(100000); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
418 LOG(INFO) << "Thread1 will add"; |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
419 |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
420 a.Add("key1", "value1"); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
421 |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
422 LOG(INFO) << "Thread1 has added"; |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
423 } |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
424 } |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
425 |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
426 void ThreadingScenarioHappyThread2() |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
427 { |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
428 Orthanc::MemoryStringCache::Accessor a(ThreadingScenarioHappyCache); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
429 std::string v; |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
430 |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
431 // nobody has added key2 -> go |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
432 if (!a.Fetch(v, "key2")) |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
433 { |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
434 a.Add("key2", "value2"); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
435 } |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
436 |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
437 // wait until thread 1 has completed its "Fetch" but not added yet |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
438 while (ThreadingScenarioHappyStep < 1) |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
439 { |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
440 Orthanc::SystemToolbox::USleep(10000); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
441 } |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
442 |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
443 ThreadingScenarioHappyStep = 2; |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
444 LOG(INFO) << "Thread2 will fetch"; |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
445 // this should wait until thread 1 has added |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
446 if (!a.Fetch(v, "key1")) |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
447 { |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
448 ASSERT_FALSE(true); // this thread should not add since thread1 should have done it |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
449 } |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
450 LOG(INFO) << "Thread2 has fetched the value"; |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
451 ASSERT_EQ("value1", v); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
452 } |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
453 |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
454 |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
455 TEST(MemoryStringCache, ThreadingScenarioHappy) |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
456 { |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
457 boost::thread thread1 = boost::thread(ThreadingScenarioHappyThread1); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
458 boost::thread thread2 = boost::thread(ThreadingScenarioHappyThread2); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
459 |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
460 thread1.join(); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
461 thread2.join(); |
3557
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
462 } |
5420
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
463 |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
464 |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
465 static int ThreadingScenarioFailureStep = 0; |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
466 static Orthanc::MemoryStringCache ThreadingScenarioFailureCache; |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
467 |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
468 void ThreadingScenarioFailureThread1() |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
469 { |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
470 // the first thread to call Fetch (will be in charge of adding) |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
471 Orthanc::MemoryStringCache::Accessor a(ThreadingScenarioFailureCache); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
472 std::string v; |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
473 |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
474 LOG(INFO) << "Thread1 will fetch"; |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
475 if (!a.Fetch(v, "key1")) |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
476 { |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
477 LOG(INFO) << "Thread1 has fetch"; |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
478 ThreadingScenarioFailureStep = 1; |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
479 |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
480 // wait for the other thread to fetch too |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
481 while (ThreadingScenarioFailureStep < 2) |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
482 { |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
483 Orthanc::SystemToolbox::USleep(10000); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
484 } |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
485 LOG(INFO) << "Thread1 will add after a short sleep"; |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
486 Orthanc::SystemToolbox::USleep(100000); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
487 LOG(INFO) << "Thread1 fails to add because of an error"; |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
488 } |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
489 } |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
490 |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
491 void ThreadingScenarioFailureThread2() |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
492 { |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
493 Orthanc::MemoryStringCache::Accessor a(ThreadingScenarioFailureCache); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
494 std::string v; |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
495 |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
496 // wait until thread 1 has completed its "Fetch" but not added yet |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
497 while (ThreadingScenarioFailureStep < 1) |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
498 { |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
499 Orthanc::SystemToolbox::USleep(10000); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
500 } |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
501 |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
502 ThreadingScenarioFailureStep = 2; |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
503 LOG(INFO) << "Thread2 will fetch and wait for thread1 to add"; |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
504 // this should wait until thread 1 has added |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
505 if (!a.Fetch(v, "key1")) |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
506 { |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
507 LOG(INFO) << "Thread2 has been awaken and will add since Thread1 has failed to add"; |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
508 a.Add("key1", "value1"); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
509 } |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
510 LOG(INFO) << "Thread2 has added the value"; |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
511 } |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
512 |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
513 |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
514 TEST(MemoryStringCache, ThreadingScenarioFailure) |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
515 { |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
516 boost::thread thread1 = boost::thread(ThreadingScenarioFailureThread1); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
517 boost::thread thread2 = boost::thread(ThreadingScenarioFailureThread2); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
518 |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
519 thread1.join(); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
520 thread2.join(); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
521 } |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
522 |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
523 |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
524 static int ThreadingScenarioInvalidateStep = 0; |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
525 static Orthanc::MemoryStringCache ThreadingScenarioInvalidateCache; |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
526 |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
527 void ThreadingScenarioInvalidateThread1() |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
528 { |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
529 // the first thread to call Fetch (will be in charge of adding) |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
530 Orthanc::MemoryStringCache::Accessor a(ThreadingScenarioInvalidateCache); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
531 std::string v; |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
532 |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
533 LOG(INFO) << "Thread1 will fetch"; |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
534 if (!a.Fetch(v, "key1")) |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
535 { |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
536 LOG(INFO) << "Thread1 has fetch"; |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
537 ThreadingScenarioInvalidateStep = 1; |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
538 |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
539 // wait for the other thread to fetch too |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
540 while (ThreadingScenarioInvalidateStep < 2) |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
541 { |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
542 Orthanc::SystemToolbox::USleep(10000); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
543 } |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
544 LOG(INFO) << "Thread1 will invalidate after a short sleep"; |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
545 Orthanc::SystemToolbox::USleep(100000); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
546 LOG(INFO) << "Thread1 is invalidating"; |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
547 ThreadingScenarioInvalidateCache.Invalidate("key1"); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
548 } |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
549 } |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
550 |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
551 void ThreadingScenarioInvalidateThread2() |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
552 { |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
553 Orthanc::MemoryStringCache::Accessor a(ThreadingScenarioInvalidateCache); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
554 std::string v; |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
555 |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
556 // wait until thread 1 has completed its "Fetch" but not added yet |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
557 while (ThreadingScenarioInvalidateStep < 1) |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
558 { |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
559 Orthanc::SystemToolbox::USleep(10000); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
560 } |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
561 |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
562 ThreadingScenarioInvalidateStep = 2; |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
563 LOG(INFO) << "Thread2 will fetch and wait for thread1 to add"; |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
564 // this should wait until thread 1 has added |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
565 if (!a.Fetch(v, "key1")) |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
566 { |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
567 LOG(INFO) << "Thread2 has been awaken because thread1 has invalidated the key"; |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
568 } |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
569 } |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
570 |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
571 |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
572 TEST(MemoryStringCache, ThreadingScenarioInvalidate) |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
573 { |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
574 boost::thread thread1 = boost::thread(ThreadingScenarioInvalidateThread1); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
575 boost::thread thread2 = boost::thread(ThreadingScenarioInvalidateThread2); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
576 |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
577 thread1.join(); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
578 thread2.join(); |
d37dff2c0028
Optimized the MemoryStringCache to prevent loading the same file multiple times if multiple users request the same file at the same time
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
579 } |