Cache: Refactor Tester hierarchy
Now that the cache key can be generated using the StorageFactory there is no need for calling back into the derived class from Tester to get hold of one. Instead the preparatory work is performed by the abstract base classes, then the control is moved back to the derived concrete class that decides what to actually do.
This commit is contained in:
2
server/modules/filter/cache/test/tester.cc
vendored
2
server/modules/filter/cache/test/tester.cc
vendored
@ -243,7 +243,7 @@ void Tester::clear_cache_items(CacheItems& cache_items)
|
||||
}
|
||||
|
||||
// static
|
||||
int Tester::run(ostream& out, size_t n_seconds, const vector<Task*>& tasks)
|
||||
int Tester::execute(ostream& out, size_t n_seconds, const vector<Task*>& tasks)
|
||||
{
|
||||
vector<Thread> threads;
|
||||
|
||||
|
5
server/modules/filter/cache/test/tester.hh
vendored
5
server/modules/filter/cache/test/tester.hh
vendored
@ -1,3 +1,4 @@
|
||||
#pragma once
|
||||
/*
|
||||
* Copyright (c) 2016 MariaDB Corporation Ab
|
||||
*
|
||||
@ -206,7 +207,7 @@ protected:
|
||||
std::ostream& out() const { return m_out; }
|
||||
|
||||
/**
|
||||
* Run a specific number of tasks in as many threads.
|
||||
* Execute a specific number of tasks in as many threads.
|
||||
*
|
||||
* @param out The stream to be used for (user) output.
|
||||
* @param n_seconds How many seconds the tasks should run.
|
||||
@ -214,7 +215,7 @@ protected:
|
||||
*
|
||||
* @return EXIT_SUCCESS if each task returned EXIT_SUCCESS, otherwise EXIT_FAILURE.
|
||||
*/
|
||||
static int run(std::ostream& out, size_t n_seconds, const Tasks& tasks);
|
||||
static int execute(std::ostream& out, size_t n_seconds, const Tasks& tasks);
|
||||
|
||||
private:
|
||||
std::ostream& m_out;
|
||||
|
@ -12,6 +12,7 @@
|
||||
*/
|
||||
|
||||
#include <maxscale/cppdefs.hh>
|
||||
#include "storage.hh"
|
||||
#include "storagefactory.hh"
|
||||
#include "testerrawstorage.hh"
|
||||
|
||||
@ -21,14 +22,24 @@ TesterRawStorage::TesterRawStorage(std::ostream* pOut, StorageFactory* pFactory)
|
||||
{
|
||||
}
|
||||
|
||||
Storage* TesterRawStorage::get_storage()
|
||||
int TesterRawStorage::execute(size_t n_threads, size_t n_seconds, const CacheItems& cache_items)
|
||||
{
|
||||
return m_factory.createRawStorage(CACHE_THREAD_MODEL_MT,
|
||||
int rv = EXIT_FAILURE;
|
||||
|
||||
Storage* pStorage = m_factory.createRawStorage(CACHE_THREAD_MODEL_MT,
|
||||
"unspecified",
|
||||
0, // No TTL
|
||||
0, // No max count
|
||||
0, // No max size
|
||||
0, NULL);
|
||||
|
||||
if (pStorage)
|
||||
{
|
||||
rv = execute_tasks(n_threads, n_seconds, cache_items, *pStorage);
|
||||
delete pStorage;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
size_t TesterRawStorage::get_n_items(size_t n_threads, size_t n_seconds)
|
||||
|
@ -1,3 +1,4 @@
|
||||
#pragma once
|
||||
/*
|
||||
* Copyright (c) 2016 MariaDB Corporation Ab
|
||||
*
|
||||
@ -26,14 +27,12 @@ public:
|
||||
*/
|
||||
TesterRawStorage(std::ostream* pOut, StorageFactory* pFactory);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Returns a raw storage.
|
||||
*
|
||||
* @return A storage instance or NULL.
|
||||
* @see TesterStorage::run
|
||||
*/
|
||||
Storage* get_storage();
|
||||
int execute(size_t n_threads, size_t n_seconds, const CacheItems& cache_items);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @see TesterStorage::get_n_items
|
||||
*/
|
||||
|
@ -153,31 +153,26 @@ int TesterStorage::run(size_t n_threads, size_t n_seconds, std::istream& in)
|
||||
|
||||
if (get_cache_items(in, n_items, m_factory, &cache_items))
|
||||
{
|
||||
rv = run(n_threads, n_seconds, cache_items);
|
||||
rv = execute(n_threads, n_seconds, cache_items);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
int TesterStorage::run(size_t n_threads,
|
||||
int TesterStorage::execute_tasks(size_t n_threads,
|
||||
size_t n_seconds,
|
||||
const CacheItems& cache_items)
|
||||
const CacheItems& cache_items,
|
||||
Storage& storage)
|
||||
{
|
||||
int rv = EXIT_FAILURE;
|
||||
|
||||
Storage* pStorage = get_storage();
|
||||
|
||||
if (pStorage)
|
||||
{
|
||||
rv = run_hit_task(n_threads, n_seconds, cache_items, *pStorage);
|
||||
|
||||
delete pStorage;
|
||||
}
|
||||
// Just one, for now.
|
||||
rv = execute_hit_task(n_threads, n_seconds, cache_items, storage);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
int TesterStorage::run_hit_task(size_t n_threads,
|
||||
int TesterStorage::execute_hit_task(size_t n_threads,
|
||||
size_t n_seconds,
|
||||
const CacheItems& cache_items,
|
||||
Storage& storage)
|
||||
@ -191,7 +186,7 @@ int TesterStorage::run_hit_task(size_t n_threads,
|
||||
tasks.push_back(new HitTask(&out(), &storage, &cache_items));
|
||||
}
|
||||
|
||||
rv = Tester::run(out(), n_seconds, tasks);
|
||||
rv = Tester::execute(out(), n_seconds, tasks);
|
||||
|
||||
for_each(tasks.begin(), tasks.end(), Task::free);
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
#pragma once
|
||||
/*
|
||||
* Copyright (c) 2016 MariaDB Corporation Ab
|
||||
*
|
||||
@ -72,6 +73,8 @@ public:
|
||||
* runs all storage tasks using as many threads as specified for the specified
|
||||
* number of seconds.
|
||||
*
|
||||
* Will call back into the virtual @c execute function below.
|
||||
*
|
||||
* @param n_threads How many threads to use.
|
||||
* @param n_seconds For how many seconds to run the test.
|
||||
* @param in Stream, assumed to refer to a file containing statements.
|
||||
@ -81,8 +84,7 @@ public:
|
||||
virtual int run(size_t n_threads, size_t n_seconds, std::istream& in);
|
||||
|
||||
/**
|
||||
* Runs all storage tasks using as many threads as specified, for the specified
|
||||
* number of seconds.
|
||||
* Execute tests; implemented by derived class.
|
||||
*
|
||||
* @param n_threads How many threads to use.
|
||||
* @param n_seconds For how many seconds to run the test.
|
||||
@ -90,10 +92,10 @@ public:
|
||||
*
|
||||
* @return EXIT_SUCCESS or EXIT_FAILURE.
|
||||
*/
|
||||
virtual int run(size_t n_threads, size_t n_seconds, const CacheItems& cache_items);
|
||||
virtual int execute(size_t n_threads, size_t n_seconds, const CacheItems& cache_items) = 0;
|
||||
|
||||
/**
|
||||
* Runs the HitTask using as many threads as specified, for the specified
|
||||
* Executes all tasks, using as many threads as specified, for the specified
|
||||
* number of seconds.
|
||||
*
|
||||
* @param n_threads How many threads to use.
|
||||
@ -103,7 +105,22 @@ public:
|
||||
*
|
||||
* @return EXIT_SUCCESS or EXIT_FAILURE.
|
||||
*/
|
||||
virtual int run_hit_task(size_t n_threads,
|
||||
virtual int execute_tasks(size_t n_threads,
|
||||
size_t n_seconds,
|
||||
const CacheItems& cache_items,
|
||||
Storage& storage);
|
||||
/**
|
||||
* Executes the HitTask using as many threads as specified, for the specified
|
||||
* number of seconds.
|
||||
*
|
||||
* @param n_threads How many threads to use.
|
||||
* @param n_seconds For how many seconds to run the test.
|
||||
* @param cache_items The cache items to use.
|
||||
* @param storage The storage to use.
|
||||
*
|
||||
* @return EXIT_SUCCESS or EXIT_FAILURE.
|
||||
*/
|
||||
virtual int execute_hit_task(size_t n_threads,
|
||||
size_t n_seconds,
|
||||
const CacheItems& cache_items,
|
||||
Storage& storage);
|
||||
@ -124,13 +141,6 @@ protected:
|
||||
*/
|
||||
TesterStorage(std::ostream* pOut, StorageFactory* pFactory);
|
||||
|
||||
/**
|
||||
* Return a storage instance. The ownership is transferred to the caller.
|
||||
*
|
||||
* @return A storage instance or NULL.
|
||||
*/
|
||||
virtual Storage* get_storage() = 0;
|
||||
|
||||
/**
|
||||
* Return the desired number of cache items to be used in the tests.
|
||||
*
|
||||
|
Reference in New Issue
Block a user