2019-12-23 19:07:53 -05:00
|
|
|
#include "teststorageprovider.h"
|
2019-12-23 23:32:04 -05:00
|
|
|
#include "../server.h"
|
2019-12-23 19:07:53 -05:00
|
|
|
|
2020-07-11 21:23:48 +00:00
|
|
|
IStorage *TestStorageFactory::create(int, key_load_iterator, void *)
|
2019-12-23 19:07:53 -05:00
|
|
|
{
|
2019-12-23 23:32:04 -05:00
|
|
|
return new (MALLOC_LOCAL) TestStorageProvider();
|
2019-12-23 19:07:53 -05:00
|
|
|
}
|
|
|
|
|
2021-11-01 03:17:13 +00:00
|
|
|
IStorage *TestStorageFactory::createMetadataDb()
|
|
|
|
{
|
2021-11-02 15:37:29 +00:00
|
|
|
IStorage *metadataDb = new (MALLOC_LOCAL) TestStorageProvider();
|
|
|
|
metadataDb->insert("KEYDB_METADATA_ID", strlen("KEYDB_METADATA_ID"), (void*)METADATA_DB_IDENTIFIER, strlen(METADATA_DB_IDENTIFIER), false);
|
|
|
|
return metadataDb;
|
2021-11-01 03:17:13 +00:00
|
|
|
}
|
|
|
|
|
2019-12-23 19:07:53 -05:00
|
|
|
const char *TestStorageFactory::name() const
|
|
|
|
{
|
|
|
|
return "TEST Storage Provider";
|
|
|
|
}
|
|
|
|
|
|
|
|
TestStorageProvider::TestStorageProvider()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
TestStorageProvider::~TestStorageProvider()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-12-23 23:32:04 -05:00
|
|
|
void TestStorageProvider::insert(const char *key, size_t cchKey, void *data, size_t cb, bool fOverwrite)
|
2019-12-23 19:07:53 -05:00
|
|
|
{
|
2019-12-23 23:32:04 -05:00
|
|
|
auto strkey = std::string(key, cchKey);
|
|
|
|
bool fActuallyExists = m_map.find(strkey) != m_map.end();
|
|
|
|
serverAssert(fActuallyExists == fOverwrite);
|
|
|
|
m_map.insert(std::make_pair(strkey, std::string((char*)data, cb)));
|
2019-12-23 19:07:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool TestStorageProvider::erase(const char *key, size_t cchKey)
|
|
|
|
{
|
|
|
|
auto itr = m_map.find(std::string(key, cchKey));
|
|
|
|
if (itr != m_map.end())
|
|
|
|
{
|
|
|
|
m_map.erase(itr);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestStorageProvider::retrieve(const char *key, size_t cchKey, callbackSingle fn) const
|
|
|
|
{
|
|
|
|
auto itr = m_map.find(std::string(key, cchKey));
|
|
|
|
if (itr != m_map.end())
|
|
|
|
fn(key, cchKey, itr->second.data(), itr->second.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t TestStorageProvider::clear()
|
|
|
|
{
|
|
|
|
size_t size = m_map.size();
|
|
|
|
m_map.clear();
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TestStorageProvider::enumerate(callback fn) const
|
|
|
|
{
|
|
|
|
bool fAll = true;
|
|
|
|
for (auto &pair : m_map)
|
|
|
|
{
|
|
|
|
if (!fn(pair.first.data(), pair.first.size(), pair.second.data(), pair.second.size()))
|
|
|
|
{
|
|
|
|
fAll = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return fAll;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t TestStorageProvider::count() const
|
|
|
|
{
|
|
|
|
return m_map.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestStorageProvider::flush()
|
|
|
|
{
|
|
|
|
/* NOP */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This is permitted to be a shallow clone */
|
|
|
|
const IStorage *TestStorageProvider::clone() const
|
|
|
|
{
|
2019-12-23 23:32:04 -05:00
|
|
|
return new (MALLOC_LOCAL) TestStorageProvider(*this);
|
2019-12-23 19:07:53 -05:00
|
|
|
}
|