testStoreHashIndex.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 "MemObject.h"
11#include "SquidConfig.h"
12#include "Store.h"
13#include "store/Disks.h"
14#include "StoreSearch.h"
15#include "testStoreHashIndex.h"
16#include "TestSwapDir.h"
17
19
20static void
22{
26}
27
28void
30{
31 StoreEntry *logEntry = new StoreEntry;
32 logEntry->createMemObject("dummy_storeId", nullptr, HttpRequestMethod());
33 logEntry->store_status = STORE_PENDING;
36 TestSwapDirPointer aStore2 (new TestSwapDir);
37 addSwapDir(aStore);
38 addSwapDir(aStore2);
39 CPPUNIT_ASSERT_EQUAL(false, aStore->statsCalled);
40 CPPUNIT_ASSERT_EQUAL(false, aStore2->statsCalled);
41 Store::Stats(logEntry);
43 CPPUNIT_ASSERT_EQUAL(true, aStore->statsCalled);
44 CPPUNIT_ASSERT_EQUAL(true, aStore2->statsCalled);
46}
47
48void
50{
51 StoreEntry *logEntry = new StoreEntry;
52 logEntry->createMemObject("dummy_storeId", nullptr, HttpRequestMethod());
53 logEntry->store_status = STORE_PENDING;
56 TestSwapDirPointer aStore2 (new TestSwapDir);
57 addSwapDir(aStore);
58 addSwapDir(aStore2);
59 CPPUNIT_ASSERT_EQUAL(static_cast<uint64_t>(6), Store::Root().maxSize());
62}
63
64static StoreEntry *
66 String name,
67 String,
68 String
69 )
70{
71 StoreEntry *e = new StoreEntry();
74 e->swap_status = SWAPOUT_DONE; /* bogus haha */
75 e->swap_filen = 0; /* garh - lower level*/
76 e->swap_dirn = -1;
77
78 for (int i=0; i < Config.cacheSwap.n_configured; ++i) {
79 if (INDEXSD(i) == aStore)
80 e->swap_dirn = i;
81 }
82
83 CPPUNIT_ASSERT (e->swap_dirn != -1);
84 e->swap_file_sz = 0; /* garh lower level */
89 e->refcount = 1;
92 e->hashInsert((const cache_key *)name.termedBuf()); /* do it after we clear KEY_PRIVATE */
93 return e;
94}
95
96static void commonInit()
97{
98 static bool inited = false;
99
100 if (inited)
101 return;
102
103 inited = true;
104
105 Mem::Init();
106
108
110
112
114
116}
117
118/* TODO make this a cbdata class */
119
120static bool cbcalled;
121
122static void
124{
125 cbcalled = true;
126}
127
128void
130{
131 commonInit();
132 Store::Init();
133 TestSwapDirPointer aStore (new TestSwapDir);
134 TestSwapDirPointer aStore2 (new TestSwapDir);
135 addSwapDir(aStore);
136 addSwapDir(aStore2);
137 Store::Root().init();
138 StoreEntry * entry1 = addedEntry(aStore.getRaw(), "name", nullptr, nullptr);
139 StoreEntry * entry2 = addedEntry(aStore2.getRaw(), "name2", nullptr, nullptr);
140 StoreSearchPointer search = Store::Root().search(); /* search for everything in the store */
141
142 /* nothing should be immediately available */
143 CPPUNIT_ASSERT_EQUAL(false, search->error());
144 CPPUNIT_ASSERT_EQUAL(false, search->isDone());
145 CPPUNIT_ASSERT_EQUAL(static_cast<StoreEntry *>(nullptr), search->currentItem());
146
147 /* trigger a callback */
148 cbcalled = false;
149 search->next(searchCallback, nullptr);
150 CPPUNIT_ASSERT_EQUAL(true, cbcalled);
151
152 /* we should have access to a entry now, that matches the entry we had before */
153 CPPUNIT_ASSERT_EQUAL(false, search->error());
154 CPPUNIT_ASSERT_EQUAL(false, search->isDone());
155 /* note the hash order is random - the test happens to be in a nice order */
156 CPPUNIT_ASSERT_EQUAL(entry1, search->currentItem());
157 //CPPUNIT_ASSERT_EQUAL(false, search->next());
158
159 /* trigger another callback */
160 cbcalled = false;
161 search->next(searchCallback, nullptr);
162 CPPUNIT_ASSERT_EQUAL(true, cbcalled);
163
164 /* we should have access to a entry now, that matches the entry we had before */
165 CPPUNIT_ASSERT_EQUAL(false, search->error());
166 CPPUNIT_ASSERT_EQUAL(false, search->isDone());
167 CPPUNIT_ASSERT_EQUAL(entry2, search->currentItem());
168 //CPPUNIT_ASSERT_EQUAL(false, search->next());
169
170 /* trigger another callback */
171 cbcalled = false;
172 search->next(searchCallback, nullptr);
173 CPPUNIT_ASSERT_EQUAL(true, cbcalled);
174
175 /* now we should have no error, we should have finished and have no current item */
176 CPPUNIT_ASSERT_EQUAL(false, search->error());
177 CPPUNIT_ASSERT_EQUAL(true, search->isDone());
178 CPPUNIT_ASSERT_EQUAL(static_cast<StoreEntry *>(nullptr), search->currentItem());
179 //CPPUNIT_ASSERT_EQUAL(false, search->next());
180
182}
183
void free_cachedir(Store::DiskConfig *swap)
Definition: Disks.cc:802
void allocate_new_swapdir(Store::DiskConfig &swap)
Definition: Disks.cc:783
time_t squid_curtime
Definition: stub_libtime.cc:20
class SquidConfig Config
Definition: SquidConfig.cc:12
#define INDEXSD(i)
Definition: SquidConfig.h:72
C * getRaw() const
Definition: RefCount.h:80
int objectsPerBucket
Definition: SquidConfig.h:262
int64_t avgObjectSize
Definition: SquidConfig.h:263
Store::DiskConfig cacheSwap
Definition: SquidConfig.h:421
struct SquidConfig::@109 Store
int64_t maxObjectSize
Definition: SquidConfig.h:264
char * store_dir_select_algorithm
Definition: SquidConfig.h:508
YesNoNone memShared
whether the memory cache is shared among workers
Definition: SquidConfig.h:87
void hashInsert(const cache_key *)
Definition: store.cc:399
uint16_t flags
Definition: Store.h:230
sdirno swap_dirn
Definition: Store.h:236
time_t expires
Definition: Store.h:224
void lastModified(const time_t when)
Definition: Store.h:174
swap_status_t swap_status
Definition: Store.h:244
time_t timestamp
Definition: Store.h:222
sfileno swap_filen
unique ID inside a cache_dir for swapped out entries; -1 for others
Definition: Store.h:234
ping_status_t ping_status
Definition: Store.h:240
store_status_t store_status
Definition: Store.h:242
time_t lastref
Definition: Store.h:223
void createMemObject()
Definition: store.cc:1552
uint64_t swap_file_sz
Definition: Store.h:228
uint16_t refcount
Definition: Store.h:229
void setMemStatus(mem_status_t)
Definition: store.cc:1501
virtual bool error() const =0
virtual void next(void(callback)(void *cbdata), void *cbdata)=0
virtual StoreEntry * currentItem()=0
virtual bool isDone() const =0
StoreSearch * search()
Definition: Controller.cc:211
virtual void init() override
Definition: Controller.cc:58
RefCount< SwapDir > * swapDirs
Definition: SquidConfig.h:66
manages a single cache_dir
Definition: Disk.h:22
char const * termedBuf() const
Definition: SquidString.h:92
void defaultTo(bool beSet)
enables or disables the option; updating to 'implicit' state
Definition: YesNoNone.h:59
#define EBIT_CLR(flag, bit)
Definition: defines.h:68
@ NOT_IN_MEMORY
Definition: enums.h:35
@ PING_NONE
Has not considered whether to send ICP queries to peers yet.
Definition: enums.h:41
@ SWAPOUT_DONE
Definition: enums.h:64
@ ENTRY_VALIDATED
Definition: enums.h:113
@ STORE_PENDING
Definition: enums.h:51
@ STORE_OK
Definition: enums.h:50
void Init()
Definition: old_api.cc:425
Controller & Root()
safely access controller singleton
Definition: Controller.cc:934
void FreeMemory()
undo Init()
Definition: Controller.cc:947
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:941
#define xstrdup
unsigned char cache_key
Store key.
Definition: forward.h:29
CPPUNIT_TEST_SUITE_REGISTRATION(testStoreHashIndex)
static void commonInit()
static void addSwapDir(TestSwapDirPointer aStore)
static StoreEntry * addedEntry(Store::Disk *aStore, String name, String, String)
static void searchCallback(void *)
static bool cbcalled

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors