From 883b82a26a9a00e50919c112a96197ee2110cd32 Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Thu, 15 Dec 2016 19:03:46 +0200 Subject: [PATCH] Cache: Use StorageFactory for creating the cache key Now the preparatory work is done using the storage factory and the storage instance is created only when the actual testing is performed. --- server/modules/filter/cache/test/tester.cc | 12 ++++--- server/modules/filter/cache/test/tester.hh | 10 +++--- .../filter/cache/test/testerstorage.cc | 33 ++++++++++--------- .../filter/cache/test/testerstorage.hh | 12 +++---- 4 files changed, 35 insertions(+), 32 deletions(-) diff --git a/server/modules/filter/cache/test/tester.cc b/server/modules/filter/cache/test/tester.cc index cc93f2407..0da53fc50 100644 --- a/server/modules/filter/cache/test/tester.cc +++ b/server/modules/filter/cache/test/tester.cc @@ -15,7 +15,7 @@ #include #include #include -#include "storage.hh" +#include "storagefactory.hh" // TODO: Move this to a common place. #include "../../../../../query_classifier/test/testreader.hh" @@ -175,7 +175,9 @@ bool Tester::get_statements(std::istream& in, size_t n_statements, Statements* p } // static -bool Tester::get_cache_items(const Statements& statements, const Storage& storage, CacheItems* pItems) +bool Tester::get_cache_items(const Statements& statements, + const StorageFactory& factory, + CacheItems* pItems) { bool success = true; @@ -187,7 +189,7 @@ bool Tester::get_cache_items(const Statements& statements, const Storage& storag if (pQuery) { CACHE_KEY key; - cache_result_t result = storage.get_key(NULL, pQuery, &key); + cache_result_t result = factory.get_key(NULL, pQuery, &key); if (result == CACHE_RESULT_OK) { @@ -214,7 +216,7 @@ bool Tester::get_cache_items(const Statements& statements, const Storage& storag //static bool Tester::get_cache_items(std::istream& in, size_t n_items, - const Storage& storage, + const StorageFactory& factory, CacheItems* pItems) { Statements statements; @@ -223,7 +225,7 @@ bool Tester::get_cache_items(std::istream& in, if (rv) { - rv = get_cache_items(statements, storage, pItems); + rv = get_cache_items(statements, factory, pItems); } return rv; diff --git a/server/modules/filter/cache/test/tester.hh b/server/modules/filter/cache/test/tester.hh index 6cc34ba65..e50089c9d 100644 --- a/server/modules/filter/cache/test/tester.hh +++ b/server/modules/filter/cache/test/tester.hh @@ -19,7 +19,7 @@ #include #include "cache_storage_api.hh" -class Storage; +class StorageFactory; class Tester { @@ -157,13 +157,13 @@ public: * Converts a set of statements into cache items (i.e. key + statement). * * @param statements A number of statements. - * @param storage The storage using which the cache keys should be generated. + * @param factory The storage factory using which the cache keys should be generated. * @param pItems Pointer to vector where the items will be back inserted. * * @return Whether the conversion was successful. */ static bool get_cache_items(const Statements& statements, - const Storage& storage, + const StorageFactory& factory, CacheItems* pItems); /** @@ -171,7 +171,7 @@ public: * * @param statements A number of statements. * @param n_items How many items should be returned. - * @param storage The storage using which the cache keys should be generated. + * @param factory The storage factory using which the cache keys should be generated. * @param pItems Pointer to vector where the items will be back inserted. * * @return Whether reading and conversion was successful, not whether @n_items @@ -179,7 +179,7 @@ public: */ static bool get_cache_items(std::istream& in, size_t n_items, - const Storage& storage, + const StorageFactory& factory, CacheItems* pItems); /** diff --git a/server/modules/filter/cache/test/testerstorage.cc b/server/modules/filter/cache/test/testerstorage.cc index 737c42682..2b6399898 100644 --- a/server/modules/filter/cache/test/testerstorage.cc +++ b/server/modules/filter/cache/test/testerstorage.cc @@ -147,20 +147,13 @@ int TesterStorage::run(size_t n_threads, size_t n_seconds, std::istream& in) { int rv = EXIT_FAILURE; - Storage* pStorage = get_storage(); + size_t n_items = get_n_items(n_threads, n_seconds); - if (pStorage) + CacheItems cache_items; + + if (get_cache_items(in, n_items, m_factory, &cache_items)) { - size_t n_items = get_n_items(n_threads, n_seconds); - - CacheItems cache_items; - - if (get_cache_items(in, n_items, *pStorage, &cache_items)) - { - rv = run(n_threads, n_seconds, cache_items, *pStorage); - } - - delete pStorage; + rv = run(n_threads, n_seconds, cache_items); } return rv; @@ -168,10 +161,20 @@ int TesterStorage::run(size_t n_threads, size_t n_seconds, std::istream& in) int TesterStorage::run(size_t n_threads, size_t n_seconds, - const CacheItems& cache_items, - Storage& storage) + const CacheItems& cache_items) { - return run_hit_task(n_threads, n_seconds, cache_items, storage); + int rv = EXIT_FAILURE; + + Storage* pStorage = get_storage(); + + if (pStorage) + { + rv = run_hit_task(n_threads, n_seconds, cache_items, *pStorage); + + delete pStorage; + } + + return rv; } int TesterStorage::run_hit_task(size_t n_threads, diff --git a/server/modules/filter/cache/test/testerstorage.hh b/server/modules/filter/cache/test/testerstorage.hh index 617b4e335..70e1f5885 100644 --- a/server/modules/filter/cache/test/testerstorage.hh +++ b/server/modules/filter/cache/test/testerstorage.hh @@ -14,6 +14,7 @@ #include #include "tester.hh" +class Storage; class StorageFactory; class TesterStorage : public Tester @@ -85,13 +86,11 @@ public: * * @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. Assumed to have been created using - * @c storage. - * @param storage The storage items to use. + * @param cache_items The cache items to use. * * @return EXIT_SUCCESS or EXIT_FAILURE. */ - virtual int run(size_t n_threads, size_t n_seconds, const CacheItems& cache_items, Storage& storage); + virtual int run(size_t n_threads, size_t n_seconds, const CacheItems& cache_items); /** * Runs the HitTask using as many threads as specified, for the specified @@ -99,9 +98,8 @@ public: * * @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. Assumed to have been created using - * @c storage. - * @param storage The storage items to use. + * @param cache_items The cache items to use. + * @param storage The storage to use. * * @return EXIT_SUCCESS or EXIT_FAILURE. */