From 68a75eeca2886a2db45b0d5681416c8713ba2a07 Mon Sep 17 00:00:00 2001 From: Dominik Gleich Date: Fri, 19 Jan 2018 13:39:18 +0100 Subject: [PATCH] Add database master test Summary: Seperate rpc server names Reviewers: florijan, teon.banek Reviewed By: florijan Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D1118 --- src/storage/concurrent_id_mapper_master.cpp | 5 ++++- src/storage/concurrent_id_mapper_rpc_messages.hpp | 10 ++++++++++ src/storage/concurrent_id_mapper_worker.cpp | 3 ++- tests/unit/database_master.cpp | 11 +++++++++++ 4 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 tests/unit/database_master.cpp diff --git a/src/storage/concurrent_id_mapper_master.cpp b/src/storage/concurrent_id_mapper_master.cpp index b19c977d0..a182ec485 100644 --- a/src/storage/concurrent_id_mapper_master.cpp +++ b/src/storage/concurrent_id_mapper_master.cpp @@ -32,7 +32,10 @@ ID_VALUE_RPC_CALLS(Property) template MasterConcurrentIdMapper::MasterConcurrentIdMapper( communication::messaging::System &system) - : rpc_server_(system, kConcurrentIdMapperRpc) { + // We have to make sure our rpc server name is unique with regards to type. + // Otherwise we will try to reuse the same rpc server name for different + // types (Label/EdgeType/Property) + : rpc_server_(system, impl::RpcServerNameFromType()) { RegisterRpc(*this, rpc_server_); } diff --git a/src/storage/concurrent_id_mapper_rpc_messages.hpp b/src/storage/concurrent_id_mapper_rpc_messages.hpp index 815e61f3e..d7c92103e 100644 --- a/src/storage/concurrent_id_mapper_rpc_messages.hpp +++ b/src/storage/concurrent_id_mapper_rpc_messages.hpp @@ -14,6 +14,16 @@ namespace storage { const std::string kConcurrentIdMapperRpc = "ConcurrentIdMapper"; const auto kConcurrentIdMapperRpcTimeout = 300ms; +namespace impl { + +/// Returns rpc server name by template type +template +std::string RpcServerNameFromType() { + return kConcurrentIdMapperRpc + "_" + typeid(TType).name(); +} + +}; // namespace impl + #define ID_VALUE_RPC(type) \ RPC_SINGLE_MEMBER_MESSAGE(type##IdReq, std::string); \ RPC_SINGLE_MEMBER_MESSAGE(type##IdRes, storage::type); \ diff --git a/src/storage/concurrent_id_mapper_worker.cpp b/src/storage/concurrent_id_mapper_worker.cpp index 2fbeaf8af..f49fa7d99 100644 --- a/src/storage/concurrent_id_mapper_worker.cpp +++ b/src/storage/concurrent_id_mapper_worker.cpp @@ -35,7 +35,8 @@ template WorkerConcurrentIdMapper::WorkerConcurrentIdMapper( communication::messaging::System &system, const io::network::Endpoint &master_endpoint) - : rpc_client_(system, master_endpoint, kConcurrentIdMapperRpc) {} + : rpc_client_(system, master_endpoint, impl::RpcServerNameFromType()) { +} template TId WorkerConcurrentIdMapper::value_to_id(const std::string &value) { diff --git a/tests/unit/database_master.cpp b/tests/unit/database_master.cpp new file mode 100644 index 000000000..24cb62664 --- /dev/null +++ b/tests/unit/database_master.cpp @@ -0,0 +1,11 @@ +#include "gtest/gtest.h" + +#include "config.hpp" +#include "database/graph_db.hpp" + +TEST(DatabaseMaster, Instantiate) { + database::Config config; + config.master_endpoint = io::network::Endpoint("127.0.0.1", 0); + config.worker_id = 0; + database::Master master(config); +}