testStore.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2022 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9#include "squid.h"
10#include "Store.h"
11#include "store/SwapMeta.h"
12#include "testStore.h"
13#include "unitTestMain.h"
14
15#include <limits>
16
18
19int
21{
22 return 1;
23}
24
27{
28 return nullptr;
29}
30
31void
32TestStore::get(String, void (*)(StoreEntry*, void*), void*)
33{}
34
35void
37{}
38
39uint64_t
41{
42 return 3;
43}
44
45uint64_t
47{
48 return 1;
49}
50
51uint64_t
53{
54 return 2;
55}
56
57uint64_t
59{
60 return 2;
61}
62
63int64_t
65{
66 return 1;
67}
68
69void
71{
72}
73
74void
76{
77 const_cast<TestStore *>(this)->statsCalled = true;
78}
79
82{
83 return nullptr;
84}
85
86void
88{
89 Store::Controller *aStore(new TestStore);
90 Store::Init(aStore);
91
92 CPPUNIT_ASSERT_EQUAL(&Store::Root(), aStore);
94}
95
96void
98{
99 Store::Controller *aStore(new TestStore);
100 Store::Controller *aStore2(new TestStore);
101 Store::Init(aStore);
103 Store::Init(aStore2);
104 CPPUNIT_ASSERT_EQUAL(&Store::Root(),aStore2);
106}
107
108void
110{
111 TestStore *aStore(new TestStore);
112 Store::Init(aStore);
113 CPPUNIT_ASSERT_EQUAL(false, aStore->statsCalled);
114 StoreEntry entry;
115 Store::Stats(&entry);
116 CPPUNIT_ASSERT_EQUAL(true, aStore->statsCalled);
118}
119
120void
122{
123 Store::Controller *aStore(new TestStore);
124 Store::Init(aStore);
125 CPPUNIT_ASSERT_EQUAL(static_cast<uint64_t>(3), aStore->maxSize());
127}
128
129namespace Store {
130
132static void
134{
135 if (IgnoredSwapMetaType(rawType)) {
136 // an ignored raw type is either deprecated or reserved
137 CPPUNIT_ASSERT(DeprecatedSwapMetaType(rawType) || ReservedSwapMetaType(rawType));
138 CPPUNIT_ASSERT(!(DeprecatedSwapMetaType(rawType) && ReservedSwapMetaType(rawType)));
139 } else {
140 // all other raw types are neither deprecated nor reserved
141 CPPUNIT_ASSERT(!DeprecatedSwapMetaType(rawType) && !ReservedSwapMetaType(rawType));
142 }
143}
144
146static void
148{
149 // RawSwapMetaTypeBottom and smaller values are unrelated to any named
150 // SwapMetaDataType values, including past, current, and future ones
151 CPPUNIT_ASSERT(!HonoredSwapMetaType(rawType)); // current
152 CPPUNIT_ASSERT(!IgnoredSwapMetaType(rawType)); // past and future
153 CPPUNIT_ASSERT(!DeprecatedSwapMetaType(rawType)); // past
154 CPPUNIT_ASSERT(!ReservedSwapMetaType(rawType)); // future
155}
156
158static void
160{
161 // an in-range rawType other than STORE_META_VOID is either honored or ignored
162 CPPUNIT_ASSERT(HonoredSwapMetaType(rawType) || IgnoredSwapMetaType(rawType));
163 CPPUNIT_ASSERT(!(HonoredSwapMetaType(rawType) && IgnoredSwapMetaType(rawType)));
165}
166
168static void
170{
171 // values beyond RawSwapMetaTypeTop() cannot be honored but may be ignored
172 CPPUNIT_ASSERT(!HonoredSwapMetaType(rawType));
174}
175
177static void
179{
180 if (rawType <= RawSwapMetaTypeBottom)
182 else if (rawType > RawSwapMetaTypeTop())
184 else
186}
187
188} // namespace Store
189
190void
192{
193 using limits = std::numeric_limits<Store::RawSwapMetaType>;
194 for (auto rawType = limits::min(); true; ++rawType) {
195
197
198 if (rawType == limits::max())
199 break;
200 }
201
202 // Store::RawSwapMetaTypeTop() is documented as an honored type value
204}
205
High-level store statistics used by mgr:info action. Used inside PODs!
Definition: StoreStats.h:14
virtual uint64_t maxSize() const override
Definition: Controller.cc:159
allows testing of methods without having all the other components live
Definition: testStore.h:43
virtual void init()
Definition: testStore.cc:36
virtual StoreSearch * search()
Definition: testStore.cc:81
virtual StoreEntry * get(const cache_key *)
Definition: testStore.cc:26
bool statsCalled
Definition: testStore.h:48
virtual uint64_t maxSize() const
Definition: testStore.cc:40
virtual int callback()
called once every main loop iteration; TODO: Move to UFS code.
Definition: testStore.cc:20
virtual uint64_t currentSize() const
current size
Definition: testStore.cc:52
virtual uint64_t currentCount() const
the total number of objects stored right now
Definition: testStore.cc:58
virtual void stat(StoreEntry &) const
Definition: testStore.cc:75
virtual void getStats(StoreInfoStats &) const
collect statistics
Definition: testStore.cc:70
virtual uint64_t minSize() const
the minimum size the store will shrink to via normal housekeeping
Definition: testStore.cc:46
virtual int64_t maxObjectSize() const
the maximum size of a storable object; -1 if unlimited
Definition: testStore.cc:64
void testStats()
Definition: testStore.cc:109
void testUnsetRoot()
Definition: testStore.cc:97
void testMaxSize()
Definition: testStore.cc:121
void testSetRoot()
Definition: testStore.cc:87
void testSwapMetaTypeClassification()
Definition: testStore.cc:191
A const & max(A const &lhs, A const &rhs)
A const & min(A const &lhs, A const &rhs)
Controller & Root()
safely access controller singleton
Definition: Controller.cc:926
const RawSwapMetaType RawSwapMetaTypeBottom
Definition: SwapMeta.h:126
bool HonoredSwapMetaType(const RawSwapMetaType type)
Definition: SwapMeta.h:199
static void checkKnownSwapMetaRawType(const RawSwapMetaType rawType)
check a raw swap meta field type within SwapMetaType range, excluding STORE_META_VOID
Definition: testStore.cc:159
char RawSwapMetaType
Definition: SwapMeta.h:95
static void checkSwapMetaRawType(const RawSwapMetaType rawType)
check a given raw swap meta field type
Definition: testStore.cc:178
static void checkIgnorableSwapMetaRawType(const RawSwapMetaType rawType)
check rawType that may be ignored
Definition: testStore.cc:133
static void checkTooSmallSwapMetaRawType(const RawSwapMetaType rawType)
check a raw swap meta field type below SwapMetaType range or STORE_META_VOID
Definition: testStore.cc:147
bool ReservedSwapMetaType(const RawSwapMetaType type)
Definition: SwapMeta.h:182
void FreeMemory()
undo Init()
Definition: Controller.cc:939
void Stats(StoreEntry *output)
Definition: store.cc:123
void Init(Controller *root=nullptr)
initialize the storage module; a custom root is used by unit tests only
Definition: Controller.cc:933
static void checkTooBigSwapMetaRawType(const RawSwapMetaType rawType)
check a raw swap meta field type exceeding RawSwapMetaTypeTop()
Definition: testStore.cc:169
bool DeprecatedSwapMetaType(const RawSwapMetaType type)
Definition: SwapMeta.h:159
bool IgnoredSwapMetaType(const RawSwapMetaType type)
Definition: SwapMeta.h:221
RawSwapMetaType RawSwapMetaTypeTop()
Definition: SwapMeta.h:132
unsigned char cache_key
Store key.
Definition: forward.h:29
CPPUNIT_TEST_SUITE_REGISTRATION(testStore)

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors