Cache: Test LRU size limit

This commit is contained in:
Johan Wikman
2016-12-16 16:07:13 +02:00
parent 83c19c0b1a
commit 3a3632e75e
2 changed files with 58 additions and 0 deletions

View File

@ -23,6 +23,15 @@ TesterLRUStorage::TesterLRUStorage(std::ostream* pOut, StorageFactory* pFactory)
}
int TesterLRUStorage::execute(size_t n_threads, size_t n_seconds, const CacheItems& cache_items)
{
int rv1 = test_max_count(n_threads, n_seconds, cache_items);
out() << endl;
int rv2 = test_max_size(n_threads, n_seconds, cache_items);
return ((rv1 == EXIT_SUCCESS) && (rv2 == EXIT_SUCCESS)) ? EXIT_SUCCESS : EXIT_FAILURE;
}
int TesterLRUStorage::test_max_count(size_t n_threads, size_t n_seconds, const CacheItems& cache_items)
{
int rv = EXIT_FAILURE;
@ -59,3 +68,48 @@ int TesterLRUStorage::execute(size_t n_threads, size_t n_seconds, const CacheIte
return rv;
}
int TesterLRUStorage::test_max_size(size_t n_threads, size_t n_seconds, const CacheItems& cache_items)
{
int rv = EXIT_FAILURE;
Storage* pStorage;
uint64_t size = 0;
for (CacheItems::const_iterator i = cache_items.begin(); i < cache_items.end(); ++i)
{
size += gwbuf_length(i->second);
}
size_t max_size = size / 10;
out() << "LRU max-size: " << max_size << "\n" << endl;
pStorage = m_factory.createStorage(CACHE_THREAD_MODEL_MT,
"unspecified",
0, // No TTL
0, // No max count
max_size,
0, NULL);
if (pStorage)
{
rv = execute_tasks(n_threads, n_seconds, cache_items, *pStorage);
uint64_t size;
cache_result_t result = pStorage->get_size(&size);
ss_dassert(result == CACHE_RESULT_OK);
out() << "Max size: " << max_size << ", size: " << size << "." << endl;
if (size > max_size)
{
rv = EXIT_FAILURE;
}
delete pStorage;
}
return rv;
}

View File

@ -33,6 +33,10 @@ public:
*/
int execute(size_t n_threads, size_t n_seconds, const CacheItems& cache_items);
private:
int test_max_count(size_t n_threads, size_t n_seconds, const CacheItems& cache_items);
int test_max_size(size_t n_threads, size_t n_seconds, const CacheItems& cache_items);
private:
TesterLRUStorage(const TesterLRUStorage&);
TesterLRUStorage& operator = (const TesterLRUStorage&);