MCPcopy Create free account
hub / github.com/apache/trafficserver / test

Function test

src/iocore/hostdb/test_RefCountCache.cc:201–280  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

199}
200
201int
202test()
203{
204 // Initialize IOBufAllocator
205 Layout::create();
206 init_diags("", nullptr);
207 RecProcessInit();
208 ink_event_system_init(EVENT_SYSTEM_MODULE_PUBLIC_VERSION);
209
210 int ret = 0;
211
212 printf("Starting tests\n");
213
214 printf("Testing refcounts\n");
215 ret |= testRefcounting();
216 printf("refcount ret %d\n", ret);
217
218 // Initialize our cache
219 int cachePartitions = 4;
220 RefCountCache<ExampleStruct> *cache = new RefCountCache<ExampleStruct>(cachePartitions);
221 printf("Created...\n");
222
223 LoadRefCountCacheFromPath<ExampleStruct>(*cache, "/tmp/hostdb_cache", ExampleStruct::unmarshall);
224 printf("Cache started...\n");
225 int numTestEntries = 10000;
226
227 // See if anything persisted across the restart
228 ret |= verifyCache(cache, 0, numTestEntries);
229 printf("done verifying startup\n");
230
231 // Clear the cache
232 cache->clear();
233 ret |= cache->count() != 0;
234 printf("clear %d\n", ret);
235
236 // fill it
237 printf("filling...\n");
238 fillCache(cache, 0, numTestEntries);
239 printf("filled...\n");
240
241 // Verify that it has items
242 printf("verifying...\n");
243 ret |= verifyCache(cache, 0, numTestEntries);
244 printf("verified %d\n", ret);
245
246 // Verify that we can alloc() with no extra space
247 printf("Alloc item idx 1\n");
248 ExampleStruct *tmp = ExampleStruct::alloc();
249 cache->put(static_cast<uint64_t>(1), tmp);
250 tmp->idx = 1;
251
252 Ptr<ExampleStruct> tmpAfter = cache->get(static_cast<uint64_t>(1));
253 printf("Item after (ret=%d) %d %d\n", ret, 1, tmpAfter->idx);
254 // Verify every item in the cache
255 ret |= verifyCache(cache, 0, numTestEntries);
256 printf("verified entire cache ret=%d\n", ret);
257
258 // Grab a pointer to item 1

Callers 1

mainFunction · 0.70

Calls 12

createFunction · 0.85
init_diagsFunction · 0.85
RecProcessInitFunction · 0.85
ink_event_system_initFunction · 0.85
testRefcountingFunction · 0.85
verifyCacheFunction · 0.85
fillCacheFunction · 0.85
clearMethod · 0.45
countMethod · 0.45
putMethod · 0.45
getMethod · 0.45
eraseMethod · 0.45

Tested by

no test coverage detected