2023-08-13 16:30:17 +00:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
|
|
#include "base.h"
|
|
|
|
#include "storage.h"
|
|
|
|
#include "cache.h"
|
|
|
|
#include "cursor.h"
|
|
|
|
|
|
|
|
class CacheCursorTest : public ::testing::Test {
|
|
|
|
protected:
|
|
|
|
CacheCursorTest():
|
|
|
|
::testing::Test(),
|
|
|
|
cache (db->getCache<uint64_t, std::string>("table1")),
|
|
|
|
emptyCache (db->getCache<uint64_t, std::string>("empty")) {}
|
|
|
|
|
|
|
|
~CacheCursorTest() {}
|
|
|
|
|
|
|
|
static void SetUpTestSuite() {
|
|
|
|
if (db == nullptr) {
|
|
|
|
db = new LMDBAL::Base("testBase");
|
|
|
|
db->addCache<uint64_t, std::string>("table1");
|
|
|
|
db->addCache<uint64_t, std::string>("empty");
|
|
|
|
db->open();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-01 22:45:42 +00:00
|
|
|
int getCacheCursorsSize() const {
|
|
|
|
return cache->cursors.size();
|
|
|
|
}
|
|
|
|
|
2023-08-13 16:30:17 +00:00
|
|
|
static void TearDownTestSuite() {
|
2023-11-01 22:45:42 +00:00
|
|
|
cursor.drop();
|
2023-10-17 21:06:11 +00:00
|
|
|
transaction.terminate();
|
2023-08-13 16:30:17 +00:00
|
|
|
db->close();
|
|
|
|
db->removeDirectory();
|
|
|
|
delete db;
|
|
|
|
db = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LMDBAL::Base* db;
|
2023-10-25 22:18:23 +00:00
|
|
|
static LMDBAL::Cursor<uint64_t, std::string> cursor;
|
2023-10-17 21:06:11 +00:00
|
|
|
static LMDBAL::Transaction transaction;
|
2023-08-13 16:30:17 +00:00
|
|
|
|
|
|
|
LMDBAL::Cache<uint64_t, std::string>* cache;
|
|
|
|
LMDBAL::Cache<uint64_t, std::string>* emptyCache;
|
|
|
|
};
|
|
|
|
|
|
|
|
LMDBAL::Base* CacheCursorTest::db = nullptr;
|
2023-10-25 22:18:23 +00:00
|
|
|
LMDBAL::Cursor<uint64_t, std::string> CacheCursorTest::cursor;
|
2023-10-17 21:06:11 +00:00
|
|
|
LMDBAL::Transaction CacheCursorTest::transaction;
|
2023-08-13 16:30:17 +00:00
|
|
|
|
|
|
|
static const std::map<uint64_t, std::string> data({
|
|
|
|
{245665783, "bothering nerds"},
|
|
|
|
{3458, "resilent pick forefront"},
|
|
|
|
{105190, "apportunity legal bat"},
|
|
|
|
{6510, "outside"},
|
|
|
|
{7438537, "damocles plush apparently rusty"},
|
|
|
|
{19373572, "local guidence"},
|
|
|
|
{138842, "forgetting tusks prepare"},
|
|
|
|
{981874, "butchered soaking pawn"},
|
|
|
|
{19302, "tanned inmate"},
|
|
|
|
{178239, "custody speaks neurotic"},
|
|
|
|
});
|
|
|
|
|
|
|
|
TEST_F(CacheCursorTest, PopulatingTheTable) {
|
|
|
|
uint32_t amount = cache->addRecords(data);
|
|
|
|
EXPECT_EQ(amount, data.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(CacheCursorTest, Creation) {
|
2023-11-01 22:45:42 +00:00
|
|
|
EXPECT_EQ(getCacheCursorsSize(), 0);
|
2023-08-13 16:30:17 +00:00
|
|
|
cursor = cache->createCursor();
|
2023-11-01 22:45:42 +00:00
|
|
|
EXPECT_EQ(getCacheCursorsSize(), 1);
|
2023-08-13 16:30:17 +00:00
|
|
|
|
2023-10-25 22:18:23 +00:00
|
|
|
EXPECT_THROW(cursor.first(), LMDBAL::CursorNotReady);
|
|
|
|
EXPECT_THROW(cursor.last(), LMDBAL::CursorNotReady);
|
|
|
|
EXPECT_THROW(cursor.next(), LMDBAL::CursorNotReady);
|
|
|
|
EXPECT_THROW(cursor.prev(), LMDBAL::CursorNotReady);
|
|
|
|
EXPECT_THROW(cursor.current(), LMDBAL::CursorNotReady);
|
2023-08-13 16:30:17 +00:00
|
|
|
|
2023-10-25 22:18:23 +00:00
|
|
|
cursor.open();
|
2023-08-13 16:30:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(CacheCursorTest, FirstPrivate) {
|
2023-11-01 22:45:42 +00:00
|
|
|
EXPECT_EQ(getCacheCursorsSize(), 1);
|
2023-08-13 16:30:17 +00:00
|
|
|
EXPECT_EQ(cache->count(), data.size());
|
|
|
|
|
2023-10-25 22:18:23 +00:00
|
|
|
std::pair<uint64_t, std::string> element = cursor.first();
|
2023-08-13 16:30:17 +00:00
|
|
|
std::map<uint64_t, std::string>::const_iterator reference = data.begin();
|
|
|
|
|
|
|
|
EXPECT_EQ(element.first, reference->first);
|
|
|
|
EXPECT_EQ(element.second, reference->second);
|
|
|
|
EXPECT_EQ(cache->count(), data.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(CacheCursorTest, NextPrivate) {
|
2023-11-01 22:45:42 +00:00
|
|
|
EXPECT_EQ(getCacheCursorsSize(), 1);
|
2023-08-13 16:30:17 +00:00
|
|
|
std::map<uint64_t, std::string>::const_iterator reference = data.begin();
|
|
|
|
|
|
|
|
reference++;
|
|
|
|
for (; reference != data.end(); ++reference) {
|
2023-10-25 22:18:23 +00:00
|
|
|
std::pair<uint64_t, std::string> element = cursor.next();
|
2023-08-13 16:30:17 +00:00
|
|
|
EXPECT_EQ(element.first, reference->first);
|
|
|
|
EXPECT_EQ(element.second, reference->second);
|
|
|
|
EXPECT_EQ(cache->count(), data.size());
|
|
|
|
}
|
|
|
|
|
2023-10-25 22:18:23 +00:00
|
|
|
EXPECT_THROW(cursor.next(), LMDBAL::NotFound);
|
2023-08-13 16:30:17 +00:00
|
|
|
EXPECT_EQ(cache->count(), data.size());
|
|
|
|
|
2023-10-25 22:18:23 +00:00
|
|
|
std::pair<uint64_t, std::string> element = cursor.first();
|
2023-08-13 16:30:17 +00:00
|
|
|
reference = data.begin();
|
|
|
|
|
|
|
|
EXPECT_EQ(element.first, reference->first);
|
|
|
|
EXPECT_EQ(element.second, reference->second);
|
|
|
|
EXPECT_EQ(cache->count(), data.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(CacheCursorTest, LastPrivate) {
|
2023-11-01 22:45:42 +00:00
|
|
|
EXPECT_EQ(getCacheCursorsSize(), 1);
|
2023-08-13 16:30:17 +00:00
|
|
|
EXPECT_EQ(cache->count(), data.size());
|
|
|
|
|
2023-10-25 22:18:23 +00:00
|
|
|
std::pair<uint64_t, std::string> element = cursor.last();
|
2023-08-13 16:30:17 +00:00
|
|
|
std::map<uint64_t, std::string>::const_reverse_iterator reference = data.rbegin();
|
|
|
|
|
|
|
|
EXPECT_EQ(element.first, reference->first);
|
|
|
|
EXPECT_EQ(element.second, reference->second);
|
|
|
|
EXPECT_EQ(cache->count(), data.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(CacheCursorTest, PrevPrivate) {
|
2023-11-01 22:45:42 +00:00
|
|
|
EXPECT_EQ(getCacheCursorsSize(), 1);
|
2023-08-13 16:30:17 +00:00
|
|
|
std::map<uint64_t, std::string>::const_reverse_iterator reference = data.rbegin();
|
|
|
|
|
|
|
|
reference++;
|
|
|
|
for (; reference != data.rend(); ++reference) {
|
2023-10-25 22:18:23 +00:00
|
|
|
std::pair<uint64_t, std::string> element = cursor.prev();
|
2023-08-13 16:30:17 +00:00
|
|
|
EXPECT_EQ(element.first, reference->first);
|
|
|
|
EXPECT_EQ(element.second, reference->second);
|
|
|
|
EXPECT_EQ(cache->count(), data.size());
|
|
|
|
}
|
|
|
|
|
2023-10-25 22:18:23 +00:00
|
|
|
EXPECT_THROW(cursor.prev(), LMDBAL::NotFound);
|
2023-08-13 16:30:17 +00:00
|
|
|
EXPECT_EQ(cache->count(), data.size());
|
|
|
|
|
2023-10-25 22:18:23 +00:00
|
|
|
std::pair<uint64_t, std::string> element = cursor.last();
|
2023-08-13 16:30:17 +00:00
|
|
|
reference = data.rbegin();
|
|
|
|
|
|
|
|
EXPECT_EQ(element.first, reference->first);
|
|
|
|
EXPECT_EQ(element.second, reference->second);
|
|
|
|
EXPECT_EQ(cache->count(), data.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(CacheCursorTest, CurrentPrivate) {
|
2023-11-01 22:45:42 +00:00
|
|
|
EXPECT_EQ(getCacheCursorsSize(), 1);
|
2023-10-25 22:18:23 +00:00
|
|
|
std::pair<uint64_t, std::string> element = cursor.first();
|
2023-08-13 16:30:17 +00:00
|
|
|
std::map<uint64_t, std::string>::const_iterator reference = data.begin();
|
|
|
|
|
|
|
|
EXPECT_EQ(element.first, reference->first);
|
|
|
|
EXPECT_EQ(element.second, reference->second);
|
|
|
|
|
2023-10-25 22:18:23 +00:00
|
|
|
element = cursor.current();
|
2023-08-13 16:30:17 +00:00
|
|
|
EXPECT_EQ(cache->count(), data.size());
|
|
|
|
|
|
|
|
EXPECT_EQ(element.first, reference->first);
|
|
|
|
EXPECT_EQ(element.second, reference->second);
|
|
|
|
|
2023-10-25 22:18:23 +00:00
|
|
|
cursor.next();
|
|
|
|
element = cursor.current();
|
2023-08-13 16:30:17 +00:00
|
|
|
++reference;
|
|
|
|
|
|
|
|
EXPECT_EQ(element.first, reference->first);
|
|
|
|
EXPECT_EQ(element.second, reference->second);
|
|
|
|
|
2023-10-25 22:18:23 +00:00
|
|
|
cursor.next();
|
|
|
|
cursor.next();
|
|
|
|
cursor.prev();
|
|
|
|
element = cursor.current();
|
2023-08-13 16:30:17 +00:00
|
|
|
++reference;
|
|
|
|
++reference;
|
|
|
|
--reference;
|
|
|
|
|
|
|
|
EXPECT_EQ(element.first, reference->first);
|
|
|
|
EXPECT_EQ(element.second, reference->second);
|
|
|
|
EXPECT_EQ(cache->count(), data.size());
|
|
|
|
}
|
|
|
|
|
2023-11-01 22:45:42 +00:00
|
|
|
TEST_F(CacheCursorTest, SettingPrivate) {
|
|
|
|
EXPECT_EQ(getCacheCursorsSize(), 1);
|
|
|
|
|
|
|
|
EXPECT_FALSE(cursor.set(6684));
|
|
|
|
EXPECT_EQ(cursor.current().second, "tanned inmate");
|
|
|
|
|
|
|
|
std::map<uint64_t, std::string>::const_iterator reference = data.begin();
|
|
|
|
std::advance(reference, 5);
|
|
|
|
EXPECT_TRUE(cursor.set(reference->first));
|
|
|
|
EXPECT_EQ(cursor.current().second, reference->second);
|
|
|
|
|
|
|
|
++reference;
|
|
|
|
cursor.next();
|
|
|
|
EXPECT_EQ(cursor.current().second, reference->second);
|
|
|
|
|
|
|
|
++reference;
|
|
|
|
cursor.next();
|
|
|
|
EXPECT_EQ(cursor.current().second, reference->second);
|
|
|
|
|
|
|
|
--reference;
|
|
|
|
cursor.prev();
|
|
|
|
EXPECT_EQ(cursor.current().second, reference->second);
|
|
|
|
|
|
|
|
--reference;
|
|
|
|
cursor.prev();
|
|
|
|
EXPECT_EQ(cursor.current().second, reference->second);
|
|
|
|
|
|
|
|
--reference;
|
|
|
|
cursor.prev();
|
|
|
|
EXPECT_EQ(cursor.current().second, reference->second);
|
|
|
|
}
|
|
|
|
|
2023-08-13 16:30:17 +00:00
|
|
|
TEST_F(CacheCursorTest, Destruction) {
|
2023-11-01 22:45:42 +00:00
|
|
|
EXPECT_EQ(getCacheCursorsSize(), 1);
|
2023-10-25 22:18:23 +00:00
|
|
|
cursor.close();
|
2023-11-01 22:45:42 +00:00
|
|
|
EXPECT_EQ(getCacheCursorsSize(), 1);
|
2023-08-13 16:30:17 +00:00
|
|
|
|
2023-10-25 22:18:23 +00:00
|
|
|
EXPECT_THROW(cursor.first(), LMDBAL::CursorNotReady);
|
|
|
|
EXPECT_THROW(cursor.last(), LMDBAL::CursorNotReady);
|
|
|
|
EXPECT_THROW(cursor.next(), LMDBAL::CursorNotReady);
|
|
|
|
EXPECT_THROW(cursor.prev(), LMDBAL::CursorNotReady);
|
|
|
|
EXPECT_THROW(cursor.current(), LMDBAL::CursorNotReady);
|
2023-08-13 16:30:17 +00:00
|
|
|
|
2023-10-25 22:18:23 +00:00
|
|
|
cursor = LMDBAL::Cursor<uint64_t, std::string>();
|
2023-11-01 22:45:42 +00:00
|
|
|
EXPECT_EQ(getCacheCursorsSize(), 0);
|
2023-08-13 16:30:17 +00:00
|
|
|
|
|
|
|
cursor = cache->createCursor();
|
2023-11-01 22:45:42 +00:00
|
|
|
EXPECT_EQ(getCacheCursorsSize(), 1);
|
2023-08-13 16:30:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(CacheCursorTest, FirstPublic) {
|
2023-11-01 22:45:42 +00:00
|
|
|
EXPECT_EQ(getCacheCursorsSize(), 1);
|
2023-08-13 16:30:17 +00:00
|
|
|
transaction = db->beginTransaction();
|
|
|
|
|
2023-10-25 22:18:23 +00:00
|
|
|
cursor.open(transaction);
|
|
|
|
std::pair<uint64_t, std::string> element = cursor.first();
|
2023-08-13 16:30:17 +00:00
|
|
|
std::map<uint64_t, std::string>::const_iterator reference = data.begin();
|
|
|
|
|
|
|
|
EXPECT_EQ(element.first, reference->first);
|
|
|
|
EXPECT_EQ(element.second, reference->second);
|
|
|
|
EXPECT_EQ(cache->count(), data.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(CacheCursorTest, NextPublic) {
|
2023-11-01 22:45:42 +00:00
|
|
|
EXPECT_EQ(getCacheCursorsSize(), 1);
|
2023-08-13 16:30:17 +00:00
|
|
|
std::map<uint64_t, std::string>::const_iterator reference = data.begin();
|
|
|
|
|
|
|
|
reference++;
|
|
|
|
for (; reference != data.end(); ++reference) {
|
2023-10-25 22:18:23 +00:00
|
|
|
std::pair<uint64_t, std::string> element = cursor.next();
|
2023-08-13 16:30:17 +00:00
|
|
|
EXPECT_EQ(element.first, reference->first);
|
|
|
|
EXPECT_EQ(element.second, reference->second);
|
|
|
|
EXPECT_EQ(cache->count(), data.size());
|
|
|
|
}
|
|
|
|
|
2023-10-25 22:18:23 +00:00
|
|
|
EXPECT_THROW(cursor.next(), LMDBAL::NotFound);
|
2023-08-13 16:30:17 +00:00
|
|
|
EXPECT_EQ(cache->count(), data.size());
|
|
|
|
|
2023-10-25 22:18:23 +00:00
|
|
|
std::pair<uint64_t, std::string> element = cursor.first();
|
2023-08-13 16:30:17 +00:00
|
|
|
reference = data.begin();
|
|
|
|
|
|
|
|
EXPECT_EQ(element.first, reference->first);
|
|
|
|
EXPECT_EQ(element.second, reference->second);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(CacheCursorTest, LastPublic) {
|
2023-11-01 22:45:42 +00:00
|
|
|
EXPECT_EQ(getCacheCursorsSize(), 1);
|
2023-10-25 22:18:23 +00:00
|
|
|
std::pair<uint64_t, std::string> element = cursor.last();
|
2023-08-13 16:30:17 +00:00
|
|
|
std::map<uint64_t, std::string>::const_reverse_iterator reference = data.rbegin();
|
|
|
|
|
|
|
|
EXPECT_EQ(element.first, reference->first);
|
|
|
|
EXPECT_EQ(element.second, reference->second);
|
|
|
|
EXPECT_EQ(cache->count(), data.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(CacheCursorTest, PrevPublic) {
|
2023-11-01 22:45:42 +00:00
|
|
|
EXPECT_EQ(getCacheCursorsSize(), 1);
|
2023-08-13 16:30:17 +00:00
|
|
|
std::map<uint64_t, std::string>::const_reverse_iterator reference = data.rbegin();
|
|
|
|
|
|
|
|
reference++;
|
|
|
|
for (; reference != data.rend(); ++reference) {
|
2023-10-25 22:18:23 +00:00
|
|
|
std::pair<uint64_t, std::string> element = cursor.prev();
|
2023-08-13 16:30:17 +00:00
|
|
|
EXPECT_EQ(element.first, reference->first);
|
|
|
|
EXPECT_EQ(element.second, reference->second);
|
|
|
|
EXPECT_EQ(cache->count(), data.size());
|
|
|
|
}
|
|
|
|
|
2023-10-25 22:18:23 +00:00
|
|
|
EXPECT_THROW(cursor.prev(), LMDBAL::NotFound);
|
2023-08-13 16:30:17 +00:00
|
|
|
|
2023-10-25 22:18:23 +00:00
|
|
|
std::pair<uint64_t, std::string> element = cursor.last();
|
2023-08-13 16:30:17 +00:00
|
|
|
reference = data.rbegin();
|
|
|
|
|
|
|
|
EXPECT_EQ(element.first, reference->first);
|
|
|
|
EXPECT_EQ(element.second, reference->second);
|
|
|
|
EXPECT_EQ(cache->count(), data.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(CacheCursorTest, CurrentPublic) {
|
2023-11-01 22:45:42 +00:00
|
|
|
EXPECT_EQ(getCacheCursorsSize(), 1);
|
2023-10-25 22:18:23 +00:00
|
|
|
std::pair<uint64_t, std::string> element = cursor.first();
|
2023-08-13 16:30:17 +00:00
|
|
|
std::map<uint64_t, std::string>::const_iterator reference = data.begin();
|
|
|
|
|
|
|
|
EXPECT_EQ(element.first, reference->first);
|
|
|
|
EXPECT_EQ(element.second, reference->second);
|
|
|
|
|
2023-10-25 22:18:23 +00:00
|
|
|
element = cursor.current();
|
2023-08-13 16:30:17 +00:00
|
|
|
EXPECT_EQ(cache->count(), data.size());
|
|
|
|
|
|
|
|
EXPECT_EQ(element.first, reference->first);
|
|
|
|
EXPECT_EQ(element.second, reference->second);
|
|
|
|
|
2023-10-25 22:18:23 +00:00
|
|
|
cursor.next();
|
|
|
|
element = cursor.current();
|
2023-08-13 16:30:17 +00:00
|
|
|
++reference;
|
|
|
|
|
|
|
|
EXPECT_EQ(element.first, reference->first);
|
|
|
|
EXPECT_EQ(element.second, reference->second);
|
|
|
|
|
2023-10-25 22:18:23 +00:00
|
|
|
cursor.next();
|
|
|
|
cursor.next();
|
|
|
|
cursor.prev();
|
|
|
|
element = cursor.current();
|
2023-08-13 16:30:17 +00:00
|
|
|
++reference;
|
|
|
|
++reference;
|
|
|
|
--reference;
|
|
|
|
|
|
|
|
EXPECT_EQ(element.first, reference->first);
|
|
|
|
EXPECT_EQ(element.second, reference->second);
|
|
|
|
EXPECT_EQ(cache->count(), data.size());
|
|
|
|
}
|
|
|
|
|
2023-11-01 22:45:42 +00:00
|
|
|
TEST_F(CacheCursorTest, SettingPublic) {
|
|
|
|
EXPECT_EQ(getCacheCursorsSize(), 1);
|
|
|
|
|
|
|
|
EXPECT_FALSE(cursor.set(557));
|
|
|
|
EXPECT_EQ(cursor.current().second, "resilent pick forefront");
|
|
|
|
|
|
|
|
std::map<uint64_t, std::string>::const_iterator reference = data.begin();
|
|
|
|
std::advance(reference, 3);
|
|
|
|
EXPECT_TRUE(cursor.set(reference->first));
|
|
|
|
EXPECT_EQ(cursor.current().second, reference->second);
|
|
|
|
|
|
|
|
++reference;
|
|
|
|
cursor.next();
|
|
|
|
EXPECT_EQ(cursor.current().second, reference->second);
|
|
|
|
|
|
|
|
++reference;
|
|
|
|
cursor.next();
|
|
|
|
EXPECT_EQ(cursor.current().second, reference->second);
|
|
|
|
|
|
|
|
--reference;
|
|
|
|
cursor.prev();
|
|
|
|
EXPECT_EQ(cursor.current().second, reference->second);
|
|
|
|
|
|
|
|
--reference;
|
|
|
|
cursor.prev();
|
|
|
|
EXPECT_EQ(cursor.current().second, reference->second);
|
|
|
|
|
|
|
|
--reference;
|
|
|
|
cursor.prev();
|
|
|
|
EXPECT_EQ(cursor.current().second, reference->second);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(CacheCursorTest, CursorRAIIBehaviour) {
|
|
|
|
int initialiCursorsAmount = getCacheCursorsSize();
|
|
|
|
{
|
|
|
|
LMDBAL::Cursor<uint64_t, std::string> cur = cache->createCursor();
|
|
|
|
EXPECT_EQ(initialiCursorsAmount + 1, getCacheCursorsSize());
|
|
|
|
cur.open(transaction);
|
|
|
|
EXPECT_NO_THROW(cur.first());
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPECT_EQ(initialiCursorsAmount, getCacheCursorsSize());
|
|
|
|
LMDBAL::Cursor<uint64_t, std::string> cur;
|
|
|
|
EXPECT_EQ(initialiCursorsAmount, getCacheCursorsSize());
|
|
|
|
EXPECT_EQ(cur.empty(), true);
|
|
|
|
cur = cache->createCursor();
|
|
|
|
EXPECT_EQ(cur.empty(), false);
|
|
|
|
EXPECT_EQ(initialiCursorsAmount + 1, getCacheCursorsSize());
|
|
|
|
EXPECT_THROW(emptyCache->destroyCursor(cur), LMDBAL::Unknown);
|
|
|
|
cache->destroyCursor(cur);
|
|
|
|
EXPECT_EQ(cur.empty(), true);
|
|
|
|
EXPECT_EQ(initialiCursorsAmount, getCacheCursorsSize());
|
|
|
|
|
|
|
|
cur = cache->createCursor();
|
|
|
|
EXPECT_EQ(initialiCursorsAmount + 1, getCacheCursorsSize());
|
|
|
|
EXPECT_EQ(cur.empty(), false);
|
|
|
|
|
|
|
|
cur.drop();
|
|
|
|
EXPECT_EQ(cur.empty(), true);
|
|
|
|
EXPECT_EQ(initialiCursorsAmount, getCacheCursorsSize());
|
|
|
|
|
|
|
|
EXPECT_NO_THROW(cur.drop());
|
|
|
|
EXPECT_THROW(cache->destroyCursor(cur), LMDBAL::Unknown);
|
|
|
|
}
|
|
|
|
|
2023-08-13 16:30:17 +00:00
|
|
|
TEST_F(CacheCursorTest, CornerCases) {
|
2023-10-17 21:06:11 +00:00
|
|
|
transaction.terminate();
|
2023-10-25 22:18:23 +00:00
|
|
|
EXPECT_THROW(cursor.current(), LMDBAL::Unknown);
|
|
|
|
cursor.close();
|
2023-08-13 16:30:17 +00:00
|
|
|
|
2023-10-25 22:18:23 +00:00
|
|
|
LMDBAL::Cursor<uint64_t, std::string> emptyCursor = emptyCache->createCursor();
|
|
|
|
emptyCursor.open();
|
|
|
|
EXPECT_THROW(emptyCursor.first(), LMDBAL::NotFound);
|
|
|
|
EXPECT_THROW(emptyCursor.last(), LMDBAL::NotFound);
|
|
|
|
EXPECT_THROW(emptyCursor.next(), LMDBAL::NotFound);
|
|
|
|
EXPECT_THROW(emptyCursor.prev(), LMDBAL::NotFound);
|
|
|
|
EXPECT_THROW(emptyCursor.current(), LMDBAL::Unknown);
|
|
|
|
emptyCursor.close();
|
2023-08-13 16:30:17 +00:00
|
|
|
|
2023-10-25 22:18:23 +00:00
|
|
|
cursor.open();
|
|
|
|
EXPECT_THROW(cursor.current(), LMDBAL::Unknown); //yeah, nice thing to write in the doc
|
2023-08-13 16:30:17 +00:00
|
|
|
|
|
|
|
std::map<uint64_t, std::string>::const_reverse_iterator breference = data.rbegin();
|
2023-10-25 22:18:23 +00:00
|
|
|
std::pair<uint64_t, std::string> element(cursor.prev());
|
2023-08-13 16:30:17 +00:00
|
|
|
EXPECT_EQ(element.first, breference->first); //nice thing to write in the doc, again!
|
|
|
|
EXPECT_EQ(element.second, breference->second);
|
2023-10-25 22:18:23 +00:00
|
|
|
element = cursor.current();
|
2023-08-13 16:30:17 +00:00
|
|
|
EXPECT_EQ(element.first, breference->first);
|
|
|
|
EXPECT_EQ(element.second, breference->second);
|
2023-10-25 22:18:23 +00:00
|
|
|
EXPECT_THROW(cursor.next(), LMDBAL::NotFound);
|
|
|
|
cursor.close();
|
2023-08-13 16:30:17 +00:00
|
|
|
|
2023-10-25 22:18:23 +00:00
|
|
|
cursor.open();
|
|
|
|
element = cursor.next();
|
2023-08-13 16:30:17 +00:00
|
|
|
std::map<uint64_t, std::string>::const_iterator reference = data.begin();
|
|
|
|
EXPECT_EQ(element.first, reference->first);
|
|
|
|
EXPECT_EQ(element.second, reference->second);
|
2023-10-25 22:18:23 +00:00
|
|
|
element = cursor.current();
|
2023-08-13 16:30:17 +00:00
|
|
|
EXPECT_EQ(element.first, reference->first);
|
|
|
|
EXPECT_EQ(element.second, reference->second);
|
2023-10-25 22:18:23 +00:00
|
|
|
EXPECT_THROW(cursor.prev(), LMDBAL::NotFound);
|
2023-08-13 16:30:17 +00:00
|
|
|
}
|
|
|
|
|