integrated object cache into session and added message bus to object_cache and update tests
This commit is contained in:
@@ -79,18 +79,30 @@ TEST_CASE_METHOD(SessionFixture, "Test insert object with has many relation", "[
|
||||
|
||||
session ses({bus, connection::dns, 4}, schema);
|
||||
|
||||
auto s_king = make_object<author>(1, "Steven", "King", "21.9.1947", 1956, false);
|
||||
{
|
||||
auto s_king = make_object<author>(1, "Steven", "King", "21.9.1947", 1956, false);
|
||||
|
||||
s_king->books.push_back(make_object<book>(2, "Carrie", nullobj, 1974));
|
||||
s_king->books.push_back(make_object<book>(3, "The Shining", nullobj, 1977));
|
||||
s_king->books.push_back(make_object<book>(4, "It", nullobj, 1986));
|
||||
s_king->books.push_back(make_object<book>(5, "Misery", nullobj, 1987));
|
||||
s_king->books.push_back(make_object<book>(6, "The Dark Tower: The Gunslinger", nullobj, 1982));
|
||||
s_king->books.push_back(make_object<book>(2, "Carrie", nullobj, 1974));
|
||||
s_king->books.push_back(make_object<book>(3, "The Shining", nullobj, 1977));
|
||||
s_king->books.push_back(make_object<book>(4, "It", nullobj, 1986));
|
||||
s_king->books.push_back(make_object<book>(5, "Misery", nullobj, 1987));
|
||||
s_king->books.push_back(make_object<book>(6, "The Dark Tower: The Gunslinger", nullobj, 1982));
|
||||
|
||||
validate_author_state(s_king, object_state::Transient);
|
||||
auto res = ses.insert(s_king);
|
||||
REQUIRE(res);
|
||||
validate_author_state(s_king, object_state::Persistent);
|
||||
validate_author_state(s_king, object_state::Transient);
|
||||
auto res = ses.insert(s_king);
|
||||
REQUIRE(res);
|
||||
validate_author_state(s_king, object_state::Persistent);
|
||||
|
||||
auto author_result = ses.find<author>(s_king->id);
|
||||
REQUIRE(author_result);
|
||||
REQUIRE(author_result->is_persistent());
|
||||
REQUIRE(author_result.value()->books.size() == 5);
|
||||
}
|
||||
|
||||
auto author_result = ses.find<author>(1);
|
||||
REQUIRE(author_result);
|
||||
REQUIRE(author_result->is_persistent());
|
||||
REQUIRE(author_result.value()->books.size() == 5);
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(SessionFixture, "Test insert object with has many relation with identity", "[session][insert][has_many][identity]") {
|
||||
@@ -214,4 +226,4 @@ TEST_CASE_METHOD(SessionFixture, "Test insert object with has many primitive rel
|
||||
for (const auto &cstr: clist->colors) {
|
||||
REQUIRE(std::find(expected_colors.begin(), expected_colors.end(), cstr) != expected_colors.end());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,9 @@
|
||||
|
||||
#include "matador/object/object_cache.hpp"
|
||||
#include "matador/object/object_resolver.hpp"
|
||||
|
||||
#include "matador/utils/identifier.hpp"
|
||||
#include "matador/utils/message_bus.hpp"
|
||||
|
||||
#include "../test/models/person.hpp"
|
||||
|
||||
@@ -58,7 +60,8 @@ private:
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("object_cache: acquire_proxy returns the same proxy instance across threads", "[object][cache][threadsafe]") {
|
||||
matador::object::object_cache cache;
|
||||
matador::utils::message_bus bus;
|
||||
matador::object::object_cache cache(bus);
|
||||
const matador::utils::identifier id{123};
|
||||
|
||||
std::atomic_int calls{0};
|
||||
@@ -89,7 +92,8 @@ TEST_CASE("object_cache: acquire_proxy returns the same proxy instance across th
|
||||
}
|
||||
|
||||
TEST_CASE("object_cache: attach_entity makes is_loaded/get_entity reflect presence", "[object][cache]") {
|
||||
matador::object::object_cache cache;
|
||||
matador::utils::message_bus bus;
|
||||
matador::object::object_cache cache(bus);
|
||||
const matador::utils::identifier id{42};
|
||||
|
||||
REQUIRE_FALSE(cache.is_loaded<person>(id));
|
||||
@@ -107,7 +111,8 @@ TEST_CASE("object_cache: attach_entity makes is_loaded/get_entity reflect presen
|
||||
}
|
||||
|
||||
TEST_CASE("object_cache: erase invalidates existing proxies", "[object][cache]") {
|
||||
matador::object::object_cache cache;
|
||||
matador::utils::message_bus bus;
|
||||
matador::object::object_cache cache(bus);
|
||||
const matador::utils::identifier id{9};
|
||||
|
||||
std::atomic_int calls{0};
|
||||
|
||||
Reference in New Issue
Block a user