4 #include "SquidConfig.h"
7 #include "StoreHashIndex.h"
8 #include "StoreSearch.h"
10 #include "testStoreHashIndex.h"
11 #include "TestSwapDir.h"
13 CPPUNIT_TEST_SUITE_REGISTRATION( testStoreHashIndex
);
16 addSwapDir(TestSwapDirPointer aStore
)
18 allocate_new_swapdir(&Config
.cacheSwap
);
19 Config
.cacheSwap
.swapDirs
[Config
.cacheSwap
.n_configured
] = aStore
.getRaw();
20 ++Config
.cacheSwap
.n_configured
;
24 testStoreHashIndex::testStats()
26 StoreEntry
*logEntry
= new StoreEntry
;
27 logEntry
->makeMemObject();
28 logEntry
->mem_obj
->setUris("dummy_storeId", NULL
, HttpRequestMethod());
29 logEntry
->store_status
= STORE_PENDING
;
30 StorePointer
aRoot (new StoreHashIndex());
32 TestSwapDirPointer
aStore (new TestSwapDir
);
33 TestSwapDirPointer
aStore2 (new TestSwapDir
);
36 CPPUNIT_ASSERT_EQUAL(false, aStore
->statsCalled
);
37 CPPUNIT_ASSERT_EQUAL(false, aStore2
->statsCalled
);
38 Store::Stats(logEntry
);
39 free_cachedir(&Config
.cacheSwap
);
40 CPPUNIT_ASSERT_EQUAL(true, aStore
->statsCalled
);
41 CPPUNIT_ASSERT_EQUAL(true, aStore2
->statsCalled
);
46 testStoreHashIndex::testMaxSize()
48 StoreEntry
*logEntry
= new StoreEntry
;
49 logEntry
->makeMemObject();
50 logEntry
->mem_obj
->setUris("dummy_storeId", NULL
, HttpRequestMethod());
51 logEntry
->store_status
= STORE_PENDING
;
52 StorePointer
aRoot (new StoreHashIndex());
54 TestSwapDirPointer
aStore (new TestSwapDir
);
55 TestSwapDirPointer
aStore2 (new TestSwapDir
);
58 CPPUNIT_ASSERT_EQUAL(static_cast<uint64_t>(6), Store::Root().maxSize());
59 free_cachedir(&Config
.cacheSwap
);
64 addedEntry(StorePointer hashStore
,
72 StoreEntry
*e
= new StoreEntry();
73 e
->store_status
= STORE_OK
;
74 e
->setMemStatus(NOT_IN_MEMORY
);
75 e
->swap_status
= SWAPOUT_DONE
; /* bogus haha */
76 e
->swap_filen
= 0; /* garh - lower level*/
79 for (int i
=0; i
< Config
.cacheSwap
.n_configured
; ++i
) {
80 if (INDEXSD (i
) == aStore
.getRaw())
84 CPPUNIT_ASSERT (e
->swap_dirn
!= -1);
85 e
->swap_file_sz
= 0; /* garh lower level */
86 e
->lastref
= squid_curtime
;
87 e
->timestamp
= squid_curtime
;
88 e
->expires
= squid_curtime
;
89 e
->lastmod
= squid_curtime
;
91 EBIT_CLR(e
->flags
, RELEASE_REQUEST
);
92 EBIT_CLR(e
->flags
, KEY_PRIVATE
);
93 e
->ping_status
= PING_NONE
;
94 EBIT_CLR(e
->flags
, ENTRY_VALIDATED
);
95 e
->hashInsert((const cache_key
*)name
.termedBuf()); /* do it after we clear KEY_PRIVATE */
101 static bool inited
= false;
108 Config
.Store
.avgObjectSize
= 1024;
110 Config
.Store
.objectsPerBucket
= 20;
112 Config
.Store
.maxObjectSize
= 2048;
115 /* TODO make this a cbdata class */
117 static bool cbcalled
;
120 searchCallback(void *cbdata
)
126 testStoreHashIndex::testSearch()
129 StorePointer
aRoot (new StoreHashIndex());
131 TestSwapDirPointer
aStore (new TestSwapDir
);
132 TestSwapDirPointer
aStore2 (new TestSwapDir
);
135 Store::Root().init();
136 StoreEntry
* entry1
= addedEntry (&Store::Root(), aStore
.getRaw(), "name", NULL
, NULL
);
137 StoreEntry
* entry2
= addedEntry (&Store::Root(), aStore2
.getRaw(), "name2", NULL
, NULL
);
138 StoreSearchPointer search
= aRoot
->search (NULL
, NULL
); /* search for everything in the store */
140 /* nothing should be immediately available */
141 CPPUNIT_ASSERT_EQUAL(false, search
->error());
142 CPPUNIT_ASSERT_EQUAL(false, search
->isDone());
143 CPPUNIT_ASSERT_EQUAL(static_cast<StoreEntry
*>(NULL
), search
->currentItem());
146 CPPUNIT_ASSERT_EQUAL(false, search
->next());
149 /* trigger a callback */
151 search
->next(searchCallback
, NULL
);
152 CPPUNIT_ASSERT_EQUAL(true, cbcalled
);
154 /* we should have access to a entry now, that matches the entry we had before */
155 CPPUNIT_ASSERT_EQUAL(false, search
->error());
156 CPPUNIT_ASSERT_EQUAL(false, search
->isDone());
157 /* note the hash order is random - the test happens to be in a nice order */
158 CPPUNIT_ASSERT_EQUAL(entry1
, search
->currentItem());
159 //CPPUNIT_ASSERT_EQUAL(false, search->next());
161 /* trigger another callback */
163 search
->next(searchCallback
, NULL
);
164 CPPUNIT_ASSERT_EQUAL(true, cbcalled
);
166 /* we should have access to a entry now, that matches the entry we had before */
167 CPPUNIT_ASSERT_EQUAL(false, search
->error());
168 CPPUNIT_ASSERT_EQUAL(false, search
->isDone());
169 CPPUNIT_ASSERT_EQUAL(entry2
, search
->currentItem());
170 //CPPUNIT_ASSERT_EQUAL(false, search->next());
172 /* trigger another callback */
174 search
->next(searchCallback
, NULL
);
175 CPPUNIT_ASSERT_EQUAL(true, cbcalled
);
177 /* now we should have no error, we should have finished and have no current item */
178 CPPUNIT_ASSERT_EQUAL(false, search
->error());
179 CPPUNIT_ASSERT_EQUAL(true, search
->isDone());
180 CPPUNIT_ASSERT_EQUAL(static_cast<StoreEntry
*>(NULL
), search
->currentItem());
181 //CPPUNIT_ASSERT_EQUAL(false, search->next());