memgraph/tests/unit/concurrent_id_mapper_distributed.cpp
Matej Ferencevic c877c87bb4 Refactor RPC
Summary:
Previously, the RPC stack used the network stack only to receive messages. The
messages were then added to a separate queue that was processed by different
thread pools. This design was inefficient because there was a lock when
inserting and getting messages from the common queue.

This diff removes the need for separate thread pools by utilising the new
network stack design. This is possible because the new network stack allows
full processing of the network request without blocking the whole queue.

Reviewers: buda, florijan, teon.banek, dgleich, mislav.bradac

Reviewed By: buda

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D1229
2018-02-23 12:07:22 +01:00

49 lines
1.5 KiB
C++

#include <experimental/optional>
#include "gtest/gtest.h"
#include "communication/rpc/server.hpp"
#include "storage/concurrent_id_mapper_master.hpp"
#include "storage/concurrent_id_mapper_worker.hpp"
#include "storage/types.hpp"
template <typename TId>
class DistributedConcurrentIdMapperTest : public ::testing::Test {
const std::string kLocal{"127.0.0.1"};
protected:
communication::rpc::Server master_server_{{kLocal, 0}};
std::experimental::optional<storage::MasterConcurrentIdMapper<TId>>
master_mapper_;
std::experimental::optional<storage::WorkerConcurrentIdMapper<TId>>
worker_mapper_;
void SetUp() override {
master_mapper_.emplace(master_server_);
worker_mapper_.emplace(master_server_.endpoint());
}
void TearDown() override {
worker_mapper_ = std::experimental::nullopt;
master_mapper_ = std::experimental::nullopt;
}
};
typedef ::testing::Types<storage::Label, storage::EdgeType, storage::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);
}