Cache: Add LRU storage test
Just initial tests; to be expanded.
This commit is contained in:
@ -3,6 +3,7 @@ include_directories(..)
|
||||
add_library(cachetester
|
||||
tester.cc
|
||||
testerstorage.cc
|
||||
testerlrustorage.cc
|
||||
testerrawstorage.cc
|
||||
../../../../../query_classifier/test/testreader.cc
|
||||
)
|
||||
@ -19,6 +20,9 @@ target_link_libraries(testkeygeneration maxscale-common cache)
|
||||
add_executable(testrawstorage testrawstorage.cc)
|
||||
target_link_libraries(testrawstorage cachetester cache maxscale-common)
|
||||
|
||||
add_executable(testlrustorage testlrustorage.cc)
|
||||
target_link_libraries(testlrustorage cachetester cache maxscale-common)
|
||||
|
||||
add_test(TestCache_rules testrules)
|
||||
|
||||
add_test(TestCache_keygeneration testkeygeneration storage_inmemory ${CMAKE_CURRENT_SOURCE_DIR}/input.test)
|
||||
@ -26,3 +30,6 @@ add_test(TestCache_keygeneration testkeygeneration storage_rocksdb ${CMAKE_CURRE
|
||||
|
||||
add_test(TestCache_storage_inmemory testrawstorage 10 storage_inmemory ${CMAKE_CURRENT_SOURCE_DIR}/input.test)
|
||||
add_test(TestCache_storage_rocksdb testrawstorage 10 storage_rocksdb ${CMAKE_CURRENT_SOURCE_DIR}/input.test)
|
||||
|
||||
add_test(TestCache_lru_inmemory testlrustorage 10 storage_inmemory ${CMAKE_CURRENT_SOURCE_DIR}/input.test)
|
||||
add_test(TestCache_lru_rocksdb testlrustorage 10 storage_rocksdb ${CMAKE_CURRENT_SOURCE_DIR}/input.test)
|
||||
|
59
server/modules/filter/cache/test/testerlrustorage.cc
vendored
Normal file
59
server/modules/filter/cache/test/testerlrustorage.cc
vendored
Normal file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (c) 2016 MariaDB Corporation Ab
|
||||
*
|
||||
* Use of this software is governed by the Business Source License included
|
||||
* in the LICENSE.TXT file and at www.mariadb.com/bsl.
|
||||
*
|
||||
* Change Date: 2019-07-01
|
||||
*
|
||||
* On the date above, in accordance with the Business Source License, use
|
||||
* of this software will be governed by version 2 or later of the General
|
||||
* Public License.
|
||||
*/
|
||||
|
||||
#include "testerlrustorage.hh"
|
||||
#include "storage.hh"
|
||||
#include "storagefactory.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
TesterLRUStorage::TesterLRUStorage(std::ostream* pOut, StorageFactory* pFactory)
|
||||
: TesterStorage(pOut, pFactory)
|
||||
{
|
||||
}
|
||||
|
||||
int TesterLRUStorage::execute(size_t n_threads, size_t n_seconds, const CacheItems& cache_items)
|
||||
{
|
||||
int rv = EXIT_FAILURE;
|
||||
|
||||
Storage* pStorage;
|
||||
|
||||
size_t max_count = cache_items.size() / 4;
|
||||
|
||||
pStorage = m_factory.createStorage(CACHE_THREAD_MODEL_MT,
|
||||
"unspecified",
|
||||
0, // No TTL
|
||||
max_count,
|
||||
0, // No max size
|
||||
0, NULL);
|
||||
|
||||
if (pStorage)
|
||||
{
|
||||
rv = execute_tasks(n_threads, n_seconds, cache_items, *pStorage);
|
||||
|
||||
uint64_t items;
|
||||
cache_result_t 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;
|
||||
}
|
||||
|
||||
delete pStorage;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
39
server/modules/filter/cache/test/testerlrustorage.hh
vendored
Normal file
39
server/modules/filter/cache/test/testerlrustorage.hh
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
#pragma once
|
||||
/*
|
||||
* Copyright (c) 2016 MariaDB Corporation Ab
|
||||
*
|
||||
* Use of this software is governed by the Business Source License included
|
||||
* in the LICENSE.TXT file and at www.mariadb.com/bsl.
|
||||
*
|
||||
* Change Date: 2019-07-01
|
||||
*
|
||||
* On the date above, in accordance with the Business Source License, use
|
||||
* of this software will be governed by version 2 or later of the General
|
||||
* Public License.
|
||||
*/
|
||||
|
||||
#include <maxscale/cppdefs.hh>
|
||||
#include "testerstorage.hh"
|
||||
|
||||
|
||||
class TesterLRUStorage : public TesterStorage
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param pOut Pointer to the stream to be used for (user) output.
|
||||
* @param pFactory Pointer to factory to be used.
|
||||
*/
|
||||
TesterLRUStorage(std::ostream* pOut, StorageFactory* pFactory);
|
||||
|
||||
/**
|
||||
* @see TesterStorage::run
|
||||
*/
|
||||
int execute(size_t n_threads, size_t n_seconds, const CacheItems& cache_items);
|
||||
|
||||
private:
|
||||
TesterLRUStorage(const TesterLRUStorage&);
|
||||
TesterLRUStorage& operator = (const TesterLRUStorage&);
|
||||
};
|
@ -11,10 +11,9 @@
|
||||
* Public License.
|
||||
*/
|
||||
|
||||
#include <maxscale/cppdefs.hh>
|
||||
#include "testerrawstorage.hh"
|
||||
#include "storage.hh"
|
||||
#include "storagefactory.hh"
|
||||
#include "testerrawstorage.hh"
|
||||
|
||||
|
||||
TesterRawStorage::TesterRawStorage(std::ostream* pOut, StorageFactory* pFactory)
|
||||
@ -41,8 +40,3 @@ int TesterRawStorage::execute(size_t n_threads, size_t n_seconds, const CacheIte
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
size_t TesterRawStorage::get_n_items(size_t n_threads, size_t n_seconds)
|
||||
{
|
||||
return n_threads * n_seconds * 10; // From the sleeve...
|
||||
}
|
||||
|
@ -32,12 +32,6 @@ public:
|
||||
*/
|
||||
int execute(size_t n_threads, size_t n_seconds, const CacheItems& cache_items);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @see TesterStorage::get_n_items
|
||||
*/
|
||||
size_t get_n_items(size_t n_threads, size_t n_seconds);
|
||||
|
||||
private:
|
||||
TesterRawStorage(const TesterRawStorage&);
|
||||
TesterRawStorage& operator = (const TesterRawStorage&);
|
||||
|
@ -215,3 +215,7 @@ TesterStorage::storage_action_t TesterStorage::get_random_action()
|
||||
return action;
|
||||
}
|
||||
|
||||
size_t TesterStorage::get_n_items(size_t n_threads, size_t n_seconds)
|
||||
{
|
||||
return n_threads * n_seconds * 10; // From the sleeve...
|
||||
}
|
||||
|
@ -149,7 +149,7 @@ protected:
|
||||
*
|
||||
* @return The desired number of items to use.
|
||||
*/
|
||||
virtual size_t get_n_items(size_t n_threads, size_t n_seconds) = 0;
|
||||
virtual size_t get_n_items(size_t n_threads, size_t n_seconds);
|
||||
|
||||
protected:
|
||||
StorageFactory& m_factory; /*< The storage factory that is used. */
|
||||
|
112
server/modules/filter/cache/test/testlrustorage.cc
vendored
Normal file
112
server/modules/filter/cache/test/testlrustorage.cc
vendored
Normal file
@ -0,0 +1,112 @@
|
||||
/*
|
||||
* Copyright (c) 2016 MariaDB Corporation Ab
|
||||
*
|
||||
* Use of this software is governed by the Business Source License included
|
||||
* in the LICENSE.TXT file and at www.mariadb.com/bsl.
|
||||
*
|
||||
* Change Date: 2019-07-01
|
||||
*
|
||||
* On the date above, in accordance with the Business Source License, use
|
||||
* of this software will be governed by version 2 or later of the General
|
||||
* Public License.
|
||||
*/
|
||||
|
||||
#include <maxscale/cppdefs.hh>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <maxscale/alloc.h>
|
||||
#include <maxscale/gwdirs.h>
|
||||
#include <maxscale/log_manager.h>
|
||||
#include <maxscale/query_classifier.h>
|
||||
#include "storagefactory.hh"
|
||||
#include "testerlrustorage.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
void print_usage(const char* zProgram)
|
||||
{
|
||||
cout << "usage: " << zProgram << " time storage-module text-file\n"
|
||||
<< "\n"
|
||||
<< "where:\n"
|
||||
<< " time is the number of seconds we should run,\n"
|
||||
<< " storage-module is the name of a storage module,\n"
|
||||
<< " test-file is the name of a text file." << endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
int rv = EXIT_FAILURE;
|
||||
|
||||
if ((argc == 3) || (argc == 4))
|
||||
{
|
||||
if (mxs_log_init(NULL, ".", MXS_LOG_TARGET_DEFAULT))
|
||||
{
|
||||
size_t n_seconds = atoi(argv[1]);
|
||||
|
||||
if (qc_init(NULL, NULL))
|
||||
{
|
||||
const char* zModule = argv[2];
|
||||
|
||||
const char FORMAT[] = "../storage/%s";
|
||||
char libdir[sizeof(FORMAT) + strlen(zModule)];
|
||||
sprintf(libdir, FORMAT, zModule);
|
||||
|
||||
set_libdir(MXS_STRDUP_A(libdir));
|
||||
|
||||
StorageFactory* pFactory = StorageFactory::Open(zModule);
|
||||
|
||||
if (pFactory)
|
||||
{
|
||||
TesterLRUStorage tester(&cout, pFactory);
|
||||
|
||||
size_t n_threads = get_processor_count() + 1;
|
||||
|
||||
if (argc == 3)
|
||||
{
|
||||
rv = tester.run(n_threads, n_seconds, cin);
|
||||
}
|
||||
else
|
||||
{
|
||||
fstream in(argv[3]);
|
||||
|
||||
if (in)
|
||||
{
|
||||
rv = tester.run(n_threads, n_seconds, in);
|
||||
}
|
||||
else
|
||||
{
|
||||
cerr << "error: Could not open " << argv[3] << "." << endl;
|
||||
}
|
||||
}
|
||||
|
||||
delete pFactory;
|
||||
}
|
||||
else
|
||||
{
|
||||
cerr << "error: Could not initialize factory " << zModule << "." << endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cerr << "error: Could not initialize query classifier." << endl;
|
||||
}
|
||||
|
||||
mxs_log_finish();
|
||||
}
|
||||
else
|
||||
{
|
||||
cerr << "error: Could not initialize log." << endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print_usage(argv[0]);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
Reference in New Issue
Block a user