Cache: Add more storage tests
- Check LRU behaviour - Limit both by count and size
This commit is contained in:
10
server/modules/filter/cache/cache_storage_api.hh
vendored
10
server/modules/filter/cache/cache_storage_api.hh
vendored
@ -49,6 +49,16 @@ struct hash<CACHE_KEY>
|
|||||||
|
|
||||||
std::string cache_key_to_string(const CACHE_KEY& key);
|
std::string cache_key_to_string(const CACHE_KEY& key);
|
||||||
|
|
||||||
|
inline bool operator == (const CACHE_KEY& lhs, const CACHE_KEY& rhs)
|
||||||
|
{
|
||||||
|
return memcmp(lhs.data, rhs.data, sizeof(lhs.data)) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool operator != (const CACHE_KEY& lhs, const CACHE_KEY& rhs)
|
||||||
|
{
|
||||||
|
return !(lhs == rhs);
|
||||||
|
}
|
||||||
|
|
||||||
class CacheKey : public CACHE_KEY
|
class CacheKey : public CACHE_KEY
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
193
server/modules/filter/cache/test/testerlrustorage.cc
vendored
193
server/modules/filter/cache/test/testerlrustorage.cc
vendored
@ -16,6 +16,7 @@
|
|||||||
#include "storagefactory.hh"
|
#include "storagefactory.hh"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
using namespace maxscale;
|
||||||
|
|
||||||
TesterLRUStorage::TesterLRUStorage(std::ostream* pOut, StorageFactory* pFactory)
|
TesterLRUStorage::TesterLRUStorage(std::ostream* pOut, StorageFactory* pFactory)
|
||||||
: TesterStorage(pOut, pFactory)
|
: TesterStorage(pOut, pFactory)
|
||||||
@ -24,14 +25,133 @@ TesterLRUStorage::TesterLRUStorage(std::ostream* pOut, StorageFactory* pFactory)
|
|||||||
|
|
||||||
int TesterLRUStorage::execute(size_t n_threads, size_t n_seconds, const CacheItems& cache_items)
|
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);
|
uint64_t size = 0;
|
||||||
out() << endl;
|
|
||||||
int rv2 = test_max_size(n_threads, n_seconds, cache_items);
|
|
||||||
|
|
||||||
return ((rv1 == EXIT_SUCCESS) && (rv2 == EXIT_SUCCESS)) ? EXIT_SUCCESS : EXIT_FAILURE;
|
for (CacheItems::const_iterator i = cache_items.begin(); i < cache_items.end(); ++i)
|
||||||
|
{
|
||||||
|
size += gwbuf_length(i->second);
|
||||||
|
}
|
||||||
|
|
||||||
|
int rv1 = test_lru(cache_items, size);
|
||||||
|
out() << endl;
|
||||||
|
int rv2 = test_max_count(n_threads, n_seconds, cache_items, size);
|
||||||
|
out() << endl;
|
||||||
|
int rv3 = test_max_size(n_threads, n_seconds, cache_items, size);
|
||||||
|
out() << endl;
|
||||||
|
int rv4 = test_max_count_and_size(n_threads, n_seconds, cache_items, size);
|
||||||
|
|
||||||
|
int rv = EXIT_SUCCESS;
|
||||||
|
|
||||||
|
if ((rv1 == EXIT_SUCCESS) && (rv2 == EXIT_SUCCESS) &&
|
||||||
|
(rv3 == EXIT_SUCCESS) && (rv4 == EXIT_SUCCESS))
|
||||||
|
{
|
||||||
|
rv = EXIT_SUCCESS;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rv = EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
int TesterLRUStorage::test_max_count(size_t n_threads, size_t n_seconds, const CacheItems& cache_items)
|
int TesterLRUStorage::test_lru(const CacheItems& cache_items, uint64_t size)
|
||||||
|
{
|
||||||
|
int rv = EXIT_FAILURE;
|
||||||
|
out() << "LRU\n" << endl;
|
||||||
|
|
||||||
|
size_t items = cache_items.size() > 100 ? 100 : cache_items.size();
|
||||||
|
|
||||||
|
Storage* pStorage = m_factory.createStorage(CACHE_THREAD_MODEL_MT,
|
||||||
|
"unspecified",
|
||||||
|
0, // No TTL
|
||||||
|
0, // No max count
|
||||||
|
0, // No max size
|
||||||
|
0, NULL);
|
||||||
|
|
||||||
|
if (pStorage)
|
||||||
|
{
|
||||||
|
rv = EXIT_SUCCESS;
|
||||||
|
|
||||||
|
cache_result_t result;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < items; ++i)
|
||||||
|
{
|
||||||
|
const CacheItems::value_type& cache_item = cache_items[i];
|
||||||
|
|
||||||
|
result = pStorage->put_value(cache_item.first, cache_item.second);
|
||||||
|
|
||||||
|
if (result == CACHE_RESULT_OK)
|
||||||
|
{
|
||||||
|
CACHE_KEY key;
|
||||||
|
GWBUF* pValue;
|
||||||
|
result = pStorage->get_head(&key, &pValue);
|
||||||
|
|
||||||
|
if (result == CACHE_RESULT_OK)
|
||||||
|
{
|
||||||
|
if (key != cache_item.first)
|
||||||
|
{
|
||||||
|
out() << "Last put value did not become the head." << endl;
|
||||||
|
rv = EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
else if (gwbuf_compare(pValue, cache_item.second) != 0)
|
||||||
|
{
|
||||||
|
out() << "Obtained value not the same as that which was put." << endl;
|
||||||
|
rv = EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
gwbuf_free(pValue);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ss_dassert(!true);
|
||||||
|
rv = EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
result = pStorage->get_tail(&key, &pValue);
|
||||||
|
|
||||||
|
if (result == CACHE_RESULT_OK)
|
||||||
|
{
|
||||||
|
if (key != cache_items[0].first)
|
||||||
|
{
|
||||||
|
out() << "First put value is not the tail." << endl;
|
||||||
|
}
|
||||||
|
else if (gwbuf_compare(pValue, cache_items[0].second))
|
||||||
|
{
|
||||||
|
out() << "Obtained value not the same as that which was put." << endl;
|
||||||
|
rv = EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
gwbuf_free(pValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ss_dassert(!true);
|
||||||
|
rv = EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CACHE_KEY key;
|
||||||
|
GWBUF* pValue;
|
||||||
|
result = pStorage->get_tail(&key, &pValue);
|
||||||
|
|
||||||
|
if (result == CACHE_RESULT_OK)
|
||||||
|
{
|
||||||
|
if (key != cache_items[0].first)
|
||||||
|
{
|
||||||
|
out() << "First put value is not the tail." << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
gwbuf_free(pValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
int TesterLRUStorage::test_max_count(size_t n_threads, size_t n_seconds,
|
||||||
|
const CacheItems& cache_items, uint64_t size)
|
||||||
{
|
{
|
||||||
int rv = EXIT_FAILURE;
|
int rv = EXIT_FAILURE;
|
||||||
|
|
||||||
@ -69,19 +189,13 @@ int TesterLRUStorage::test_max_count(size_t n_threads, size_t n_seconds, const C
|
|||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
int TesterLRUStorage::test_max_size(size_t n_threads, size_t n_seconds, const CacheItems& cache_items)
|
int TesterLRUStorage::test_max_size(size_t n_threads, size_t n_seconds,
|
||||||
|
const CacheItems& cache_items, uint64_t size)
|
||||||
{
|
{
|
||||||
int rv = EXIT_FAILURE;
|
int rv = EXIT_FAILURE;
|
||||||
|
|
||||||
Storage* pStorage;
|
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;
|
size_t max_size = size / 10;
|
||||||
|
|
||||||
out() << "LRU max-size: " << max_size << "\n" << endl;
|
out() << "LRU max-size: " << max_size << "\n" << endl;
|
||||||
@ -113,3 +227,56 @@ int TesterLRUStorage::test_max_size(size_t n_threads, size_t n_seconds, const Ca
|
|||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int TesterLRUStorage::test_max_count_and_size(size_t n_threads, size_t n_seconds,
|
||||||
|
const CacheItems& cache_items, uint64_t size)
|
||||||
|
{
|
||||||
|
int rv = EXIT_FAILURE;
|
||||||
|
|
||||||
|
Storage* pStorage;
|
||||||
|
|
||||||
|
size_t max_count = cache_items.size() / 4;
|
||||||
|
size_t max_size = size / 10;
|
||||||
|
|
||||||
|
out() << "LRU max-count: " << max_count << "\n" << endl;
|
||||||
|
out() << "LRU max-size : " << max_size << "\n" << endl;
|
||||||
|
|
||||||
|
pStorage = m_factory.createStorage(CACHE_THREAD_MODEL_MT,
|
||||||
|
"unspecified",
|
||||||
|
0, // No TTL
|
||||||
|
max_count,
|
||||||
|
max_size,
|
||||||
|
0, NULL);
|
||||||
|
|
||||||
|
if (pStorage)
|
||||||
|
{
|
||||||
|
rv = execute_tasks(n_threads, n_seconds, cache_items, *pStorage);
|
||||||
|
|
||||||
|
cache_result_t result;
|
||||||
|
uint64_t items;
|
||||||
|
result = pStorage->get_items(&items);
|
||||||
|
ss_dassert(result == CACHE_RESULT_OK);
|
||||||
|
|
||||||
|
out() << "Max count: " << max_count << ", count: " << items << "." << endl;
|
||||||
|
|
||||||
|
if (items > max_count)
|
||||||
|
{
|
||||||
|
rv = EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t size;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
@ -34,8 +34,13 @@ public:
|
|||||||
int execute(size_t n_threads, size_t n_seconds, const CacheItems& cache_items);
|
int execute(size_t n_threads, size_t n_seconds, const CacheItems& cache_items);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int test_max_count(size_t n_threads, size_t n_seconds, const CacheItems& cache_items);
|
int test_lru(const CacheItems& cache_items, uint64_t size);
|
||||||
int test_max_size(size_t n_threads, size_t n_seconds, const CacheItems& cache_items);
|
int test_max_count(size_t n_threads, size_t n_seconds,
|
||||||
|
const CacheItems& cache_items, uint64_t size);
|
||||||
|
int test_max_size(size_t n_threads, size_t n_seconds,
|
||||||
|
const CacheItems& cache_items, uint64_t size);
|
||||||
|
int test_max_count_and_size(size_t n_threads, size_t n_seconds,
|
||||||
|
const CacheItems& cache_items, uint64_t size);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TesterLRUStorage(const TesterLRUStorage&);
|
TesterLRUStorage(const TesterLRUStorage&);
|
||||||
|
Reference in New Issue
Block a user