Cache: Test TTL behaviour
This commit is contained in:
20
server/modules/filter/cache/test/tester.hh
vendored
20
server/modules/filter/cache/test/tester.hh
vendored
@ -215,6 +215,26 @@ public:
|
||||
*/
|
||||
static void clear_cache_items(CacheItems& cache_items);
|
||||
|
||||
static int combine_rvs(int rv1, int rv2)
|
||||
{
|
||||
return ((rv1 == EXIT_FAILURE) || (rv2 == EXIT_FAILURE)) ? EXIT_FAILURE : EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
static int combine_rvs(int rv1, int rv2, int rv3)
|
||||
{
|
||||
return combine_rvs(rv1, combine_rvs(rv2, rv3));
|
||||
}
|
||||
|
||||
static int combine_rvs(int rv1, int rv2, int rv3, int rv4)
|
||||
{
|
||||
return combine_rvs(rv1, combine_rvs(rv2, rv3, rv4));
|
||||
}
|
||||
|
||||
static int combine_rvs(int rv1, int rv2, int rv3, int rv4, int rv5)
|
||||
{
|
||||
return combine_rvs(rv1, combine_rvs(rv2, rv3, rv4, rv5));
|
||||
}
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Constructor
|
||||
|
@ -32,27 +32,22 @@ int TesterLRUStorage::execute(size_t n_threads, size_t n_seconds, const CacheIte
|
||||
size += gwbuf_length(i->second);
|
||||
}
|
||||
|
||||
int rv1 = test_lru(cache_items, size);
|
||||
int rv1 = test_smoke(cache_items);
|
||||
out() << endl;
|
||||
int rv2 = test_max_count(n_threads, n_seconds, cache_items, size);
|
||||
int rv2 = test_lru(cache_items, size);
|
||||
out() << endl;
|
||||
int rv3 = test_max_size(n_threads, n_seconds, cache_items, size);
|
||||
int rv3 = test_max_count(n_threads, n_seconds, cache_items, size);
|
||||
out() << endl;
|
||||
int rv4 = test_max_count_and_size(n_threads, n_seconds, cache_items, size);
|
||||
int rv4 = test_max_size(n_threads, n_seconds, cache_items, size);
|
||||
out() << endl;
|
||||
int rv5 = test_max_count_and_size(n_threads, n_seconds, cache_items, size);
|
||||
|
||||
int rv = EXIT_SUCCESS;
|
||||
return combine_rvs(rv1, rv2, rv3, rv4, rv5);
|
||||
}
|
||||
|
||||
if ((rv1 == EXIT_SUCCESS) && (rv2 == EXIT_SUCCESS) &&
|
||||
(rv3 == EXIT_SUCCESS) && (rv4 == EXIT_SUCCESS))
|
||||
{
|
||||
rv = EXIT_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
rv = EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return rv;
|
||||
Storage* TesterLRUStorage::get_storage(const CACHE_STORAGE_CONFIG& config) const
|
||||
{
|
||||
return m_factory.createStorage("unspecified", config);
|
||||
}
|
||||
|
||||
int TesterLRUStorage::test_lru(const CacheItems& cache_items, uint64_t size)
|
||||
@ -64,7 +59,7 @@ int TesterLRUStorage::test_lru(const CacheItems& cache_items, uint64_t size)
|
||||
|
||||
CacheStorageConfig config(CACHE_THREAD_MODEL_MT);
|
||||
|
||||
Storage* pStorage = m_factory.createStorage("unspecified", config);
|
||||
Storage* pStorage = get_storage(config);
|
||||
|
||||
if (pStorage)
|
||||
{
|
||||
@ -163,7 +158,7 @@ int TesterLRUStorage::test_max_count(size_t n_threads, size_t n_seconds,
|
||||
CacheStorageConfig config(CACHE_THREAD_MODEL_MT);
|
||||
config.max_count = max_count;
|
||||
|
||||
pStorage = m_factory.createStorage("unspecified", config);
|
||||
pStorage = get_storage(config);
|
||||
|
||||
if (pStorage)
|
||||
{
|
||||
@ -200,7 +195,7 @@ int TesterLRUStorage::test_max_size(size_t n_threads, size_t n_seconds,
|
||||
CacheStorageConfig config(CACHE_THREAD_MODEL_MT);
|
||||
config.max_size = max_size;
|
||||
|
||||
pStorage = m_factory.createStorage("unspecified", config);
|
||||
pStorage = get_storage(config);
|
||||
|
||||
if (pStorage)
|
||||
{
|
||||
@ -240,7 +235,7 @@ int TesterLRUStorage::test_max_count_and_size(size_t n_threads, size_t n_seconds
|
||||
config.max_count = max_count;
|
||||
config.max_size = max_size;
|
||||
|
||||
pStorage = m_factory.createStorage("unspecified", config);
|
||||
pStorage = get_storage(config);
|
||||
|
||||
if (pStorage)
|
||||
{
|
||||
|
@ -33,6 +33,11 @@ public:
|
||||
*/
|
||||
int execute(size_t n_threads, size_t n_seconds, const CacheItems& cache_items);
|
||||
|
||||
/**
|
||||
* @see TesterStorage::get_storage
|
||||
*/
|
||||
Storage* get_storage(const CACHE_STORAGE_CONFIG& config) const;
|
||||
|
||||
private:
|
||||
int test_lru(const CacheItems& cache_items, uint64_t size);
|
||||
int test_max_count(size_t n_threads, size_t n_seconds,
|
||||
|
@ -23,17 +23,24 @@ TesterRawStorage::TesterRawStorage(std::ostream* pOut, StorageFactory* pFactory)
|
||||
|
||||
int TesterRawStorage::execute(size_t n_threads, size_t n_seconds, const CacheItems& cache_items)
|
||||
{
|
||||
int rv = EXIT_FAILURE;
|
||||
int rv1 = test_smoke(cache_items);
|
||||
|
||||
int rv2 = EXIT_FAILURE;
|
||||
CacheStorageConfig config(CACHE_THREAD_MODEL_MT);
|
||||
|
||||
Storage* pStorage = m_factory.createRawStorage("unspecified", config);
|
||||
Storage* pStorage = get_storage(config);
|
||||
|
||||
if (pStorage)
|
||||
{
|
||||
rv = execute_tasks(n_threads, n_seconds, cache_items, *pStorage);
|
||||
rv2 = execute_tasks(n_threads, n_seconds, cache_items, *pStorage);
|
||||
delete pStorage;
|
||||
}
|
||||
|
||||
return rv;
|
||||
return combine_rvs(rv1, rv2);
|
||||
}
|
||||
|
||||
Storage* TesterRawStorage::get_storage(const CACHE_STORAGE_CONFIG& config) const
|
||||
{
|
||||
return m_factory.createRawStorage("unspecified", config);
|
||||
}
|
||||
|
||||
|
@ -32,6 +32,11 @@ public:
|
||||
*/
|
||||
int execute(size_t n_threads, size_t n_seconds, const CacheItems& cache_items);
|
||||
|
||||
/**
|
||||
* @see TesterStorage::get_storage
|
||||
*/
|
||||
Storage* get_storage(const CACHE_STORAGE_CONFIG& config) const;
|
||||
|
||||
private:
|
||||
TesterRawStorage(const TesterRawStorage&);
|
||||
TesterRawStorage& operator = (const TesterRawStorage&);
|
||||
|
127
server/modules/filter/cache/test/testerstorage.cc
vendored
127
server/modules/filter/cache/test/testerstorage.cc
vendored
@ -260,3 +260,130 @@ TesterStorage::storage_action_t TesterStorage::get_random_action()
|
||||
|
||||
return action;
|
||||
}
|
||||
|
||||
// static
|
||||
int TesterStorage::test_smoke(const CacheItems& cache_items)
|
||||
{
|
||||
return test_ttl(cache_items);
|
||||
}
|
||||
|
||||
int TesterStorage::test_ttl(const CacheItems& cache_items)
|
||||
{
|
||||
CacheStorageConfig config;
|
||||
|
||||
out() << "ST" << endl;
|
||||
|
||||
config.thread_model = CACHE_THREAD_MODEL_ST;
|
||||
config.ttl = 5;
|
||||
|
||||
Storage* pStorage;
|
||||
|
||||
int rv1 = EXIT_FAILURE;
|
||||
pStorage = get_storage(config);
|
||||
|
||||
if (pStorage)
|
||||
{
|
||||
rv1 = test_ttl(cache_items, *pStorage);
|
||||
delete pStorage;
|
||||
}
|
||||
|
||||
out() << "MT" << endl;
|
||||
|
||||
config.thread_model = CACHE_THREAD_MODEL_MT;
|
||||
config.ttl = 5;
|
||||
|
||||
int rv2 = EXIT_FAILURE;
|
||||
pStorage = get_storage(config);
|
||||
|
||||
if (pStorage)
|
||||
{
|
||||
rv2 = test_ttl(cache_items, *pStorage);
|
||||
delete pStorage;
|
||||
}
|
||||
|
||||
return combine_rvs(rv1, rv2);
|
||||
}
|
||||
|
||||
int TesterStorage::test_ttl(const CacheItems& cache_items, Storage& storage)
|
||||
{
|
||||
int rv = EXIT_SUCCESS;
|
||||
|
||||
out() << "Testing ttl." << endl;
|
||||
|
||||
CacheStorageConfig config;
|
||||
storage.get_config(&config);
|
||||
|
||||
uint32_t ttl = config.ttl;
|
||||
|
||||
if (ttl != 0)
|
||||
{
|
||||
ss_dassert(cache_items.size() > 0);
|
||||
|
||||
const CacheItems::value_type& cache_item = cache_items[0];
|
||||
|
||||
cache_result_t result = storage.put_value(cache_item.first, cache_item.second);
|
||||
|
||||
if (result != CACHE_RESULT_OK)
|
||||
{
|
||||
out() << "Could not put item." << endl;
|
||||
rv = EXIT_FAILURE;
|
||||
}
|
||||
else
|
||||
{
|
||||
sleep(ttl - 1);
|
||||
|
||||
GWBUF* pValue;
|
||||
|
||||
pValue = NULL;
|
||||
result = storage.get_value(cache_item.first, 0, &pValue);
|
||||
|
||||
if (result != CACHE_RESULT_OK)
|
||||
{
|
||||
out() << "Did not get value withing ttl." << endl;
|
||||
rv = EXIT_FAILURE;
|
||||
}
|
||||
|
||||
gwbuf_free(pValue);
|
||||
|
||||
sleep(2); // Should get us past the ttl
|
||||
|
||||
pValue = NULL;
|
||||
result = storage.get_value(cache_item.first, CACHE_FLAGS_INCLUDE_STALE, &pValue);
|
||||
|
||||
if (result == CACHE_RESULT_OK)
|
||||
{
|
||||
out() << "Got value normally when accepting stale, although ttl has passed." << endl;
|
||||
rv = EXIT_FAILURE;
|
||||
}
|
||||
else if (result != CACHE_RESULT_STALE)
|
||||
{
|
||||
out() << "Did not get expected stale value after ttl." << endl;
|
||||
rv = EXIT_FAILURE;
|
||||
}
|
||||
|
||||
gwbuf_free(pValue);
|
||||
|
||||
pValue = NULL;
|
||||
result = storage.get_value(cache_item.first, 0, &pValue);
|
||||
|
||||
if (result == CACHE_RESULT_OK)
|
||||
{
|
||||
out() << "Got value normally, although ttl has passed." << endl;
|
||||
rv = EXIT_FAILURE;
|
||||
}
|
||||
else if (result != CACHE_RESULT_NOT_FOUND)
|
||||
{
|
||||
out() << "Unexpected failure." << endl;
|
||||
rv = EXIT_FAILURE;
|
||||
}
|
||||
|
||||
gwbuf_free(pValue);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
out() << "No ttl, not testing." << endl;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
@ -148,6 +148,15 @@ public:
|
||||
const CacheItems& cache_items,
|
||||
Storage& storage);
|
||||
|
||||
/**
|
||||
* Return a storage.
|
||||
*
|
||||
* @param config The storage configuration
|
||||
*
|
||||
* @return A storage or NULL in case of error.
|
||||
*/
|
||||
virtual Storage* get_storage(const CACHE_STORAGE_CONFIG& config) const = 0;
|
||||
|
||||
/**
|
||||
* Get a random action.
|
||||
*
|
||||
@ -155,6 +164,11 @@ public:
|
||||
*/
|
||||
static storage_action_t get_random_action();
|
||||
|
||||
int test_smoke(const CacheItems& cache_items);
|
||||
|
||||
int test_ttl(const CacheItems& cache_items);
|
||||
int test_ttl(const CacheItems& cache_items, Storage& storage);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Constructor
|
||||
|
Reference in New Issue
Block a user