diff --git a/server/modules/filter/cache/test/tester.cc b/server/modules/filter/cache/test/tester.cc index 0da53fc50..b1c3f3b53 100644 --- a/server/modules/filter/cache/test/tester.cc +++ b/server/modules/filter/cache/test/tester.cc @@ -243,7 +243,7 @@ void Tester::clear_cache_items(CacheItems& cache_items) } // static -int Tester::run(ostream& out, size_t n_seconds, const vector& tasks) +int Tester::execute(ostream& out, size_t n_seconds, const vector& tasks) { vector threads; diff --git a/server/modules/filter/cache/test/tester.hh b/server/modules/filter/cache/test/tester.hh index e50089c9d..a51cb6ce7 100644 --- a/server/modules/filter/cache/test/tester.hh +++ b/server/modules/filter/cache/test/tester.hh @@ -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; diff --git a/server/modules/filter/cache/test/testerrawstorage.cc b/server/modules/filter/cache/test/testerrawstorage.cc index b72dca04d..df591874d 100644 --- a/server/modules/filter/cache/test/testerrawstorage.cc +++ b/server/modules/filter/cache/test/testerrawstorage.cc @@ -12,6 +12,7 @@ */ #include +#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, - "unspecified", - 0, // No TTL - 0, // No max count - 0, // No max size - 0, NULL); + 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) diff --git a/server/modules/filter/cache/test/testerrawstorage.hh b/server/modules/filter/cache/test/testerrawstorage.hh index 1ea6e87bf..ba10e459e 100644 --- a/server/modules/filter/cache/test/testerrawstorage.hh +++ b/server/modules/filter/cache/test/testerrawstorage.hh @@ -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 */ diff --git a/server/modules/filter/cache/test/testerstorage.cc b/server/modules/filter/cache/test/testerstorage.cc index 2b6399898..764bade17 100644 --- a/server/modules/filter/cache/test/testerstorage.cc +++ b/server/modules/filter/cache/test/testerstorage.cc @@ -153,34 +153,29 @@ 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, - size_t n_seconds, - const CacheItems& cache_items) +int TesterStorage::execute_tasks(size_t n_threads, + size_t n_seconds, + 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, - size_t n_seconds, - const CacheItems& cache_items, - Storage& storage) +int TesterStorage::execute_hit_task(size_t n_threads, + size_t n_seconds, + const CacheItems& cache_items, + Storage& storage) { int rv = EXIT_FAILURE; @@ -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); diff --git a/server/modules/filter/cache/test/testerstorage.hh b/server/modules/filter/cache/test/testerstorage.hh index 70e1f5885..3c9c278ed 100644 --- a/server/modules/filter/cache/test/testerstorage.hh +++ b/server/modules/filter/cache/test/testerstorage.hh @@ -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,10 +105,25 @@ public: * * @return EXIT_SUCCESS or EXIT_FAILURE. */ - virtual int run_hit_task(size_t n_threads, - size_t n_seconds, - const CacheItems& cache_items, - Storage& storage); + 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); /** * Get a random action. @@ -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. *