3 #include "testStoreHashIndex.h"
6 #include "TestSwapDir.h"
7 #include "StoreHashIndex.h"
9 #include "StoreSearch.h"
10 #include "SquidTime.h"
12 CPPUNIT_TEST_SUITE_REGISTRATION( testStoreHashIndex
);
15 addSwapDir(TestSwapDirPointer aStore
)
17 allocate_new_swapdir(&Config
.cacheSwap
);
18 Config
.cacheSwap
.swapDirs
[Config
.cacheSwap
.n_configured
] = aStore
.getRaw();
19 ++Config
.cacheSwap
.n_configured
;
24 testStoreHashIndex::testStats()
26 StoreEntry
* logEntry
= new StoreEntry("dummy_url", "dummy_log_url");
27 logEntry
->store_status
= STORE_PENDING
;
28 StorePointer
aRoot (new StoreHashIndex());
30 TestSwapDirPointer
aStore (new TestSwapDir
);
31 TestSwapDirPointer
aStore2 (new TestSwapDir
);
34 CPPUNIT_ASSERT(aStore
->statsCalled
== false);
35 CPPUNIT_ASSERT(aStore2
->statsCalled
== false);
36 Store::Stats(logEntry
);
37 free_cachedir(&Config
.cacheSwap
);
38 CPPUNIT_ASSERT(aStore
->statsCalled
== true);
39 CPPUNIT_ASSERT(aStore2
->statsCalled
== true);
44 testStoreHashIndex::testMaxSize()
46 StoreEntry
* logEntry
= new StoreEntry("dummy_url", "dummy_log_url");
47 logEntry
->store_status
= STORE_PENDING
;
48 StorePointer
aRoot (new StoreHashIndex());
50 TestSwapDirPointer
aStore (new TestSwapDir
);
51 TestSwapDirPointer
aStore2 (new TestSwapDir
);
54 CPPUNIT_ASSERT(Store::Root().maxSize() == 6);
55 free_cachedir(&Config
.cacheSwap
);
60 addedEntry(StorePointer hashStore
,
68 StoreEntry
*e
= new StoreEntry();
69 e
->store_status
= STORE_OK
;
70 e
->setMemStatus(NOT_IN_MEMORY
);
71 e
->swap_status
= SWAPOUT_DONE
; /* bogus haha */
72 e
->swap_filen
= 0; /* garh - lower level*/
75 for (int i
=0; i
< Config
.cacheSwap
.n_configured
; i
++) {
76 if (INDEXSD (i
) == aStore
.getRaw())
80 CPPUNIT_ASSERT (e
->swap_dirn
!= -1);
81 e
->swap_file_sz
= 0; /* garh lower level */
83 e
->lastref
= squid_curtime
;
84 e
->timestamp
= squid_curtime
;
85 e
->expires
= squid_curtime
;
86 e
->lastmod
= squid_curtime
;
88 EBIT_SET(e
->flags
, ENTRY_CACHABLE
);
89 EBIT_CLR(e
->flags
, RELEASE_REQUEST
);
90 EBIT_CLR(e
->flags
, KEY_PRIVATE
);
91 e
->ping_status
= PING_NONE
;
92 EBIT_CLR(e
->flags
, ENTRY_VALIDATED
);
93 e
->hashInsert((const cache_key
*)name
.buf()); /* do it after we clear KEY_PRIVATE */
99 static bool inited
= false;
106 Config
.Store
.avgObjectSize
= 1024;
108 Config
.Store
.objectsPerBucket
= 20;
110 Config
.Store
.maxObjectSize
= 2048;
113 /* TODO make this a cbdata class */
115 static bool cbcalled
;
118 searchCallback(void *cbdata
)
124 testStoreHashIndex::testSearch()
127 StorePointer
aRoot (new StoreHashIndex());
129 TestSwapDirPointer
aStore (new TestSwapDir
);
130 TestSwapDirPointer
aStore2 (new TestSwapDir
);
133 Store::Root().init();
134 StoreEntry
* entry1
= addedEntry (&Store::Root(), aStore
.getRaw(), "name", NULL
, NULL
);
135 StoreEntry
* entry2
= addedEntry (&Store::Root(), aStore2
.getRaw(), "name2", NULL
, NULL
);
136 StoreSearchPointer search
= aRoot
->search (NULL
, NULL
); /* search for everything in the store */
138 /* nothing should be immediately available */
139 CPPUNIT_ASSERT(search
->error() == false);
140 CPPUNIT_ASSERT(search
->isDone() == false);
141 CPPUNIT_ASSERT(search
->currentItem() == NULL
);
144 CPPUNIT_ASSERT(search
->next() == false);
147 /* trigger a callback */
149 search
->next(searchCallback
, NULL
);
150 CPPUNIT_ASSERT(cbcalled
== true);
152 /* we should have access to a entry now, that matches the entry we had before */
153 CPPUNIT_ASSERT(search
->error() == false);
154 CPPUNIT_ASSERT(search
->isDone() == false);
155 /* note the hash order is random - the test happens to be in a nice order */
156 CPPUNIT_ASSERT(search
->currentItem() == entry1
);
157 //CPPUNIT_ASSERT(search->next() == false);
159 /* trigger another callback */
161 search
->next(searchCallback
, NULL
);
162 CPPUNIT_ASSERT(cbcalled
== true);
164 /* we should have access to a entry now, that matches the entry we had before */
165 CPPUNIT_ASSERT(search
->error() == false);
166 CPPUNIT_ASSERT(search
->isDone() == false);
167 CPPUNIT_ASSERT(search
->currentItem() == entry2
);
168 //CPPUNIT_ASSERT(search->next() == false);
170 /* trigger another callback */
172 search
->next(searchCallback
, NULL
);
173 CPPUNIT_ASSERT(cbcalled
== true);
175 /* now we should have no error, we should have finished and have no current item */
176 CPPUNIT_ASSERT(search
->error() == false);
177 CPPUNIT_ASSERT(search
->isDone() == true);
178 CPPUNIT_ASSERT(search
->currentItem() == NULL
);
179 //CPPUNIT_ASSERT(search->next() == false);