6fc6a27288
Summary: GraphDb is refactored to become an API exposing different parts necessary for the database to function. These different parts can have different implementations in SingleNode or distributed Master/Server GraphDb implementations. Interally GraphDb is implemented using two class heirarchies. One contains all the members and correct wiring for each situation. The other takes care of initialization and shutdown. This architecture is practical because it can guarantee that the initialization of the object structure is complete, before initializing state. Reviewers: buda, mislav.bradac, dgleich, teon.banek Reviewed By: teon.banek Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D1093
51 lines
1.5 KiB
C++
51 lines
1.5 KiB
C++
#include <experimental/optional>
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
#include "communication/messaging/distributed.hpp"
|
|
#include "database/types.hpp"
|
|
#include "storage/concurrent_id_mapper_master.hpp"
|
|
#include "storage/concurrent_id_mapper_worker.hpp"
|
|
|
|
using namespace communication::messaging;
|
|
using namespace storage;
|
|
using namespace database;
|
|
|
|
template <typename TId>
|
|
class DistributedConcurrentIdMapperTest : public ::testing::Test {
|
|
const std::string kLocal{"127.0.0.1"};
|
|
|
|
protected:
|
|
System master_system_{kLocal, 0};
|
|
std::experimental::optional<MasterConcurrentIdMapper<TId>> master_mapper_;
|
|
System worker_system_{kLocal, 0};
|
|
std::experimental::optional<WorkerConcurrentIdMapper<TId>> worker_mapper_;
|
|
|
|
void SetUp() override {
|
|
master_mapper_.emplace(master_system_);
|
|
worker_mapper_.emplace(worker_system_, master_system_.endpoint());
|
|
}
|
|
void TearDown() override {
|
|
worker_mapper_ = std::experimental::nullopt;
|
|
master_mapper_ = std::experimental::nullopt;
|
|
}
|
|
};
|
|
|
|
typedef ::testing::Types<Label, EdgeType, Property> GraphDbTestTypes;
|
|
TYPED_TEST_CASE(DistributedConcurrentIdMapperTest, GraphDbTestTypes);
|
|
|
|
TYPED_TEST(DistributedConcurrentIdMapperTest, Basic) {
|
|
auto &master = this->master_mapper_.value();
|
|
auto &worker = this->worker_mapper_.value();
|
|
|
|
auto id1 = master.value_to_id("v1");
|
|
EXPECT_EQ(worker.id_to_value(id1), "v1");
|
|
EXPECT_EQ(worker.value_to_id("v1"), id1);
|
|
|
|
auto id2 = worker.value_to_id("v2");
|
|
EXPECT_EQ(master.id_to_value(id2), "v2");
|
|
EXPECT_EQ(master.value_to_id("v2"), id2);
|
|
|
|
EXPECT_NE(id1, id2);
|
|
}
|