diff --git a/tests/benchmark/expansion.cpp b/tests/benchmark/expansion.cpp index db43b3c6b..b5fa63bf3 100644 --- a/tests/benchmark/expansion.cpp +++ b/tests/benchmark/expansion.cpp @@ -36,11 +36,11 @@ class ExpansionBenchFixture : public benchmark::Fixture { // the fixed part is one vertex expanding to 1000 others auto start = dba->CreateVertex(); - MG_ASSERT(start->AddLabel(label).HasValue()); + MG_ASSERT(start.AddLabel(label).HasValue()); auto edge_type = dba->NameToEdgeType("edge_type"); for (int i = 0; i < 1000; i++) { auto dest = dba->CreateVertex(); - MG_ASSERT(dba->CreateEdge(start.get(), dest.get(), edge_type).HasValue()); + MG_ASSERT(dba->CreateEdge(&start, &dest, edge_type).HasValue()); } MG_ASSERT(!dba->Commit().HasError()); } diff --git a/tests/benchmark/query/execution.cpp b/tests/benchmark/query/execution.cpp index 010bd170d..1d1f26d3f 100644 --- a/tests/benchmark/query/execution.cpp +++ b/tests/benchmark/query/execution.cpp @@ -72,13 +72,13 @@ static void AddStarGraph(memgraph::storage::Storage *db, int spoke_count, int de { auto dba = db->Access(); auto center_vertex = dba->CreateVertex(); - MG_ASSERT(center_vertex->AddLabel(dba->NameToLabel(kStartLabel)).HasValue()); + MG_ASSERT(center_vertex.AddLabel(dba->NameToLabel(kStartLabel)).HasValue()); for (int i = 0; i < spoke_count; ++i) { - auto prev_vertex = std::move(center_vertex); + auto prev_vertex = center_vertex; for (int j = 0; j < depth; ++j) { auto dest = dba->CreateVertex(); - MG_ASSERT(dba->CreateEdge(prev_vertex.get(), dest.get(), dba->NameToEdgeType("Type")).HasValue()); - prev_vertex = std::move(dest); + MG_ASSERT(dba->CreateEdge(&prev_vertex, &dest, dba->NameToEdgeType("Type")).HasValue()); + prev_vertex = dest; } } MG_ASSERT(!dba->Commit().HasError()); @@ -89,19 +89,19 @@ static void AddStarGraph(memgraph::storage::Storage *db, int spoke_count, int de static void AddTree(memgraph::storage::Storage *db, int vertex_count) { { auto dba = db->Access(); - std::vector> vertices; + std::vector vertices; vertices.reserve(vertex_count); auto root = dba->CreateVertex(); - MG_ASSERT(root->AddLabel(dba->NameToLabel(kStartLabel)).HasValue()); - vertices.push_back(std::move(root)); + MG_ASSERT(root.AddLabel(dba->NameToLabel(kStartLabel)).HasValue()); + vertices.push_back(root); // NOLINTNEXTLINE(cert-msc32-c,cert-msc51-cpp) std::mt19937_64 rg(42); for (int i = 1; i < vertex_count; ++i) { auto v = dba->CreateVertex(); std::uniform_int_distribution<> dis(0U, vertices.size() - 1U); auto &parent = vertices.at(dis(rg)); - MG_ASSERT(dba->CreateEdge(parent.get(), v.get(), dba->NameToEdgeType("Type")).HasValue()); - vertices.push_back(std::move(v)); + MG_ASSERT(dba->CreateEdge(&parent, &v, dba->NameToEdgeType("Type")).HasValue()); + vertices.push_back(v); } MG_ASSERT(!dba->Commit().HasError()); } diff --git a/tests/benchmark/query/planner.cpp b/tests/benchmark/query/planner.cpp index 1648ebd6d..f093935b2 100644 --- a/tests/benchmark/query/planner.cpp +++ b/tests/benchmark/query/planner.cpp @@ -99,8 +99,8 @@ static auto CreateIndexedVertices(int index_count, int vertex_count, memgraph::s for (int vi = 0; vi < vertex_count; ++vi) { for (int index = 0; index < index_count; ++index) { auto vertex = dba->CreateVertex(); - MG_ASSERT(vertex->AddLabel(label).HasValue()); - MG_ASSERT(vertex->SetProperty(prop, memgraph::storage::PropertyValue(index)).HasValue()); + MG_ASSERT(vertex.AddLabel(label).HasValue()); + MG_ASSERT(vertex.SetProperty(prop, memgraph::storage::PropertyValue(index)).HasValue()); } } MG_ASSERT(!dba->Commit().HasError()); diff --git a/tests/property_based/random_graph.cpp b/tests/property_based/random_graph.cpp index 840df22a9..5beb22930 100644 --- a/tests/property_based/random_graph.cpp +++ b/tests/property_based/random_graph.cpp @@ -36,25 +36,25 @@ RC_GTEST_PROP(RandomGraph, RandomGraph, (std::vector vertex_labels, int edges_num = edge_types.size(); std::unique_ptr db{new memgraph::storage::InMemoryStorage()}; - std::vector> vertices; - std::unordered_map, std::string> vertex_label_map; - std::unordered_map, std::string> edge_type_map; + std::vector vertices; + std::unordered_map vertex_label_map; + std::unordered_map edge_type_map; auto dba = db->Access(); for (auto label : vertex_labels) { auto vertex_accessor = dba->CreateVertex(); - RC_ASSERT(vertex_accessor->AddLabel(dba->NameToLabel(label)).HasValue()); - vertex_label_map.emplace(vertex_accessor->Copy(), label); - vertices.push_back(std::move(vertex_accessor)); + RC_ASSERT(vertex_accessor.AddLabel(dba->NameToLabel(label)).HasValue()); + vertex_label_map.emplace(vertex_accessor, label); + vertices.push_back(vertex_accessor); } for (auto type : edge_types) { auto &from = vertices[*rc::gen::inRange(0, vertices_num)]; auto &to = vertices[*rc::gen::inRange(0, vertices_num)]; - auto maybe_edge_accessor = dba->CreateEdge(from.get(), to.get(), dba->NameToEdgeType(type)); + auto maybe_edge_accessor = dba->CreateEdge(&from, &to, dba->NameToEdgeType(type)); RC_ASSERT(maybe_edge_accessor.HasValue()); - edge_type_map.emplace(std::move(maybe_edge_accessor.GetValue()), type); + edge_type_map.insert({*maybe_edge_accessor, type}); } dba->AdvanceCommand(); @@ -62,18 +62,18 @@ RC_GTEST_PROP(RandomGraph, RandomGraph, (std::vector vertex_labels, int edges_num_check = 0; int vertices_num_check = 0; for (auto vertex : dba->Vertices(memgraph::storage::View::OLD)) { - auto label = vertex_label_map.at(vertex->Copy()); - auto maybe_labels = vertex->Labels(memgraph::storage::View::OLD); + auto label = vertex_label_map.at(vertex); + auto maybe_labels = vertex.Labels(memgraph::storage::View::OLD); RC_ASSERT(maybe_labels.HasValue()); const auto &labels = *maybe_labels; RC_ASSERT(labels.size() == 1); RC_ASSERT(dba->LabelToName(labels[0]) == label); vertices_num_check++; - auto maybe_edges = vertex->OutEdges(memgraph::storage::View::OLD); + auto maybe_edges = vertex.OutEdges(memgraph::storage::View::OLD); RC_ASSERT(maybe_edges.HasValue()); for (auto &edge : *maybe_edges) { const auto &type = edge_type_map.at(edge); - RC_ASSERT(dba->EdgeTypeToName(edge->EdgeType()) == type); + RC_ASSERT(dba->EdgeTypeToName(edge.EdgeType()) == type); edges_num_check++; } } diff --git a/tests/unit/query_dump.cpp b/tests/unit/query_dump.cpp index 3606c2d39..a8f86158e 100644 --- a/tests/unit/query_dump.cpp +++ b/tests/unit/query_dump.cpp @@ -134,38 +134,38 @@ DatabaseState GetState(memgraph::storage::Storage *db) { auto dba = db->Access(); for (const auto &vertex : dba->Vertices(memgraph::storage::View::NEW)) { std::set labels; - auto maybe_labels = vertex->Labels(memgraph::storage::View::NEW); + auto maybe_labels = vertex.Labels(memgraph::storage::View::NEW); MG_ASSERT(maybe_labels.HasValue()); for (const auto &label : *maybe_labels) { labels.insert(dba->LabelToName(label)); } std::map props; - auto maybe_properties = vertex->Properties(memgraph::storage::View::NEW); + auto maybe_properties = vertex.Properties(memgraph::storage::View::NEW); MG_ASSERT(maybe_properties.HasValue()); for (const auto &kv : *maybe_properties) { props.emplace(dba->PropertyToName(kv.first), kv.second); } MG_ASSERT(props.count(kPropertyId) == 1); const auto id = props[kPropertyId].ValueInt(); - gid_mapping[vertex->Gid()] = id; + gid_mapping[vertex.Gid()] = id; vertices.insert({id, labels, props}); } // Capture all edges std::set edges; for (const auto &vertex : dba->Vertices(memgraph::storage::View::NEW)) { - auto maybe_edges = vertex->OutEdges(memgraph::storage::View::NEW); + auto maybe_edges = vertex.OutEdges(memgraph::storage::View::NEW); MG_ASSERT(maybe_edges.HasValue()); for (const auto &edge : *maybe_edges) { - const auto &edge_type_name = dba->EdgeTypeToName(edge->EdgeType()); + const auto &edge_type_name = dba->EdgeTypeToName(edge.EdgeType()); std::map props; - auto maybe_properties = edge->Properties(memgraph::storage::View::NEW); + auto maybe_properties = edge.Properties(memgraph::storage::View::NEW); MG_ASSERT(maybe_properties.HasValue()); for (const auto &kv : *maybe_properties) { props.emplace(dba->PropertyToName(kv.first), kv.second); } - const auto from = gid_mapping[edge->FromVertex()->Gid()]; - const auto to = gid_mapping[edge->ToVertex()->Gid()]; + const auto from = gid_mapping[edge.FromVertex().Gid()]; + const auto to = gid_mapping[edge.ToVertex().Gid()]; edges.insert({from, to, edge_type_name, props}); } } @@ -217,39 +217,41 @@ auto Execute(memgraph::storage::Storage *db, const std::string &query) { return stream; } -std::unique_ptr CreateVertex( - memgraph::storage::Storage::Accessor *dba, const std::vector &labels, - const std::map &props, bool add_property_id = true) { +memgraph::storage::VertexAccessor CreateVertex(memgraph::storage::Storage::Accessor *dba, + const std::vector &labels, + const std::map &props, + bool add_property_id = true) { MG_ASSERT(dba); auto vertex = dba->CreateVertex(); for (const auto &label_name : labels) { - MG_ASSERT(vertex->AddLabel(dba->NameToLabel(label_name)).HasValue()); + MG_ASSERT(vertex.AddLabel(dba->NameToLabel(label_name)).HasValue()); } for (const auto &kv : props) { - MG_ASSERT(vertex->SetProperty(dba->NameToProperty(kv.first), kv.second).HasValue()); + MG_ASSERT(vertex.SetProperty(dba->NameToProperty(kv.first), kv.second).HasValue()); } if (add_property_id) { MG_ASSERT( - vertex->SetProperty(dba->NameToProperty(kPropertyId), memgraph::storage::PropertyValue(vertex->Gid().AsInt())) + vertex.SetProperty(dba->NameToProperty(kPropertyId), memgraph::storage::PropertyValue(vertex.Gid().AsInt())) .HasValue()); } return vertex; } -std::unique_ptr CreateEdge( - memgraph::storage::Storage::Accessor *dba, memgraph::storage::VertexAccessor *from, - memgraph::storage::VertexAccessor *to, const std::string &edge_type_name, - const std::map &props, bool add_property_id = true) { +memgraph::storage::EdgeAccessor CreateEdge(memgraph::storage::Storage::Accessor *dba, + memgraph::storage::VertexAccessor *from, + memgraph::storage::VertexAccessor *to, const std::string &edge_type_name, + const std::map &props, + bool add_property_id = true) { MG_ASSERT(dba); auto edge = dba->CreateEdge(from, to, dba->NameToEdgeType(edge_type_name)); MG_ASSERT(edge.HasValue()); auto edgeAcc = std::move(edge.GetValue()); for (const auto &kv : props) { - MG_ASSERT(edgeAcc->SetProperty(dba->NameToProperty(kv.first), kv.second).HasValue()); + MG_ASSERT(edgeAcc.SetProperty(dba->NameToProperty(kv.first), kv.second).HasValue()); } if (add_property_id) { MG_ASSERT( - edgeAcc->SetProperty(dba->NameToProperty(kPropertyId), memgraph::storage::PropertyValue(edgeAcc->Gid().AsInt())) + edgeAcc.SetProperty(dba->NameToProperty(kPropertyId), memgraph::storage::PropertyValue(edgeAcc.Gid().AsInt())) .HasValue()); } return edgeAcc; @@ -444,7 +446,7 @@ TEST(DumpTest, SingleEdge) { auto dba = db->Access(); auto u = CreateVertex(dba.get(), {}, {}, false); auto v = CreateVertex(dba.get(), {}, {}, false); - CreateEdge(dba.get(), u.get(), v.get(), "EdgeType", {}, false); + CreateEdge(dba.get(), &u, &v, "EdgeType", {}, false); ASSERT_FALSE(dba->Commit().HasError()); } @@ -472,9 +474,9 @@ TEST(DumpTest, MultipleEdges) { auto u = CreateVertex(dba.get(), {}, {}, false); auto v = CreateVertex(dba.get(), {}, {}, false); auto w = CreateVertex(dba.get(), {}, {}, false); - CreateEdge(dba.get(), u.get(), v.get(), "EdgeType", {}, false); - CreateEdge(dba.get(), v.get(), u.get(), "EdgeType 2", {}, false); - CreateEdge(dba.get(), v.get(), w.get(), "EdgeType `!\"", {}, false); + CreateEdge(dba.get(), &u, &v, "EdgeType", {}, false); + CreateEdge(dba.get(), &v, &u, "EdgeType 2", {}, false); + CreateEdge(dba.get(), &v, &w, "EdgeType `!\"", {}, false); ASSERT_FALSE(dba->Commit().HasError()); } @@ -505,7 +507,7 @@ TEST(DumpTest, EdgeWithProperties) { auto dba = db->Access(); auto u = CreateVertex(dba.get(), {}, {}, false); auto v = CreateVertex(dba.get(), {}, {}, false); - CreateEdge(dba.get(), u.get(), v.get(), "EdgeType", {{"prop", memgraph::storage::PropertyValue(13)}}, false); + CreateEdge(dba.get(), &u, &v, "EdgeType", {{"prop", memgraph::storage::PropertyValue(13)}}, false); ASSERT_FALSE(dba->Commit().HasError()); } @@ -664,32 +666,32 @@ TEST(DumpTest, CheckStateSimpleGraph) { auto z = CreateVertex(dba.get(), {"Person"}, {{"name", memgraph::storage::PropertyValue("Buha")}, {"id", memgraph::storage::PropertyValue(1)}}); - CreateEdge(dba.get(), u.get(), v.get(), "Knows", {}); - CreateEdge(dba.get(), v.get(), w.get(), "Knows", {{"how_long", memgraph::storage::PropertyValue(5)}}); - CreateEdge(dba.get(), w.get(), u.get(), "Knows", {{"how", memgraph::storage::PropertyValue("distant past")}}); - CreateEdge(dba.get(), v.get(), u.get(), "Knows", {}); - CreateEdge(dba.get(), v.get(), u.get(), "Likes", {}); - CreateEdge(dba.get(), z.get(), u.get(), "Knows", {}); - CreateEdge(dba.get(), w.get(), z.get(), "Knows", {{"how", memgraph::storage::PropertyValue("school")}}); - CreateEdge(dba.get(), w.get(), z.get(), "Likes", {{"how", memgraph::storage::PropertyValue("very much")}}); - CreateEdge(dba.get(), w.get(), z.get(), "Date", + CreateEdge(dba.get(), &u, &v, "Knows", {}); + CreateEdge(dba.get(), &v, &w, "Knows", {{"how_long", memgraph::storage::PropertyValue(5)}}); + CreateEdge(dba.get(), &w, &u, "Knows", {{"how", memgraph::storage::PropertyValue("distant past")}}); + CreateEdge(dba.get(), &v, &u, "Knows", {}); + CreateEdge(dba.get(), &v, &u, "Likes", {}); + CreateEdge(dba.get(), &z, &u, "Knows", {}); + CreateEdge(dba.get(), &w, &z, "Knows", {{"how", memgraph::storage::PropertyValue("school")}}); + CreateEdge(dba.get(), &w, &z, "Likes", {{"how", memgraph::storage::PropertyValue("very much")}}); + CreateEdge(dba.get(), &w, &z, "Date", {{"time", memgraph::storage::PropertyValue(memgraph::storage::TemporalData( memgraph::storage::TemporalType::Date, memgraph::utils::Date({1994, 12, 7}).MicrosecondsSinceEpoch()))}}); - CreateEdge(dba.get(), w.get(), z.get(), "LocalTime", + CreateEdge(dba.get(), &w, &z, "LocalTime", {{"time", memgraph::storage::PropertyValue(memgraph::storage::TemporalData( memgraph::storage::TemporalType::LocalTime, memgraph::utils::LocalTime({14, 10, 44, 99, 99}).MicrosecondsSinceEpoch()))}}); CreateEdge( - dba.get(), w.get(), z.get(), "LocalDateTime", + dba.get(), &w, &z, "LocalDateTime", {{"time", memgraph::storage::PropertyValue(memgraph::storage::TemporalData( memgraph::storage::TemporalType::LocalDateTime, memgraph::utils::LocalDateTime({1994, 12, 7}, {14, 10, 44, 99, 99}).MicrosecondsSinceEpoch()))}}); - CreateEdge(dba.get(), w.get(), z.get(), "Duration", + CreateEdge(dba.get(), &w, &z, "Duration", {{"time", memgraph::storage::PropertyValue(memgraph::storage::TemporalData( memgraph::storage::TemporalType::Duration, memgraph::utils::Duration({3, 4, 5, 6, 10, 11}).microseconds))}}); - CreateEdge(dba.get(), w.get(), z.get(), "NegativeDuration", + CreateEdge(dba.get(), &w, &z, "NegativeDuration", {{"time", memgraph::storage::PropertyValue(memgraph::storage::TemporalData( memgraph::storage::TemporalType::Duration, memgraph::utils::Duration({-3, -4, -5, -6, -10, -11}).microseconds))}}); @@ -902,10 +904,10 @@ TEST(DumpTest, MultiplePartialPulls) { {{"name", memgraph::storage::PropertyValue("Person5")}, {"surname", memgraph::storage::PropertyValue("Unique5")}}, false); - CreateEdge(dba.get(), p1.get(), p2.get(), "REL", {}, false); - CreateEdge(dba.get(), p1.get(), p3.get(), "REL", {}, false); - CreateEdge(dba.get(), p4.get(), p5.get(), "REL", {}, false); - CreateEdge(dba.get(), p2.get(), p5.get(), "REL", {}, false); + CreateEdge(dba.get(), &p1, &p2, "REL", {}, false); + CreateEdge(dba.get(), &p1, &p3, "REL", {}, false); + CreateEdge(dba.get(), &p4, &p5, "REL", {}, false); + CreateEdge(dba.get(), &p2, &p5, "REL", {}, false); ASSERT_FALSE(dba->Commit().HasError()); } diff --git a/tests/unit/query_plan_common.hpp b/tests/unit/query_plan_common.hpp index 1e5609111..45008fcbd 100644 --- a/tests/unit/query_plan_common.hpp +++ b/tests/unit/query_plan_common.hpp @@ -219,7 +219,7 @@ auto CountIterable(TIterable &&iterable) { inline uint64_t CountEdges(memgraph::query::DbAccessor *dba, memgraph::storage::View view) { uint64_t count = 0; for (auto vertex : dba->Vertices(view)) { - dba->PrefetchOutEdges(); + dba->PrefetchOutEdges(vertex); auto maybe_edges = vertex.OutEdges(view); MG_ASSERT(maybe_edges.HasValue()); count += CountIterable(*maybe_edges); diff --git a/tests/unit/storage_rocks.cpp b/tests/unit/storage_rocks.cpp index ec4cdc90c..01e847b08 100644 --- a/tests/unit/storage_rocks.cpp +++ b/tests/unit/storage_rocks.cpp @@ -25,299 +25,299 @@ #include "storage/v2/vertex_accessor.hpp" #include "storage/v2/view.hpp" -class RocksDBStorageTest : public ::testing::TestWithParam { - public: - ~RocksDBStorageTest() { db.Clear(); } +// class RocksDBStorageTest : public ::testing::TestWithParam { +// public: +// ~RocksDBStorageTest() { db.Clear(); } - protected: - memgraph::storage::rocks::RocksDBStorage db; - memgraph::storage::Storage storage; -}; +// protected: +// memgraph::storage::rocks::RocksDBStorage db; +// memgraph::storage::Storage storage; +// }; -TEST_F(RocksDBStorageTest, SerializeVertexGID) { - // empty vertices, only gid is serialized - auto storage_dba = storage.Access(memgraph::storage::IsolationLevel::READ_UNCOMMITTED); - memgraph::query::DbAccessor dba(&storage_dba); - std::unordered_set gids; - for (uint64_t i = 0; i < 5; ++i) { - gids.insert(i); - auto impl = dba.InsertVertex(); - impl.SetGid(memgraph::storage::Gid::FromUint(i)); - db.StoreVertex(impl); - } - // load vertices from disk - auto loaded_vertices = db.Vertices(dba); - ASSERT_EQ(loaded_vertices.size(), 5); - for (const auto &vertex_acc : loaded_vertices) { - ASSERT_TRUE(gids.contains(vertex_acc.Gid().AsUint())); - } -} +// TEST_F(RocksDBStorageTest, SerializeVertexGID) { +// // empty vertices, only gid is serialized +// auto storage_dba = storage.Access(memgraph::storage::IsolationLevel::READ_UNCOMMITTED); +// memgraph::query::DbAccessor dba(&storage_dba); +// std::unordered_set gids; +// for (uint64_t i = 0; i < 5; ++i) { +// gids.insert(i); +// auto impl = dba.InsertVertex(); +// impl.SetGid(memgraph::storage::Gid::FromUint(i)); +// db.StoreVertex(impl); +// } +// // load vertices from disk +// auto loaded_vertices = db.Vertices(dba); +// ASSERT_EQ(loaded_vertices.size(), 5); +// for (const auto &vertex_acc : loaded_vertices) { +// ASSERT_TRUE(gids.contains(vertex_acc.Gid().AsUint())); +// } +// } -TEST_F(RocksDBStorageTest, SerializeVertexGIDLabels) { - // serialize vertex's gid with its single label - auto storage_dba = storage.Access(memgraph::storage::IsolationLevel::READ_UNCOMMITTED); - memgraph::query::DbAccessor dba(&storage_dba); - // save vertices on disk - std::unordered_set gids; - std::vector label_ids{dba.NameToLabel("Player"), dba.NameToLabel("Person"), - dba.NameToLabel("Ball")}; - for (int i = 0; i < 5; ++i) { - gids.insert(i); - auto impl = dba.InsertVertex(); - impl.SetGid(memgraph::storage::Gid::FromUint(i)); - impl.AddLabel(label_ids[i % 3]); - db.StoreVertex(impl); - } - // load vertices from disk - auto loaded_vertices = db.Vertices(dba); - ASSERT_EQ(loaded_vertices.size(), 5); - for (const auto &vertex_acc : loaded_vertices) { - ASSERT_TRUE(gids.contains(vertex_acc.Gid().AsUint())); - auto labels = vertex_acc.Labels(memgraph::storage::View::OLD); - ASSERT_EQ(labels->size(), 1); - ASSERT_TRUE(std::all_of(labels->begin(), labels->end(), [&label_ids](const auto &label_id) { - return std::find(label_ids.begin(), label_ids.end(), label_id) != label_ids.end(); - })); - } -} +// TEST_F(RocksDBStorageTest, SerializeVertexGIDLabels) { +// // serialize vertex's gid with its single label +// auto storage_dba = storage.Access(memgraph::storage::IsolationLevel::READ_UNCOMMITTED); +// memgraph::query::DbAccessor dba(&storage_dba); +// // save vertices on disk +// std::unordered_set gids; +// std::vector label_ids{dba.NameToLabel("Player"), dba.NameToLabel("Person"), +// dba.NameToLabel("Ball")}; +// for (int i = 0; i < 5; ++i) { +// gids.insert(i); +// auto impl = dba.InsertVertex(); +// impl.SetGid(memgraph::storage::Gid::FromUint(i)); +// impl.AddLabel(label_ids[i % 3]); +// db.StoreVertex(impl); +// } +// // load vertices from disk +// auto loaded_vertices = db.Vertices(dba); +// ASSERT_EQ(loaded_vertices.size(), 5); +// for (const auto &vertex_acc : loaded_vertices) { +// ASSERT_TRUE(gids.contains(vertex_acc.Gid().AsUint())); +// auto labels = vertex_acc.Labels(memgraph::storage::View::OLD); +// ASSERT_EQ(labels->size(), 1); +// ASSERT_TRUE(std::all_of(labels->begin(), labels->end(), [&label_ids](const auto &label_id) { +// return std::find(label_ids.begin(), label_ids.end(), label_id) != label_ids.end(); +// })); +// } +// } -TEST_F(RocksDBStorageTest, SerializeVertexGIDMutlipleLabels) { - // serialize vertex's gid with multiple labels it contains - auto storage_dba = storage.Access(memgraph::storage::IsolationLevel::READ_UNCOMMITTED); - memgraph::query::DbAccessor dba(&storage_dba); - // save vertices on disk - std::unordered_set gids; - std::vector label_ids{dba.NameToLabel("Player"), dba.NameToLabel("Person"), - dba.NameToLabel("Ball")}; - for (int i = 0; i < 5; ++i) { - gids.insert(i); - auto impl = dba.InsertVertex(); - impl.SetGid(memgraph::storage::Gid::FromUint(i)); - impl.AddLabel(label_ids[i % 3]); - impl.AddLabel(label_ids[(i + 1) % 3]); - db.StoreVertex(impl); - } - // load vertices from disk - auto loaded_vertices = db.Vertices(dba); - ASSERT_EQ(loaded_vertices.size(), 5); - for (const auto &vertex_acc : loaded_vertices) { - ASSERT_TRUE(gids.contains(vertex_acc.Gid().AsUint())); - auto labels = vertex_acc.Labels(memgraph::storage::View::OLD); - ASSERT_EQ(labels->size(), 2); - ASSERT_TRUE(std::all_of(labels->begin(), labels->end(), [&label_ids](const auto &label_id) { - return std::find(label_ids.begin(), label_ids.end(), label_id) != label_ids.end(); - })); - } -} +// TEST_F(RocksDBStorageTest, SerializeVertexGIDMutlipleLabels) { +// // serialize vertex's gid with multiple labels it contains +// auto storage_dba = storage.Access(memgraph::storage::IsolationLevel::READ_UNCOMMITTED); +// memgraph::query::DbAccessor dba(&storage_dba); +// // save vertices on disk +// std::unordered_set gids; +// std::vector label_ids{dba.NameToLabel("Player"), dba.NameToLabel("Person"), +// dba.NameToLabel("Ball")}; +// for (int i = 0; i < 5; ++i) { +// gids.insert(i); +// auto impl = dba.InsertVertex(); +// impl.SetGid(memgraph::storage::Gid::FromUint(i)); +// impl.AddLabel(label_ids[i % 3]); +// impl.AddLabel(label_ids[(i + 1) % 3]); +// db.StoreVertex(impl); +// } +// // load vertices from disk +// auto loaded_vertices = db.Vertices(dba); +// ASSERT_EQ(loaded_vertices.size(), 5); +// for (const auto &vertex_acc : loaded_vertices) { +// ASSERT_TRUE(gids.contains(vertex_acc.Gid().AsUint())); +// auto labels = vertex_acc.Labels(memgraph::storage::View::OLD); +// ASSERT_EQ(labels->size(), 2); +// ASSERT_TRUE(std::all_of(labels->begin(), labels->end(), [&label_ids](const auto &label_id) { +// return std::find(label_ids.begin(), label_ids.end(), label_id) != label_ids.end(); +// })); +// } +// } -TEST_F(RocksDBStorageTest, GetVerticesByLabel) { - // search vertices by label - auto storage_dba = storage.Access(memgraph::storage::IsolationLevel::READ_UNCOMMITTED); - memgraph::query::DbAccessor dba(&storage_dba); - // prepare labels - std::vector label_ids{dba.NameToLabel("Player"), dba.NameToLabel("Player"), - dba.NameToLabel("Ball")}; - // insert vertices - for (int i = 0; i < 5; ++i) { - auto impl = dba.InsertVertex(); - impl.AddLabel(label_ids[i % 3]); - db.StoreVertex(impl); - } - // load vertices from disk - auto player_vertices = db.Vertices(dba, dba.NameToLabel("Player")); - auto ball_vertices = db.Vertices(dba, dba.NameToLabel("Ball")); - ASSERT_EQ(player_vertices.size(), 4); - ASSERT_EQ(ball_vertices.size(), 1); -} +// TEST_F(RocksDBStorageTest, GetVerticesByLabel) { +// // search vertices by label +// auto storage_dba = storage.Access(memgraph::storage::IsolationLevel::READ_UNCOMMITTED); +// memgraph::query::DbAccessor dba(&storage_dba); +// // prepare labels +// std::vector label_ids{dba.NameToLabel("Player"), dba.NameToLabel("Player"), +// dba.NameToLabel("Ball")}; +// // insert vertices +// for (int i = 0; i < 5; ++i) { +// auto impl = dba.InsertVertex(); +// impl.AddLabel(label_ids[i % 3]); +// db.StoreVertex(impl); +// } +// // load vertices from disk +// auto player_vertices = db.Vertices(dba, dba.NameToLabel("Player")); +// auto ball_vertices = db.Vertices(dba, dba.NameToLabel("Ball")); +// ASSERT_EQ(player_vertices.size(), 4); +// ASSERT_EQ(ball_vertices.size(), 1); +// } -TEST_F(RocksDBStorageTest, GetVerticesByProperty) { - // search vertices by property value - auto storage_dba = storage.Access(memgraph::storage::IsolationLevel::READ_UNCOMMITTED); - memgraph::query::DbAccessor dba(&storage_dba); - // prepare ssd properties - std::map ssd_properties_1; - ssd_properties_1.emplace(dba.NameToProperty("price"), memgraph::storage::PropertyValue(225.84)); - std::map ssd_properties_2; - ssd_properties_2.emplace(dba.NameToProperty("price"), memgraph::storage::PropertyValue(226.84)); - // prepare hdd properties - std::map hdd_properties_1; - hdd_properties_1.emplace(dba.NameToProperty("price"), memgraph::storage::PropertyValue(125.84)); - std::vector properties{ssd_properties_1, ssd_properties_2, hdd_properties_1, hdd_properties_1}; - // insert vertices - for (int i = 0; i < 4; ++i) { - auto impl = dba.InsertVertex(); - memgraph::query::MultiPropsInitChecked(&impl, properties[i]); - db.StoreVertex(impl); - } - // load vertices from disk - auto ssd_vertices_1 = db.Vertices(dba, dba.NameToProperty("price"), memgraph::storage::PropertyValue(225.84)); - auto hdd_vertices = db.Vertices(dba, dba.NameToProperty("price"), memgraph::storage::PropertyValue(125.84)); - auto hdd_vertices_non_existing = - db.Vertices(dba, dba.NameToProperty("price"), memgraph::storage::PropertyValue(125.81)); - ASSERT_EQ(ssd_vertices_1.size(), 1); - ASSERT_EQ(hdd_vertices.size(), 2); - ASSERT_EQ(hdd_vertices_non_existing.size(), 0); -} +// TEST_F(RocksDBStorageTest, GetVerticesByProperty) { +// // search vertices by property value +// auto storage_dba = storage.Access(memgraph::storage::IsolationLevel::READ_UNCOMMITTED); +// memgraph::query::DbAccessor dba(&storage_dba); +// // prepare ssd properties +// std::map ssd_properties_1; +// ssd_properties_1.emplace(dba.NameToProperty("price"), memgraph::storage::PropertyValue(225.84)); +// std::map ssd_properties_2; +// ssd_properties_2.emplace(dba.NameToProperty("price"), memgraph::storage::PropertyValue(226.84)); +// // prepare hdd properties +// std::map hdd_properties_1; +// hdd_properties_1.emplace(dba.NameToProperty("price"), memgraph::storage::PropertyValue(125.84)); +// std::vector properties{ssd_properties_1, ssd_properties_2, hdd_properties_1, hdd_properties_1}; +// // insert vertices +// for (int i = 0; i < 4; ++i) { +// auto impl = dba.InsertVertex(); +// memgraph::query::MultiPropsInitChecked(&impl, properties[i]); +// db.StoreVertex(impl); +// } +// // load vertices from disk +// auto ssd_vertices_1 = db.Vertices(dba, dba.NameToProperty("price"), memgraph::storage::PropertyValue(225.84)); +// auto hdd_vertices = db.Vertices(dba, dba.NameToProperty("price"), memgraph::storage::PropertyValue(125.84)); +// auto hdd_vertices_non_existing = +// db.Vertices(dba, dba.NameToProperty("price"), memgraph::storage::PropertyValue(125.81)); +// ASSERT_EQ(ssd_vertices_1.size(), 1); +// ASSERT_EQ(hdd_vertices.size(), 2); +// ASSERT_EQ(hdd_vertices_non_existing.size(), 0); +// } -TEST_F(RocksDBStorageTest, DeleteVertex) { - // auto storage_dba = storage.Access(memgraph::storage::IsolationLevel::READ_UNCOMMITTE); - auto storage_dba = storage.Access(); - memgraph::query::DbAccessor dba(&storage_dba); - std::map properties; - // samo 1 property stane - properties.emplace(dba.NameToProperty("sum"), memgraph::storage::PropertyValue("2TB")); - properties.emplace(dba.NameToProperty("same_type"), memgraph::storage::PropertyValue(true)); - // properties.emplace(dba.NameToProperty("cluster_price"), memgraph::storage::PropertyValue(2000.42)); - // create vertex - auto impl = dba.InsertVertex(); - impl.AddLabel(dba.NameToLabel("Player")); - memgraph::query::MultiPropsInitChecked(&impl, properties); - db.StoreVertex(impl); - // find vertex should work now - ASSERT_TRUE(db.FindVertex(std::to_string(impl.Gid().AsUint()), dba).has_value()); - db.FindVertex(std::to_string(impl.Gid().AsUint()), dba); - // RocksDB doesn't physically delete entry so deletion will pass two times - ASSERT_TRUE(db.DeleteVertex(impl).has_value()); - ASSERT_TRUE(db.DeleteVertex(impl).has_value()); - // second time you shouldn't be able to find the vertex - ASSERT_FALSE(db.FindVertex(std::to_string(impl.Gid().AsUint()), dba).has_value()); -} +// TEST_F(RocksDBStorageTest, DeleteVertex) { +// // auto storage_dba = storage.Access(memgraph::storage::IsolationLevel::READ_UNCOMMITTE); +// auto storage_dba = storage.Access(); +// memgraph::query::DbAccessor dba(&storage_dba); +// std::map properties; +// // samo 1 property stane +// properties.emplace(dba.NameToProperty("sum"), memgraph::storage::PropertyValue("2TB")); +// properties.emplace(dba.NameToProperty("same_type"), memgraph::storage::PropertyValue(true)); +// // properties.emplace(dba.NameToProperty("cluster_price"), memgraph::storage::PropertyValue(2000.42)); +// // create vertex +// auto impl = dba.InsertVertex(); +// impl.AddLabel(dba.NameToLabel("Player")); +// memgraph::query::MultiPropsInitChecked(&impl, properties); +// db.StoreVertex(impl); +// // find vertex should work now +// ASSERT_TRUE(db.FindVertex(std::to_string(impl.Gid().AsUint()), dba).has_value()); +// db.FindVertex(std::to_string(impl.Gid().AsUint()), dba); +// // RocksDB doesn't physically delete entry so deletion will pass two times +// ASSERT_TRUE(db.DeleteVertex(impl).has_value()); +// ASSERT_TRUE(db.DeleteVertex(impl).has_value()); +// // second time you shouldn't be able to find the vertex +// ASSERT_FALSE(db.FindVertex(std::to_string(impl.Gid().AsUint()), dba).has_value()); +// } -TEST_F(RocksDBStorageTest, SerializeVertexGIDProperties) { - // serializes vertex's gid, multiple labels and properties - auto storage_dba = storage.Access(memgraph::storage::IsolationLevel::READ_UNCOMMITTED); - memgraph::query::DbAccessor dba(&storage_dba); - // prepare labels - std::vector label_ids{dba.NameToLabel("Player"), dba.NameToLabel("Person"), - dba.NameToLabel("Ball")}; - // prepare properties - std::map properties; - properties.emplace(dba.NameToProperty("name"), memgraph::storage::PropertyValue("disk")); - properties.emplace(dba.NameToProperty("memory"), memgraph::storage::PropertyValue("1TB")); - properties.emplace(dba.NameToProperty("price"), memgraph::storage::PropertyValue(1000.21)); - properties.emplace(dba.NameToProperty("price2"), memgraph::storage::PropertyValue(1000.212)); - // gids - std::unordered_set gids; - for (int i = 0; i < 5; ++i) { - gids.insert(i); - auto impl = dba.InsertVertex(); - impl.SetGid(memgraph::storage::Gid::FromUint(i)); - impl.AddLabel(label_ids[i % 3]); - impl.AddLabel(label_ids[(i + 1) % 3]); - memgraph::query::MultiPropsInitChecked(&impl, properties); - db.StoreVertex(impl); - } - // load vertices from disk - auto loaded_vertices = db.Vertices(dba); - ASSERT_EQ(loaded_vertices.size(), 5); - for (const auto &vertex_acc : loaded_vertices) { - ASSERT_TRUE(gids.contains(vertex_acc.Gid().AsUint())); - // labels - auto labels = vertex_acc.Labels(memgraph::storage::View::OLD); - ASSERT_EQ(labels->size(), 2); - ASSERT_TRUE(std::all_of(labels->begin(), labels->end(), [&label_ids](const auto &label_id) { - return std::find(label_ids.begin(), label_ids.end(), label_id) != label_ids.end(); - })); - // check properties - auto props = vertex_acc.Properties(memgraph::storage::View::OLD); - ASSERT_FALSE(props.HasError()); - auto prop_name = vertex_acc.GetProperty(memgraph::storage::View::OLD, dba.NameToProperty("name")); - auto prop_memory = vertex_acc.GetProperty(memgraph::storage::View::OLD, dba.NameToProperty("memory")); - auto prop_price = vertex_acc.GetProperty(memgraph::storage::View::OLD, dba.NameToProperty("price")); - auto prop_unexisting = vertex_acc.GetProperty(memgraph::storage::View::OLD, dba.NameToProperty("random")); - ASSERT_TRUE(prop_name->IsString()); - ASSERT_EQ(prop_name->ValueString(), "disk"); - ASSERT_TRUE(prop_memory->IsString()); - ASSERT_EQ(prop_memory->ValueString(), "1TB"); - ASSERT_TRUE(prop_price->IsDouble()); - ASSERT_DOUBLE_EQ(prop_price->ValueDouble(), 1000.21); - ASSERT_TRUE(prop_unexisting->IsNull()); - } -} +// TEST_F(RocksDBStorageTest, SerializeVertexGIDProperties) { +// // serializes vertex's gid, multiple labels and properties +// auto storage_dba = storage.Access(memgraph::storage::IsolationLevel::READ_UNCOMMITTED); +// memgraph::query::DbAccessor dba(&storage_dba); +// // prepare labels +// std::vector label_ids{dba.NameToLabel("Player"), dba.NameToLabel("Person"), +// dba.NameToLabel("Ball")}; +// // prepare properties +// std::map properties; +// properties.emplace(dba.NameToProperty("name"), memgraph::storage::PropertyValue("disk")); +// properties.emplace(dba.NameToProperty("memory"), memgraph::storage::PropertyValue("1TB")); +// properties.emplace(dba.NameToProperty("price"), memgraph::storage::PropertyValue(1000.21)); +// properties.emplace(dba.NameToProperty("price2"), memgraph::storage::PropertyValue(1000.212)); +// // gids +// std::unordered_set gids; +// for (int i = 0; i < 5; ++i) { +// gids.insert(i); +// auto impl = dba.InsertVertex(); +// impl.SetGid(memgraph::storage::Gid::FromUint(i)); +// impl.AddLabel(label_ids[i % 3]); +// impl.AddLabel(label_ids[(i + 1) % 3]); +// memgraph::query::MultiPropsInitChecked(&impl, properties); +// db.StoreVertex(impl); +// } +// // load vertices from disk +// auto loaded_vertices = db.Vertices(dba); +// ASSERT_EQ(loaded_vertices.size(), 5); +// for (const auto &vertex_acc : loaded_vertices) { +// ASSERT_TRUE(gids.contains(vertex_acc.Gid().AsUint())); +// // labels +// auto labels = vertex_acc.Labels(memgraph::storage::View::OLD); +// ASSERT_EQ(labels->size(), 2); +// ASSERT_TRUE(std::all_of(labels->begin(), labels->end(), [&label_ids](const auto &label_id) { +// return std::find(label_ids.begin(), label_ids.end(), label_id) != label_ids.end(); +// })); +// // check properties +// auto props = vertex_acc.Properties(memgraph::storage::View::OLD); +// ASSERT_FALSE(props.HasError()); +// auto prop_name = vertex_acc.GetProperty(memgraph::storage::View::OLD, dba.NameToProperty("name")); +// auto prop_memory = vertex_acc.GetProperty(memgraph::storage::View::OLD, dba.NameToProperty("memory")); +// auto prop_price = vertex_acc.GetProperty(memgraph::storage::View::OLD, dba.NameToProperty("price")); +// auto prop_unexisting = vertex_acc.GetProperty(memgraph::storage::View::OLD, dba.NameToProperty("random")); +// ASSERT_TRUE(prop_name->IsString()); +// ASSERT_EQ(prop_name->ValueString(), "disk"); +// ASSERT_TRUE(prop_memory->IsString()); +// ASSERT_EQ(prop_memory->ValueString(), "1TB"); +// ASSERT_TRUE(prop_price->IsDouble()); +// ASSERT_DOUBLE_EQ(prop_price->ValueDouble(), 1000.21); +// ASSERT_TRUE(prop_unexisting->IsNull()); +// } +// } -TEST_F(RocksDBStorageTest, SerializeEdge) { - // create two vertices and edge between them - // search by one of the vertices, return edge - // check deserialization for both vertices and edge - auto storage_dba = storage.Access(memgraph::storage::IsolationLevel::READ_UNCOMMITTED); - memgraph::query::DbAccessor dba(&storage_dba); - std::vector label_ids{dba.NameToLabel("Player"), dba.NameToLabel("Referee")}; - std::map properties_1; - properties_1.emplace(dba.NameToProperty("price"), memgraph::storage::PropertyValue(221.84)); - std::map properties_2; - properties_2.emplace(dba.NameToProperty("price"), memgraph::storage::PropertyValue(222.84)); - std::vector properties{properties_1, properties_2}; - for (int i = 0; i < 2; ++i) { - auto impl = dba.InsertVertex(); - impl.AddLabel(label_ids[i]); - memgraph::query::MultiPropsInitChecked(&impl, properties[i]); - db.StoreVertex(impl); - } - // prepare edge properties - std::map edge_properties; - edge_properties.emplace(dba.NameToProperty("sum"), memgraph::storage::PropertyValue("2TB")); - edge_properties.emplace(dba.NameToProperty("same_type"), memgraph::storage::PropertyValue(true)); - edge_properties.emplace(dba.NameToProperty("cluster_price"), memgraph::storage::PropertyValue(2000.42)); - // Before inserting edge, find two vertices - // find source vertex by the property - auto src_vertices = db.Vertices(dba, dba.NameToProperty("price"), memgraph::storage::PropertyValue(221.84)); - ASSERT_EQ(src_vertices.size(), 1); - auto src_vertex = src_vertices[0]; - // find destination vertex by the property - auto dest_vertices = db.Vertices(dba, dba.NameToProperty("price"), memgraph::storage::PropertyValue(222.84)); - ASSERT_EQ(dest_vertices.size(), 1); - auto dest_vertex = dest_vertices[0]; - // insert the edge - uint64_t edge_gid = 2; - auto edge_type_id = "CONNECTION"; - auto impl_edge = dba.InsertEdge(&src_vertex, &dest_vertex, dba.NameToEdgeType(edge_type_id)); - ASSERT_FALSE(impl_edge.HasError()); - (*impl_edge).SetGid(memgraph::storage::Gid::FromUint(edge_gid)); - memgraph::query::MultiPropsInitChecked(&*impl_edge, edge_properties); - db.StoreEdge(*impl_edge); - // Test out edges of the source vertex - auto src_out_edges = db.OutEdges(src_vertex, dba); - ASSERT_EQ(src_out_edges.size(), 1); - auto src_out_edge = src_out_edges[0]; - // test from edge accessor - auto from_out_edge_acc = src_out_edge.From(); - ASSERT_EQ(from_out_edge_acc.Gid(), src_vertex.Gid()); - ASSERT_EQ(from_out_edge_acc.Labels(memgraph::storage::View::OLD)->size(), 1); - ASSERT_EQ(from_out_edge_acc.Labels(memgraph::storage::View::OLD)->at(0), label_ids[0]); - ASSERT_EQ(*from_out_edge_acc.Properties(memgraph::storage::View::OLD), properties_1); - // test to edge accessor - auto to_out_edge_acc = src_out_edge.To(); - ASSERT_EQ(to_out_edge_acc.Gid(), dest_vertex.Gid()); - ASSERT_EQ(to_out_edge_acc.Labels(memgraph::storage::View::OLD)->size(), 1); - ASSERT_EQ(to_out_edge_acc.Labels(memgraph::storage::View::OLD)->at(0), label_ids[1]); - ASSERT_EQ(*to_out_edge_acc.Properties(memgraph::storage::View::OLD), properties_2); - // test edge accessor - ASSERT_EQ(src_out_edge.Gid().AsUint(), edge_gid); - ASSERT_EQ(src_out_edge.EdgeType(), dba.NameToEdgeType(edge_type_id)); - ASSERT_EQ(*src_out_edge.Properties(memgraph::storage::View::OLD), edge_properties); - // Test in edge of the destination vertex - auto dest_in_edges = db.InEdges(dest_vertex, dba); - ASSERT_EQ(dest_in_edges.size(), 1); - auto dest_in_edge = dest_in_edges[0]; - // test from edge accessor - auto from_in_edge_acc = dest_in_edge.From(); - ASSERT_EQ(from_in_edge_acc.Gid(), from_out_edge_acc.Gid()); - ASSERT_EQ(from_in_edge_acc.Labels(memgraph::storage::View::OLD)->size(), 1); - ASSERT_EQ(from_in_edge_acc.Labels(memgraph::storage::View::OLD)->at(0), - from_out_edge_acc.Labels(memgraph::storage::View::OLD)->at(0)); - ASSERT_EQ(*from_in_edge_acc.Properties(memgraph::storage::View::OLD), - *from_out_edge_acc.Properties(memgraph::storage::View::OLD)); - // test in edge accessors - auto to_in_edge_acc = dest_in_edge.To(); - ASSERT_EQ(to_in_edge_acc.Gid(), to_out_edge_acc.Gid()); - ASSERT_EQ(to_in_edge_acc.Labels(memgraph::storage::View::OLD)->size(), 1); - ASSERT_EQ(to_in_edge_acc.Labels(memgraph::storage::View::OLD)->at(0), - to_out_edge_acc.Labels(memgraph::storage::View::OLD)->at(0)); - ASSERT_EQ(*to_in_edge_acc.Properties(memgraph::storage::View::OLD), - *to_out_edge_acc.Properties(memgraph::storage::View::OLD)); - // test edge accessors - ASSERT_EQ(dest_in_edge.Gid(), src_out_edge.Gid()); - ASSERT_EQ(dest_in_edge.EdgeType(), src_out_edge.EdgeType()); - ASSERT_EQ(*dest_in_edge.Properties(memgraph::storage::View::OLD), - *src_out_edge.Properties(memgraph::storage::View::OLD)); -} +// TEST_F(RocksDBStorageTest, SerializeEdge) { +// // create two vertices and edge between them +// // search by one of the vertices, return edge +// // check deserialization for both vertices and edge +// auto storage_dba = storage.Access(memgraph::storage::IsolationLevel::READ_UNCOMMITTED); +// memgraph::query::DbAccessor dba(&storage_dba); +// std::vector label_ids{dba.NameToLabel("Player"), dba.NameToLabel("Referee")}; +// std::map properties_1; +// properties_1.emplace(dba.NameToProperty("price"), memgraph::storage::PropertyValue(221.84)); +// std::map properties_2; +// properties_2.emplace(dba.NameToProperty("price"), memgraph::storage::PropertyValue(222.84)); +// std::vector properties{properties_1, properties_2}; +// for (int i = 0; i < 2; ++i) { +// auto impl = dba.InsertVertex(); +// impl.AddLabel(label_ids[i]); +// memgraph::query::MultiPropsInitChecked(&impl, properties[i]); +// db.StoreVertex(impl); +// } +// // prepare edge properties +// std::map edge_properties; +// edge_properties.emplace(dba.NameToProperty("sum"), memgraph::storage::PropertyValue("2TB")); +// edge_properties.emplace(dba.NameToProperty("same_type"), memgraph::storage::PropertyValue(true)); +// edge_properties.emplace(dba.NameToProperty("cluster_price"), memgraph::storage::PropertyValue(2000.42)); +// // Before inserting edge, find two vertices +// // find source vertex by the property +// auto src_vertices = db.Vertices(dba, dba.NameToProperty("price"), memgraph::storage::PropertyValue(221.84)); +// ASSERT_EQ(src_vertices.size(), 1); +// auto src_vertex = src_vertices[0]; +// // find destination vertex by the property +// auto dest_vertices = db.Vertices(dba, dba.NameToProperty("price"), memgraph::storage::PropertyValue(222.84)); +// ASSERT_EQ(dest_vertices.size(), 1); +// auto dest_vertex = dest_vertices[0]; +// // insert the edge +// uint64_t edge_gid = 2; +// auto edge_type_id = "CONNECTION"; +// auto impl_edge = dba.InsertEdge(&src_vertex, &dest_vertex, dba.NameToEdgeType(edge_type_id)); +// ASSERT_FALSE(impl_edge.HasError()); +// (*impl_edge).SetGid(memgraph::storage::Gid::FromUint(edge_gid)); +// memgraph::query::MultiPropsInitChecked(&*impl_edge, edge_properties); +// db.StoreEdge(*impl_edge); +// // Test out edges of the source vertex +// auto src_out_edges = db.OutEdges(src_vertex, dba); +// ASSERT_EQ(src_out_edges.size(), 1); +// auto src_out_edge = src_out_edges[0]; +// // test from edge accessor +// auto from_out_edge_acc = src_out_edge.From(); +// ASSERT_EQ(from_out_edge_acc.Gid(), src_vertex.Gid()); +// ASSERT_EQ(from_out_edge_acc.Labels(memgraph::storage::View::OLD)->size(), 1); +// ASSERT_EQ(from_out_edge_acc.Labels(memgraph::storage::View::OLD)->at(0), label_ids[0]); +// ASSERT_EQ(*from_out_edge_acc.Properties(memgraph::storage::View::OLD), properties_1); +// // test to edge accessor +// auto to_out_edge_acc = src_out_edge.To(); +// ASSERT_EQ(to_out_edge_acc.Gid(), dest_vertex.Gid()); +// ASSERT_EQ(to_out_edge_acc.Labels(memgraph::storage::View::OLD)->size(), 1); +// ASSERT_EQ(to_out_edge_acc.Labels(memgraph::storage::View::OLD)->at(0), label_ids[1]); +// ASSERT_EQ(*to_out_edge_acc.Properties(memgraph::storage::View::OLD), properties_2); +// // test edge accessor +// ASSERT_EQ(src_out_edge.Gid().AsUint(), edge_gid); +// ASSERT_EQ(src_out_edge.EdgeType(), dba.NameToEdgeType(edge_type_id)); +// ASSERT_EQ(*src_out_edge.Properties(memgraph::storage::View::OLD), edge_properties); +// // Test in edge of the destination vertex +// auto dest_in_edges = db.InEdges(dest_vertex, dba); +// ASSERT_EQ(dest_in_edges.size(), 1); +// auto dest_in_edge = dest_in_edges[0]; +// // test from edge accessor +// auto from_in_edge_acc = dest_in_edge.From(); +// ASSERT_EQ(from_in_edge_acc.Gid(), from_out_edge_acc.Gid()); +// ASSERT_EQ(from_in_edge_acc.Labels(memgraph::storage::View::OLD)->size(), 1); +// ASSERT_EQ(from_in_edge_acc.Labels(memgraph::storage::View::OLD)->at(0), +// from_out_edge_acc.Labels(memgraph::storage::View::OLD)->at(0)); +// ASSERT_EQ(*from_in_edge_acc.Properties(memgraph::storage::View::OLD), +// *from_out_edge_acc.Properties(memgraph::storage::View::OLD)); +// // test in edge accessors +// auto to_in_edge_acc = dest_in_edge.To(); +// ASSERT_EQ(to_in_edge_acc.Gid(), to_out_edge_acc.Gid()); +// ASSERT_EQ(to_in_edge_acc.Labels(memgraph::storage::View::OLD)->size(), 1); +// ASSERT_EQ(to_in_edge_acc.Labels(memgraph::storage::View::OLD)->at(0), +// to_out_edge_acc.Labels(memgraph::storage::View::OLD)->at(0)); +// ASSERT_EQ(*to_in_edge_acc.Properties(memgraph::storage::View::OLD), +// *to_out_edge_acc.Properties(memgraph::storage::View::OLD)); +// // test edge accessors +// ASSERT_EQ(dest_in_edge.Gid(), src_out_edge.Gid()); +// ASSERT_EQ(dest_in_edge.EdgeType(), src_out_edge.EdgeType()); +// ASSERT_EQ(*dest_in_edge.Properties(memgraph::storage::View::OLD), +// *src_out_edge.Properties(memgraph::storage::View::OLD)); +// } diff --git a/tests/unit/storage_test_utils.cpp b/tests/unit/storage_test_utils.cpp index 74094c084..aef87b985 100644 --- a/tests/unit/storage_test_utils.cpp +++ b/tests/unit/storage_test_utils.cpp @@ -11,8 +11,8 @@ #include "storage_test_utils.hpp" -size_t CountVertices(memgraph::storage::Storage::Accessor *storage_accessor, memgraph::storage::View view) { - auto vertices = storage_accessor->Vertices(view); +size_t CountVertices(memgraph::storage::Storage::Accessor &storage_accessor, memgraph::storage::View view) { + auto vertices = storage_accessor.Vertices(view); size_t count = 0U; for (auto it = vertices.begin(); it != vertices.end(); ++it, ++count) ; diff --git a/tests/unit/storage_v2.cpp b/tests/unit/storage_v2.cpp index 168cb5bdb..9e92bd0f6 100644 --- a/tests/unit/storage_v2.cpp +++ b/tests/unit/storage_v2.cpp @@ -230,7 +230,7 @@ TEST(StorageV2, AccessorMove) { ASSERT_TRUE(moved->FindVertex(gid, memgraph::storage::View::NEW).has_value()); EXPECT_EQ(CountVertices(*moved, memgraph::storage::View::NEW), 1U); - ASSERT_FALSE(moved.Commit().HasError()); + ASSERT_FALSE(moved->Commit().HasError()); } { auto acc = store->Access(); @@ -244,7 +244,7 @@ TEST(StorageV2, AccessorMove) { // NOLINTNEXTLINE(hicpp-special-member-functions) TEST(StorageV2, VertexDeleteCommit) { - memgraph::storage::Storage store; + std::unique_ptr store{new memgraph::storage::InMemoryStorage()}; memgraph::storage::Gid gid = memgraph::storage::Gid::FromUint(std::numeric_limits::max()); auto acc1 = store->Access(); // read transaction @@ -280,19 +280,19 @@ TEST(StorageV2, VertexDeleteCommit) { { auto vertex = acc4->FindVertex(gid, memgraph::storage::View::NEW); ASSERT_TRUE(vertex); - EXPECT_EQ(CountVertices(acc4, memgraph::storage::View::OLD), 1U); - EXPECT_EQ(CountVertices(acc4, memgraph::storage::View::NEW), 1U); + EXPECT_EQ(CountVertices(*acc4, memgraph::storage::View::OLD), 1U); + EXPECT_EQ(CountVertices(*acc4, memgraph::storage::View::NEW), 1U); - auto res = acc4.DeleteVertex(&*vertex); + auto res = acc4->DeleteVertex(&*vertex); ASSERT_TRUE(res.HasValue()); - EXPECT_EQ(CountVertices(acc4, memgraph::storage::View::OLD), 1U); - EXPECT_EQ(CountVertices(acc4, memgraph::storage::View::NEW), 0U); + EXPECT_EQ(CountVertices(*acc4, memgraph::storage::View::OLD), 1U); + EXPECT_EQ(CountVertices(*acc4, memgraph::storage::View::NEW), 0U); - acc4.AdvanceCommand(); - EXPECT_EQ(CountVertices(acc4, memgraph::storage::View::OLD), 0U); - EXPECT_EQ(CountVertices(acc4, memgraph::storage::View::NEW), 0U); + acc4->AdvanceCommand(); + EXPECT_EQ(CountVertices(*acc4, memgraph::storage::View::OLD), 0U); + EXPECT_EQ(CountVertices(*acc4, memgraph::storage::View::NEW), 0U); - ASSERT_FALSE(acc4.Commit().HasError()); + ASSERT_FALSE(acc4->Commit().HasError()); } auto acc5 = store->Access(); // read transaction @@ -311,14 +311,14 @@ TEST(StorageV2, VertexDeleteCommit) { // Check whether the vertex exists in transaction 5 ASSERT_FALSE(acc5->FindVertex(gid, memgraph::storage::View::OLD).has_value()); - EXPECT_EQ(CountVertices(acc5, memgraph::storage::View::OLD), 0U); + EXPECT_EQ(CountVertices(*acc5, memgraph::storage::View::OLD), 0U); ASSERT_FALSE(acc5->FindVertex(gid, memgraph::storage::View::NEW).has_value()); - EXPECT_EQ(CountVertices(acc5, memgraph::storage::View::NEW), 0U); + EXPECT_EQ(CountVertices(*acc5, memgraph::storage::View::NEW), 0U); } // NOLINTNEXTLINE(hicpp-special-member-functions) TEST(StorageV2, VertexDeleteAbort) { - memgraph::storage::Storage store; + std::unique_ptr store{new memgraph::storage::InMemoryStorage()}; memgraph::storage::Gid gid = memgraph::storage::Gid::FromUint(std::numeric_limits::max()); auto acc1 = store->Access(); // read transaction @@ -354,19 +354,19 @@ TEST(StorageV2, VertexDeleteAbort) { { auto vertex = acc4->FindVertex(gid, memgraph::storage::View::NEW); ASSERT_TRUE(vertex); - EXPECT_EQ(CountVertices(acc4, memgraph::storage::View::OLD), 1U); - EXPECT_EQ(CountVertices(acc4, memgraph::storage::View::NEW), 1U); + EXPECT_EQ(CountVertices(*acc4, memgraph::storage::View::OLD), 1U); + EXPECT_EQ(CountVertices(*acc4, memgraph::storage::View::NEW), 1U); - auto res = acc4.DeleteVertex(&*vertex); + auto res = acc4->DeleteVertex(&*vertex); ASSERT_TRUE(res.HasValue()); - EXPECT_EQ(CountVertices(acc4, memgraph::storage::View::OLD), 1U); - EXPECT_EQ(CountVertices(acc4, memgraph::storage::View::NEW), 0U); + EXPECT_EQ(CountVertices(*acc4, memgraph::storage::View::OLD), 1U); + EXPECT_EQ(CountVertices(*acc4, memgraph::storage::View::NEW), 0U); - acc4.AdvanceCommand(); - EXPECT_EQ(CountVertices(acc4, memgraph::storage::View::OLD), 0U); - EXPECT_EQ(CountVertices(acc4, memgraph::storage::View::NEW), 0U); + acc4->AdvanceCommand(); + EXPECT_EQ(CountVertices(*acc4, memgraph::storage::View::OLD), 0U); + EXPECT_EQ(CountVertices(*acc4, memgraph::storage::View::NEW), 0U); - acc4.Abort(); + acc4->Abort(); } auto acc5 = store->Access(); // read transaction @@ -386,27 +386,27 @@ TEST(StorageV2, VertexDeleteAbort) { // Check whether the vertex exists in transaction 5 ASSERT_TRUE(acc5->FindVertex(gid, memgraph::storage::View::OLD).has_value()); - EXPECT_EQ(CountVertices(acc5, memgraph::storage::View::OLD), 1U); + EXPECT_EQ(CountVertices(*acc5, memgraph::storage::View::OLD), 1U); ASSERT_TRUE(acc5->FindVertex(gid, memgraph::storage::View::NEW).has_value()); - EXPECT_EQ(CountVertices(acc5, memgraph::storage::View::NEW), 1U); + EXPECT_EQ(CountVertices(*acc5, memgraph::storage::View::NEW), 1U); // Delete the vertex in transaction 6 { auto vertex = acc6->FindVertex(gid, memgraph::storage::View::NEW); ASSERT_TRUE(vertex); - EXPECT_EQ(CountVertices(acc6, memgraph::storage::View::OLD), 1U); - EXPECT_EQ(CountVertices(acc6, memgraph::storage::View::NEW), 1U); + EXPECT_EQ(CountVertices(*acc6, memgraph::storage::View::OLD), 1U); + EXPECT_EQ(CountVertices(*acc6, memgraph::storage::View::NEW), 1U); - auto res = acc6.DeleteVertex(&*vertex); + auto res = acc6->DeleteVertex(&*vertex); ASSERT_TRUE(res.HasValue()); - EXPECT_EQ(CountVertices(acc6, memgraph::storage::View::OLD), 1U); - EXPECT_EQ(CountVertices(acc6, memgraph::storage::View::NEW), 0U); + EXPECT_EQ(CountVertices(*acc6, memgraph::storage::View::OLD), 1U); + EXPECT_EQ(CountVertices(*acc6, memgraph::storage::View::NEW), 0U); - acc6.AdvanceCommand(); - EXPECT_EQ(CountVertices(acc6, memgraph::storage::View::OLD), 0U); - EXPECT_EQ(CountVertices(acc6, memgraph::storage::View::NEW), 0U); + acc6->AdvanceCommand(); + EXPECT_EQ(CountVertices(*acc6, memgraph::storage::View::OLD), 0U); + EXPECT_EQ(CountVertices(*acc6, memgraph::storage::View::NEW), 0U); - ASSERT_FALSE(acc6.Commit().HasError()); + ASSERT_FALSE(acc6->Commit().HasError()); } auto acc7 = store->Access(); // read transaction @@ -425,26 +425,26 @@ TEST(StorageV2, VertexDeleteAbort) { // Check whether the vertex exists in transaction 5 ASSERT_TRUE(acc5->FindVertex(gid, memgraph::storage::View::OLD).has_value()); - EXPECT_EQ(CountVertices(acc5, memgraph::storage::View::OLD), 1U); + EXPECT_EQ(CountVertices(*acc5, memgraph::storage::View::OLD), 1U); ASSERT_TRUE(acc5->FindVertex(gid, memgraph::storage::View::NEW).has_value()); - EXPECT_EQ(CountVertices(acc5, memgraph::storage::View::NEW), 1U); + EXPECT_EQ(CountVertices(*acc5, memgraph::storage::View::NEW), 1U); // Check whether the vertex exists in transaction 7 ASSERT_FALSE(acc7->FindVertex(gid, memgraph::storage::View::OLD).has_value()); - EXPECT_EQ(CountVertices(acc7, memgraph::storage::View::OLD), 0U); + EXPECT_EQ(CountVertices(*acc7, memgraph::storage::View::OLD), 0U); ASSERT_FALSE(acc7->FindVertex(gid, memgraph::storage::View::NEW).has_value()); - EXPECT_EQ(CountVertices(acc7, memgraph::storage::View::NEW), 0U); + EXPECT_EQ(CountVertices(*acc7, memgraph::storage::View::NEW), 0U); // Commit all accessors ASSERT_FALSE(acc1->Commit().HasError()); ASSERT_FALSE(acc3->Commit().HasError()); - ASSERT_FALSE(acc5.Commit().HasError()); - ASSERT_FALSE(acc7.Commit().HasError()); + ASSERT_FALSE(acc5->Commit().HasError()); + ASSERT_FALSE(acc7->Commit().HasError()); } // NOLINTNEXTLINE(hicpp-special-member-functions) TEST(StorageV2, VertexDeleteSerializationError) { - memgraph::storage::Storage store; + std::unique_ptr store{new memgraph::storage::InMemoryStorage()}; memgraph::storage::Gid gid = memgraph::storage::Gid::FromUint(std::numeric_limits::max()); // Create vertex @@ -519,7 +519,7 @@ TEST(StorageV2, VertexDeleteSerializationError) { // NOLINTNEXTLINE(hicpp-special-member-functions) TEST(StorageV2, VertexDeleteSpecialCases) { - memgraph::storage::Storage store; + std::unique_ptr store{new memgraph::storage::InMemoryStorage()}; memgraph::storage::Gid gid1 = memgraph::storage::Gid::FromUint(std::numeric_limits::max()); memgraph::storage::Gid gid2 = memgraph::storage::Gid::FromUint(std::numeric_limits::max()); @@ -579,7 +579,7 @@ TEST(StorageV2, VertexDeleteSpecialCases) { // NOLINTNEXTLINE(hicpp-special-member-functions) TEST(StorageV2, VertexDeleteLabel) { - memgraph::storage::Storage store; + std::unique_ptr store{new memgraph::storage::InMemoryStorage()}; memgraph::storage::Gid gid = memgraph::storage::Gid::FromUint(std::numeric_limits::max()); // Create the vertex @@ -735,7 +735,7 @@ TEST(StorageV2, VertexDeleteLabel) { // NOLINTNEXTLINE(hicpp-special-member-functions) TEST(StorageV2, VertexDeleteProperty) { - memgraph::storage::Storage store; + std::unique_ptr store{new memgraph::storage::InMemoryStorage()}; memgraph::storage::Gid gid = memgraph::storage::Gid::FromUint(std::numeric_limits::max()); // Create the vertex @@ -878,7 +878,7 @@ TEST(StorageV2, VertexDeleteProperty) { // NOLINTNEXTLINE(hicpp-special-member-functions) TEST(StorageV2, VertexLabelCommit) { - memgraph::storage::Storage store; + std::unique_ptr store{new memgraph::storage::InMemoryStorage()}; memgraph::storage::Gid gid = memgraph::storage::Gid::FromUint(std::numeric_limits::max()); { auto acc = store->Access(); @@ -993,7 +993,7 @@ TEST(StorageV2, VertexLabelCommit) { // NOLINTNEXTLINE(hicpp-special-member-functions) TEST(StorageV2, VertexLabelAbort) { - memgraph::storage::Storage store; + std::unique_ptr store{new memgraph::storage::InMemoryStorage()}; memgraph::storage::Gid gid = memgraph::storage::Gid::FromUint(std::numeric_limits::max()); // Create the vertex. @@ -1241,7 +1241,7 @@ TEST(StorageV2, VertexLabelAbort) { // NOLINTNEXTLINE(hicpp-special-member-functions) TEST(StorageV2, VertexLabelSerializationError) { - memgraph::storage::Storage store; + std::unique_ptr store{new memgraph::storage::InMemoryStorage()}; memgraph::storage::Gid gid = memgraph::storage::Gid::FromUint(std::numeric_limits::max()); { auto acc = store->Access(); @@ -1349,7 +1349,7 @@ TEST(StorageV2, VertexLabelSerializationError) { // NOLINTNEXTLINE(hicpp-special-member-functions) TEST(StorageV2, VertexPropertyCommit) { - memgraph::storage::Storage store; + std::unique_ptr store{new memgraph::storage::InMemoryStorage()}; memgraph::storage::Gid gid = memgraph::storage::Gid::FromUint(std::numeric_limits::max()); { auto acc = store->Access(); @@ -1471,7 +1471,7 @@ TEST(StorageV2, VertexPropertyCommit) { // NOLINTNEXTLINE(hicpp-special-member-functions) TEST(StorageV2, VertexPropertyAbort) { - memgraph::storage::Storage store; + std::unique_ptr store{new memgraph::storage::InMemoryStorage()}; memgraph::storage::Gid gid = memgraph::storage::Gid::FromUint(std::numeric_limits::max()); // Create the vertex. @@ -1749,7 +1749,7 @@ TEST(StorageV2, VertexPropertyAbort) { // NOLINTNEXTLINE(hicpp-special-member-functions) TEST(StorageV2, VertexPropertySerializationError) { - memgraph::storage::Storage store; + std::unique_ptr store{new memgraph::storage::InMemoryStorage()}; memgraph::storage::Gid gid = memgraph::storage::Gid::FromUint(std::numeric_limits::max()); { auto acc = store->Access(); @@ -1851,7 +1851,7 @@ TEST(StorageV2, VertexPropertySerializationError) { // NOLINTNEXTLINE(hicpp-special-member-functions) TEST(StorageV2, VertexLabelPropertyMixed) { - memgraph::storage::Storage store; + std::unique_ptr store{new memgraph::storage::InMemoryStorage()}; auto acc = store->Access(); auto vertex = acc->CreateVertex(); @@ -2090,7 +2090,7 @@ TEST(StorageV2, VertexLabelPropertyMixed) { } TEST(StorageV2, VertexPropertyClear) { - memgraph::storage::Storage store; + std::unique_ptr store{new memgraph::storage::InMemoryStorage()}; memgraph::storage::Gid gid; auto property1 = store->NameToProperty("property1"); auto property2 = store->NameToProperty("property2"); @@ -2195,7 +2195,7 @@ TEST(StorageV2, VertexPropertyClear) { } TEST(StorageV2, VertexNonexistentLabelPropertyEdgeAPI) { - memgraph::storage::Storage store; + std::unique_ptr store{new memgraph::storage::InMemoryStorage()}; auto label = store->NameToLabel("label"); auto property = store->NameToProperty("property"); @@ -2256,7 +2256,7 @@ TEST(StorageV2, VertexNonexistentLabelPropertyEdgeAPI) { } TEST(StorageV2, VertexVisibilitySingleTransaction) { - memgraph::storage::Storage store; + std::unique_ptr store{new memgraph::storage::InMemoryStorage()}; auto acc1 = store->Access(); auto acc2 = store->Access(); @@ -2312,7 +2312,7 @@ TEST(StorageV2, VertexVisibilitySingleTransaction) { } TEST(StorageV2, VertexVisibilityMultipleTransactions) { - memgraph::storage::Storage store; + std::unique_ptr store{new memgraph::storage::InMemoryStorage()}; memgraph::storage::Gid gid; { @@ -2552,7 +2552,7 @@ TEST(StorageV2, VertexVisibilityMultipleTransactions) { // NOLINTNEXTLINE(hicpp-special-member-functions) TEST(StorageV2, DeletedVertexAccessor) { - memgraph::storage::Storage store; + std::unique_ptr store{new memgraph::storage::InMemoryStorage()}; const auto property = store->NameToProperty("property"); const memgraph::storage::PropertyValue property_value{"property_value"}; diff --git a/tests/unit/storage_v2_durability.cpp b/tests/unit/storage_v2_durability.cpp index b73dbf96b..cdba0a3c3 100644 --- a/tests/unit/storage_v2_durability.cpp +++ b/tests/unit/storage_v2_durability.cpp @@ -490,7 +490,7 @@ class DurabilityTest : public ::testing::TestWithParam { // Verify label indices. { - std::vector> vertices; + std::vector vertices; vertices.reserve(kNumExtendedVertices / 2); for (auto vertex : acc->Vertices(extended_label_unused, memgraph::storage::View::OLD)) { vertices.emplace_back(vertex); diff --git a/tests/unit/storage_v2_replication.cpp b/tests/unit/storage_v2_replication.cpp index 23792063e..685d09ecb 100644 --- a/tests/unit/storage_v2_replication.cpp +++ b/tests/unit/storage_v2_replication.cpp @@ -72,10 +72,10 @@ TEST_F(ReplicationTest, BasicSynchronousReplicationTest) { { auto acc = main_store->Access(); auto v = acc->CreateVertex(); - vertex_gid.emplace(v->Gid()); - ASSERT_TRUE(v->AddLabel(main_store->NameToLabel(vertex_label)).HasValue()); - ASSERT_TRUE(v->SetProperty(main_store->NameToProperty(vertex_property), - memgraph::storage::PropertyValue(vertex_property_value)) + vertex_gid.emplace(v.Gid()); + ASSERT_TRUE(v.AddLabel(main_store->NameToLabel(vertex_label)).HasValue()); + ASSERT_TRUE(v.SetProperty(main_store->NameToProperty(vertex_property), + memgraph::storage::PropertyValue(vertex_property_value)) .HasValue()); ASSERT_FALSE(acc->Commit().HasError()); } @@ -122,7 +122,7 @@ TEST_F(ReplicationTest, BasicSynchronousReplicationTest) { auto acc = main_store->Access(); auto v = acc->FindVertex(*vertex_gid, memgraph::storage::View::OLD); ASSERT_TRUE(v); - ASSERT_TRUE(acc->DeleteVertex(v.get()).HasValue()); + ASSERT_TRUE(acc->DeleteVertex(&*v).HasValue()); ASSERT_FALSE(acc->Commit().HasError()); } @@ -143,25 +143,25 @@ TEST_F(ReplicationTest, BasicSynchronousReplicationTest) { { auto acc = main_store->Access(); auto v = acc->CreateVertex(); - vertex_gid.emplace(v->Gid()); - auto edgeRes = acc->CreateEdge(v.get(), v.get(), main_store->NameToEdgeType(edge_type)); + vertex_gid.emplace(v.Gid()); + auto edgeRes = acc->CreateEdge(&v, &v, main_store->NameToEdgeType(edge_type)); ASSERT_TRUE(edgeRes.HasValue()); - auto edge = std::move(edgeRes.GetValue()); - ASSERT_TRUE(edge->SetProperty(main_store->NameToProperty(edge_property), - memgraph::storage::PropertyValue(edge_property_value)) + auto edge = edgeRes.GetValue(); + ASSERT_TRUE(edge.SetProperty(main_store->NameToProperty(edge_property), + memgraph::storage::PropertyValue(edge_property_value)) .HasValue()); - edge_gid.emplace(edge->Gid()); + edge_gid.emplace(edge.Gid()); ASSERT_FALSE(acc->Commit().HasError()); } const auto find_edge = [&](const auto &edges, - const memgraph::storage::Gid edge_gid) -> memgraph::storage::EdgeAccessor * { + const memgraph::storage::Gid edge_gid) -> std::optional { for (const auto &edge : edges) { - if (edge->Gid() == edge_gid) { - return edge.get(); + if (edge.Gid() == edge_gid) { + return edge; } } - return nullptr; + return std::nullopt; }; { @@ -307,11 +307,11 @@ TEST_F(ReplicationTest, MultipleSynchronousReplicationTest) { { auto acc = main_store->Access(); auto v = acc->CreateVertex(); - ASSERT_TRUE(v->AddLabel(main_store->NameToLabel(vertex_label)).HasValue()); - ASSERT_TRUE(v->SetProperty(main_store->NameToProperty(vertex_property), - memgraph::storage::PropertyValue(vertex_property_value)) + ASSERT_TRUE(v.AddLabel(main_store->NameToLabel(vertex_label)).HasValue()); + ASSERT_TRUE(v.SetProperty(main_store->NameToProperty(vertex_property), + memgraph::storage::PropertyValue(vertex_property_value)) .HasValue()); - vertex_gid.emplace(v->Gid()); + vertex_gid.emplace(v.Gid()); ASSERT_FALSE(acc->Commit().HasError()); } @@ -332,7 +332,7 @@ TEST_F(ReplicationTest, MultipleSynchronousReplicationTest) { { auto acc = main_store->Access(); auto v = acc->CreateVertex(); - vertex_gid.emplace(v->Gid()); + vertex_gid.emplace(v.Gid()); ASSERT_FALSE(acc->Commit().HasError()); } @@ -368,7 +368,7 @@ TEST_F(ReplicationTest, RecoveryProcess) { auto acc = main_store->Access(); // Create the vertex before registering a replica auto v = acc->CreateVertex(); - vertex_gids.emplace_back(v->Gid()); + vertex_gids.emplace_back(v.Gid()); ASSERT_FALSE(acc->Commit().HasError()); } } @@ -384,13 +384,13 @@ TEST_F(ReplicationTest, RecoveryProcess) { { auto acc = main_store->Access(); auto v = acc->CreateVertex(); - vertex_gids.emplace_back(v->Gid()); + vertex_gids.emplace_back(v.Gid()); ASSERT_FALSE(acc->Commit().HasError()); } { auto acc = main_store->Access(); auto v = acc->CreateVertex(); - vertex_gids.emplace_back(v->Gid()); + vertex_gids.emplace_back(v.Gid()); ASSERT_FALSE(acc->Commit().HasError()); } } @@ -513,7 +513,7 @@ TEST_F(ReplicationTest, BasicAsynchronousReplicationTest) { for (size_t i = 0; i < vertices_create_num; ++i) { auto acc = main_store->Access(); auto v = acc->CreateVertex(); - created_vertices.push_back(v->Gid()); + created_vertices.push_back(v.Gid()); ASSERT_FALSE(acc->Commit().HasError()); if (i == 0) { @@ -531,7 +531,7 @@ TEST_F(ReplicationTest, BasicAsynchronousReplicationTest) { ASSERT_TRUE(std::all_of(created_vertices.begin(), created_vertices.end(), [&](const auto vertex_gid) { auto acc = replica_store_async->Access(); auto v = acc->FindVertex(vertex_gid, memgraph::storage::View::OLD); - const bool exists = (v != nullptr); + const bool exists = v.has_value(); EXPECT_FALSE(acc->Commit().HasError()); return exists; })); @@ -563,7 +563,7 @@ TEST_F(ReplicationTest, EpochTest) { { auto acc = main_store->Access(); const auto v = acc->CreateVertex(); - vertex_gid.emplace(v->Gid()); + vertex_gid.emplace(v.Gid()); ASSERT_FALSE(acc->Commit().HasError()); } { @@ -597,7 +597,7 @@ TEST_F(ReplicationTest, EpochTest) { { auto acc = replica_store1->Access(); auto v = acc->CreateVertex(); - vertex_gid.emplace(v->Gid()); + vertex_gid.emplace(v.Gid()); ASSERT_FALSE(acc->Commit().HasError()); } // Replica1 should forward it's vertex to Replica2 @@ -618,7 +618,7 @@ TEST_F(ReplicationTest, EpochTest) { { auto acc = main_store->Access(); const auto v = acc->CreateVertex(); - vertex_gid.emplace(v->Gid()); + vertex_gid.emplace(v.Gid()); ASSERT_FALSE(acc->Commit().HasError()); } // Replica1 is not compatible with the main so it shouldn't contain