From 54882be04580971c4ba87ef3cdb45bf57543d1af Mon Sep 17 00:00:00 2001 From: Matej Ferencevic Date: Fri, 3 May 2019 15:26:15 +0200 Subject: [PATCH] Rewrite `distributed_serialization` test to use SLK Reviewers: teon.banek Reviewed By: teon.banek Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D2004 --- tests/unit/distributed_serialization.cpp | 63 +++++++++++++++--------- 1 file changed, 40 insertions(+), 23 deletions(-) diff --git a/tests/unit/distributed_serialization.cpp b/tests/unit/distributed_serialization.cpp index 5d4b4b5d2..7b385993b 100644 --- a/tests/unit/distributed_serialization.cpp +++ b/tests/unit/distributed_serialization.cpp @@ -1,17 +1,17 @@ #include #include -#include - -#include "storage/distributed/mvcc/version_list.hpp" #include "query/typed_value.hpp" #include "storage/common/types/property_value_store.hpp" #include "storage/common/types/types.hpp" #include "storage/distributed/edge.hpp" +#include "storage/distributed/mvcc/version_list.hpp" #include "storage/distributed/rpc/serialization.hpp" #include "storage/distributed/vertex.hpp" #include "transactions/distributed/engine_single_node.hpp" +#include "slk_common.hpp" + using namespace storage; template @@ -68,35 +68,52 @@ bool CheckEdge(const Edge &e1, int w1, const Edge &e2, int w2) { #undef CHECK_RETURN -#define SAVE_AND_LOAD(type, name, element) \ - std::unique_ptr name; \ - { \ - ::capnp::MallocMessageBuilder message; \ - auto builder = message.initRoot(); \ - storage::Save##type(element, &builder, 0); \ - auto reader = message.getRoot(); \ - name = storage::Load##type(reader); \ +#define SAVE_AND_LOAD_VERTEX(name, element) \ + Vertex name; \ + { \ + slk::Loopback loopback; \ + auto builder = loopback.GetBuilder(); \ + slk::Save(element, builder, 0); \ + auto reader = loopback.GetReader(); \ + slk::Load(&name, reader); \ + } + +#define SAVE_AND_LOAD_EDGE(name, element) \ + std::unique_ptr name; \ + { \ + slk::Loopback loopback; \ + auto builder = loopback.GetBuilder(); \ + slk::Save(element, builder, 0); \ + auto reader = loopback.GetReader(); \ + slk::Load(&name, reader); \ } TEST(DistributedSerialization, Empty) { Vertex v; int w_id{0}; - SAVE_AND_LOAD(Vertex, v_recovered, v) - EXPECT_TRUE(CheckVertex(v, w_id, *v_recovered, w_id)); + SAVE_AND_LOAD_VERTEX(v_recovered, v) + EXPECT_TRUE(CheckVertex(v, w_id, v_recovered, w_id)); } -#define UPDATE_AND_CHECK(type, x, action) \ - { \ - SAVE_AND_LOAD(type, before, x) \ - EXPECT_TRUE(Check##type(x, 0, *before, 0)); \ - action; \ - EXPECT_FALSE(Check##type(x, 0, *before, 0)); \ - SAVE_AND_LOAD(type, after, x) \ - EXPECT_TRUE(Check##type(x, 0, *after, 0)); \ +#define UPDATE_AND_CHECK_V(v, action) \ + { \ + SAVE_AND_LOAD_VERTEX(before, v) \ + EXPECT_TRUE(CheckVertex(v, 0, before, 0)); \ + action; \ + EXPECT_FALSE(CheckVertex(v, 0, before, 0)); \ + SAVE_AND_LOAD_VERTEX(after, v) \ + EXPECT_TRUE(CheckVertex(v, 0, after, 0)); \ } -#define UPDATE_AND_CHECK_V(v, action) UPDATE_AND_CHECK(Vertex, v, action) -#define UPDATE_AND_CHECK_E(e, action) UPDATE_AND_CHECK(Edge, e, action) +#define UPDATE_AND_CHECK_E(e, action) \ + { \ + SAVE_AND_LOAD_EDGE(before, e) \ + EXPECT_TRUE(CheckEdge(e, 0, *before, 0)); \ + action; \ + EXPECT_FALSE(CheckEdge(e, 0, *before, 0)); \ + SAVE_AND_LOAD_EDGE(after, e) \ + EXPECT_TRUE(CheckEdge(e, 0, *after, 0)); \ + } TEST(DistributedSerialization, VertexLabels) { Vertex v;