1
0
forked from blue/lmdbal

cache change bugfix, covered that case with unit tests, unittests for forcing records

This commit is contained in:
Blue 2023-03-09 22:50:53 +03:00
parent a79dae8fd0
commit 6a8f67ac34
Signed by untrusted user: blue
GPG Key ID: 9B203B252A63EE38
2 changed files with 60 additions and 1 deletions

View File

@ -90,7 +90,7 @@ void DataBase::Cache<K, V>::changeRecord(const K& key, const V& value) {
if (*mode == Mode::full) {
typename std::map<K, V>::iterator itr = cache->find(key);
if (itr != cache->end()) {
if (itr == cache->end()) {
throw NotFound(DataBase::_Table::toString(key), DataBase::Table<K, V>::db->name, DataBase::Table<K, V>::name);
}
Table<K, V>::changeRecord(key, value);

View File

@ -219,3 +219,62 @@ TEST_F(DataBaseTest, CountAndDrop) {
EXPECT_EQ(c1->count(), 2);
}
TEST_F(DataBaseTest, Change) {
EXPECT_EQ(db->ready(), true);
EXPECT_EQ(t1->count(), 1);
EXPECT_EQ(t2->count(), 1);
EXPECT_EQ(c1->count(), 2);
EXPECT_EQ(t1->getRecord(2), 2);
EXPECT_EQ(t2->getRecord("sdfhga"), "world");
EXPECT_EQ(c1->getRecord(15), "world");
EXPECT_EQ(c1->getRecord(12), "grr grr");
t1->addRecord(58, 39);
t2->addRecord("lawfirm", "stumble");
c1->addRecord(89, "answer");
t1->changeRecord(2, 49);
t2->changeRecord("sdfhga", "void");
c1->changeRecord(15, "recording");
c1->changeRecord(12, "thermal");
EXPECT_EQ(t1->getRecord(2), 49);
EXPECT_EQ(t2->getRecord("sdfhga"), "void");
EXPECT_EQ(c1->getRecord(15), "recording");
EXPECT_EQ(c1->getRecord(12), "thermal");
EXPECT_EQ(t1->getRecord(58), 39);
EXPECT_EQ(t2->getRecord("lawfirm"), "stumble");
EXPECT_EQ(c1->getRecord(89), "answer");
EXPECT_EQ(t1->count(), 2);
EXPECT_EQ(t2->count(), 2);
EXPECT_EQ(c1->count(), 3);
}
TEST_F(DataBaseTest, Force) {
EXPECT_EQ(db->ready(), true);
t1->forceRecord(58, 35); //changing
t1->forceRecord(68, 36); //adding
t2->forceRecord("prophecy", "dumpling"); //adding
t2->forceRecord("lawfirm", "paracetamol"); //changing
c1->forceRecord(89, "canine"); //changing
c1->forceRecord(98, "duration"); //adding
EXPECT_EQ(t1->getRecord(2), 49);
EXPECT_EQ(t1->getRecord(58), 35);
EXPECT_EQ(t1->getRecord(68), 36);
EXPECT_EQ(t2->getRecord("sdfhga"), "void");
EXPECT_EQ(t2->getRecord("prophecy"), "dumpling");
EXPECT_EQ(t2->getRecord("lawfirm"), "paracetamol");
EXPECT_EQ(c1->getRecord(15), "recording");
EXPECT_EQ(c1->getRecord(12), "thermal");
EXPECT_EQ(c1->getRecord(89), "canine");
EXPECT_EQ(c1->getRecord(98), "duration");
EXPECT_EQ(t1->count(), 3);
EXPECT_EQ(t2->count(), 3);
EXPECT_EQ(c1->count(), 4);
}