Mercurial > hg > orthanc
annotate UnitTestsSources/MemoryCacheTests.cpp @ 3740:e69c556f1913 storage-commitment
storage commitment SCU against a list of Orthanc IDs
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 11 Mar 2020 11:04:48 +0100 |
parents | 0540b54324f1 |
children |
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 |
3640
94f4a18a79cc
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3557
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
827
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
6 * |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
8 * modify it under the terms of the GNU General Public License as |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
9 * published by the Free Software Foundation, either version 3 of the |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
10 * License, or (at your option) any later version. |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
11 * |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
12 * In addition, as a special exception, the copyright holders of this |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
13 * program give permission to link the code of its release with the |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
15 * that use the same license as the "OpenSSL" library), and distribute |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
16 * the linked executables. You must obey the GNU General Public License |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
17 * in all respects for all of the code used other than "OpenSSL". If you |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
18 * modify file(s) with this exception, you may extend this exception to |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
19 * your version of the file(s), but you are not obligated to do so. If |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
20 * you do not wish to do so, delete this exception statement from your |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
21 * version. If you delete this exception statement from all source files |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
22 * in the program, then also delete it here. |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
23 * |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
24 * This program is distributed in the hope that it will be useful, but |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
25 * WITHOUT ANY WARRANTY; without even the implied warranty of |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
27 * General Public License for more details. |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
28 * |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
29 * You should have received a copy of the GNU General Public License |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
30 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
31 **/ |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
32 |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
33 |
831
84513f2ee1f3
pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
827
diff
changeset
|
34 #include "PrecompiledHeadersUnitTests.h" |
282 | 35 #include "gtest/gtest.h" |
36 | |
37 #include <memory> | |
3454
0e3c26e4b8ec
LeastRecentlyUsedIndex::GetAllKeys (test)
Alain Mazy <alain@mazy.be>
parents:
3060
diff
changeset
|
38 #include <algorithm> |
283 | 39 #include <boost/thread.hpp> |
40 #include <boost/lexical_cast.hpp> | |
1486
f967bdf8534e
refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1367
diff
changeset
|
41 |
284
06aa7b7b6723
implementation of a single-threaded cache mechanism
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
283
diff
changeset
|
42 #include "../Core/Cache/MemoryCache.h" |
3557
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
43 #include "../Core/Cache/MemoryStringCache.h" |
1367 | 44 #include "../Core/Cache/SharedArchive.h" |
1486
f967bdf8534e
refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1367
diff
changeset
|
45 #include "../Core/IDynamicObject.h" |
f967bdf8534e
refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1367
diff
changeset
|
46 #include "../Core/Logging.h" |
3736
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
47 #include "../OrthancServer/StorageCommitmentReports.h" |
282 | 48 |
49 | |
505
f59e4518fd57
rename CacheIndex as LeastRecentlyUsedIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
50 TEST(LRU, Basic) |
282 | 51 { |
505
f59e4518fd57
rename CacheIndex as LeastRecentlyUsedIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
52 Orthanc::LeastRecentlyUsedIndex<std::string> r; |
282 | 53 |
54 r.Add("d"); | |
55 r.Add("a"); | |
56 r.Add("c"); | |
57 r.Add("b"); | |
58 | |
509
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
59 r.MakeMostRecent("a"); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
60 r.MakeMostRecent("d"); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
61 r.MakeMostRecent("b"); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
62 r.MakeMostRecent("c"); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
63 r.MakeMostRecent("d"); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
64 r.MakeMostRecent("c"); |
282 | 65 |
507
c4122c3a47c1
access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
505
diff
changeset
|
66 ASSERT_EQ("a", r.GetOldest()); |
282 | 67 ASSERT_EQ("a", r.RemoveOldest()); |
507
c4122c3a47c1
access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
505
diff
changeset
|
68 ASSERT_EQ("b", r.GetOldest()); |
282 | 69 ASSERT_EQ("b", r.RemoveOldest()); |
507
c4122c3a47c1
access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
505
diff
changeset
|
70 ASSERT_EQ("d", r.GetOldest()); |
282 | 71 ASSERT_EQ("d", r.RemoveOldest()); |
507
c4122c3a47c1
access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
505
diff
changeset
|
72 ASSERT_EQ("c", r.GetOldest()); |
282 | 73 ASSERT_EQ("c", r.RemoveOldest()); |
74 | |
75 ASSERT_TRUE(r.IsEmpty()); | |
507
c4122c3a47c1
access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
505
diff
changeset
|
76 |
c4122c3a47c1
access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
505
diff
changeset
|
77 ASSERT_THROW(r.GetOldest(), Orthanc::OrthancException); |
c4122c3a47c1
access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
505
diff
changeset
|
78 ASSERT_THROW(r.RemoveOldest(), Orthanc::OrthancException); |
282 | 79 } |
80 | |
81 | |
505
f59e4518fd57
rename CacheIndex as LeastRecentlyUsedIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
82 TEST(LRU, Payload) |
282 | 83 { |
505
f59e4518fd57
rename CacheIndex as LeastRecentlyUsedIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
285
diff
changeset
|
84 Orthanc::LeastRecentlyUsedIndex<std::string, int> r; |
282 | 85 |
86 r.Add("a", 420); | |
87 r.Add("b", 421); | |
88 r.Add("c", 422); | |
89 r.Add("d", 423); | |
90 | |
509
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
91 r.MakeMostRecent("a"); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
92 r.MakeMostRecent("d"); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
93 r.MakeMostRecent("b"); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
94 r.MakeMostRecent("c"); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
95 r.MakeMostRecent("d"); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
96 r.MakeMostRecent("c"); |
282 | 97 |
98 ASSERT_TRUE(r.Contains("b")); | |
99 ASSERT_EQ(421, r.Invalidate("b")); | |
100 ASSERT_FALSE(r.Contains("b")); | |
101 | |
102 int p; | |
283 | 103 ASSERT_TRUE(r.Contains("a", p)); ASSERT_EQ(420, p); |
104 ASSERT_TRUE(r.Contains("c", p)); ASSERT_EQ(422, p); | |
105 ASSERT_TRUE(r.Contains("d", p)); ASSERT_EQ(423, p); | |
106 | |
507
c4122c3a47c1
access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
505
diff
changeset
|
107 ASSERT_EQ("a", r.GetOldest()); |
c4122c3a47c1
access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
505
diff
changeset
|
108 ASSERT_EQ(420, r.GetOldestPayload()); |
282 | 109 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
|
110 |
c4122c3a47c1
access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
505
diff
changeset
|
111 ASSERT_EQ("d", r.GetOldest()); |
c4122c3a47c1
access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
505
diff
changeset
|
112 ASSERT_EQ(423, r.GetOldestPayload()); |
282 | 113 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
|
114 |
c4122c3a47c1
access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
505
diff
changeset
|
115 ASSERT_EQ("c", r.GetOldest()); |
c4122c3a47c1
access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
505
diff
changeset
|
116 ASSERT_EQ(422, r.GetOldestPayload()); |
282 | 117 ASSERT_EQ("c", r.RemoveOldest(p)); ASSERT_EQ(422, p); |
118 | |
119 ASSERT_TRUE(r.IsEmpty()); | |
120 } | |
121 | |
122 | |
509
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
123 TEST(LRU, PayloadUpdate) |
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 Orthanc::LeastRecentlyUsedIndex<std::string, int> r; |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
126 |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
127 r.Add("a", 420); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
128 r.Add("b", 421); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
129 r.Add("d", 423); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
130 |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
131 r.MakeMostRecent("a", 424); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
132 r.MakeMostRecent("d", 421); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
133 |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
134 ASSERT_EQ("b", r.GetOldest()); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
135 ASSERT_EQ(421, r.GetOldestPayload()); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
136 r.RemoveOldest(); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
137 |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
138 ASSERT_EQ("a", r.GetOldest()); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
139 ASSERT_EQ(424, r.GetOldestPayload()); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
140 r.RemoveOldest(); |
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 ASSERT_EQ("d", r.GetOldest()); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
143 ASSERT_EQ(421, r.GetOldestPayload()); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
144 r.RemoveOldest(); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
145 |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
146 ASSERT_TRUE(r.IsEmpty()); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
147 } |
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 |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
150 |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
151 TEST(LRU, PayloadUpdateBis) |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
152 { |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
153 Orthanc::LeastRecentlyUsedIndex<std::string, int> r; |
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 r.AddOrMakeMostRecent("a", 420); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
156 r.AddOrMakeMostRecent("b", 421); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
157 r.AddOrMakeMostRecent("d", 423); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
158 r.AddOrMakeMostRecent("a", 424); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
159 r.AddOrMakeMostRecent("d", 421); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
160 |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
161 ASSERT_EQ("b", r.GetOldest()); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
162 ASSERT_EQ(421, r.GetOldestPayload()); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
163 r.RemoveOldest(); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
164 |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
165 ASSERT_EQ("a", r.GetOldest()); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
166 ASSERT_EQ(424, r.GetOldestPayload()); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
167 r.RemoveOldest(); |
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 ASSERT_EQ("d", r.GetOldest()); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
170 ASSERT_EQ(421, r.GetOldestPayload()); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
171 r.RemoveOldest(); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
172 |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
173 ASSERT_TRUE(r.IsEmpty()); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
174 } |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
175 |
3454
0e3c26e4b8ec
LeastRecentlyUsedIndex::GetAllKeys (test)
Alain Mazy <alain@mazy.be>
parents:
3060
diff
changeset
|
176 TEST(LRU, GetAllKeys) |
0e3c26e4b8ec
LeastRecentlyUsedIndex::GetAllKeys (test)
Alain Mazy <alain@mazy.be>
parents:
3060
diff
changeset
|
177 { |
0e3c26e4b8ec
LeastRecentlyUsedIndex::GetAllKeys (test)
Alain Mazy <alain@mazy.be>
parents:
3060
diff
changeset
|
178 Orthanc::LeastRecentlyUsedIndex<std::string, int> r; |
0e3c26e4b8ec
LeastRecentlyUsedIndex::GetAllKeys (test)
Alain Mazy <alain@mazy.be>
parents:
3060
diff
changeset
|
179 std::vector<std::string> keys; |
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("a", 420); |
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(1u, keys.size()); |
3454
0e3c26e4b8ec
LeastRecentlyUsedIndex::GetAllKeys (test)
Alain Mazy <alain@mazy.be>
parents:
3060
diff
changeset
|
185 ASSERT_EQ("a", keys[0]); |
0e3c26e4b8ec
LeastRecentlyUsedIndex::GetAllKeys (test)
Alain Mazy <alain@mazy.be>
parents:
3060
diff
changeset
|
186 |
0e3c26e4b8ec
LeastRecentlyUsedIndex::GetAllKeys (test)
Alain Mazy <alain@mazy.be>
parents:
3060
diff
changeset
|
187 r.AddOrMakeMostRecent("b", 421); |
0e3c26e4b8ec
LeastRecentlyUsedIndex::GetAllKeys (test)
Alain Mazy <alain@mazy.be>
parents:
3060
diff
changeset
|
188 r.GetAllKeys(keys); |
0e3c26e4b8ec
LeastRecentlyUsedIndex::GetAllKeys (test)
Alain Mazy <alain@mazy.be>
parents:
3060
diff
changeset
|
189 |
3497
db71bd11affc
fix unit tests if dcmtk != 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3454
diff
changeset
|
190 ASSERT_EQ(2u, keys.size()); |
3454
0e3c26e4b8ec
LeastRecentlyUsedIndex::GetAllKeys (test)
Alain Mazy <alain@mazy.be>
parents:
3060
diff
changeset
|
191 ASSERT_TRUE(std::find(keys.begin(), keys.end(),"a") != keys.end()); |
0e3c26e4b8ec
LeastRecentlyUsedIndex::GetAllKeys (test)
Alain Mazy <alain@mazy.be>
parents:
3060
diff
changeset
|
192 ASSERT_TRUE(std::find(keys.begin(), keys.end(),"b") != keys.end()); |
0e3c26e4b8ec
LeastRecentlyUsedIndex::GetAllKeys (test)
Alain Mazy <alain@mazy.be>
parents:
3060
diff
changeset
|
193 } |
509
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
194 |
283 | 195 |
196 | |
197 namespace | |
198 { | |
199 class Integer : public Orthanc::IDynamicObject | |
200 { | |
201 private: | |
202 std::string& log_; | |
203 int value_; | |
282 | 204 |
205 public: | |
283 | 206 Integer(std::string& log, int v) : log_(log), value_(v) |
207 { | |
208 } | |
209 | |
2924
22524fd06225
macros ORTHANC_OVERRIDE and ORTHANC_FINAL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
210 virtual ~Integer() ORTHANC_OVERRIDE |
283 | 211 { |
212 LOG(INFO) << "Removing cache entry for " << value_; | |
213 log_ += boost::lexical_cast<std::string>(value_) + " "; | |
214 } | |
215 }; | |
216 | |
3557
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
217 class IntegerProvider : public Orthanc::Deprecated::ICachePageProvider |
283 | 218 { |
219 public: | |
220 std::string log_; | |
221 | |
2924
22524fd06225
macros ORTHANC_OVERRIDE and ORTHANC_FINAL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
222 virtual Orthanc::IDynamicObject* Provide(const std::string& s) ORTHANC_OVERRIDE |
283 | 223 { |
224 LOG(INFO) << "Providing " << s; | |
225 return new Integer(log_, boost::lexical_cast<int>(s)); | |
226 } | |
282 | 227 }; |
228 } | |
283 | 229 |
230 | |
231 TEST(MemoryCache, Basic) | |
232 { | |
233 IntegerProvider provider; | |
234 | |
235 { | |
3557
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
236 Orthanc::Deprecated::MemoryCache cache(provider, 3); |
285
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
284
diff
changeset
|
237 cache.Access("42"); // 42 -> exit |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
284
diff
changeset
|
238 cache.Access("43"); // 43, 42 -> exit |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
284
diff
changeset
|
239 cache.Access("45"); // 45, 43, 42 -> exit |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
284
diff
changeset
|
240 cache.Access("42"); // 42, 45, 43 -> exit |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
284
diff
changeset
|
241 cache.Access("43"); // 43, 42, 45 -> exit |
4031f73fe0e4
access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
284
diff
changeset
|
242 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
|
243 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
|
244 cache.Access("42"); // 43 is removed; 42, 44, 47 -> exit |
283 | 245 // Closing the cache: 47, 44, 42 are successively removed |
246 } | |
247 | |
248 ASSERT_EQ("45 42 43 47 44 42 ", provider.log_); | |
249 } | |
1367 | 250 |
251 | |
252 | |
253 | |
254 | |
255 namespace | |
256 { | |
257 class S : public Orthanc::IDynamicObject | |
258 { | |
259 private: | |
260 std::string value_; | |
261 | |
262 public: | |
263 S(const std::string& value) : value_(value) | |
264 { | |
265 } | |
266 | |
267 const std::string& GetValue() const | |
268 { | |
269 return value_; | |
270 } | |
271 }; | |
272 } | |
273 | |
274 | |
275 TEST(LRU, SharedArchive) | |
276 { | |
277 std::string first, second; | |
278 Orthanc::SharedArchive a(3); | |
279 first = a.Add(new S("First item")); | |
280 second = a.Add(new S("Second item")); | |
281 | |
282 for (int i = 1; i < 100; i++) | |
283 { | |
284 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
|
285 |
1367 | 286 // 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
|
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, first); |
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("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
|
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, second); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2924
diff
changeset
|
295 ASSERT_TRUE(accessor.IsValid()); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2924
diff
changeset
|
296 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
|
297 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2924
diff
changeset
|
298 |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2924
diff
changeset
|
299 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2924
diff
changeset
|
300 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
|
301 ASSERT_FALSE(accessor.IsValid()); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2924
diff
changeset
|
302 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
|
303 } |
1367 | 304 } |
305 | |
306 std::list<std::string> i; | |
307 a.List(i); | |
308 | |
309 size_t count = 0; | |
310 for (std::list<std::string>::const_iterator | |
311 it = i.begin(); it != i.end(); it++) | |
312 { | |
313 if (*it == first || | |
314 *it == second) | |
315 { | |
316 count++; | |
317 } | |
318 } | |
319 | |
1492 | 320 ASSERT_EQ(2u, count); |
1367 | 321 } |
3557
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
322 |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
323 |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
324 TEST(MemoryStringCache, Basic) |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
325 { |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
326 Orthanc::MemoryStringCache c; |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
327 ASSERT_THROW(c.SetMaximumSize(0), Orthanc::OrthancException); |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
328 |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
329 c.SetMaximumSize(2); |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
330 |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
331 std::string v; |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
332 ASSERT_FALSE(c.Fetch(v, "hello")); |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
333 |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
334 c.Add("hello", "a"); |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
335 ASSERT_TRUE(c.Fetch(v, "hello")); ASSERT_EQ("a", v); |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
336 ASSERT_FALSE(c.Fetch(v, "hello2")); |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
337 ASSERT_FALSE(c.Fetch(v, "hello3")); |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
338 |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
339 c.Add("hello2", "b"); |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
340 ASSERT_TRUE(c.Fetch(v, "hello")); ASSERT_EQ("a", v); |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
341 ASSERT_TRUE(c.Fetch(v, "hello2")); ASSERT_EQ("b", v); |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
342 ASSERT_FALSE(c.Fetch(v, "hello3")); |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
343 |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
344 c.Add("hello3", "too large value"); |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
345 ASSERT_TRUE(c.Fetch(v, "hello")); ASSERT_EQ("a", v); |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
346 ASSERT_TRUE(c.Fetch(v, "hello2")); ASSERT_EQ("b", v); |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
347 ASSERT_FALSE(c.Fetch(v, "hello3")); |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
348 |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
349 c.Add("hello3", "c"); |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
350 ASSERT_FALSE(c.Fetch(v, "hello")); // Recycled |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
351 ASSERT_TRUE(c.Fetch(v, "hello2")); ASSERT_EQ("b", v); |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
352 ASSERT_TRUE(c.Fetch(v, "hello3")); ASSERT_EQ("c", v); |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
353 } |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
354 |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
355 |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
356 TEST(MemoryStringCache, Invalidate) |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
357 { |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
358 Orthanc::MemoryStringCache c; |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
359 c.Add("hello", "a"); |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
360 c.Add("hello2", "b"); |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
361 |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
362 std::string v; |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
363 ASSERT_TRUE(c.Fetch(v, "hello")); ASSERT_EQ("a", v); |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
364 ASSERT_TRUE(c.Fetch(v, "hello2")); ASSERT_EQ("b", v); |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
365 |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
366 c.Invalidate("hello"); |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
367 ASSERT_FALSE(c.Fetch(v, "hello")); |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
368 ASSERT_TRUE(c.Fetch(v, "hello2")); ASSERT_EQ("b", v); |
4d809b2e1141
better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3497
diff
changeset
|
369 } |
3736
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
370 |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
371 |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
372 TEST(StorageCommitmentReports, Basic) |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
373 { |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
374 Orthanc::StorageCommitmentReports reports(2); |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
375 ASSERT_EQ(2u, reports.GetMaxSize()); |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
376 |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
377 { |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
378 Orthanc::StorageCommitmentReports::Accessor accessor(reports, "nope"); |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
379 ASSERT_EQ("nope", accessor.GetTransactionUid()); |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
380 ASSERT_FALSE(accessor.IsValid()); |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
381 ASSERT_THROW(accessor.GetReport(), Orthanc::OrthancException); |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
382 } |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
383 |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
384 reports.Store("a", new Orthanc::StorageCommitmentReports::Report("aet_a")); |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
385 reports.Store("b", new Orthanc::StorageCommitmentReports::Report("aet_b")); |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
386 reports.Store("c", new Orthanc::StorageCommitmentReports::Report("aet_c")); |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
387 |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
388 { |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
389 Orthanc::StorageCommitmentReports::Accessor accessor(reports, "a"); |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
390 ASSERT_FALSE(accessor.IsValid()); |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
391 } |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
392 |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
393 { |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
394 Orthanc::StorageCommitmentReports::Accessor accessor(reports, "b"); |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
395 ASSERT_TRUE(accessor.IsValid()); |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
396 ASSERT_EQ("aet_b", accessor.GetReport().GetRemoteAet()); |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
397 ASSERT_EQ(Orthanc::StorageCommitmentReports::Report::Status_Pending, |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
398 accessor.GetReport().GetStatus()); |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
399 } |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
400 |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
401 { |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
402 Orthanc::StorageCommitmentReports::Accessor accessor(reports, "c"); |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
403 ASSERT_EQ("aet_c", accessor.GetReport().GetRemoteAet()); |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
404 ASSERT_TRUE(accessor.IsValid()); |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
405 } |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
406 |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
407 { |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
408 std::unique_ptr<Orthanc::StorageCommitmentReports::Report> report |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
409 (new Orthanc::StorageCommitmentReports::Report("aet")); |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
410 report->AddSuccess("class1", "instance1"); |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
411 report->AddFailure("class2", "instance2", |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
412 Orthanc::StorageCommitmentFailureReason_ReferencedSOPClassNotSupported); |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
413 report->MarkAsComplete(); |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
414 reports.Store("a", report.release()); |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
415 } |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
416 |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
417 { |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
418 Orthanc::StorageCommitmentReports::Accessor accessor(reports, "a"); |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
419 ASSERT_TRUE(accessor.IsValid()); |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
420 ASSERT_EQ("aet", accessor.GetReport().GetRemoteAet()); |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
421 ASSERT_EQ(Orthanc::StorageCommitmentReports::Report::Status_Failure, |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
422 accessor.GetReport().GetStatus()); |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
423 } |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
424 |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
425 { |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
426 Orthanc::StorageCommitmentReports::Accessor accessor(reports, "b"); |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
427 ASSERT_FALSE(accessor.IsValid()); |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
428 } |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
429 |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
430 { |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
431 Orthanc::StorageCommitmentReports::Accessor accessor(reports, "c"); |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
432 ASSERT_TRUE(accessor.IsValid()); |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
433 } |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
434 |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
435 { |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
436 std::unique_ptr<Orthanc::StorageCommitmentReports::Report> report |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
437 (new Orthanc::StorageCommitmentReports::Report("aet")); |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
438 report->AddSuccess("class1", "instance1"); |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
439 report->MarkAsComplete(); |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
440 reports.Store("a", report.release()); |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
441 } |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
442 |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
443 { |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
444 Orthanc::StorageCommitmentReports::Accessor accessor(reports, "a"); |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
445 ASSERT_TRUE(accessor.IsValid()); |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
446 ASSERT_EQ("aet", accessor.GetReport().GetRemoteAet()); |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
447 ASSERT_EQ(Orthanc::StorageCommitmentReports::Report::Status_Success, |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
448 accessor.GetReport().GetStatus()); |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
449 } |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
450 |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
451 { |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
452 Orthanc::StorageCommitmentReports::Accessor accessor(reports, "b"); |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
453 ASSERT_FALSE(accessor.IsValid()); |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
454 } |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
455 |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
456 { |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
457 Orthanc::StorageCommitmentReports::Accessor accessor(reports, "c"); |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
458 ASSERT_TRUE(accessor.IsValid()); |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
459 } |
0540b54324f1
StorageCommitmentReports
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
460 } |